mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improve sql parser for sql server
This commit is contained in:
+11
@@ -27,6 +27,8 @@ public class SQLServerInsertStatement extends SQLInsertStatement implements SQLS
|
||||
|
||||
private List<ValuesClause> valuesList = new ArrayList<ValuesClause>();
|
||||
|
||||
private boolean defaultValues;
|
||||
|
||||
public ValuesClause getValues() {
|
||||
if (valuesList.size() == 0) {
|
||||
return null;
|
||||
@@ -62,4 +64,13 @@ public class SQLServerInsertStatement extends SQLInsertStatement implements SQLS
|
||||
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public boolean isDefaultValues() {
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
public void setDefaultValues(boolean defaultValues) {
|
||||
this.defaultValues = defaultValues;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-5
@@ -18,6 +18,7 @@ package com.alibaba.druid.sql.dialect.sqlserver.parser;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
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.dialect.sqlserver.ast.SQLServerColumnDefinition;
|
||||
@@ -132,7 +133,7 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected SQLColumnDefinition createColumnDefinition() {
|
||||
SQLColumnDefinition column = new SQLServerColumnDefinition();
|
||||
return column;
|
||||
@@ -151,12 +152,18 @@ public class SQLServerExprParser extends SQLExprParser {
|
||||
SQLServerColumnDefinition.Identity identity = new SQLServerColumnDefinition.Identity();
|
||||
identity.setSeed((Integer) seed.getNumber());
|
||||
identity.setIncrement((Integer) increment.getNumber());
|
||||
|
||||
|
||||
if (lexer.token() == Token.NOT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.FOR);
|
||||
identifierEquals("REPLICATION ");
|
||||
identity.setNotForReplication(true);
|
||||
|
||||
if (lexer.token() == Token.NULL) {
|
||||
lexer.nextToken();
|
||||
column.setDefaultExpr(new SQLNullExpr());
|
||||
} else {
|
||||
accept(Token.FOR);
|
||||
identifierEquals("REPLICATION ");
|
||||
identity.setNotForReplication(true);
|
||||
}
|
||||
}
|
||||
|
||||
SQLServerColumnDefinition sqlSreverColumn = (SQLServerColumnDefinition) column;
|
||||
|
||||
+4
@@ -133,6 +133,10 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
} else if (acceptSubQuery && (lexer.token() == Token.SELECT || lexer.token() == Token.LPAREN)) {
|
||||
SQLQueryExpr queryExpr = (SQLQueryExpr) this.exprParser.expr();
|
||||
insertStatement.setQuery(queryExpr.getSubQuery());
|
||||
} else if (lexer.token() == Token.DEFAULT) {
|
||||
lexer.nextToken();
|
||||
accept(Token.VALUES);
|
||||
insertStatement.setDefaultValues(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -167,6 +167,10 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
println();
|
||||
x.getQuery().accept(this);
|
||||
}
|
||||
|
||||
if (x.isDefaultValues()) {
|
||||
print(" DEFAULT VALUES");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user