Search in sources :

Example 1 with SQLSequenceExpr

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

the class DB2ExprParser method dotRest.

protected SQLExpr dotRest(SQLExpr 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("PREVVAL")) {
        if (expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
            SQLSequenceExpr seqExpr = new SQLSequenceExpr(identExpr, SQLSequenceExpr.Function.PrevVal);
            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) SQLSequenceExpr(com.alibaba.druid.sql.ast.expr.SQLSequenceExpr)

Example 2 with SQLSequenceExpr

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

the class DB2ExprParser method primaryRest.

public SQLExpr primaryRest(SQLExpr expr) {
    if (identifierEquals("VALUE")) {
        if (expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
            String ident = identExpr.getName();
            if (ident.equalsIgnoreCase("NEXT")) {
                lexer.nextToken();
                accept(Token.FOR);
                SQLName seqName = this.name();
                SQLSequenceExpr seqExpr = new SQLSequenceExpr(seqName, SQLSequenceExpr.Function.NextVal);
                return seqExpr;
            } else if (ident.equalsIgnoreCase("PREVIOUS")) {
                lexer.nextToken();
                accept(Token.FOR);
                SQLName seqName = this.name();
                SQLSequenceExpr seqExpr = new SQLSequenceExpr(seqName, SQLSequenceExpr.Function.PrevVal);
                return seqExpr;
            }
        }
    } else if (identifierEquals("DATE")) {
        if (expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
            String ident = identExpr.getName();
            if (ident.equalsIgnoreCase("CURRENT")) {
                lexer.nextToken();
                expr = new SQLIdentifierExpr("CURRENT DATE");
            }
        }
    } else if (identifierEquals("TIMESTAMP")) {
        if (expr instanceof SQLIdentifierExpr) {
            SQLIdentifierExpr identExpr = (SQLIdentifierExpr) expr;
            String ident = identExpr.getName();
            if (ident.equalsIgnoreCase("CURRENT")) {
                lexer.nextToken();
                expr = new SQLIdentifierExpr("CURRENT DATE");
            }
        }
    }
    return super.primaryRest(expr);
}
Also used : SQLName(com.alibaba.druid.sql.ast.SQLName) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) SQLSequenceExpr(com.alibaba.druid.sql.ast.expr.SQLSequenceExpr)

Example 3 with SQLSequenceExpr

use of com.alibaba.druid.sql.ast.expr.SQLSequenceExpr 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)3 SQLSequenceExpr (com.alibaba.druid.sql.ast.expr.SQLSequenceExpr)3 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)1