Search in sources :

Example 1 with MySqlDeclareStatement

use of com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlDeclareStatement in project druid by alibaba.

the class MySqlStatementParser method parseDeclare.

/**
     * parse declare statement
     */
public MySqlDeclareStatement parseDeclare() {
    MySqlDeclareStatement stmt = new MySqlDeclareStatement();
    accept(Token.DECLARE);
    // lexer.nextToken();
    for (; ; ) {
        SQLDeclareItem item = new SQLDeclareItem();
        item.setName(exprParser.name());
        stmt.addVar(item);
        if (lexer.token() == Token.COMMA) {
            accept(Token.COMMA);
            continue;
        } else if (lexer.token() != Token.EOF) {
            // var type
            item.setDataType(exprParser.parseDataType());
            if (lexer.token() == Token.DEFAULT) {
                lexer.nextToken();
                SQLExpr defaultValue = this.exprParser.primary();
                item.setValue(defaultValue);
            }
            break;
        } else {
            throw new ParserException("TODO");
        }
    }
    return stmt;
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) MySqlDeclareStatement(com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlDeclareStatement) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLDeclareItem(com.alibaba.druid.sql.ast.SQLDeclareItem)

Aggregations

SQLDeclareItem (com.alibaba.druid.sql.ast.SQLDeclareItem)1 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 MySqlDeclareStatement (com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlDeclareStatement)1 ParserException (com.alibaba.druid.sql.parser.ParserException)1