use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class OdpsLexerTest method test_error_1.
public void test_error_1() throws Exception {
String str = "`aaa\n${PN}_events";
OdpsLexer lexer = new OdpsLexer(str);
int pos = lexer.pos();
try {
lexer.nextToken();
} catch (ParserException error) {
lexer.skipToNextLineOrParameter(pos);
lexer.nextToken();
}
assertEquals(Token.IDENTIFIER, lexer.token());
assertEquals("${PN}_events", lexer.stringVal());
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class PGCommentTest method test_0.
public void test_0() {
String sql = "/*multiline comment test" + ".\r\n multiline comment test select * from a;";
PGSQLStatementParser parser;
try {
parser = new PGSQLStatementParser(sql);
parser.parseStatementList();
} catch (Exception e) {
assertTrue(e instanceof ParserException);
}
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlExprParser method parseColumnRest.
public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) {
if (lexer.token() == Token.ON) {
lexer.nextToken();
accept(Token.UPDATE);
SQLExpr expr = this.expr();
column.setOnUpdate(expr);
}
if (identifierEquals("CHARSET")) {
lexer.nextToken();
MySqlCharExpr charSetCollateExpr = new MySqlCharExpr();
charSetCollateExpr.setCharset(lexer.stringVal());
lexer.nextToken();
if (identifierEquals("COLLATE")) {
lexer.nextToken();
charSetCollateExpr.setCollate(lexer.stringVal());
lexer.nextToken();
}
column.setCharsetExpr(charSetCollateExpr);
return parseColumnRest(column);
}
if (identifierEquals("AUTO_INCREMENT")) {
lexer.nextToken();
column.setAutoIncrement(true);
return parseColumnRest(column);
}
if (identifierEquals("precision") && column.getDataType().getName().equalsIgnoreCase("double")) {
lexer.nextToken();
}
if (lexer.token() == Token.PARTITION) {
throw new ParserException("syntax error " + lexer.token() + " " + lexer.stringVal());
}
if (identifierEquals("STORAGE")) {
lexer.nextToken();
SQLExpr expr = expr();
column.setStorage(expr);
}
if (lexer.token() == Token.AS) {
lexer.nextToken();
accept(Token.LPAREN);
SQLExpr expr = expr();
column.setAsExpr(expr);
accept(Token.RPAREN);
}
if (identifierEquals("STORED")) {
lexer.nextToken();
column.setSorted(true);
}
if (identifierEquals("VIRTUAL")) {
lexer.nextToken();
column.setVirtual(true);
}
super.parseColumnRest(column);
return column;
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlExprParser method parseReferenceOption.
protected Option parseReferenceOption() {
Option option;
if (lexer.token() == Token.RESTRICT || identifierEquals("RESTRICT")) {
option = Option.RESTRICT;
lexer.nextToken();
} else if (identifierEquals("CASCADE")) {
option = Option.CASCADE;
lexer.nextToken();
} else if (lexer.token() == Token.SET) {
lexer.nextToken();
accept(Token.NULL);
option = Option.SET_NULL;
} else if (identifierEquals("ON")) {
lexer.nextToken();
if (identifierEquals("ACTION")) {
option = Option.NO_ACTION;
lexer.nextToken();
} else {
throw new ParserException("syntax error, expect ACTION, actual " + lexer.token() + " " + lexer.stringVal());
}
} else {
throw new ParserException("syntax error, expect ACTION, actual " + lexer.token() + " " + lexer.stringVal());
}
return option;
}
use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.
the class MySqlLexer method scanIdentifier.
public void scanIdentifier() {
final char first = ch;
if (ch == '`') {
mark = pos;
bufPos = 1;
char ch;
for (; ; ) {
ch = charAt(++pos);
if (ch == '`') {
bufPos++;
ch = charAt(++pos);
break;
} else if (ch == EOI) {
throw new ParserException("illegal identifier");
}
bufPos++;
continue;
}
this.ch = charAt(pos);
stringVal = subString(mark, bufPos);
Token tok = keywods.getKeyword(stringVal);
if (tok != null) {
token = tok;
} else {
token = Token.IDENTIFIER;
}
} else {
final boolean firstFlag = isFirstIdentifierChar(first);
if (!firstFlag) {
throw new ParserException("illegal identifier");
}
mark = pos;
bufPos = 1;
char ch = '\0', last_ch;
for (; ; ) {
last_ch = ch;
ch = charAt(++pos);
if (!isIdentifierChar(ch)) {
if (ch == '-' && pos < text.length() - 1) {
if (mark > 0 && text.charAt(mark - 1) == '.') {
break;
}
char next_char = text.charAt(pos + 1);
if (isIdentifierChar(next_char)) {
bufPos++;
continue;
}
}
if (last_ch == '-' && charAt(pos - 2) != '-') {
ch = last_ch;
bufPos--;
pos--;
}
break;
}
bufPos++;
continue;
}
this.ch = charAt(pos);
stringVal = addSymbol();
Token tok = keywods.getKeyword(stringVal);
if (tok != null) {
token = tok;
} else {
token = Token.IDENTIFIER;
}
}
}
Aggregations