use of java.sql.SQLSyntaxErrorException in project dble by actiontech.
the class DQLRouteTest method test.
@Test
public void test() throws Exception {
String stmt = "select * from `offer` where id = 100";
SchemaConfig schema = schemaMap.get("mysqldb");
RouteResultset rrs = new RouteResultset(stmt, 7);
SQLStatementParser parser = null;
parser = new MySqlStatementParser(stmt);
SQLStatement statement;
ServerSchemaStatVisitor visitor = null;
try {
statement = parser.parseStatement();
visitor = new ServerSchemaStatVisitor();
} catch (Exception t) {
throw new SQLSyntaxErrorException(t);
}
ctx = new DruidShardingParseInfo();
List<RouteCalculateUnit> taskList = visitorParse(rrs, statement, visitor);
Assert.assertEquals(true, !taskList.get(0).getTablesAndConditions().isEmpty());
}
use of java.sql.SQLSyntaxErrorException in project dble by actiontech.
the class NonBlockingSession method executeMultiResultSet.
private void executeMultiResultSet(PlanNode node) {
init();
HandlerBuilder builder = new HandlerBuilder(node, this);
try {
// no next
builder.build(false);
} catch (SQLSyntaxErrorException e) {
LOGGER.info(String.valueOf(source) + " execute plan is : " + node, e);
source.writeErrMessage(ErrorCode.ER_YES, "optimizer build error");
} catch (NoSuchElementException e) {
LOGGER.info(String.valueOf(source) + " execute plan is : " + node, e);
this.terminate();
source.writeErrMessage(ErrorCode.ER_NO_VALID_CONNECTION, "no valid connection");
} catch (MySQLOutPutException e) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(String.valueOf(source) + " execute plan is : " + node, e);
}
this.terminate();
source.writeErrMessage(e.getSqlState(), e.getMessage(), e.getErrorCode());
} catch (Exception e) {
LOGGER.info(String.valueOf(source) + " execute plan is : " + node, e);
this.terminate();
source.writeErrMessage(ErrorCode.ER_HANDLE_DATA, e.toString());
}
}
use of java.sql.SQLSyntaxErrorException in project cobar by alibaba.
the class MySQLDataNode method setHeartbeat.
private void setHeartbeat(String heartbeat) {
if (heartbeat == null) {
heartbeatAST = null;
placeHolderToStringer = null;
return;
}
try {
final Set<PlaceHolder> plist = new HashSet<PlaceHolder>(1, 1);
SQLStatement ast = SQLParserDelegate.parse(heartbeat);
ast.accept(new EmptySQLASTVisitor() {
@Override
public void visit(PlaceHolder node) {
plist.add(node);
}
});
if (plist.isEmpty()) {
heartbeatAST = null;
placeHolderToStringer = null;
return;
}
Map<PlaceHolder, Object> phm = new HashMap<PlaceHolder, Object>(plist.size(), 1);
for (PlaceHolder ph : plist) {
final String content = ph.getName();
final int low = Integer.parseInt(content.substring(content.indexOf('(') + 1, content.indexOf(',')).trim());
final int high = Integer.parseInt(content.substring(content.indexOf(',') + 1, content.indexOf(')')).trim());
phm.put(ph, new Object() {
private Random rnd = new Random();
@Override
public String toString() {
return String.valueOf(rnd.nextInt(high - low + 1) + low);
}
});
}
heartbeatAST = ast;
placeHolderToStringer = phm;
} catch (SQLSyntaxErrorException e) {
throw new ConfigException("heartbeat syntax err: " + heartbeat, e);
}
}
use of java.sql.SQLSyntaxErrorException in project cobar by alibaba.
the class MySQLDDLParser method columnDefinition.
// column_definition:
// data_type [NOT NULL | NULL] [DEFAULT default_value]
// [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY]
// [COMMENT 'string']
// [COLUMN_FORMAT {FIXED|DYNAMIC|DEFAULT}]
// [reference_definition]
private ColumnDefinition columnDefinition() throws SQLSyntaxErrorException {
DataType dataType = dataType();
boolean notNull = false;
Expression defaultVal = null;
boolean autoIncrement = false;
ColumnDefinition.SpecialIndex sindex = null;
ColumnDefinition.ColumnFormat format = null;
LiteralString comment = null;
if (lexer.token() == KW_NOT) {
lexer.nextToken();
match(LITERAL_NULL);
notNull = true;
} else if (lexer.token() == LITERAL_NULL) {
lexer.nextToken();
}
if (lexer.token() == KW_DEFAULT) {
lexer.nextToken();
defaultVal = exprParser.expression();
if (!(defaultVal instanceof Literal)) {
throw new SQLSyntaxErrorException("default value of column must be a literal: " + defaultVal);
}
}
if (lexer.token() == IDENTIFIER && "AUTO_INCREMENT".equals(lexer.stringValueUppercase())) {
lexer.nextToken();
autoIncrement = true;
}
switch(lexer.token()) {
case KW_UNIQUE:
if (lexer.nextToken() == KW_KEY) {
lexer.nextToken();
}
sindex = ColumnDefinition.SpecialIndex.UNIQUE;
break;
case KW_PRIMARY:
lexer.nextToken();
case KW_KEY:
match(KW_KEY);
sindex = ColumnDefinition.SpecialIndex.PRIMARY;
break;
}
if (lexer.token() == IDENTIFIER && "COMMENT".equals(lexer.stringValueUppercase())) {
lexer.nextToken();
comment = (LiteralString) exprParser.expression();
}
if (lexer.token() == IDENTIFIER && "COLUMN_FORMAT".equals(lexer.stringValueUppercase())) {
switch(lexer.nextToken()) {
case KW_DEFAULT:
lexer.nextToken();
format = ColumnDefinition.ColumnFormat.DEFAULT;
break;
case IDENTIFIER:
SpecialIdentifier si = specialIdentifiers.get(lexer.stringValueUppercase());
if (si != null) {
switch(si) {
case FIXED:
lexer.nextToken();
format = ColumnDefinition.ColumnFormat.FIXED;
break;
case DYNAMIC:
lexer.nextToken();
format = ColumnDefinition.ColumnFormat.DYNAMIC;
break;
}
}
}
}
return new ColumnDefinition(dataType, notNull, defaultVal, autoIncrement, sindex, comment, format);
}
use of java.sql.SQLSyntaxErrorException in project cobar by alibaba.
the class MySQLDDLParser method createTableDefs.
private void createTableDefs(DDLCreateTableStatement stmt) throws SQLSyntaxErrorException {
if (lexer.token() != PUNC_LEFT_PAREN) {
return;
}
match(PUNC_LEFT_PAREN);
IndexDefinition indexDef;
Identifier id;
for (int i = 0; lexer.token() != PUNC_RIGHT_PAREN; ++i) {
if (i > 0) {
match(PUNC_COMMA);
}
switch(lexer.token()) {
case KW_PRIMARY:
lexer.nextToken();
match(KW_KEY);
indexDef = indexDefinition();
stmt.setPrimaryKey(indexDef);
break;
case KW_INDEX:
case KW_KEY:
lexer.nextToken();
if (lexer.token() == IDENTIFIER) {
id = identifier();
} else {
id = null;
}
indexDef = indexDefinition();
stmt.addIndex(id, indexDef);
break;
case KW_UNIQUE:
switch(lexer.nextToken()) {
case KW_INDEX:
case KW_KEY:
lexer.nextToken();
break;
}
if (lexer.token() == IDENTIFIER) {
id = identifier();
} else {
id = null;
}
indexDef = indexDefinition();
stmt.addUniqueIndex(id, indexDef);
break;
case KW_FULLTEXT:
switch(lexer.nextToken()) {
case KW_INDEX:
case KW_KEY:
lexer.nextToken();
break;
}
if (lexer.token() == IDENTIFIER) {
id = identifier();
} else {
id = null;
}
indexDef = indexDefinition();
if (indexDef.getIndexType() != null) {
throw new SQLSyntaxErrorException("FULLTEXT INDEX can specify no index_type");
}
stmt.addFullTextIndex(id, indexDef);
break;
case KW_SPATIAL:
switch(lexer.nextToken()) {
case KW_INDEX:
case KW_KEY:
lexer.nextToken();
break;
}
if (lexer.token() == IDENTIFIER) {
id = identifier();
} else {
id = null;
}
indexDef = indexDefinition();
if (indexDef.getIndexType() != null) {
throw new SQLSyntaxErrorException("SPATIAL INDEX can specify no index_type");
}
stmt.addSpatialIndex(id, indexDef);
break;
case KW_CHECK:
lexer.nextToken();
match(PUNC_LEFT_PAREN);
Expression expr = exprParser.expression();
match(PUNC_RIGHT_PAREN);
stmt.addCheck(expr);
break;
case IDENTIFIER:
Identifier columnName = identifier();
ColumnDefinition columnDef = columnDefinition();
stmt.addColumnDefinition(columnName, columnDef);
break;
default:
throw new SQLSyntaxErrorException("unsupportted column definition");
}
}
match(PUNC_RIGHT_PAREN);
}
Aggregations