use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SQLStatementParser method parseTruncate.
public SQLStatement parseTruncate() {
accept(Token.TRUNCATE);
if (lexer.token() == Token.TABLE) {
lexer.nextToken();
}
SQLTruncateStatement stmt = new SQLTruncateStatement(getDbType());
if (lexer.token() == Token.ONLY) {
lexer.nextToken();
stmt.setOnly(true);
}
for (; ; ) {
SQLName name = this.exprParser.name();
stmt.addTableSource(name);
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
}
break;
}
for (; ; ) {
if (lexer.token() == Token.PURGE) {
lexer.nextToken();
if (identifierEquals("SNAPSHOT")) {
lexer.nextToken();
acceptIdentifier("LOG");
stmt.setPurgeSnapshotLog(true);
} else {
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
continue;
}
if (lexer.token() == Token.RESTART) {
lexer.nextToken();
accept(Token.IDENTITY);
stmt.setRestartIdentity(Boolean.TRUE);
continue;
} else if (lexer.token() == Token.SHARE) {
lexer.nextToken();
accept(Token.IDENTITY);
stmt.setRestartIdentity(Boolean.FALSE);
continue;
}
if (lexer.token() == Token.CASCADE) {
lexer.nextToken();
stmt.setCascade(Boolean.TRUE);
continue;
} else if (lexer.token() == Token.RESTRICT) {
lexer.nextToken();
stmt.setCascade(Boolean.FALSE);
continue;
}
if (lexer.token() == Token.DROP) {
lexer.nextToken();
acceptIdentifier("STORAGE");
stmt.setDropStorage(true);
continue;
}
if (identifierEquals("REUSE")) {
lexer.nextToken();
acceptIdentifier("STORAGE");
stmt.setReuseStorage(true);
continue;
}
if (identifierEquals("IGNORE")) {
lexer.nextToken();
accept(Token.DELETE);
acceptIdentifier("TRIGGERS");
stmt.setIgnoreDeleteTriggers(true);
continue;
}
if (identifierEquals("RESTRICT")) {
lexer.nextToken();
accept(Token.WHEN);
accept(Token.DELETE);
acceptIdentifier("TRIGGERS");
stmt.setRestrictWhenDeleteTriggers(true);
continue;
}
if (lexer.token() == Token.CONTINUE) {
lexer.nextToken();
accept(Token.IDENTITY);
continue;
}
if (identifierEquals("IMMEDIATE")) {
lexer.nextToken();
stmt.setImmediate(true);
continue;
}
break;
}
return stmt;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SQLStatementParser method parseDropFunction.
protected SQLDropFunctionStatement parseDropFunction(boolean acceptDrop) {
if (acceptDrop) {
accept(Token.DROP);
}
SQLDropFunctionStatement stmt = new SQLDropFunctionStatement(getDbType());
accept(Token.FUNCTION);
if (lexer.token() == Token.IF) {
lexer.nextToken();
accept(Token.EXISTS);
stmt.setIfExists(true);
}
SQLName name = this.exprParser.name();
stmt.setName(name);
return stmt;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SchemaStatVisitor method visit.
@Override
public boolean visit(SQLDropTableStatement x) {
setMode(x, Mode.Insert);
setAliasMap();
String originalTable = getCurrentTable();
for (SQLExprTableSource tableSource : x.getTableSources()) {
SQLName name = (SQLName) tableSource.getExpr();
String ident = name.toString();
setCurrentTable(ident);
x.putAttribute("_old_local_", originalTable);
TableStat stat = getTableStat(ident);
stat.incrementDropCount();
Map<String, String> aliasMap = getAliasMap();
putAliasMap(aliasMap, ident, ident);
}
return false;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class PGSchemaStatVisitor method visit.
@Override
public boolean visit(PGDeleteStatement x) {
if (x.getWith() != null) {
x.getWith().accept(this);
}
setAliasMap();
for (SQLName name : x.getUsing()) {
String ident = name.toString();
TableStat stat = getTableStat(ident);
stat.incrementSelectCount();
Map<String, String> aliasMap = getAliasMap();
if (aliasMap != null) {
aliasMap.put(ident, ident);
}
}
x.putAttribute("_original_use_mode", getMode());
setMode(x, Mode.Delete);
String ident = ((SQLIdentifierExpr) x.getTableName()).getName();
setCurrentTable(ident);
TableStat stat = getTableStat(ident, x.getAlias());
stat.incrementDeleteCount();
accept(x.getWhere());
return false;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class PGSchemaStatVisitor method visit.
@Override
public boolean visit(PGInsertStatement x) {
setAliasMap();
if (x.getWith() != null) {
x.getWith().accept(this);
}
x.putAttribute("_original_use_mode", getMode());
setMode(x, Mode.Insert);
String originalTable = getCurrentTable();
if (x.getTableName() instanceof SQLName) {
String ident = ((SQLName) x.getTableName()).toString();
setCurrentTable(ident);
x.putAttribute("_old_local_", originalTable);
TableStat stat = getTableStat(ident);
stat.incrementInsertCount();
Map<String, String> aliasMap = getAliasMap();
if (aliasMap != null) {
if (x.getAlias() != null) {
aliasMap.put(x.getAlias(), ident);
}
aliasMap.put(ident, ident);
}
}
accept(x.getColumns());
accept(x.getQuery());
return false;
}
Aggregations