use of com.alibaba.druid.sql.ast.SQLDeclareItem 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;
}
use of com.alibaba.druid.sql.ast.SQLDeclareItem in project druid by alibaba.
the class SQLServerStatementParser method parseDeclare.
public SQLStatement parseDeclare() {
this.accept(Token.DECLARE);
SQLServerDeclareStatement declareStatement = new SQLServerDeclareStatement();
for (; ; ) {
SQLDeclareItem item = new SQLDeclareItem();
declareStatement.addItem(item);
item.setName(this.exprParser.name());
if (lexer.token() == Token.AS) {
lexer.nextToken();
}
if (lexer.token() == Token.TABLE) {
lexer.nextToken();
item.setType(SQLDeclareItem.Type.TABLE);
if (lexer.token() == Token.LPAREN) {
lexer.nextToken();
for (; ; ) {
if (//
lexer.token() == Token.IDENTIFIER || lexer.token() == Token.LITERAL_ALIAS) {
SQLColumnDefinition column = this.exprParser.parseColumn();
item.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(item);
item.getTableElementList().add((SQLTableElement) constraint);
} else if (lexer.token() == Token.TABLESPACE) {
throw new ParserException("TODO " + lexer.token());
} else {
SQLColumnDefinition column = this.exprParser.parseColumn();
item.getTableElementList().add(column);
}
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
if (lexer.token() == Token.RPAREN) {
break;
}
continue;
}
break;
}
accept(Token.RPAREN);
}
break;
} else if (lexer.token() == Token.CURSOR) {
item.setType(SQLDeclareItem.Type.CURSOR);
lexer.nextToken();
} else {
item.setType(SQLDeclareItem.Type.LOCAL);
item.setDataType(this.exprParser.parseDataType());
if (lexer.token() == Token.EQ) {
lexer.nextToken();
item.setValue(this.exprParser.expr());
}
}
if (lexer.token() == Token.COMMA) {
lexer.nextToken();
continue;
} else {
break;
}
}
return declareStatement;
}
use of com.alibaba.druid.sql.ast.SQLDeclareItem in project druid by alibaba.
the class SQLServerSchemaStatVisitor method visit.
@Override
public boolean visit(SQLServerDeclareStatement x) {
for (SQLDeclareItem item : x.getItems()) {
item.setParent(x);
SQLExpr name = item.getName();
this.variants.put(name.toString(), name);
}
return true;
}
use of com.alibaba.druid.sql.ast.SQLDeclareItem in project druid by alibaba.
the class MySqlSchemaStatVisitor method visit.
@Override
public boolean visit(MySqlDeclareStatement x) {
for (SQLDeclareItem item : x.getVarList()) {
item.setParent(x);
SQLName var = (SQLName) item.getName();
this.variants.put(var.toString(), var);
}
return false;
}
Aggregations