Search in sources :

Example 91 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class SQLStatementParser method parsePrivileages.

protected void parsePrivileages(List<SQLExpr> privileges, SQLObject parent) {
    for (; ; ) {
        String privilege = null;
        if (lexer.token() == Token.ALL) {
            lexer.nextToken();
            if (identifierEquals("PRIVILEGES")) {
                privilege = "ALL PRIVILEGES";
            } else {
                privilege = "ALL";
            }
        } else if (lexer.token() == Token.SELECT) {
            privilege = "SELECT";
            lexer.nextToken();
        } else if (lexer.token() == Token.UPDATE) {
            privilege = "UPDATE";
            lexer.nextToken();
        } else if (lexer.token() == Token.DELETE) {
            privilege = "DELETE";
            lexer.nextToken();
        } else if (lexer.token() == Token.INSERT) {
            privilege = "INSERT";
            lexer.nextToken();
        } else if (lexer.token() == Token.INDEX) {
            lexer.nextToken();
            privilege = "INDEX";
        } else if (lexer.token() == Token.TRIGGER) {
            lexer.nextToken();
            privilege = "TRIGGER";
        } else if (lexer.token() == Token.REFERENCES) {
            privilege = "REFERENCES";
            lexer.nextToken();
        } else if (lexer.token() == Token.CREATE) {
            lexer.nextToken();
            if (lexer.token() == Token.TABLE) {
                privilege = "CREATE TABLE";
                lexer.nextToken();
            } else if (lexer.token() == Token.SESSION) {
                privilege = "CREATE SESSION";
                lexer.nextToken();
            } else if (lexer.token() == Token.TABLESPACE) {
                privilege = "CREATE TABLESPACE";
                lexer.nextToken();
            } else if (lexer.token() == Token.USER) {
                privilege = "CREATE USER";
                lexer.nextToken();
            } else if (lexer.token() == Token.VIEW) {
                privilege = "CREATE VIEW";
                lexer.nextToken();
            } else if (lexer.token() == Token.ANY) {
                lexer.nextToken();
                if (lexer.token() == Token.TABLE) {
                    lexer.nextToken();
                    privilege = "CREATE ANY TABLE";
                } else if (identifierEquals("MATERIALIZED")) {
                    lexer.nextToken();
                    accept(Token.VIEW);
                    privilege = "CREATE ANY MATERIALIZED VIEW";
                } else {
                    throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
                }
            } else if (identifierEquals("SYNONYM")) {
                privilege = "CREATE SYNONYM";
                lexer.nextToken();
            } else if (identifierEquals("ROUTINE")) {
                privilege = "CREATE ROUTINE";
                lexer.nextToken();
            } else if (identifierEquals("TEMPORARY")) {
                lexer.nextToken();
                accept(Token.TABLE);
                privilege = "CREATE TEMPORARY TABLE";
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
        } else if (lexer.token() == Token.ALTER) {
            lexer.nextToken();
            if (lexer.token() == Token.TABLE) {
                privilege = "ALTER TABLE";
                lexer.nextToken();
            } else if (lexer.token() == Token.SESSION) {
                privilege = "ALTER SESSION";
                lexer.nextToken();
            } else if (lexer.token() == Token.ANY) {
                lexer.nextToken();
                if (lexer.token() == Token.TABLE) {
                    lexer.nextToken();
                    privilege = "ALTER ANY TABLE";
                } else if (identifierEquals("MATERIALIZED")) {
                    lexer.nextToken();
                    accept(Token.VIEW);
                    privilege = "ALTER ANY MATERIALIZED VIEW";
                } else {
                    throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
                }
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
        } else if (lexer.token() == Token.DROP) {
            lexer.nextToken();
            if (lexer.token() == Token.DROP) {
                privilege = "DROP TABLE";
                lexer.nextToken();
            } else if (lexer.token() == Token.SESSION) {
                privilege = "DROP SESSION";
                lexer.nextToken();
            } else if (lexer.token() == Token.ANY) {
                lexer.nextToken();
                if (lexer.token() == Token.TABLE) {
                    lexer.nextToken();
                    privilege = "DROP ANY TABLE";
                } else if (identifierEquals("MATERIALIZED")) {
                    lexer.nextToken();
                    accept(Token.VIEW);
                    privilege = "DROP ANY MATERIALIZED VIEW";
                } else {
                    throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
                }
            } else {
                privilege = "DROP";
            }
        } else if (identifierEquals("USAGE")) {
            privilege = "USAGE";
            lexer.nextToken();
        } else if (identifierEquals("EXECUTE")) {
            privilege = "EXECUTE";
            lexer.nextToken();
        } else if (identifierEquals("PROXY")) {
            privilege = "PROXY";
            lexer.nextToken();
        } else if (identifierEquals("QUERY")) {
            lexer.nextToken();
            acceptIdentifier("REWRITE");
            privilege = "QUERY REWRITE";
        } else if (identifierEquals("GLOBAL")) {
            lexer.nextToken();
            acceptIdentifier("QUERY");
            acceptIdentifier("REWRITE");
            privilege = "GLOBAL QUERY REWRITE";
        } else if (identifierEquals("INHERIT")) {
            lexer.nextToken();
            acceptIdentifier("PRIVILEGES");
            privilege = "INHERIT PRIVILEGES";
        } else if (identifierEquals("EVENT")) {
            lexer.nextToken();
            privilege = "EVENT";
        } else if (identifierEquals("FILE")) {
            lexer.nextToken();
            privilege = "FILE";
        } else if (lexer.token() == Token.GRANT) {
            lexer.nextToken();
            acceptIdentifier("OPTION");
            privilege = "GRANT OPTION";
        } else if (lexer.token() == Token.LOCK) {
            lexer.nextToken();
            acceptIdentifier("TABLES");
            privilege = "LOCK TABLES";
        } else if (identifierEquals("PROCESS")) {
            lexer.nextToken();
            privilege = "PROCESS";
        } else if (identifierEquals("RELOAD")) {
            lexer.nextToken();
            privilege = "RELOAD";
        } else if (identifierEquals("REPLICATION")) {
            lexer.nextToken();
            if (identifierEquals("SLAVE")) {
                lexer.nextToken();
                privilege = "REPLICATION SLAVE";
            } else {
                acceptIdentifier("CLIENT");
                privilege = "REPLICATION CLIENT";
            }
        } else if (lexer.token() == Token.SHOW) {
            lexer.nextToken();
            if (lexer.token() == Token.VIEW) {
                lexer.nextToken();
                privilege = "SHOW VIEW";
            } else {
                acceptIdentifier("DATABASES");
                privilege = "SHOW DATABASES";
            }
        } else if (identifierEquals("SHUTDOWN")) {
            lexer.nextToken();
            privilege = "SHUTDOWN";
        } else if (identifierEquals("SUPER")) {
            lexer.nextToken();
            privilege = "SUPER";
        } else if (identifierEquals("CONTROL")) {
            // sqlserver
            lexer.nextToken();
            privilege = "CONTROL";
        } else if (identifierEquals("IMPERSONATE")) {
            // sqlserver
            lexer.nextToken();
            privilege = "IMPERSONATE";
        }
        if (privilege != null) {
            SQLExpr expr = new SQLIdentifierExpr(privilege);
            if (lexer.token() == Token.LPAREN) {
                expr = this.exprParser.primaryRest(expr);
            }
            expr.setParent(parent);
            privileges.add(expr);
        }
        if (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            continue;
        }
        break;
    }
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 92 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class OdpsStatementParser method parsePrivileages.

protected void parsePrivileages(List<SQLExpr> privileges, SQLObject parent) {
    for (; ; ) {
        String privilege = null;
        if (lexer.token() == Token.ALL) {
            lexer.nextToken();
            privilege = "ALL";
        } else if (lexer.token() == Token.SELECT) {
            privilege = "SELECT";
            lexer.nextToken();
        } else if (lexer.token() == Token.UPDATE) {
            privilege = "UPDATE";
            lexer.nextToken();
        } else if (lexer.token() == Token.DELETE) {
            privilege = "DELETE";
            lexer.nextToken();
        } else if (lexer.token() == Token.INSERT) {
            privilege = "INSERT";
            lexer.nextToken();
        } else if (lexer.token() == Token.DROP) {
            lexer.nextToken();
            privilege = "DROP";
        } else if (lexer.token() == Token.ALTER) {
            lexer.nextToken();
            privilege = "ALTER";
        } else if (identifierEquals("DESCRIBE")) {
            privilege = "DESCRIBE";
            lexer.nextToken();
        } else if (identifierEquals("READ")) {
            privilege = "READ";
            lexer.nextToken();
        } else if (identifierEquals("WRITE")) {
            privilege = "WRITE";
            lexer.nextToken();
        } else if (identifierEquals("EXECUTE")) {
            lexer.nextToken();
            privilege = "EXECUTE";
        } else if (identifierEquals("LIST")) {
            lexer.nextToken();
            privilege = "LIST";
        } else if (identifierEquals("CreateTable")) {
            lexer.nextToken();
            privilege = "CreateTable";
        } else if (identifierEquals("CreateInstance")) {
            lexer.nextToken();
            privilege = "CreateInstance";
        } else if (identifierEquals("CreateFunction")) {
            lexer.nextToken();
            privilege = "CreateFunction";
        } else if (identifierEquals("CreateResource")) {
            lexer.nextToken();
            privilege = "CreateResource";
        } else if (identifierEquals("CreateJob")) {
            lexer.nextToken();
            privilege = "CreateJob";
        } else if (identifierEquals("CreateVolume")) {
            lexer.nextToken();
            privilege = "CreateVolume";
        } else if (identifierEquals("CreateOfflineModel")) {
            lexer.nextToken();
            privilege = "CreateOfflineModel";
        } else if (identifierEquals("CreateXflow")) {
            lexer.nextToken();
            privilege = "CreateXflow";
        }
        SQLExpr expr = null;
        if (privilege != null) {
            expr = new SQLIdentifierExpr(privilege);
        } else {
            expr = this.exprParser.expr();
        }
        expr.setParent(parent);
        privileges.add(expr);
        if (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            continue;
        }
        break;
    }
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 93 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class OracleExprParser method methodRest.

@Override
protected SQLExpr methodRest(SQLExpr expr, boolean acceptLPAREN) {
    if (acceptLPAREN) {
        accept(Token.LPAREN);
    }
    if (lexer.token() == Token.PLUS) {
        lexer.nextToken();
        accept(Token.RPAREN);
        return new OracleOuterExpr(expr);
    }
    if (expr instanceof SQLIdentifierExpr) {
        String methodName = ((SQLIdentifierExpr) expr).getName();
        SQLMethodInvokeExpr methodExpr = new SQLMethodInvokeExpr(methodName);
        if ("trim".equalsIgnoreCase(methodName)) {
            if (//
            identifierEquals("LEADING") || //
            identifierEquals("TRAILING") || identifierEquals("BOTH")) {
                methodExpr.putAttribute("trim_option", lexer.stringVal());
                lexer.nextToken();
            }
            if (lexer.token() != Token.FROM) {
                SQLExpr trim_character = this.primary();
                trim_character.setParent(methodExpr);
                if (trim_character instanceof SQLCharExpr) {
                    methodExpr.putAttribute("trim_character", trim_character);
                } else {
                    methodExpr.getParameters().add(trim_character);
                }
            }
            if (lexer.token() == Token.FROM) {
                lexer.nextToken();
                SQLExpr trim_source = this.expr();
                methodExpr.addParameter(trim_source);
            }
            accept(Token.RPAREN);
            return primaryRest(methodExpr);
        }
    }
    return super.methodRest(expr, false);
}
Also used : OracleOuterExpr(com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleOuterExpr) SQLCharExpr(com.alibaba.druid.sql.ast.expr.SQLCharExpr) SQLMethodInvokeExpr(com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 94 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class OracleExprParser method equalityRest.

public SQLExpr equalityRest(SQLExpr expr) {
    SQLExpr rightExp;
    if (lexer.token() == Token.EQ) {
        lexer.nextToken();
        if (lexer.token() == Token.GT) {
            lexer.nextToken();
            rightExp = expr();
            String argumentName = ((SQLIdentifierExpr) expr).getName();
            return new OracleArgumentExpr(argumentName, rightExp);
        }
        rightExp = shift();
        rightExp = equalityRest(rightExp);
        expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.Equality, rightExp, getDbType());
    } else if (lexer.token() == Token.BANGEQ) {
        lexer.nextToken();
        rightExp = shift();
        rightExp = equalityRest(rightExp);
        expr = new SQLBinaryOpExpr(expr, SQLBinaryOperator.NotEqual, rightExp, getDbType());
    }
    return expr;
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) OracleArgumentExpr(com.alibaba.druid.sql.dialect.oracle.ast.expr.OracleArgumentExpr)

Example 95 with SQLIdentifierExpr

use of com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr in project druid by alibaba.

the class OracleExprParser method dotRest.

protected SQLExpr dotRest(SQLExpr expr) {
    if (lexer.token() == Token.LITERAL_ALIAS) {
        String name = '"' + lexer.stringVal() + '"';
        lexer.nextToken();
        expr = new SQLPropertyExpr(expr, name);
        if (lexer.token() == Token.DOT) {
            lexer.nextToken();
            expr = dotRest(expr);
        }
        return expr;
    }
    if (identifierEquals("NEXTVAL")) {
        if (expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
            SQLSequenceExpr seqExpr = new SQLSequenceExpr(identExpr, SQLSequenceExpr.Function.NextVal);
            lexer.nextToken();
            return seqExpr;
        }
    } else if (identifierEquals("CURRVAL")) {
        if (expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
            SQLSequenceExpr seqExpr = new SQLSequenceExpr(identExpr, SQLSequenceExpr.Function.CurrVal);
            lexer.nextToken();
            return seqExpr;
        }
    }
    return super.dotRest(expr);
}
Also used : SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) SQLSequenceExpr(com.alibaba.druid.sql.ast.expr.SQLSequenceExpr)

Aggregations

SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)152 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)68 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)45 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)19 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)18 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)17 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)16 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)16 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)15 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)15 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)14 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)13 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)11 SQLAssignItem (com.alibaba.druid.sql.ast.statement.SQLAssignItem)11 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)10 SQLColumnDefinition (com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)10 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)10 SQLAllColumnExpr (com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr)9 ArrayList (java.util.ArrayList)9 SQLName (com.alibaba.druid.sql.ast.SQLName)8