Search in sources :

Example 36 with SQLName

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

the class SQLServerOutputVisitor method visit.

@Override
public boolean visit(SQLServerExecStatement x) {
    print0(ucase ? "EXEC " : "exec ");
    SQLName returnStatus = x.getReturnStatus();
    if (returnStatus != null) {
        returnStatus.accept(this);
        print0(" = ");
    }
    SQLName moduleName = x.getModuleName();
    if (moduleName != null) {
        moduleName.accept(this);
        print(' ');
    } else {
        print0(" (");
    }
    printAndAccept(x.getParameters(), ", ");
    if (moduleName == null) {
        print(')');
    }
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 37 with SQLName

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

the class SQLCreateTableParser method parseCrateTable.

public SQLCreateTableStatement parseCrateTable(boolean acceptCreate) {
    if (acceptCreate) {
        accept(Token.CREATE);
    }
    SQLCreateTableStatement createTable = newCreateStatement();
    if (identifierEquals("GLOBAL")) {
        lexer.nextToken();
        if (identifierEquals("TEMPORARY")) {
            lexer.nextToken();
            createTable.setType(SQLCreateTableStatement.Type.GLOBAL_TEMPORARY);
        } else {
            throw new ParserException("syntax error " + lexer.token() + " " + lexer.stringVal());
        }
    } else if (lexer.token() == Token.IDENTIFIER && lexer.stringVal().equalsIgnoreCase("LOCAL")) {
        lexer.nextToken();
        if (lexer.token() == Token.IDENTIFIER && lexer.stringVal().equalsIgnoreCase("TEMPORAY")) {
            lexer.nextToken();
            createTable.setType(SQLCreateTableStatement.Type.LOCAL_TEMPORARY);
        } else {
            throw new ParserException("syntax error");
        }
    }
    accept(Token.TABLE);
    createTable.setName(this.exprParser.name());
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        for (; ; ) {
            if (//
            lexer.token() == Token.IDENTIFIER || lexer.token() == Token.LITERAL_ALIAS) {
                SQLColumnDefinition column = this.exprParser.parseColumn();
                createTable.getTableElementList().add(column);
            } else if (//
            lexer.token == Token.PRIMARY || //
            lexer.token == Token.UNIQUE || //
            lexer.token == Token.CHECK || lexer.token == Token.CONSTRAINT) {
                SQLConstraint constraint = this.exprParser.parseConstaint();
                constraint.setParent(createTable);
                createTable.getTableElementList().add((SQLTableElement) constraint);
            } else if (lexer.token() == Token.TABLESPACE) {
                throw new ParserException("TODO " + lexer.token());
            } else {
                SQLColumnDefinition column = this.exprParser.parseColumn();
                createTable.getTableElementList().add(column);
            }
            if (lexer.token() == Token.COMMA) {
                lexer.nextToken();
                if (lexer.token() == Token.RPAREN) {
                    // compatible for sql server
                    break;
                }
                continue;
            }
            break;
        }
        // while
        // (this.tokenList.current().equals(OracleToken.ConstraintToken)) {
        // parseConstaint(table.getConstraints());
        //
        // if (this.tokenList.current().equals(OracleToken.CommaToken))
        // ;
        // lexer.nextToken();
        // }
        accept(Token.RPAREN);
        if (identifierEquals("INHERITS")) {
            lexer.nextToken();
            accept(Token.LPAREN);
            SQLName inherits = this.exprParser.name();
            createTable.setInherits(new SQLExprTableSource(inherits));
            accept(Token.RPAREN);
        }
    }
    return createTable;
}
Also used : SQLCreateTableStatement(com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement) SQLConstraint(com.alibaba.druid.sql.ast.statement.SQLConstraint) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLTableElement(com.alibaba.druid.sql.ast.statement.SQLTableElement) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition)

Example 38 with SQLName

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

the class SQLStatementParser method parseDropTablespace.

protected SQLDropTableSpaceStatement parseDropTablespace(boolean acceptDrop) {
    SQLDropTableSpaceStatement stmt = new SQLDropTableSpaceStatement(getDbType());
    if (lexer.isKeepComments() && lexer.hasComment()) {
        stmt.addBeforeComment(lexer.readAndResetComments());
    }
    if (acceptDrop) {
        accept(Token.DROP);
    }
    accept(Token.TABLESPACE);
    if (lexer.token() == Token.IF) {
        lexer.nextToken();
        accept(Token.EXISTS);
        stmt.setIfExists(true);
    }
    SQLName name = this.exprParser.name();
    stmt.setName(name);
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 39 with SQLName

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

the class SQLStatementParser method parseDropTrigger.

protected SQLDropTriggerStatement parseDropTrigger(boolean acceptDrop) {
    if (acceptDrop) {
        accept(Token.DROP);
    }
    lexer.nextToken();
    SQLName name = this.exprParser.name();
    SQLDropTriggerStatement stmt = new SQLDropTriggerStatement(getDbType());
    stmt.setName(name);
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

Example 40 with SQLName

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

the class SQLStatementParser method parseAlterTableDropPartition.

protected SQLAlterTableDropPartition parseAlterTableDropPartition(boolean ifExists) {
    lexer.nextToken();
    SQLAlterTableDropPartition dropPartition = new SQLAlterTableDropPartition();
    dropPartition.setIfExists(ifExists);
    if (lexer.token() == Token.LPAREN) {
        accept(Token.LPAREN);
        parseAssignItems(dropPartition.getPartitions(), dropPartition);
        accept(Token.RPAREN);
        if (identifierEquals("PURGE")) {
            lexer.nextToken();
            dropPartition.setPurge(true);
        }
    } else {
        SQLName partition = this.exprParser.name();
        dropPartition.addPartition(partition);
    }
    return dropPartition;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName)

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