use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class MySqlStatementParser method parseAnalyze.
public MySqlAnalyzeStatement parseAnalyze() {
accept(Token.ANALYZE);
accept(Token.TABLE);
MySqlAnalyzeStatement stmt = new MySqlAnalyzeStatement();
List<SQLName> names = new ArrayList<SQLName>();
this.exprParser.names(names, stmt);
for (SQLName name : names) {
stmt.addTableSource(new SQLExprTableSource(name));
}
return stmt;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class MySqlStatementParser method parseInsert.
public SQLInsertStatement parseInsert() {
MySqlInsertStatement insertStatement = new MySqlInsertStatement();
if (lexer.token() == Token.INSERT) {
lexer.nextToken();
for (; ; ) {
if (identifierEquals(LOW_PRIORITY)) {
insertStatement.setLowPriority(true);
lexer.nextToken();
continue;
}
if (identifierEquals(DELAYED)) {
insertStatement.setDelayed(true);
lexer.nextToken();
continue;
}
if (identifierEquals("HIGH_PRIORITY")) {
insertStatement.setHighPriority(true);
lexer.nextToken();
continue;
}
if (identifierEquals(IGNORE)) {
insertStatement.setIgnore(true);
lexer.nextToken();
continue;
}
if (identifierEquals("ROLLBACK_ON_FAIL")) {
insertStatement.setRollbackOnFail(true);
lexer.nextToken();
continue;
}
break;
}
if (lexer.token() == Token.INTO) {
lexer.nextToken();
}
SQLName tableName = this.exprParser.name();
insertStatement.setTableName(tableName);
if (lexer.token() == Token.IDENTIFIER && !identifierEquals("VALUE")) {
insertStatement.setAlias(lexer.stringVal());
lexer.nextToken();
}
}
int columnSize = 0;
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
if (lexer.token() == (Token.SELECT)) {
SQLSelect select = this.exprParser.createSelectParser().select();
select.setParent(insertStatement);
insertStatement.setQuery(select);
} else {
this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
columnSize = insertStatement.getColumns().size();
}
accept(Token.RPAREN);
}
if (lexer.token() == Token.VALUES || identifierEquals("VALUE")) {
lexer.nextTokenLParen();
parseValueClause(insertStatement.getValuesList(), columnSize);
} else if (lexer.token() == Token.SET) {
lexer.nextToken();
SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause();
insertStatement.getValuesList().add(values);
for (; ; ) {
SQLName name = this.exprParser.name();
insertStatement.addColumn(name);
if (lexer.token() == Token.EQ) {
lexer.nextToken();
} else {
accept(Token.COLONEQ);
}
values.addValue(this.exprParser.expr());
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
} else if (lexer.token() == (Token.SELECT)) {
SQLSelect select = this.exprParser.createSelectParser().select();
select.setParent(insertStatement);
insertStatement.setQuery(select);
} else if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
SQLSelect select = this.exprParser.createSelectParser().select();
select.setParent(insertStatement);
insertStatement.setQuery(select);
accept(Token.RPAREN);
}
if (lexer.token() == Token.ON) {
lexer.nextToken();
acceptIdentifier("DUPLICATE");
accept(Token.KEY);
accept(Token.UPDATE);
exprParser.exprList(insertStatement.getDuplicateKeyUpdate(), insertStatement);
}
return insertStatement;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OracleStatementParser method parseDeleteStatement.
public OracleDeleteStatement parseDeleteStatement() {
OracleDeleteStatement deleteStatement = new OracleDeleteStatement();
if (lexer.token() == Token.DELETE) {
lexer.nextToken();
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
}
parseHints(deleteStatement.getHints());
if (lexer.token() == (Token.FROM)) {
lexer.nextToken();
}
if (identifierEquals("ONLY")) {
lexer.nextToken();
accept(Token.LPAREN);
SQLName tableName = exprParser.name();
deleteStatement.setTableName(tableName);
accept(Token.RPAREN);
} else if (lexer.token() == Token.LPAREN) {
SQLTableSource tableSource = this.createSQLSelectParser().parseTableSource();
deleteStatement.setTableSource(tableSource);
} else {
SQLName tableName = exprParser.name();
deleteStatement.setTableName(tableName);
}
deleteStatement.setAlias(as());
}
if (lexer.token() == (Token.WHERE)) {
lexer.nextToken();
deleteStatement.setWhere(this.exprParser.expr());
}
if (lexer.token() == Token.RETURNING) {
OracleReturningClause clause = this.parseReturningClause();
deleteStatement.setReturning(clause);
}
if (identifierEquals("RETURN") || identifierEquals("RETURNING")) {
throw new ParserException("TODO");
}
if (identifierEquals("LOG")) {
throw new ParserException("TODO");
}
return deleteStatement;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OracleCreateTableParser method parsePartitionByRest.
protected void parsePartitionByRest(SQLPartitionBy clause) {
if (lexer.token() == Token.STORE) {
lexer.nextToken();
accept(Token.IN);
accept(Token.LPAREN);
for (; ; ) {
SQLName tablespace = this.exprParser.name();
clause.getStoreIn().add(tablespace);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
}
if (identifierEquals("SUBPARTITION")) {
SQLSubPartitionBy subPartitionBy = subPartitionBy();
clause.setSubPartitionBy(subPartitionBy);
}
accept(Token.LPAREN);
for (; ; ) {
SQLPartition partition = parsePartition();
clause.addPartition(partition);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OracleCreateTableParser method subPartitionBy.
protected SQLSubPartitionBy subPartitionBy() {
lexer.nextToken();
accept(Token.BY);
if (identifierEquals("HASH")) {
lexer.nextToken();
accept(Token.LPAREN);
SQLSubPartitionByHash byHash = new SQLSubPartitionByHash();
SQLExpr expr = this.exprParser.expr();
byHash.setExpr(expr);
accept(Token.RPAREN);
return byHash;
} else if (identifierEquals("LIST")) {
lexer.nextToken();
accept(Token.LPAREN);
SQLSubPartitionByList byList = new SQLSubPartitionByList();
SQLName column = this.exprParser.name();
byList.setColumn(column);
accept(Token.RPAREN);
if (identifierEquals("SUBPARTITION")) {
lexer.nextToken();
acceptIdentifier("TEMPLATE");
accept(Token.LPAREN);
for (; ; ) {
SQLSubPartition subPartition = parseSubPartition();
subPartition.setParent(byList);
byList.getSubPartitionTemplate().add(subPartition);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
accept(Token.RPAREN);
}
return byList;
}
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
Aggregations