mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
@@ -15,16 +15,21 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCreateDatabaseStatement extends SQLStatementImpl {
|
||||
|
||||
private SQLName name;
|
||||
private SQLName name;
|
||||
|
||||
private String characterSet;
|
||||
private String collate;
|
||||
private String characterSet;
|
||||
private String collate;
|
||||
|
||||
private List<SQLCommentHint> hints;
|
||||
|
||||
public SQLCreateDatabaseStatement(){
|
||||
}
|
||||
@@ -61,4 +66,12 @@ public class SQLCreateDatabaseStatement extends SQLStatementImpl {
|
||||
this.collate = collate;
|
||||
}
|
||||
|
||||
public List<SQLCommentHint> getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
public void setHints(List<SQLCommentHint> hints) {
|
||||
this.hints = hints;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,13 +15,18 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLExplainStatement extends SQLStatementImpl {
|
||||
|
||||
protected SQLStatement statement;
|
||||
protected SQLStatement statement;
|
||||
|
||||
private List<SQLCommentHint> hints;
|
||||
|
||||
public SQLStatement getStatement() {
|
||||
return statement;
|
||||
@@ -41,4 +46,12 @@ public class SQLExplainStatement extends SQLStatementImpl {
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public List<SQLCommentHint> getHints() {
|
||||
return hints;
|
||||
}
|
||||
|
||||
public void setHints(List<SQLCommentHint> hints) {
|
||||
this.hints = hints;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2542,6 +2542,10 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
if (lexer.token() == Token.DEFAULT) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.HINT) {
|
||||
stmt.setHints(this.exprParser.parseHints());
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -1128,12 +1128,9 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(" WITH CONSISTENT SNAPSHOT");
|
||||
}
|
||||
|
||||
List<SQLCommentHint> hints = x.getHints();
|
||||
if (hints != null && !hints.isEmpty()) {
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(" ");
|
||||
for (SQLCommentHint hint : hints) {
|
||||
hint.accept(this);
|
||||
}
|
||||
printAndAccept(x.getHints(), " ");
|
||||
}
|
||||
|
||||
if (x.isBegin()) {
|
||||
@@ -2148,12 +2145,9 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
x.getTable().accept(this);
|
||||
}
|
||||
|
||||
List<SQLCommentHint> hints = x.getHints();
|
||||
if (hints != null && !hints.isEmpty()) {
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(" ");
|
||||
for (SQLCommentHint hint : hints) {
|
||||
hint.accept(this);
|
||||
}
|
||||
printAndAccept(x.getHints(), " ");
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -2690,12 +2684,9 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
print(x.getLockType().name);
|
||||
}
|
||||
|
||||
List<SQLCommentHint> hints = x.getHints();
|
||||
if (hints != null && !hints.isEmpty()) {
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(" ");
|
||||
for (SQLCommentHint hint : hints) {
|
||||
hint.accept(this);
|
||||
}
|
||||
printAndAccept(x.getHints(), " ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
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 SQLServerSetStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
|
||||
private SQLAssignItem item = new SQLAssignItem();
|
||||
|
||||
|
||||
public SQLServerSetStatement(){
|
||||
}
|
||||
|
||||
public SQLServerSetStatement(SQLExpr target, SQLExpr value){
|
||||
this.item = new SQLAssignItem(target, value);
|
||||
}
|
||||
|
||||
public SQLAssignItem getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(SQLAssignItem item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public void output(StringBuffer buf) {
|
||||
buf.append("SET ");
|
||||
item.output(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, this.item);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.sqlserver.ast.stmt;
|
||||
|
||||
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 SQLServerSetTransactionIsolationLevelStatement extends SQLServerObjectImpl implements SQLServerStatement {
|
||||
|
||||
private String level;
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
}
|
||||
+90
@@ -19,16 +19,21 @@ import java.util.List;
|
||||
|
||||
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.SQLInsertInto;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerTop;
|
||||
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;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetTransactionIsolationLevelStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement;
|
||||
import com.alibaba.druid.sql.parser.Lexer;
|
||||
import com.alibaba.druid.sql.parser.ParserException;
|
||||
import com.alibaba.druid.sql.parser.SQLSelectParser;
|
||||
import com.alibaba.druid.sql.parser.SQLStatementParser;
|
||||
import com.alibaba.druid.sql.parser.Token;
|
||||
@@ -181,4 +186,89 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
public SQLServerExprParser getExprParser() {
|
||||
return (SQLServerExprParser) exprParser;
|
||||
}
|
||||
|
||||
public SQLStatement parseSet() {
|
||||
accept(Token.SET);
|
||||
|
||||
if (identifierEquals("TRANSACTION")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("ISOLATION");
|
||||
acceptIdentifier("LEVEL");
|
||||
|
||||
SQLServerSetTransactionIsolationLevelStatement stmt = new SQLServerSetTransactionIsolationLevelStatement();
|
||||
|
||||
if (identifierEquals("READ")) {
|
||||
lexer.nextToken();
|
||||
|
||||
if (identifierEquals("UNCOMMITTED")) {
|
||||
stmt.setLevel("READ UNCOMMITTED");
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("COMMITTED")) {
|
||||
stmt.setLevel("READ COMMITTED");
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
|
||||
}
|
||||
} else if (identifierEquals("SERIALIZABLE")) {
|
||||
stmt.setLevel("SERIALIZABLE");
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("SNAPSHOT")) {
|
||||
stmt.setLevel("SNAPSHOT");
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("REPEATABLE")) {
|
||||
lexer.nextToken();
|
||||
if (identifierEquals("READ")) {
|
||||
stmt.setLevel("REPEATABLE READ");
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
|
||||
}
|
||||
} else {
|
||||
throw new ParserException("UNKOWN TRANSACTION LEVEL : " + lexer.stringVal());
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
if (identifierEquals("STATISTICS")) {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLServerSetStatement stmt = new SQLServerSetStatement();
|
||||
|
||||
if (identifierEquals("IO") || identifierEquals("XML") || identifierEquals("PROFILE")
|
||||
|| identifierEquals("TIME")) {
|
||||
stmt.getItem().setTarget(new SQLIdentifierExpr("STATISTICS " + lexer.stringVal().toUpperCase()));
|
||||
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.ON) {
|
||||
stmt.getItem().setValue(new SQLIdentifierExpr("ON"));
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("OFF")) {
|
||||
stmt.getItem().setValue(new SQLIdentifierExpr("OFF"));
|
||||
lexer.nextToken();
|
||||
}
|
||||
}
|
||||
return stmt;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.VARIANT) {
|
||||
SQLSetStatement stmt = new SQLSetStatement();
|
||||
parseAssignItems(stmt.getItems(), stmt);
|
||||
return stmt;
|
||||
} else {
|
||||
SQLServerSetStatement stmt = new SQLServerSetStatement();
|
||||
stmt.getItem().setTarget(this.exprParser.expr());
|
||||
|
||||
if (lexer.token() == Token.ON) {
|
||||
stmt.getItem().setValue(new SQLIdentifierExpr("ON"));
|
||||
lexer.nextToken();
|
||||
} else if (identifierEquals("OFF")) {
|
||||
stmt.getItem().setValue(new SQLIdentifierExpr("OFF"));
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
stmt.getItem().setValue(this.exprParser.expr());
|
||||
}
|
||||
return stmt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ 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.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetTransactionIsolationLevelStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
@@ -58,4 +60,11 @@ public interface SQLServerASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(SQLServerExecStatement x);
|
||||
|
||||
boolean visit(SQLServerSetTransactionIsolationLevelStatement x);
|
||||
|
||||
void endVisit(SQLServerSetTransactionIsolationLevelStatement x);
|
||||
|
||||
boolean visit(SQLServerSetStatement x);
|
||||
|
||||
void endVisit(SQLServerSetStatement x);
|
||||
}
|
||||
|
||||
+22
@@ -21,6 +21,8 @@ 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.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetTransactionIsolationLevelStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter;
|
||||
|
||||
@@ -106,4 +108,24 @@ public class SQLServerASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSetTransactionIsolationLevelStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSetTransactionIsolationLevelStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSetStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSetStatement x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+30
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
@@ -27,6 +28,8 @@ 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.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetTransactionIsolationLevelStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
|
||||
@@ -320,4 +323,31 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
public void endVisit(SQLServerExecStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSetTransactionIsolationLevelStatement x) {
|
||||
print("SET TRANSACTION ISOLATION LEVEL ");
|
||||
print(x.getLevel());
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSetTransactionIsolationLevelStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSetStatement x) {
|
||||
print("SET ");
|
||||
SQLAssignItem item = x.getItem();
|
||||
item.getTarget().accept(this);
|
||||
print(" ");
|
||||
item.getValue().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSetStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -17,6 +17,7 @@ package com.alibaba.druid.sql.dialect.sqlserver.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLHexExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
@@ -99,5 +100,13 @@ public class SQLServerParameterizedOutputVisitor extends SQLServerOutputVisitor
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLHexExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+22
@@ -27,6 +27,8 @@ 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.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerSetTransactionIsolationLevelStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerUpdateStatement;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
@@ -135,4 +137,24 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSetTransactionIsolationLevelStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSetTransactionIsolationLevelStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerSetStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerSetStatement x) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1534,8 +1534,13 @@ public class SQLStatementParser extends SQLParser {
|
||||
if (lexer.token() == Token.FOR) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
SQLExplainStatement explain = new SQLExplainStatement();
|
||||
|
||||
if(lexer.token == Token.HINT) {
|
||||
explain.setHints(this.exprParser.parseHints());
|
||||
}
|
||||
|
||||
explain.setStatement(parseStatement());
|
||||
|
||||
return explain;
|
||||
|
||||
@@ -1149,13 +1149,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
print("SET ");
|
||||
printAndAccept(x.getItems(), ", ");
|
||||
|
||||
List<SQLCommentHint> hints = x.getHints();
|
||||
if (hints != null && !hints.isEmpty()) {
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(" ");
|
||||
for (SQLCommentHint hint : hints) {
|
||||
hint.accept(this);
|
||||
}
|
||||
printAndAccept(x.getHints(), " ");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1770,6 +1768,10 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
@Override
|
||||
public boolean visit(SQLExplainStatement x) {
|
||||
print("EXPLAIN");
|
||||
if (x.getHints() != null && x.getHints().size() > 0) {
|
||||
print(" ");
|
||||
printAndAccept(x.getHints(), " ");
|
||||
}
|
||||
println();
|
||||
x.getStatement().accept(this);
|
||||
return false;
|
||||
|
||||
@@ -110,4 +110,22 @@ public class MySqlWallTest_hint extends TestCase {
|
||||
+ ") /*!40000 ENGINE=INNODB */ /*!40101 CHARACTER SET utf8 COLLATE utf8_general_ci */ ";
|
||||
Assert.assertTrue(WallUtils.isValidateMySql(sql, config)); //
|
||||
}
|
||||
|
||||
public void test_true_10() throws Exception {
|
||||
WallConfig config = new WallConfig();
|
||||
config.setHintAllow(true);
|
||||
config.setMultiStatementAllow(true);
|
||||
config.setNoneBaseStatementAllow(true);
|
||||
String sql = "CREATE DATABASE `newsfocus` /*!40100 COLLATE 'big5_chinese_ci' */ ";
|
||||
Assert.assertTrue(WallUtils.isValidateMySql(sql, config)); //
|
||||
}
|
||||
|
||||
public void test_true_11() throws Exception {
|
||||
WallConfig config = new WallConfig();
|
||||
config.setHintAllow(true);
|
||||
config.setMultiStatementAllow(true);
|
||||
config.setNoneBaseStatementAllow(true);
|
||||
String sql = "EXPLAIN /*!40100 EXTENDED */ SELECT * FROM trade_order_header WHERE id = ?";
|
||||
Assert.assertTrue(WallUtils.isValidateMySql(sql, config)); //
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 1999-2011 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.alibaba.druid.bvt.sql.sqlserver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.parser.SQLServerStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerSchemaStatVisitor;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class SQLServerSetTest extends TestCase {
|
||||
|
||||
public void test_0() {
|
||||
String sql = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals(1, stmtList.size());
|
||||
|
||||
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
System.out.println("Tables : " + visitor.getTables());
|
||||
System.out.println("fields : " + visitor.getColumns());
|
||||
System.out.println("coditions : " + visitor.getConditions());
|
||||
System.out.println("orderBy : " + visitor.getOrderByColumns());
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
|
||||
|
||||
Assert.assertEquals("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED", text);
|
||||
}
|
||||
|
||||
public void test_1() {
|
||||
String sql = "SET FMTONLY ON";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals(1, stmtList.size());
|
||||
|
||||
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
|
||||
|
||||
Assert.assertEquals("SET FMTONLY ON", text);
|
||||
}
|
||||
|
||||
public void test_2() {
|
||||
String sql = "SET STATISTICS XML OFF";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals(1, stmtList.size());
|
||||
|
||||
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
|
||||
|
||||
Assert.assertEquals("SET STATISTICS XML OFF", text);
|
||||
}
|
||||
|
||||
public void test_3() {
|
||||
String sql = "SET @state = N'Oregon'";
|
||||
|
||||
SQLServerStatementParser parser = new SQLServerStatementParser(sql);
|
||||
List<SQLStatement> stmtList = parser.parseStatementList();
|
||||
SQLStatement stmt = stmtList.get(0);
|
||||
|
||||
Assert.assertEquals(1, stmtList.size());
|
||||
|
||||
SQLServerSchemaStatVisitor visitor = new SQLServerSchemaStatVisitor();
|
||||
stmt.accept(visitor);
|
||||
|
||||
Assert.assertEquals(0, visitor.getTables().size());
|
||||
Assert.assertEquals(0, visitor.getColumns().size());
|
||||
Assert.assertEquals(0, visitor.getConditions().size());
|
||||
|
||||
String text = SQLUtils.toSQLString(stmtList, JdbcUtils.SQL_SERVER);
|
||||
|
||||
Assert.assertEquals("SET @state = N'Oregon'", text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user