use of java.sql.SQLSyntaxErrorException in project orientdb by orientechnologies.
the class OrientJdbcPreparedStatement method executeQuery.
@SuppressWarnings("unchecked")
public ResultSet executeQuery() throws SQLException {
// return super.executeQuery(sql);
sql = mayCleanForSpark(sql);
if (sql.equalsIgnoreCase("select 1")) {
// OPTIMIZATION
documents = new ArrayList<ODocument>();
documents.add(new ODocument().field("1", 1));
} else {
try {
query = new OSQLSynchQuery<ODocument>(mayCleanForSpark(sql));
documents = database.query((OQuery<? extends Object>) query, params.values().toArray());
} catch (OQueryParsingException e) {
throw new SQLSyntaxErrorException("Error while parsing query", e);
} catch (OException e) {
throw new SQLException("Error while executing query", e);
}
}
// return super.executeQuery(sql);
resultSet = new OrientJdbcResultSet(this, documents, resultSetType, resultSetConcurrency, resultSetHoldability);
return resultSet;
}
use of java.sql.SQLSyntaxErrorException in project Mycat-Server by MyCATApache.
the class DruidMycatRouteStrategy method getDisTable.
private SQLExprTableSource getDisTable(SQLTableSource tableSource, RouteResultsetNode node) throws SQLSyntaxErrorException {
if (node.getSubTableName() == null) {
String msg = " sub table not exists for " + node.getName() + " on " + tableSource;
LOGGER.error("DruidMycatRouteStrategyError " + msg);
throw new SQLSyntaxErrorException(msg);
}
SQLIdentifierExpr sqlIdentifierExpr = new SQLIdentifierExpr();
sqlIdentifierExpr.setParent(tableSource.getParent());
sqlIdentifierExpr.setName(node.getSubTableName());
SQLExprTableSource from2 = new SQLExprTableSource(sqlIdentifierExpr);
return from2;
}
use of java.sql.SQLSyntaxErrorException in project Mycat-Server by MyCATApache.
the class DruidInsertParser method statementParse.
/**
* 考虑因素:isChildTable、批量、是否分片
*/
@Override
public void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt) throws SQLNonTransientException {
MySqlInsertStatement insert = (MySqlInsertStatement) stmt;
String tableName = StringUtil.removeBackquote(insert.getTableName().getSimpleName()).toUpperCase();
ctx.addTable(tableName);
if (RouterUtil.isNoSharding(schema, tableName)) {
// 整个schema都不分库或者该表不拆分
RouterUtil.routeForTableMeta(rrs, schema, tableName, rrs.getStatement());
rrs.setFinishedRoute(true);
return;
}
TableConfig tc = schema.getTables().get(tableName);
if (tc == null) {
String msg = "can't find table define in schema " + tableName + " schema:" + schema.getName();
LOGGER.warn(msg);
throw new SQLNonTransientException(msg);
} else {
// childTable的insert直接在解析过程中完成路由
if (tc.isChildTable()) {
parserChildTable(schema, rrs, tableName, insert);
return;
}
String partitionColumn = tc.getPartitionColumn();
if (partitionColumn != null) {
// 拆分表必须给出column list,否则无法寻找分片字段的值
if (insert.getColumns() == null || insert.getColumns().size() == 0) {
throw new SQLSyntaxErrorException("partition table, insert must provide ColumnList");
}
// 批量insert
if (isMultiInsert(insert)) {
// String msg = "multi insert not provided" ;
// LOGGER.warn(msg);
// throw new SQLNonTransientException(msg);
parserBatchInsert(schema, rrs, partitionColumn, tableName, insert);
} else {
parserSingleInsert(schema, rrs, partitionColumn, tableName, insert);
}
}
}
}
use of java.sql.SQLSyntaxErrorException in project Mycat-Server by MyCATApache.
the class RouterUtil method routeToDDLNode.
/**
* 修复DDL路由
*
* @return RouteResultset
* @author aStoneGod
*/
public static RouteResultset routeToDDLNode(RouteResultset rrs, int sqlType, String stmt, SchemaConfig schema) throws SQLSyntaxErrorException {
stmt = getFixedSql(stmt);
String tablename = "";
final String upStmt = stmt.toUpperCase();
if (upStmt.startsWith("CREATE")) {
if (upStmt.contains("CREATE INDEX ") || upStmt.contains("CREATE UNIQUE INDEX ")) {
tablename = RouterUtil.getTableName(stmt, RouterUtil.getCreateIndexPos(upStmt, 0));
} else {
tablename = RouterUtil.getTableName(stmt, RouterUtil.getCreateTablePos(upStmt, 0));
}
} else if (upStmt.startsWith("DROP")) {
if (upStmt.contains("DROP INDEX ")) {
tablename = RouterUtil.getTableName(stmt, RouterUtil.getDropIndexPos(upStmt, 0));
} else {
tablename = RouterUtil.getTableName(stmt, RouterUtil.getDropTablePos(upStmt, 0));
}
} else if (upStmt.startsWith("ALTER")) {
tablename = RouterUtil.getTableName(stmt, RouterUtil.getAlterTablePos(upStmt, 0));
} else if (upStmt.startsWith("TRUNCATE")) {
tablename = RouterUtil.getTableName(stmt, RouterUtil.getTruncateTablePos(upStmt, 0));
}
tablename = tablename.toUpperCase();
if (schema.getTables().containsKey(tablename)) {
if (ServerParse.DDL == sqlType) {
List<String> dataNodes = new ArrayList<>();
Map<String, TableConfig> tables = schema.getTables();
TableConfig tc = tables.get(tablename);
if (tables != null && (tc != null)) {
dataNodes = tc.getDataNodes();
}
boolean isSlotFunction = tc.getRule() != null && tc.getRule().getRuleAlgorithm() instanceof SlotFunction;
Iterator<String> iterator1 = dataNodes.iterator();
int nodeSize = dataNodes.size();
RouteResultsetNode[] nodes = new RouteResultsetNode[nodeSize];
if (isSlotFunction) {
stmt = changeCreateTable(schema, tablename, stmt);
}
for (int i = 0; i < nodeSize; i++) {
String name = iterator1.next();
nodes[i] = new RouteResultsetNode(name, sqlType, stmt);
nodes[i].setSource(rrs);
if (rrs.getDataNodeSlotMap().containsKey(name)) {
nodes[i].setSlot(rrs.getDataNodeSlotMap().get(name));
} else if (isSlotFunction) {
nodes[i].setSlot(-1);
}
}
rrs.setNodes(nodes);
}
return rrs;
} else if (schema.getDataNode() != null) {
// 默认节点ddl
RouteResultsetNode[] nodes = new RouteResultsetNode[1];
nodes[0] = new RouteResultsetNode(schema.getDataNode(), sqlType, stmt);
nodes[0].setSource(rrs);
rrs.setNodes(nodes);
return rrs;
}
// both tablename and defaultnode null
LOGGER.error("table not in schema----" + tablename);
throw new SQLSyntaxErrorException("op table not in schema----" + tablename);
}
use of java.sql.SQLSyntaxErrorException in project zipkin by openzipkin.
the class SchemaTest method hasIpv6_falseWhenKnownSQLState.
@Test
public void hasIpv6_falseWhenKnownSQLState() throws SQLException {
SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException("Unknown column 'zipkin_annotations.endpoint_ipv6' in 'field list'", "42S22", 1054);
// cheats to lower mock count: this exception is really thrown during execution of the query
when(dataSource.getConnection()).thenThrow(new DataAccessException(sqlException.getMessage(), sqlException));
assertThat(schema.hasIpv6).isFalse();
}
Aggregations