Search in sources :

Example 11 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class MySqlStatementParser method parseShowColumns.

private MySqlShowColumnsStatement parseShowColumns() {
    MySqlShowColumnsStatement stmt = new MySqlShowColumnsStatement();
    if (lexer.token() == Token.FROM) {
        lexer.nextToken();
        SQLName table = exprParser.name();
        stmt.setTable(table);
        if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
            lexer.nextToken();
            SQLName database = exprParser.name();
            stmt.setDatabase(database);
        }
    }
    if (lexer.token() == Token.LIKE) {
        lexer.nextToken();
        SQLExpr like = exprParser.expr();
        stmt.setLike(like);
    }
    if (lexer.token() == Token.WHERE) {
        lexer.nextToken();
        SQLExpr where = exprParser.expr();
        stmt.setWhere(where);
    }
    return stmt;
}
Also used : MySqlShowColumnsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowColumnsStatement) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 12 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class MySqlStatementParser method parseAlterDrop.

public void parseAlterDrop(SQLAlterTableStatement stmt) {
    lexer.nextToken();
    if (lexer.token() == Token.INDEX) {
        lexer.nextToken();
        SQLName indexName = this.exprParser.name();
        SQLAlterTableDropIndex item = new SQLAlterTableDropIndex();
        item.setIndexName(indexName);
        stmt.addItem(item);
    } else if (lexer.token() == Token.FOREIGN) {
        lexer.nextToken();
        accept(Token.KEY);
        SQLName indexName = this.exprParser.name();
        SQLAlterTableDropForeignKey item = new SQLAlterTableDropForeignKey();
        item.setIndexName(indexName);
        stmt.addItem(item);
    } else if (lexer.token() == Token.KEY) {
        lexer.nextToken();
        SQLName keyName = this.exprParser.name();
        SQLAlterTableDropKey item = new SQLAlterTableDropKey();
        item.setKeyName(keyName);
        stmt.addItem(item);
    } else if (lexer.token() == Token.PRIMARY) {
        lexer.nextToken();
        accept(Token.KEY);
        SQLAlterTableDropPrimaryKey item = new SQLAlterTableDropPrimaryKey();
        stmt.addItem(item);
    } else 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();
        SQLName name = exprParser.name();
        name.setParent(item);
        item.addColumn(name);
        while (lexer.token() == Token.COMMA) {
            lexer.mark();
            lexer.nextToken();
            if (identifierEquals("CHANGE")) {
                lexer.reset();
                break;
            }
            if (lexer.token() == Token.IDENTIFIER) {
                name = exprParser.name();
                name.setParent(item);
            } else {
                lexer.reset();
                break;
            }
        }
        stmt.addItem(item);
    } else if (lexer.token() == Token.PARTITION) {
        SQLAlterTableDropPartition dropPartition = parseAlterTableDropPartition(false);
        stmt.addItem(dropPartition);
    } else if (lexer.token() == Token.IDENTIFIER) {
        SQLAlterTableDropColumnItem item = new SQLAlterTableDropColumnItem();
        this.exprParser.names(item.getColumns());
        stmt.addItem(item);
    } else {
        super.parseAlterDrop(stmt);
    }
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 13 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class MySqlStatementParser method parseAlterDatabase.

public SQLStatement parseAlterDatabase() {
    accept(Token.DATABASE);
    SQLAlterDatabaseStatement stmt = new SQLAlterDatabaseStatement();
    SQLName name = this.exprParser.name();
    stmt.setName(name);
    if (identifierEquals("UPGRADE")) {
        lexer.nextToken();
        acceptIdentifier("DATA");
        acceptIdentifier("DIRECTORY");
        acceptIdentifier("NAME");
        stmt.setUpgradeDataDirectoryName(true);
    }
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 14 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class MySqlStatementParser method parseShowTabless.

private SQLShowTablesStatement parseShowTabless() {
    SQLShowTablesStatement stmt = new SQLShowTablesStatement();
    if (lexer.token() == Token.FROM) {
        lexer.nextToken();
        SQLName database = exprParser.name();
        stmt.setDatabase(database);
    }
    if (lexer.token() == Token.LIKE) {
        lexer.nextToken();
        SQLExpr like = exprParser.expr();
        stmt.setLike(like);
    }
    if (lexer.token() == Token.WHERE) {
        lexer.nextToken();
        SQLExpr where = exprParser.expr();
        stmt.setWhere(where);
    }
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 15 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project druid by alibaba.

the class MySqlStatementParser method parseLoadDataInFile.

protected MySqlLoadDataInFileStatement parseLoadDataInFile() {
    acceptIdentifier("DATA");
    MySqlLoadDataInFileStatement stmt = new MySqlLoadDataInFileStatement();
    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("FIELDS") || identifierEquals("COLUMNS")) {
        lexer.nextToken();
        if (identifierEquals("TERMINATED")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setColumnsTerminatedBy(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
        if (identifierEquals("OPTIONALLY")) {
            stmt.setColumnsEnclosedOptionally(true);
            lexer.nextToken();
        }
        if (identifierEquals("ENCLOSED")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setColumnsEnclosedBy(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
        if (identifierEquals("ESCAPED")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setColumnsEscaped(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
    }
    if (identifierEquals("LINES")) {
        lexer.nextToken();
        if (identifierEquals("STARTING")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setLinesStartingBy(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
        if (identifierEquals("TERMINATED")) {
            lexer.nextToken();
            accept(Token.BY);
            stmt.setLinesTerminatedBy(new SQLCharExpr(lexer.stringVal()));
            lexer.nextToken();
        }
    }
    if (identifierEquals(IGNORE)) {
        lexer.nextToken();
        stmt.setIgnoreLinesNumber(this.exprParser.expr());
        acceptIdentifier("LINES");
    }
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        this.exprParser.exprList(stmt.getColumns(), stmt);
        accept(Token.RPAREN);
    }
    if (lexer.token() == Token.SET) {
        lexer.nextToken();
        this.exprParser.exprList(stmt.getSetList(), stmt);
    }
    return stmt;
}
Also used : SQLLiteralExpr(com.alibaba.druid.sql.ast.expr.SQLLiteralExpr) ParserException(com.alibaba.druid.sql.parser.ParserException) SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) SQLName(com.alibaba.druid.sql.ast.SQLName) MySqlLoadDataInFileStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLoadDataInFileStatement)

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