use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class MySqlStatementParser method parseLoadXml.
protected MySqlLoadXmlStatement parseLoadXml() {
acceptIdentifier("XML");
MySqlLoadXmlStatement stmt = new MySqlLoadXmlStatement();
if (identifierEquals(LOW_PRIORITY)) {
stmt.setLowPriority(true);
lexer.nextToken();
}
if (identifierEquals("CONCURRENT")) {
stmt.setConcurrent(true);
lexer.nextToken();
}
if (identifierEquals(LOCAL)) {
stmt.setLocal(true);
lexer.nextToken();
}
acceptIdentifier("INFILE");
SQLLiteralExpr fileName = (SQLLiteralExpr) exprParser.expr();
stmt.setFileName(fileName);
if (lexer.token() == Token.REPLACE) {
stmt.setReplicate(true);
lexer.nextToken();
}
if (identifierEquals(IGNORE)) {
stmt.setIgnore(true);
lexer.nextToken();
}
accept(Token.INTO);
accept(Token.TABLE);
SQLName tableName = exprParser.name();
stmt.setTableName(tableName);
if (identifierEquals(CHARACTER)) {
lexer.nextToken();
accept(Token.SET);
if (lexer.token() != Token.LITERAL_CHARS) {
throw new ParserException("syntax error, illegal charset");
}
String charset = lexer.stringVal();
lexer.nextToken();
stmt.setCharset(charset);
}
if (identifierEquals("ROWS")) {
lexer.nextToken();
accept(Token.IDENTIFIED);
accept(Token.BY);
SQLExpr rowsIdentifiedBy = exprParser.expr();
stmt.setRowsIdentifiedBy(rowsIdentifiedBy);
}
if (identifierEquals(IGNORE)) {
throw new ParserException("TODO");
}
if (lexer.token() == Token.SET) {
throw new ParserException("TODO");
}
return stmt;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class MySqlStatementParser method parseOptimize.
public MySqlOptimizeStatement parseOptimize() {
accept(Token.OPTIMIZE);
accept(Token.TABLE);
MySqlOptimizeStatement stmt = new MySqlOptimizeStatement();
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 SchemaStatVisitor method getTable.
private String getTable(SQLTableSource from, String tableAlias) {
if (from instanceof SQLExprTableSource) {
boolean aliasEq = StringUtils.equals(from.getAlias(), tableAlias);
SQLExpr tableSourceExpr = ((SQLExprTableSource) from).getExpr();
if (tableSourceExpr instanceof SQLName) {
String tableName = ((SQLName) tableSourceExpr).toString();
if (tableAlias == null || aliasEq) {
return tableName;
}
}
} else if (from instanceof SQLJoinTableSource) {
SQLJoinTableSource joinTableSource = (SQLJoinTableSource) from;
String leftMatchTableName = getTable(joinTableSource.getLeft(), tableAlias);
if (leftMatchTableName != null) {
return leftMatchTableName;
}
return getTable(joinTableSource.getRight(), tableAlias);
}
return null;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SchemaStatVisitor method visit.
public boolean visit(SQLUpdateStatement x) {
setAliasMap();
setMode(x, Mode.Update);
SQLName identName = x.getTableName();
if (identName != null) {
String ident = identName.toString();
setCurrentTable(ident);
TableStat stat = getTableStat(ident);
stat.incrementUpdateCount();
Map<String, String> aliasMap = getAliasMap();
putAliasMap(aliasMap, ident, ident);
} else {
x.getTableSource().accept(this);
}
accept(x.getFrom());
accept(x.getItems());
accept(x.getWhere());
return false;
}
use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.
the class SchemaStatVisitor method visit.
@Override
public boolean visit(SQLTruncateStatement x) {
setMode(x, Mode.Delete);
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.incrementDeleteCount();
Map<String, String> aliasMap = getAliasMap();
putAliasMap(aliasMap, ident, ident);
}
return false;
}
Aggregations