use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SQLStatementParser method parseDropTable.
protected SQLDropTableStatement parseDropTable(boolean acceptDrop) {
if (acceptDrop) {
accept(Token.DROP);
}
SQLDropTableStatement stmt = new SQLDropTableStatement(getDbType());
if (identifierEquals("TEMPORARY")) {
lexer.nextToken();
stmt.setTemporary(true);
}
accept(Token.TABLE);
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
for (; ; ) {
SQLName name = this.exprParser.name();
stmt.addPartition(new SQLExprTableSource(name));
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
for (; ; ) {
if (identifierEquals("RESTRICT")) {
lexer.nextToken();
stmt.setRestrict(true);
continue;
}
if (identifierEquals("CASCADE")) {
lexer.nextToken();
stmt.setCascade(true);
if (identifierEquals("CONSTRAINTS")) {
// for oracle
lexer.nextToken();
}
continue;
}
if (lexer.token() == Token.PURGE || identifierEquals("PURGE")) {
lexer.nextToken();
stmt.setPurge(true);
continue;
}
break;
}
return stmt;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SQLStatementParser method parseAlterDrop.
public void parseAlterDrop(SQLAlterTableStatement stmt) {
lexer.nextToken();
boolean ifExists = false;
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
ifExists = true;
}
if (lexer.token() == Token.CONSTRAINT) {
lexer.nextToken();
SQLAlterTableDropConstraint item = new SQLAlterTableDropConstraint();
item.setConstraintName(this.exprParser.name());
stmt.addItem(item);
} else if (lexer.token() == Token.COLUMN) {
lexer.nextToken();
SQLAlterTableDropColumnItem item = new SQLAlterTableDropColumnItem();
this.exprParser.names(item.getColumns());
if (lexer.token == Token.CASCADE) {
item.setCascade(true);
lexer.nextToken();
}
stmt.addItem(item);
} else if (lexer.token() == Token.LITERAL_ALIAS) {
SQLAlterTableDropColumnItem item = new SQLAlterTableDropColumnItem();
this.exprParser.names(item.getColumns());
if (lexer.token == Token.CASCADE) {
item.setCascade(true);
lexer.nextToken();
}
stmt.addItem(item);
} else if (lexer.token() == Token.PARTITION) {
SQLAlterTableDropPartition dropPartition = parseAlterTableDropPartition(ifExists);
stmt.addItem(dropPartition);
} else if (lexer.token() == Token.INDEX) {
lexer.nextToken();
SQLName indexName = this.exprParser.name();
SQLAlterTableDropIndex item = new SQLAlterTableDropIndex();
item.setIndexName(indexName);
stmt.addItem(item);
} else {
throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
}
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SQLStatementParser method parseDeleteStatement.
public SQLDeleteStatement parseDeleteStatement() {
SQLDeleteStatement deleteStatement = new SQLDeleteStatement(getDbType());
if (lexer.token() == Token.DELETE) {
lexer.nextToken();
if (lexer.token() == (Token.FROM)) {
lexer.nextToken();
}
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
}
SQLName tableName = exprParser.name();
deleteStatement.setTableName(tableName);
if (lexer.token() == Token.FROM) {
lexer.nextToken();
SQLTableSource tableSource = createSQLSelectParser().parseTableSource();
deleteStatement.setFrom(tableSource);
}
}
if (lexer.token() == (Token.WHERE)) {
lexer.nextToken();
SQLExpr where = this.exprParser.expr();
deleteStatement.setWhere(where);
}
return deleteStatement;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SQLStatementParser method parseInsert0.
protected void parseInsert0(SQLInsertInto insertStatement, boolean acceptSubQuery) {
if (lexer.token() == Token.INTO) {
lexer.nextToken();
SQLName tableName = this.exprParser.name();
insertStatement.setTableName(tableName);
if (lexer.token() == Token.LITERAL_ALIAS) {
insertStatement.setAlias(as());
}
parseInsert0_hinits(insertStatement);
if (lexer.token() == Token.IDENTIFIER) {
insertStatement.setAlias(lexer.stringVal());
lexer.nextToken();
}
}
if (lexer.token() == (Token.LPAREN)) {
lexer.nextToken();
parseInsertColumns(insertStatement);
accept(Token.RPAREN);
}
if (lexer.token() == Token.VALUES) {
lexer.nextToken();
for (; ; ) {
accept(Token.LPAREN);
SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause();
this.exprParser.exprList(values.getValues(), values);
insertStatement.getValuesList().add(values);
accept(Token.RPAREN);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
} else {
break;
}
}
} else if (acceptSubQuery && (lexer.token() == Token.SELECT || lexer.token() == Token.LPAREN)) {
SQLSelect select = this.createSQLSelectParser().select();
insertStatement.setQuery(select);
}
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SQLStatementParser method parseCreateView.
public SQLCreateViewStatement parseCreateView() {
SQLCreateViewStatement createView = new SQLCreateViewStatement(getDbType());
if (lexer.token() == Token.CREATE) {
lexer.nextToken();
}
if (lexer.token() == Token.OR) {
lexer.nextToken();
accept(Token.REPLACE);
createView.setOrReplace(true);
}
if (identifierEquals("ALGORITHM")) {
lexer.nextToken();
accept(Token.EQ);
String algorithm = lexer.stringVal();
createView.setAlgorithm(algorithm);
lexer.nextToken();
}
if (identifierEquals("DEFINER")) {
lexer.nextToken();
accept(Token.EQ);
SQLName definer = this.exprParser.name();
createView.setDefiner(definer);
lexer.nextToken();
}
if (identifierEquals("SQL")) {
lexer.nextToken();
acceptIdentifier("SECURITY");
String sqlSecurity = lexer.stringVal();
createView.setSqlSecurity(sqlSecurity);
lexer.nextToken();
}
this.accept(Token.VIEW);
if (lexer.token() == Token.IF || identifierEquals("IF")) {
lexer.nextToken();
accept(Token.NOT);
accept(Token.EXISTS);
createView.setIfNotExists(true);
}
createView.setName(exprParser.name());
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
for (; ; ) {
SQLCreateViewStatement.Column column = new SQLCreateViewStatement.Column();
SQLExpr expr = this.exprParser.expr();
column.setExpr(expr);
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
column.setComment((SQLCharExpr) exprParser.primary());
}
column.setParent(createView);
createView.addColumn(column);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
} else {
break;
}
}
accept(Token.RPAREN);
}
if (lexer.token() == Token.COMMENT) {
lexer.nextToken();
SQLCharExpr comment = (SQLCharExpr) exprParser.primary();
createView.setComment(comment);
}
this.accept(Token.AS);
createView.setSubQuery(new SQLSelectParser(this.exprParser).select());
return createView;
}
Aggregations