Search in sources :

Example 71 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project Mycat-Server by MyCATApache.

the class DruidSelectParser method buildGroupByCols.

private String[] buildGroupByCols(List<SQLExpr> groupByItems, Map<String, String> aliaColumns) {
    String[] groupByCols = new String[groupByItems.size()];
    for (int i = 0; i < groupByItems.size(); i++) {
        SQLExpr sqlExpr = groupByItems.get(i);
        String column = null;
        if (sqlExpr instanceof SQLIdentifierExpr) {
            column = ((SQLIdentifierExpr) sqlExpr).getName();
        } else if (sqlExpr instanceof SQLMethodInvokeExpr) {
            column = ((SQLMethodInvokeExpr) sqlExpr).toString();
        } else if (sqlExpr instanceof MySqlOrderingExpr) {
            //todo czn
            SQLExpr expr = ((MySqlOrderingExpr) sqlExpr).getExpr();
            if (expr instanceof SQLName) {
                //不要转大写 2015-2-10 sohudo StringUtil.removeBackquote(expr.getSimpleName().toUpperCase());
                column = StringUtil.removeBackquote(((SQLName) expr).getSimpleName());
            } else {
                column = StringUtil.removeBackquote(expr.toString());
            }
        } else if (sqlExpr instanceof SQLPropertyExpr) {
            /**
				 * 针对子查询别名,例如select id from (select h.id from hotnews h  union select h.title from hotnews h ) as t1 group by t1.id;
				 */
            column = sqlExpr.toString();
        }
        if (column == null) {
            column = sqlExpr.toString();
        }
        int dotIndex = column.indexOf(".");
        int bracketIndex = column.indexOf("(");
        //通过判断含有括号来决定是否为函数列
        if (dotIndex != -1 && bracketIndex == -1) {
            //此步骤得到的column必须是不带.的,有别名的用别名,无别名的用字段名
            column = column.substring(dotIndex + 1);
        }
        //column;
        groupByCols[i] = getAliaColumn(aliaColumns, column);
    }
    return groupByCols;
}
Also used : MySqlOrderingExpr(com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 72 with SQLName

use of com.alibaba.druid.sql.ast.SQLName in project Mycat-Server by MyCATApache.

the class DruidMysqlCreateTableTest method hasColumn.

private static boolean hasColumn(SQLStatement statement) {
    for (SQLTableElement tableElement : ((SQLCreateTableStatement) statement).getTableElementList()) {
        SQLName sqlName = null;
        if (tableElement instanceof SQLColumnDefinition) {
            sqlName = ((SQLColumnDefinition) tableElement).getName();
        }
        if (sqlName != null) {
            String simpleName = sqlName.getSimpleName();
            simpleName = StringUtil.removeBackquote(simpleName);
            if (tableElement instanceof SQLColumnDefinition && "_slot".equalsIgnoreCase(simpleName)) {
                return true;
            }
        }
    }
    return false;
}
Also used : SQLCreateTableStatement(com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLTableElement(com.alibaba.druid.sql.ast.statement.SQLTableElement) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)

Example 73 with SQLName

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

the class MySqlSchemaStatVisitorTest_pk_0 method test_0.

public void test_0() throws Exception {
    String sql = "CREATE TABLE `m_dt` (\n" + "  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',\n" + "  `gmt_create` datetime NOT NULL COMMENT '创建时间',\n" + "  `gmt_modified` datetime NOT NULL COMMENT '修改时间',\n" + "  `instance_id` int(11) NOT NULL COMMENT '实例id',\n" + "  `schema_name` varchar(128) NOT NULL COMMENT '数据库schema名称',\n" + "  `state` tinyint(4) NOT NULL DEFAULT '0' COMMENT ' x dd ',\n" + "  `busi_user` varchar(64) DEFAULT NULL COMMENT 'JDBC业务用户',\n" + "  `bzp` varchar(128) DEFAULT NULL COMMENT 'bcp',\n" + "  `ecd` varchar(32) DEFAULT NULL COMMENT 'xxx',\n" + "  `last_sync_time` datetime DEFAULT NULL COMMENT '最后同步时间',\n" + "  `catalog_name` varchar(128) NOT NULL COMMENT '物理库名称',\n" + "  `search_name` varchar(256) NOT NULL COMMENT '用于搜索,区分不同数据库的不同字段信息',\n" + "  `db_type` tinyint(4) NOT NULL COMMENT '数据库类型,和meta_instance表一致',\n" + "  `et` varchar(32) NOT NULL DEFAULT '' COMMENT 'et',\n" + "  `ae` varchar(32) DEFAULT NULL COMMENT 'ae',\n" + "  PRIMARY KEY (`id`),\n" + "  UNIQUE KEY `uk_instanceid_schemaname` (`instance_id`,`catalog_name`,`schema_name`),\n" + "  KEY `idx_schema_name` (`schema_name`),\n" + "  KEY `idx_instance_id_state` (`instance_id`,`id`,`state`),\n" + "  KEY `idx_search_name` (`search_name`(255))\n" + ") ENGINE=InnoDB AUTO_INCREMENT=408695 DEFAULT CHARSET=utf8 COMMENT='数据库表信息'";
    //		sql = "select columnName from table1 where id in (select id from table3 where name = ?)";
    MySqlStatementParser parser = new MySqlStatementParser(sql);
    List<SQLStatement> statementList = parser.parseStatementList();
    SQLCreateTableStatement stmt = (SQLCreateTableStatement) statementList.get(0);
    Assert.assertEquals(1, statementList.size());
    MySqlSchemaStatVisitor visitor = new MySqlSchemaStatVisitor();
    stmt.accept(visitor);
    System.out.println(sql);
    System.out.println("Tables : " + visitor.getTables());
    System.out.println("fields : " + visitor.getColumns());
    Assert.assertEquals(1, visitor.getTables().size());
    Assert.assertEquals(true, visitor.containsTable("m_dt"));
    Assert.assertEquals(15, visitor.getColumns().size());
    {
        TableStat.Column column = visitor.getColumn("m_dt", "id");
        assertNotNull(column);
        assertTrue(column.isPrimaryKey());
    }
    {
        TableStat.Column column = visitor.getColumn("m_dt", "schema_name");
        assertNotNull(column);
        assertTrue(column.isUnique());
    }
    {
        TableStat.Column column = visitor.getColumn("m_dt", "instance_id");
        assertNotNull(column);
        assertTrue(column.isUnique());
    }
    for (SQLTableElement element : stmt.getTableElementList()) {
        if (element instanceof SQLUnique) {
            SQLName name = ((SQLUnique) element).getName();
            if (name != null) {
                String uniqueName = name.toString();
            }
        }
    }
// Assert.assertEquals(true, visitor.getFields().contains(new
// Column("users", "id")));
// Assert.assertEquals(true, visitor.getFields().contains(new
// Column("users", "name")));
}
Also used : MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) SQLCreateTableStatement(com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLTableElement(com.alibaba.druid.sql.ast.statement.SQLTableElement) SQLUnique(com.alibaba.druid.sql.ast.statement.SQLUnique) MySqlStatementParser(com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement)

Example 74 with SQLName

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

the class MySqlStatementParser method parseCreateProcedure.

/**
     * parse create procedure statement
     */
public SQLCreateProcedureStatement parseCreateProcedure() {
    /**
         * CREATE OR REPALCE PROCEDURE SP_NAME(parameter_list) BEGIN block_statement END
         */
    SQLCreateProcedureStatement stmt = new SQLCreateProcedureStatement();
    if (identifierEquals("DEFINER")) {
        lexer.nextToken();
        accept(Token.EQ);
        SQLName definer = this.exprParser.name();
        stmt.setDefiner(definer);
    } else {
        accept(Token.CREATE);
        if (lexer.token() == Token.OR) {
            lexer.nextToken();
            accept(Token.REPLACE);
            stmt.setOrReplace(true);
        }
    }
    accept(Token.PROCEDURE);
    stmt.setName(this.exprParser.name());
    if (lexer.token() == Token.LPAREN) {
        // match "("
        lexer.nextToken();
        parserParameters(stmt.getParameters());
        // match ")"
        accept(Token.RPAREN);
    }
    SQLBlockStatement block = this.parseBlock();
    stmt.setBlock(block);
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 75 with SQLName

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

the class MySqlStatementParser method parseShow.

public SQLStatement parseShow() {
    accept(Token.SHOW);
    if (lexer.token() == Token.COMMENT) {
        lexer.nextToken();
    }
    boolean full = false;
    if (lexer.token() == Token.FULL) {
        lexer.nextToken();
        full = true;
    }
    if (identifierEquals("PROCESSLIST")) {
        lexer.nextToken();
        MySqlShowProcessListStatement stmt = new MySqlShowProcessListStatement();
        stmt.setFull(full);
        return stmt;
    }
    if (identifierEquals("COLUMNS") || identifierEquals("FIELDS")) {
        lexer.nextToken();
        MySqlShowColumnsStatement stmt = parseShowColumns();
        stmt.setFull(full);
        return stmt;
    }
    if (identifierEquals("COLUMNS")) {
        lexer.nextToken();
        MySqlShowColumnsStatement stmt = parseShowColumns();
        return stmt;
    }
    if (identifierEquals(TABLES)) {
        lexer.nextToken();
        SQLShowTablesStatement stmt = parseShowTabless();
        stmt.setFull(full);
        return stmt;
    }
    if (identifierEquals("DATABASES")) {
        lexer.nextToken();
        MySqlShowDatabasesStatement stmt = parseShowDatabases();
        return stmt;
    }
    if (identifierEquals("WARNINGS")) {
        lexer.nextToken();
        MySqlShowWarningsStatement stmt = parseShowWarnings();
        return stmt;
    }
    if (identifierEquals("COUNT")) {
        lexer.nextToken();
        accept(Token.LPAREN);
        accept(Token.STAR);
        accept(Token.RPAREN);
        if (identifierEquals(ERRORS)) {
            lexer.nextToken();
            MySqlShowErrorsStatement stmt = new MySqlShowErrorsStatement();
            stmt.setCount(true);
            return stmt;
        } else {
            acceptIdentifier("WARNINGS");
            MySqlShowWarningsStatement stmt = new MySqlShowWarningsStatement();
            stmt.setCount(true);
            return stmt;
        }
    }
    if (identifierEquals(ERRORS)) {
        lexer.nextToken();
        MySqlShowErrorsStatement stmt = new MySqlShowErrorsStatement();
        stmt.setLimit(this.exprParser.parseLimit());
        return stmt;
    }
    if (identifierEquals(STATUS)) {
        lexer.nextToken();
        MySqlShowStatusStatement stmt = parseShowStatus();
        return stmt;
    }
    if (identifierEquals(VARIABLES)) {
        lexer.nextToken();
        MySqlShowVariantsStatement stmt = parseShowVariants();
        return stmt;
    }
    if (identifierEquals(GLOBAL)) {
        lexer.nextToken();
        if (identifierEquals(STATUS)) {
            lexer.nextToken();
            MySqlShowStatusStatement stmt = parseShowStatus();
            stmt.setGlobal(true);
            return stmt;
        }
        if (identifierEquals(VARIABLES)) {
            lexer.nextToken();
            MySqlShowVariantsStatement stmt = parseShowVariants();
            stmt.setGlobal(true);
            return stmt;
        }
    }
    if (identifierEquals(SESSION)) {
        lexer.nextToken();
        if (identifierEquals(STATUS)) {
            lexer.nextToken();
            MySqlShowStatusStatement stmt = parseShowStatus();
            stmt.setSession(true);
            return stmt;
        }
        if (identifierEquals(VARIABLES)) {
            lexer.nextToken();
            MySqlShowVariantsStatement stmt = parseShowVariants();
            stmt.setSession(true);
            return stmt;
        }
    }
    if (identifierEquals("COBAR_STATUS")) {
        lexer.nextToken();
        return new CobarShowStatus();
    }
    if (identifierEquals("AUTHORS")) {
        lexer.nextToken();
        return new MySqlShowAuthorsStatement();
    }
    if (lexer.token() == Token.BINARY) {
        lexer.nextToken();
        acceptIdentifier("LOGS");
        return new MySqlShowBinaryLogsStatement();
    }
    if (identifierEquals("MASTER")) {
        lexer.nextToken();
        if (identifierEquals("LOGS")) {
            lexer.nextToken();
            return new MySqlShowMasterLogsStatement();
        }
        acceptIdentifier(STATUS);
        return new MySqlShowMasterStatusStatement();
    }
    if (identifierEquals(CHARACTER)) {
        lexer.nextToken();
        accept(Token.SET);
        MySqlShowCharacterSetStatement stmt = new MySqlShowCharacterSetStatement();
        if (lexer.token() == Token.LIKE) {
            lexer.nextToken();
            stmt.setPattern(this.exprParser.expr());
        }
        if (lexer.token() == Token.WHERE) {
            lexer.nextToken();
            stmt.setWhere(this.exprParser.expr());
        }
        return stmt;
    }
    if (identifierEquals("COLLATION")) {
        lexer.nextToken();
        MySqlShowCollationStatement stmt = new MySqlShowCollationStatement();
        if (lexer.token() == Token.LIKE) {
            lexer.nextToken();
            stmt.setPattern(this.exprParser.expr());
        }
        if (lexer.token() == Token.WHERE) {
            lexer.nextToken();
            stmt.setWhere(this.exprParser.expr());
        }
        return stmt;
    }
    if (identifierEquals(BINLOG)) {
        lexer.nextToken();
        acceptIdentifier(EVENTS);
        MySqlShowBinLogEventsStatement stmt = new MySqlShowBinLogEventsStatement();
        if (lexer.token() == Token.IN) {
            lexer.nextToken();
            stmt.setIn(this.exprParser.expr());
        }
        if (lexer.token() == Token.FROM) {
            lexer.nextToken();
            stmt.setFrom(this.exprParser.expr());
        }
        stmt.setLimit(this.exprParser.parseLimit());
        return stmt;
    }
    if (identifierEquals("CONTRIBUTORS")) {
        lexer.nextToken();
        return new MySqlShowContributorsStatement();
    }
    if (lexer.token() == Token.CREATE) {
        lexer.nextToken();
        if (lexer.token() == Token.DATABASE) {
            lexer.nextToken();
            MySqlShowCreateDatabaseStatement stmt = new MySqlShowCreateDatabaseStatement();
            stmt.setDatabase(this.exprParser.name());
            return stmt;
        }
        if (identifierEquals("EVENT")) {
            lexer.nextToken();
            MySqlShowCreateEventStatement stmt = new MySqlShowCreateEventStatement();
            stmt.setEventName(this.exprParser.name());
            return stmt;
        }
        if (lexer.token() == Token.FUNCTION) {
            lexer.nextToken();
            MySqlShowCreateFunctionStatement stmt = new MySqlShowCreateFunctionStatement();
            stmt.setName(this.exprParser.name());
            return stmt;
        }
        if (lexer.token() == Token.PROCEDURE) {
            lexer.nextToken();
            MySqlShowCreateProcedureStatement stmt = new MySqlShowCreateProcedureStatement();
            stmt.setName(this.exprParser.name());
            return stmt;
        }
        if (lexer.token() == Token.TABLE) {
            lexer.nextToken();
            MySqlShowCreateTableStatement stmt = new MySqlShowCreateTableStatement();
            stmt.setName(this.exprParser.name());
            return stmt;
        }
        if (lexer.token() == Token.VIEW) {
            lexer.nextToken();
            MySqlShowCreateViewStatement stmt = new MySqlShowCreateViewStatement();
            stmt.setName(this.exprParser.name());
            return stmt;
        }
        if (lexer.token() == Token.TRIGGER) {
            lexer.nextToken();
            MySqlShowCreateTriggerStatement stmt = new MySqlShowCreateTriggerStatement();
            stmt.setName(this.exprParser.name());
            return stmt;
        }
        throw new ParserException("TODO " + lexer.stringVal());
    }
    if (identifierEquals(ENGINE)) {
        lexer.nextToken();
        MySqlShowEngineStatement stmt = new MySqlShowEngineStatement();
        stmt.setName(this.exprParser.name());
        stmt.setOption(MySqlShowEngineStatement.Option.valueOf(lexer.stringVal().toUpperCase()));
        lexer.nextToken();
        return stmt;
    }
    if (identifierEquals("STORAGE")) {
        lexer.nextToken();
        acceptIdentifier(ENGINES);
        MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
        stmt.setStorage(true);
        return stmt;
    }
    if (identifierEquals(ENGINES)) {
        lexer.nextToken();
        MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
        return stmt;
    }
    if (identifierEquals(EVENTS)) {
        lexer.nextToken();
        MySqlShowEventsStatement stmt = new MySqlShowEventsStatement();
        if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
            lexer.nextToken();
            stmt.setSchema(this.exprParser.name());
        }
        if (lexer.token() == Token.LIKE) {
            lexer.nextToken();
            stmt.setLike(this.exprParser.expr());
        }
        if (lexer.token() == Token.WHERE) {
            lexer.nextToken();
            stmt.setWhere(this.exprParser.expr());
        }
        return stmt;
    }
    if (lexer.token() == Token.FUNCTION) {
        lexer.nextToken();
        if (identifierEquals("CODE")) {
            lexer.nextToken();
            MySqlShowFunctionCodeStatement stmt = new MySqlShowFunctionCodeStatement();
            stmt.setName(this.exprParser.name());
            return stmt;
        }
        acceptIdentifier(STATUS);
        MySqlShowFunctionStatusStatement stmt = new MySqlShowFunctionStatusStatement();
        if (lexer.token() == Token.LIKE) {
            lexer.nextToken();
            stmt.setLike(this.exprParser.expr());
        }
        if (lexer.token() == Token.WHERE) {
            lexer.nextToken();
            stmt.setWhere(this.exprParser.expr());
        }
        return stmt;
    }
    if (identifierEquals(ENGINE)) {
        lexer.nextToken();
        MySqlShowEngineStatement stmt = new MySqlShowEngineStatement();
        stmt.setName(this.exprParser.name());
        stmt.setOption(MySqlShowEngineStatement.Option.valueOf(lexer.stringVal().toUpperCase()));
        lexer.nextToken();
        return stmt;
    }
    if (identifierEquals("STORAGE")) {
        lexer.nextToken();
        accept(Token.EQ);
        accept(Token.DEFAULT);
        MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
        stmt.setStorage(true);
        return stmt;
    }
    if (identifierEquals(ENGINES)) {
        lexer.nextToken();
        MySqlShowEnginesStatement stmt = new MySqlShowEnginesStatement();
        return stmt;
    }
    if (identifierEquals("GRANTS")) {
        lexer.nextToken();
        MySqlShowGrantsStatement stmt = new MySqlShowGrantsStatement();
        if (lexer.token() == Token.FOR) {
            lexer.nextToken();
            stmt.setUser(this.exprParser.expr());
        }
        return stmt;
    }
    if (lexer.token() == Token.INDEX || identifierEquals("INDEXES")) {
        lexer.nextToken();
        MySqlShowIndexesStatement stmt = new MySqlShowIndexesStatement();
        if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
            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.HINT) {
            stmt.setHints(this.exprParser.parseHints());
        }
        return stmt;
    }
    if (identifierEquals("KEYS")) {
        lexer.nextToken();
        MySqlShowKeysStatement stmt = new MySqlShowKeysStatement();
        if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
            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);
            }
        }
        return stmt;
    }
    if (lexer.token() == Token.OPEN || identifierEquals("OPEN")) {
        lexer.nextToken();
        acceptIdentifier(TABLES);
        MySqlShowOpenTablesStatement stmt = new MySqlShowOpenTablesStatement();
        if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
            lexer.nextToken();
            stmt.setDatabase(this.exprParser.name());
        }
        if (lexer.token() == Token.LIKE) {
            lexer.nextToken();
            stmt.setLike(this.exprParser.expr());
        }
        if (lexer.token() == Token.WHERE) {
            lexer.nextToken();
            stmt.setWhere(this.exprParser.expr());
        }
        return stmt;
    }
    if (identifierEquals("PLUGINS")) {
        lexer.nextToken();
        MySqlShowPluginsStatement stmt = new MySqlShowPluginsStatement();
        return stmt;
    }
    if (identifierEquals("PRIVILEGES")) {
        lexer.nextToken();
        MySqlShowPrivilegesStatement stmt = new MySqlShowPrivilegesStatement();
        return stmt;
    }
    if (lexer.token() == Token.PROCEDURE) {
        lexer.nextToken();
        if (identifierEquals("CODE")) {
            lexer.nextToken();
            MySqlShowProcedureCodeStatement stmt = new MySqlShowProcedureCodeStatement();
            stmt.setName(this.exprParser.name());
            return stmt;
        }
        acceptIdentifier(STATUS);
        MySqlShowProcedureStatusStatement stmt = new MySqlShowProcedureStatusStatement();
        if (lexer.token() == Token.LIKE) {
            lexer.nextToken();
            stmt.setLike(this.exprParser.expr());
        }
        if (lexer.token() == Token.WHERE) {
            lexer.nextToken();
            stmt.setWhere(this.exprParser.expr());
        }
        return stmt;
    }
    if (identifierEquals("PROCESSLIST")) {
        lexer.nextToken();
        MySqlShowProcessListStatement stmt = new MySqlShowProcessListStatement();
        return stmt;
    }
    if (identifierEquals("PROFILES")) {
        lexer.nextToken();
        MySqlShowProfilesStatement stmt = new MySqlShowProfilesStatement();
        return stmt;
    }
    if (identifierEquals("PROFILE")) {
        lexer.nextToken();
        MySqlShowProfileStatement stmt = new MySqlShowProfileStatement();
        for (; ; ) {
            if (lexer.token() == Token.ALL) {
                stmt.getTypes().add(MySqlShowProfileStatement.Type.ALL);
                lexer.nextToken();
            } else if (identifierEquals("BLOCK")) {
                lexer.nextToken();
                acceptIdentifier("IO");
                stmt.getTypes().add(MySqlShowProfileStatement.Type.BLOCK_IO);
            } else if (identifierEquals("CONTEXT")) {
                lexer.nextToken();
                acceptIdentifier("SWITCHES");
                stmt.getTypes().add(MySqlShowProfileStatement.Type.CONTEXT_SWITCHES);
            } else if (identifierEquals("CPU")) {
                lexer.nextToken();
                stmt.getTypes().add(MySqlShowProfileStatement.Type.CPU);
            } else if (identifierEquals("IPC")) {
                lexer.nextToken();
                stmt.getTypes().add(MySqlShowProfileStatement.Type.IPC);
            } else if (identifierEquals("MEMORY")) {
                lexer.nextToken();
                stmt.getTypes().add(MySqlShowProfileStatement.Type.MEMORY);
            } else if (identifierEquals("PAGE")) {
                lexer.nextToken();
                acceptIdentifier("FAULTS");
                stmt.getTypes().add(MySqlShowProfileStatement.Type.PAGE_FAULTS);
            } else if (identifierEquals("SOURCE")) {
                lexer.nextToken();
                stmt.getTypes().add(MySqlShowProfileStatement.Type.SOURCE);
            } else if (identifierEquals("SWAPS")) {
                lexer.nextToken();
                stmt.getTypes().add(MySqlShowProfileStatement.Type.SWAPS);
            } else {
                break;
            }
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                continue;
            }
            break;
        }
        if (lexer.token() == Token.FOR) {
            lexer.nextToken();
            acceptIdentifier("QUERY");
            stmt.setForQuery(this.exprParser.primary());
        }
        stmt.setLimit(this.exprParser.parseLimit());
        return stmt;
    }
    if (identifierEquals("RELAYLOG")) {
        lexer.nextToken();
        acceptIdentifier(EVENTS);
        MySqlShowRelayLogEventsStatement stmt = new MySqlShowRelayLogEventsStatement();
        if (lexer.token() == Token.IN) {
            lexer.nextToken();
            stmt.setLogName(this.exprParser.primary());
        }
        if (lexer.token() == Token.FROM) {
            lexer.nextToken();
            stmt.setFrom(this.exprParser.primary());
        }
        stmt.setLimit(this.exprParser.parseLimit());
        return stmt;
    }
    if (identifierEquals("RELAYLOG")) {
        lexer.nextToken();
        acceptIdentifier(EVENTS);
        MySqlShowRelayLogEventsStatement stmt = new MySqlShowRelayLogEventsStatement();
        if (lexer.token() == Token.IN) {
            lexer.nextToken();
            stmt.setLogName(this.exprParser.primary());
        }
        if (lexer.token() == Token.FROM) {
            lexer.nextToken();
            stmt.setFrom(this.exprParser.primary());
        }
        stmt.setLimit(this.exprParser.parseLimit());
        return stmt;
    }
    if (identifierEquals("SLAVE")) {
        lexer.nextToken();
        if (identifierEquals(STATUS)) {
            lexer.nextToken();
            return new MySqlShowSlaveStatusStatement();
        } else {
            acceptIdentifier("HOSTS");
            MySqlShowSlaveHostsStatement stmt = new MySqlShowSlaveHostsStatement();
            return stmt;
        }
    }
    if (lexer.token() == Token.TABLE) {
        lexer.nextToken();
        acceptIdentifier(STATUS);
        MySqlShowTableStatusStatement stmt = new MySqlShowTableStatusStatement();
        if (lexer.token() == Token.FROM || lexer.token() == Token.IN) {
            lexer.nextToken();
            stmt.setDatabase(this.exprParser.name());
        }
        if (lexer.token() == Token.LIKE) {
            lexer.nextToken();
            stmt.setLike(this.exprParser.expr());
        }
        if (lexer.token() == Token.WHERE) {
            lexer.nextToken();
            stmt.setWhere(this.exprParser.expr());
        }
        return stmt;
    }
    if (identifierEquals("TRIGGERS")) {
        lexer.nextToken();
        MySqlShowTriggersStatement stmt = new MySqlShowTriggersStatement();
        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;
    }
    // MySqlShowSlaveHostsStatement
    throw new ParserException("TODO " + lexer.stringVal());
}
Also used : MySqlShowProcedureStatusStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcedureStatusStatement) MySqlShowProfilesStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProfilesStatement) MySqlShowIndexesStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowIndexesStatement) MySqlShowDatabasesStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowDatabasesStatement) MySqlShowCreateDatabaseStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateDatabaseStatement) MySqlShowErrorsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowErrorsStatement) MySqlShowEnginesStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEnginesStatement) MySqlShowVariantsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowVariantsStatement) MySqlShowColumnsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowColumnsStatement) MySqlShowWarningsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowWarningsStatement) MySqlShowMasterLogsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterLogsStatement) MySqlShowCollationStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCollationStatement) MySqlShowOpenTablesStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowOpenTablesStatement) MySqlShowSlaveHostsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowSlaveHostsStatement) MySqlShowProcedureCodeStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcedureCodeStatement) MySqlShowProfileStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProfileStatement) MySqlShowMasterStatusStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowMasterStatusStatement) MySqlShowProcessListStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowProcessListStatement) MySqlShowCreateTriggerStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTriggerStatement) MySqlShowTableStatusStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTableStatusStatement) MySqlShowKeysStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowKeysStatement) MySqlShowPluginsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowPluginsStatement) MySqlShowFunctionCodeStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowFunctionCodeStatement) MySqlShowCreateEventStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateEventStatement) ParserException(com.alibaba.druid.sql.parser.ParserException) MySqlShowPrivilegesStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowPrivilegesStatement) MySqlShowFunctionStatusStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowFunctionStatusStatement) MySqlShowStatusStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowStatusStatement) MySqlShowEventsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEventsStatement) MySqlShowBinLogEventsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowBinLogEventsStatement) CobarShowStatus(com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus) SQLName(com.alibaba.druid.sql.ast.SQLName) MySqlShowCreateViewStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateViewStatement) MySqlShowCreateFunctionStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateFunctionStatement) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) MySqlShowSlaveStatusStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowSlaveStatusStatement) MySqlShowRelayLogEventsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowRelayLogEventsStatement) MySqlShowCharacterSetStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCharacterSetStatement) MySqlShowTriggersStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowTriggersStatement) MySqlShowAuthorsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowAuthorsStatement) MySqlShowContributorsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowContributorsStatement) MySqlShowCreateProcedureStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateProcedureStatement) MySqlShowBinaryLogsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowBinaryLogsStatement) MySqlShowEngineStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowEngineStatement) MySqlShowGrantsStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowGrantsStatement) MySqlShowCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlShowCreateTableStatement)

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