use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class OracleSchemaStatVisitor method visit.
public boolean visit(OracleUpdateStatement x) {
setAliasMap();
setMode(x, Mode.Update);
SQLTableSource tableSource = x.getTableSource();
SQLExpr tableExpr = null;
if (tableSource instanceof SQLExprTableSource) {
tableExpr = ((SQLExprTableSource) tableSource).getExpr();
}
if (tableExpr instanceof SQLName) {
String ident = tableExpr.toString();
setCurrentTable(ident);
TableStat stat = getTableStat(ident);
stat.incrementUpdateCount();
Map<String, String> aliasMap = getAliasMap();
aliasMap.put(ident, ident);
aliasMap.put(tableSource.getAlias(), ident);
} else {
tableSource.accept(this);
}
accept(x.getItems());
accept(x.getWhere());
return false;
}
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);
}
}
Aggregations