Search in sources :

Example 86 with SQLName

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;
}
Also used : SQLLiteralExpr(com.alibaba.druid.sql.ast.expr.SQLLiteralExpr) ParserException(com.alibaba.druid.sql.parser.ParserException) SQLName(com.alibaba.druid.sql.ast.SQLName) MySqlLoadXmlStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadXmlStatement) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 87 with SQLName

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;
}
Also used : MySqlOptimizeStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlOptimizeStatement) ArrayList(java.util.ArrayList) SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 88 with SQLName

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;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 89 with SQLName

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;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Example 90 with SQLName

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;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) TableStat(com.alibaba.druid.stat.TableStat)

Aggregations

SQLName (com.alibaba.druid.sql.ast.SQLName)102 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)33 TableStat (com.alibaba.druid.stat.TableStat)20 ParserException (com.alibaba.druid.sql.parser.ParserException)17 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)8 SQLObject (com.alibaba.druid.sql.ast.SQLObject)6 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)6 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)6 WallContext (com.alibaba.druid.wall.WallContext)6 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)5 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)5 WallSqlTableStat (com.alibaba.druid.wall.WallSqlTableStat)5 SQLPartition (com.alibaba.druid.sql.ast.SQLPartition)4 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)4 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)4 SQLCreateTableStatement (com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement)4 SQLTableElement (com.alibaba.druid.sql.ast.statement.SQLTableElement)4 SQLSubPartition (com.alibaba.druid.sql.ast.SQLSubPartition)3 SQLLiteralExpr (com.alibaba.druid.sql.ast.expr.SQLLiteralExpr)3 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)3