mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2014 Alibaba.com All right reserved. This software is the
|
||||
* confidential and proprietary information of Alibaba.com ("Confidential
|
||||
* Information"). You shall not disclose such Confidential Information and shall
|
||||
* use it only in accordance with the terms of the license agreement you entered
|
||||
* into with Alibaba.com.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.ast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerDeclareItem extends SQLServerObjectImpl {
|
||||
|
||||
protected Type type;
|
||||
|
||||
protected SQLExpr name;
|
||||
|
||||
protected SQLDataType dataType;
|
||||
|
||||
protected SQLExpr value;
|
||||
|
||||
protected List<SQLTableElement> tableElementList = new ArrayList<SQLTableElement>();
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.name);
|
||||
acceptChild(visitor, this.dataType);
|
||||
acceptChild(visitor, this.value);
|
||||
acceptChild(visitor, this.tableElementList);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExpr getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(SQLExpr name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public SQLDataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(SQLDataType dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public SQLExpr getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(SQLExpr value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public List<SQLTableElement> getTableElementList() {
|
||||
return tableElementList;
|
||||
}
|
||||
|
||||
public void setTableElementList(List<SQLTableElement> tableElementList) {
|
||||
this.tableElementList = tableElementList;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
TABLE, LOCAL, CURSOR;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2014 Alibaba.com All right reserved. This software is the
|
||||
* confidential and proprietary information of Alibaba.com ("Confidential
|
||||
* Information"). You shall not disclose such Confidential Information and shall
|
||||
* use it only in accordance with the terms of the license agreement you entered
|
||||
* into with Alibaba.com.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.ast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerOutput extends SQLServerObjectImpl {
|
||||
|
||||
protected SQLExprTableSource into;
|
||||
|
||||
protected final List<SQLExpr> columns = new ArrayList<SQLExpr>();
|
||||
|
||||
protected final List<SQLSelectItem> selectList = new ArrayList<SQLSelectItem>();
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
this.acceptChild(visitor, selectList);
|
||||
this.acceptChild(visitor, into);
|
||||
this.acceptChild(visitor, columns);
|
||||
}
|
||||
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLExprTableSource getInto() {
|
||||
return into;
|
||||
}
|
||||
|
||||
public void setInto(SQLExprTableSource into) {
|
||||
this.into = into;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getColumns() {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public List<SQLSelectItem> getSelectList() {
|
||||
return selectList;
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2014 Alibaba.com All right reserved. This software is the
|
||||
* confidential and proprietary information of Alibaba.com ("Confidential
|
||||
* Information"). You shall not disclose such Confidential Information and shall
|
||||
* use it only in accordance with the terms of the license agreement you entered
|
||||
* into with Alibaba.com.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.ast.stmt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerDeclareStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
|
||||
protected List<SQLServerDeclareItem> items = new ArrayList<SQLServerDeclareItem>();
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
this.acceptChild(visitor, items);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLServerDeclareItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public void setItems(List<SQLServerDeclareItem> items) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
}
|
||||
+24
@@ -20,6 +20,8 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerObject;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
@@ -29,6 +31,10 @@ public class SQLServerInsertStatement extends SQLInsertStatement implements SQLS
|
||||
|
||||
private boolean defaultValues;
|
||||
|
||||
private SQLServerTop top;
|
||||
|
||||
private SQLServerOutput output;
|
||||
|
||||
public ValuesClause getValues() {
|
||||
if (valuesList.size() == 0) {
|
||||
return null;
|
||||
@@ -56,8 +62,10 @@ public class SQLServerInsertStatement extends SQLInsertStatement implements SQLS
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
this.acceptChild(visitor, getTop());
|
||||
this.acceptChild(visitor, getTableSource());
|
||||
this.acceptChild(visitor, getColumns());
|
||||
this.acceptChild(visitor, getOutput());
|
||||
this.acceptChild(visitor, getValuesList());
|
||||
this.acceptChild(visitor, getQuery());
|
||||
}
|
||||
@@ -73,4 +81,20 @@ public class SQLServerInsertStatement extends SQLInsertStatement implements SQLS
|
||||
this.defaultValues = defaultValues;
|
||||
}
|
||||
|
||||
public SQLServerOutput getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public void setOutput(SQLServerOutput output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public SQLServerTop getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public void setTop(SQLServerTop top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-2
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.dialect.sqlserver.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
@@ -24,8 +25,9 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLServerUpdateStatement extends SQLUpdateStatement implements SQLServerStatement {
|
||||
|
||||
private SQLServerTop top;
|
||||
private SQLTableSource from;
|
||||
private SQLServerTop top;
|
||||
private SQLTableSource from;
|
||||
private SQLServerOutput output;
|
||||
|
||||
public SQLServerTop getTop() {
|
||||
return top;
|
||||
@@ -43,6 +45,14 @@ public class SQLServerUpdateStatement extends SQLUpdateStatement implements SQLS
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public SQLServerOutput getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
public void setOutput(SQLServerOutput output) {
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
this.accept0((SQLServerASTVisitor) visitor);
|
||||
@@ -54,6 +64,7 @@ public class SQLServerUpdateStatement extends SQLUpdateStatement implements SQLS
|
||||
acceptChild(visitor, top);
|
||||
acceptChild(visitor, tableSource);
|
||||
acceptChild(visitor, items);
|
||||
acceptChild(visitor, output);
|
||||
acceptChild(visitor, from);
|
||||
acceptChild(visitor, where);
|
||||
}
|
||||
|
||||
@@ -15,13 +15,19 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.parser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
@@ -133,6 +139,54 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected SQLServerOutput parserOutput() {
|
||||
if (identifierEquals("OUTPUT")) {
|
||||
lexer.nextToken();
|
||||
SQLServerOutput output = new SQLServerOutput();
|
||||
|
||||
final List<SQLSelectItem> selectList = output.getSelectList();
|
||||
for (;;) {
|
||||
final SQLSelectItem selectItem = parseSelectItem();
|
||||
selectList.add(selectItem);
|
||||
|
||||
if (lexer.token() != Token.COMMA) {
|
||||
break;
|
||||
}
|
||||
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.INTO) {
|
||||
lexer.nextToken();
|
||||
output.setInto(new SQLExprTableSource(this.name()));
|
||||
if (lexer.token() == (Token.LPAREN)) {
|
||||
lexer.nextToken();
|
||||
this.exprList(output.getColumns(), output);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected SQLSelectItem parseSelectItem() {
|
||||
SQLExpr expr;
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
expr = new SQLIdentifierExpr(lexer.stringVal());
|
||||
lexer.nextTokenComma();
|
||||
|
||||
if (lexer.token() != Token.COMMA) {
|
||||
expr = this.primaryRest(expr);
|
||||
expr = this.exprRest(expr);
|
||||
}
|
||||
} else {
|
||||
expr = this.expr();
|
||||
}
|
||||
final String alias = as();
|
||||
return new SQLSelectItem(expr, alias);
|
||||
}
|
||||
|
||||
protected SQLColumnDefinition createColumnDefinition() {
|
||||
SQLColumnDefinition column = new SQLServerColumnDefinition();
|
||||
|
||||
@@ -41,6 +41,7 @@ public class SQLServerLexer extends Lexer {
|
||||
map.put("WITH", Token.WITH);
|
||||
map.put("PERCENT", Token.PERCENT);
|
||||
map.put("IDENTITY", Token.IDENTITY);
|
||||
map.put("DECLARE", Token.DECLARE);
|
||||
|
||||
DEFAULT_SQL_SERVER_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
+105
-2
@@ -21,12 +21,18 @@ import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertInto;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableElement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerDeclareStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
@@ -76,9 +82,91 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
statementList.add(execStmt);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.DECLARE) {
|
||||
statementList.add(this.parseDeclare());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public SQLStatement parseDeclare() {
|
||||
this.accept(Token.DECLARE);
|
||||
|
||||
SQLServerDeclareStatement declareStatement = new SQLServerDeclareStatement();
|
||||
|
||||
for (;;) {
|
||||
SQLServerDeclareItem item = new SQLServerDeclareItem();
|
||||
declareStatement.getItems().add(item);
|
||||
|
||||
item.setName(this.exprParser.name());
|
||||
|
||||
if (lexer.token() == Token.AS) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.TABLE) {
|
||||
lexer.nextToken();
|
||||
item.setType(SQLServerDeclareItem.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(SQLServerDeclareItem.Type.CURSOR);
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
item.setType(SQLServerDeclareItem.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;
|
||||
}
|
||||
|
||||
public SQLStatement parseInsert() {
|
||||
SQLServerInsertStatement insertStatement = new SQLServerInsertStatement();
|
||||
@@ -93,6 +181,11 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
|
||||
protected void parseInsert0(SQLInsertInto insert, boolean acceptSubQuery) {
|
||||
SQLServerInsertStatement insertStatement = (SQLServerInsertStatement) insert;
|
||||
|
||||
SQLServerTop top = this.getExprParser().parseTop();
|
||||
if (top != null) {
|
||||
insertStatement.setTop(top);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.INTO) {
|
||||
lexer.nextToken();
|
||||
@@ -107,7 +200,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
|
||||
parseInsert0_hinits(insertStatement);
|
||||
|
||||
if (lexer.token() == Token.IDENTIFIER) {
|
||||
if (lexer.token() == Token.IDENTIFIER && !lexer.stringVal().equalsIgnoreCase("OUTPUT")) {
|
||||
insertStatement.setAlias(lexer.stringVal());
|
||||
lexer.nextToken();
|
||||
}
|
||||
@@ -117,6 +210,11 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
this.exprParser.exprList(insertStatement.getColumns(), insertStatement);
|
||||
accept(Token.RPAREN);
|
||||
}
|
||||
|
||||
SQLServerOutput output = this.getExprParser().parserOutput();
|
||||
if (output != null) {
|
||||
insertStatement.setOutput(output);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.VALUES) {
|
||||
lexer.nextToken();
|
||||
@@ -168,6 +266,11 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
udpateStatement.setTableSource(tableSource);
|
||||
|
||||
parseUpdateSet(udpateStatement);
|
||||
|
||||
SQLServerOutput output = this.getExprParser().parserOutput();
|
||||
if (output != null) {
|
||||
udpateStatement.setOutput(output);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.FROM) {
|
||||
lexer.nextToken();
|
||||
@@ -182,7 +285,7 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
|
||||
return udpateStatement;
|
||||
}
|
||||
|
||||
|
||||
public SQLServerExprParser getExprParser() {
|
||||
return (SQLServerExprParser) exprParser;
|
||||
}
|
||||
|
||||
+16
@@ -16,9 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerDeclareStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
@@ -67,4 +70,17 @@ public interface SQLServerASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(SQLServerSetStatement x);
|
||||
|
||||
void endVisit(SQLServerSetStatement x);
|
||||
|
||||
boolean visit(SQLServerOutput x);
|
||||
|
||||
void endVisit(SQLServerOutput x);
|
||||
|
||||
boolean visit(SQLServerDeclareItem x);
|
||||
|
||||
void endVisit(SQLServerDeclareItem x);
|
||||
|
||||
boolean visit(SQLServerDeclareStatement x);
|
||||
|
||||
void endVisit(SQLServerDeclareStatement x);
|
||||
|
||||
}
|
||||
|
||||
+33
@@ -16,9 +16,12 @@
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerDeclareStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
@@ -128,4 +131,34 @@ public class SQLServerASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerOutput x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerOutput x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareItem x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareItem x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareStatement x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+119
-4
@@ -23,9 +23,12 @@ import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition.Identity;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerDeclareStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
@@ -95,7 +98,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
boolean paren = false;
|
||||
|
||||
if (x.getParent() instanceof SQLServerUpdateStatement) {
|
||||
if (x.getParent() instanceof SQLServerUpdateStatement || x.getParent() instanceof SQLServerInsertStatement) {
|
||||
paren = true;
|
||||
print("(");
|
||||
}
|
||||
@@ -131,8 +134,16 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerInsertStatement x) {
|
||||
print("INSERT INTO ");
|
||||
print("INSERT ");
|
||||
|
||||
if (x.getTop() != null) {
|
||||
x.getTop().setParent(x);
|
||||
x.getTop().accept(this);
|
||||
print(' ');
|
||||
}
|
||||
|
||||
print("INTO ");
|
||||
|
||||
x.getTableSource().accept(this);
|
||||
|
||||
if (x.getColumns().size() > 0) {
|
||||
@@ -152,6 +163,12 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
print(")");
|
||||
decrementIndent();
|
||||
}
|
||||
|
||||
if (x.getOutput() != null) {
|
||||
println();
|
||||
x.getOutput().setParent(x);
|
||||
x.getOutput().accept(this);
|
||||
}
|
||||
|
||||
if (x.getValuesList().size() != 0) {
|
||||
println();
|
||||
@@ -170,7 +187,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
println();
|
||||
x.getQuery().accept(this);
|
||||
}
|
||||
|
||||
|
||||
if (x.isDefaultValues()) {
|
||||
print(" DEFAULT VALUES");
|
||||
}
|
||||
@@ -202,6 +219,12 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
}
|
||||
x.getItems().get(i).accept(this);
|
||||
}
|
||||
|
||||
if (x.getOutput() != null) {
|
||||
println();
|
||||
x.getOutput().setParent(x);
|
||||
x.getOutput().accept(this);
|
||||
}
|
||||
|
||||
if (x.getFrom() != null) {
|
||||
println();
|
||||
@@ -333,7 +356,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSetTransactionIsolationLevelStatement x) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -348,6 +371,98 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSetStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerOutput x) {
|
||||
print("OUTPUT ");
|
||||
printSelectList(x.getSelectList());
|
||||
|
||||
if (x.getInto() != null) {
|
||||
incrementIndent();
|
||||
println();
|
||||
print("INTO ");
|
||||
x.getInto().accept(this);
|
||||
|
||||
if (x.getColumns().size() > 0) {
|
||||
incrementIndent();
|
||||
println();
|
||||
print("(");
|
||||
for (int i = 0, size = x.getColumns().size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
if (i % 5 == 0) {
|
||||
println();
|
||||
}
|
||||
print(", ");
|
||||
}
|
||||
|
||||
x.getColumns().get(i).accept(this);
|
||||
}
|
||||
print(")");
|
||||
decrementIndent();
|
||||
}
|
||||
}
|
||||
decrementIndent();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerOutput x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareItem x) {
|
||||
x.getName().accept(this);
|
||||
|
||||
if(x.getType() == SQLServerDeclareItem.Type.TABLE) {
|
||||
print(" TABLE");
|
||||
int size = x.getTableElementList().size();
|
||||
|
||||
if (size > 0) {
|
||||
print(" (");
|
||||
incrementIndent();
|
||||
println();
|
||||
for (int i = 0; i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print(",");
|
||||
println();
|
||||
}
|
||||
x.getTableElementList().get(i).accept(this);
|
||||
}
|
||||
decrementIndent();
|
||||
println();
|
||||
print(")");
|
||||
}
|
||||
} else if (x.getType() == SQLServerDeclareItem.Type.CURSOR) {
|
||||
print(" CURSOR");
|
||||
} else {
|
||||
print(" ");
|
||||
x.getDataType().accept(this);
|
||||
if (x.getValue() != null) {
|
||||
print(" = ");
|
||||
x.getValue().accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareItem x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareStatement x) {
|
||||
print("DECLARE ");
|
||||
this.printAndAccept(x.getItems(), ", ");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -22,9 +22,12 @@ import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerColumnDefinition.Identity;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerDeclareItem;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerOutput;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.expr.SQLServerObjectReferenceExpr;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerDeclareStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
@@ -157,4 +160,34 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerOutput x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerOutput x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareItem x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareItem x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerDeclareStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerDeclareStatement x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user