use of com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerDeclareStatement 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;
}
Aggregations