Search in sources :

Example 81 with SQLName

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

the class OracleExprParser method parseDataType.

public SQLDataType parseDataType() {
    if (lexer.token() == Token.CONSTRAINT || lexer.token() == Token.COMMA) {
        return null;
    }
    if (lexer.token() == Token.DEFAULT || lexer.token() == Token.NOT || lexer.token() == Token.NULL) {
        return null;
    }
    if (lexer.token() == Token.INTERVAL) {
        lexer.nextToken();
        if (identifierEquals("YEAR")) {
            lexer.nextToken();
            OracleDataTypeIntervalYear interval = new OracleDataTypeIntervalYear();
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                interval.addArgument(this.expr());
                accept(Token.RPAREN);
            }
            accept(Token.TO);
            acceptIdentifier("MONTH");
            return interval;
        } else {
            acceptIdentifier("DAY");
            OracleDataTypeIntervalDay interval = new OracleDataTypeIntervalDay();
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                interval.addArgument(this.expr());
                accept(Token.RPAREN);
            }
            accept(Token.TO);
            acceptIdentifier("SECOND");
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                interval.getFractionalSeconds().add(this.expr());
                accept(Token.RPAREN);
            }
            return interval;
        }
    }
    String typeName;
    if (identifierEquals("LONG")) {
        lexer.nextToken();
        acceptIdentifier("RAW");
        typeName = "LONG RAW";
    } else {
        SQLName typeExpr = name();
        typeName = typeExpr.toString();
    }
    if ("TIMESTAMP".equalsIgnoreCase(typeName)) {
        OracleDataTypeTimestamp timestamp = new OracleDataTypeTimestamp();
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            timestamp.addArgument(this.expr());
            accept(Token.RPAREN);
        }
        if (lexer.token() == Token.WITH) {
            lexer.nextToken();
            if (identifierEquals("LOCAL")) {
                lexer.nextToken();
                timestamp.setWithLocalTimeZone(true);
            } else {
                timestamp.setWithTimeZone(true);
            }
            acceptIdentifier("TIME");
            acceptIdentifier("ZONE");
        }
        return timestamp;
    }
    if (isCharType(typeName)) {
        SQLCharacterDataType charType = new SQLCharacterDataType(typeName);
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            charType.addArgument(this.expr());
            if (identifierEquals("CHAR")) {
                lexer.nextToken();
                charType.setCharType(SQLCharacterDataType.CHAR_TYPE_CHAR);
            } else if (identifierEquals("BYTE")) {
                lexer.nextToken();
                charType.setCharType(SQLCharacterDataType.CHAR_TYPE_BYTE);
            }
            accept(Token.RPAREN);
        }
        return parseCharTypeRest(charType);
    }
    if (lexer.token() == Token.PERCENT) {
        lexer.nextToken();
        if (identifierEquals("TYPE")) {
            lexer.nextToken();
            typeName += "%TYPE";
        } else if (identifierEquals("ROWTYPE")) {
            lexer.nextToken();
            typeName += "%ROWTYPE";
        } else {
            throw new ParserException("syntax error : " + lexer.token() + " " + lexer.stringVal());
        }
    }
    SQLDataType dataType = new SQLDataTypeImpl(typeName);
    return parseDataTypeRest(dataType);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) OracleDataTypeIntervalYear(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear) OracleDataTypeTimestamp(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeTimestamp) SQLDataType(com.alibaba.druid.sql.ast.SQLDataType) SQLCharacterDataType(com.alibaba.druid.sql.ast.statement.SQLCharacterDataType) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl) OracleDataTypeIntervalDay(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay)

Example 82 with SQLName

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

the class MySqlSchemaStatVisitor method visit.

@Override
public boolean visit(MySqlReplaceStatement x) {
    setMode(x, Mode.Replace);
    setAliasMap();
    SQLName tableName = x.getTableName();
    String ident = null;
    if (tableName instanceof SQLIdentifierExpr) {
        ident = ((SQLIdentifierExpr) tableName).getName();
    } else if (tableName instanceof SQLPropertyExpr) {
        SQLPropertyExpr propertyExpr = (SQLPropertyExpr) tableName;
        if (propertyExpr.getOwner() instanceof SQLIdentifierExpr) {
            ident = propertyExpr.toString();
        }
    }
    if (ident != null) {
        setCurrentTable(x, ident);
        TableStat stat = getTableStat(ident);
        stat.incrementInsertCount();
        Map<String, String> aliasMap = getAliasMap();
        putAliasMap(aliasMap, ident, ident);
    }
    accept(x.getColumns());
    accept(x.getValuesList());
    accept(x.getQuery());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) TableStat(com.alibaba.druid.stat.TableStat) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)

Example 83 with SQLName

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

the class MySqlSchemaStatVisitor method visit.

@Override
public boolean visit(MySqlInsertStatement x) {
    setMode(x, Mode.Insert);
    setAliasMap();
    SQLName tableName = x.getTableName();
    String ident = null;
    if (tableName instanceof SQLIdentifierExpr) {
        ident = ((SQLIdentifierExpr) tableName).getName();
    } else if (tableName instanceof SQLPropertyExpr) {
        SQLPropertyExpr propertyExpr = (SQLPropertyExpr) tableName;
        if (propertyExpr.getOwner() instanceof SQLIdentifierExpr) {
            ident = propertyExpr.toString();
        }
    }
    if (ident != null) {
        setCurrentTable(x, ident);
        TableStat stat = getTableStat(ident);
        stat.incrementInsertCount();
        Map<String, String> aliasMap = getAliasMap();
        putAliasMap(aliasMap, x.getAlias(), ident);
        putAliasMap(aliasMap, ident, ident);
    }
    accept(x.getColumns());
    accept(x.getValuesList());
    accept(x.getQuery());
    accept(x.getDuplicateKeyUpdate());
    return false;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) TableStat(com.alibaba.druid.stat.TableStat) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)

Example 84 with SQLName

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

the class OdpsStatementParser method parseInsert.

public SQLStatement parseInsert() {
    OdpsInsertStatement stmt = new OdpsInsertStatement();
    if (lexer.token() == Token.FROM) {
        lexer.nextToken();
        if (lexer.token() == Token.IDENTIFIER) {
            SQLName tableName = this.exprParser.name();
            SQLExprTableSource from = new SQLExprTableSource(tableName);
            stmt.setFrom(from);
        } else {
            accept(Token.LPAREN);
            SQLSelectParser selectParser = createSQLSelectParser();
            SQLSelect select = selectParser.select();
            accept(Token.RPAREN);
            String alias = lexer.stringVal();
            accept(Token.IDENTIFIER);
            SQLSubqueryTableSource from = new SQLSubqueryTableSource(select, alias);
            stmt.setFrom(from);
        }
    }
    for (; ; ) {
        OdpsInsert insert = parseOdpsInsert();
        stmt.addItem(insert);
        if (lexer.token() != Token.INSERT) {
            break;
        }
    }
    return stmt;
}
Also used : SQLSubqueryTableSource(com.alibaba.druid.sql.ast.statement.SQLSubqueryTableSource) SQLSelectParser(com.alibaba.druid.sql.parser.SQLSelectParser) SQLSelect(com.alibaba.druid.sql.ast.statement.SQLSelect) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) OdpsInsert(com.alibaba.druid.sql.dialect.odps.ast.OdpsInsert) OdpsInsertStatement(com.alibaba.druid.sql.dialect.odps.ast.OdpsInsertStatement)

Example 85 with SQLName

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

the class MySqlStatementParser method parseDeallocatePrepare.

public MysqlDeallocatePrepareStatement parseDeallocatePrepare() {
    acceptIdentifier("DEALLOCATE");
    acceptIdentifier("PREPARE");
    MysqlDeallocatePrepareStatement stmt = new MysqlDeallocatePrepareStatement();
    SQLName statementName = exprParser.name();
    stmt.setStatementName(statementName);
    return stmt;
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) MysqlDeallocatePrepareStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement)

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