mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql parser.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package com.alibaba.druid.sql.ast;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 29/05/2017.
|
||||
*/
|
||||
public class SQLArgument extends SQLObjectImpl {
|
||||
private SQLParameter.ParameterType type;
|
||||
private SQLExpr expr;
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, expr);
|
||||
}
|
||||
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLParameter.ParameterType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public SQLExpr getExpr() {
|
||||
return expr;
|
||||
}
|
||||
|
||||
public void setType(SQLParameter.ParameterType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setExpr(SQLExpr expr) {
|
||||
if (expr != null) {
|
||||
expr.setParent(this);
|
||||
}
|
||||
this.expr = expr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 1999-2017 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.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLCommitStatement extends SQLStatementImpl {
|
||||
|
||||
// oracle
|
||||
private boolean write;
|
||||
private Boolean wait;
|
||||
private Boolean immediate;
|
||||
|
||||
// mysql
|
||||
private boolean work = false;
|
||||
private Boolean chain;
|
||||
private Boolean release;
|
||||
|
||||
// sql server
|
||||
private SQLExpr transactionName;
|
||||
private SQLExpr delayedDurability;
|
||||
|
||||
public void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor.visit(this)) {
|
||||
acceptChild(visitor, transactionName);
|
||||
acceptChild(visitor, delayedDurability);
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
// oracle
|
||||
public boolean isWrite() {
|
||||
return write;
|
||||
}
|
||||
|
||||
public void setWrite(boolean write) {
|
||||
this.write = write;
|
||||
}
|
||||
|
||||
public Boolean getWait() {
|
||||
return wait;
|
||||
}
|
||||
|
||||
public void setWait(Boolean wait) {
|
||||
this.wait = wait;
|
||||
}
|
||||
|
||||
public Boolean getImmediate() {
|
||||
return immediate;
|
||||
}
|
||||
|
||||
public void setImmediate(Boolean immediate) {
|
||||
this.immediate = immediate;
|
||||
}
|
||||
|
||||
// mysql
|
||||
public Boolean getChain() {
|
||||
return chain;
|
||||
}
|
||||
|
||||
public void setChain(Boolean chain) {
|
||||
this.chain = chain;
|
||||
}
|
||||
|
||||
public Boolean getRelease() {
|
||||
return release;
|
||||
}
|
||||
|
||||
public void setRelease(Boolean release) {
|
||||
this.release = release;
|
||||
}
|
||||
|
||||
public boolean isWork() {
|
||||
return work;
|
||||
}
|
||||
|
||||
public void setWork(boolean work) {
|
||||
this.work = work;
|
||||
}
|
||||
|
||||
// sql server
|
||||
public SQLExpr getTransactionName() {
|
||||
return transactionName;
|
||||
}
|
||||
|
||||
public void setTransactionName(SQLExpr transactionName) {
|
||||
if (transactionName != null) {
|
||||
transactionName.setParent(this);
|
||||
}
|
||||
this.transactionName = transactionName;
|
||||
}
|
||||
|
||||
public SQLExpr getDelayedDurability() {
|
||||
return delayedDurability;
|
||||
}
|
||||
|
||||
public void setDelayedDurability(SQLExpr delayedDurability) {
|
||||
if (delayedDurability != null) {
|
||||
delayedDurability.setParent(this);
|
||||
}
|
||||
this.delayedDurability = delayedDurability;
|
||||
}
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2017 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.mysql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
|
||||
public class MySqlCommitStatement extends MySqlStatementImpl {
|
||||
|
||||
private boolean work = false;
|
||||
|
||||
private Boolean chain;
|
||||
private Boolean release;
|
||||
|
||||
public Boolean getChain() {
|
||||
return chain;
|
||||
}
|
||||
|
||||
public void setChain(Boolean chain) {
|
||||
this.chain = chain;
|
||||
}
|
||||
|
||||
public Boolean getRelease() {
|
||||
return release;
|
||||
}
|
||||
|
||||
public void setRelease(Boolean release) {
|
||||
this.release = release;
|
||||
}
|
||||
|
||||
public boolean isWork() {
|
||||
return work;
|
||||
}
|
||||
|
||||
public void setWork(boolean work) {
|
||||
this.work = work;
|
||||
}
|
||||
|
||||
public void accept0(MySqlASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
@@ -34,56 +34,8 @@ import com.alibaba.druid.sql.ast.expr.SQLLiteralExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAnalyzePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableCheckPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableCoalescePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableConvertCharSet;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableKeys;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDiscardPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropColumnItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropForeignKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropIndex;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableDropPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableEnableKeys;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableImportPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableOptimizePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableReOrganizePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRebuildPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableRepairPartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableTruncatePartition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLBlockStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateDatabaseStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateProcedureStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLIfStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLLoopStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLPrimaryKey;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSetStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLShowTablesStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLStartTransactionStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnique;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MysqlForeignKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.ConditionValue;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.ConditionValue.ConditionType;
|
||||
@@ -98,7 +50,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlIterateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlLeaveStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlRepeatStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.clause.MySqlSelectIntoStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLWhileStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.CobarShowStatus;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableAlterColumn;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableChangeColumn;
|
||||
@@ -110,7 +61,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement;
|
||||
@@ -1728,10 +1678,10 @@ public class MySqlStatementParser extends SQLStatementParser {
|
||||
return stmt;
|
||||
}
|
||||
|
||||
public MySqlCommitStatement parseCommit() {
|
||||
public SQLStatement parseCommit() {
|
||||
acceptIdentifier("COMMIT");
|
||||
|
||||
MySqlCommitStatement stmt = new MySqlCommitStatement();
|
||||
SQLCommitStatement stmt = new SQLCommitStatement();
|
||||
|
||||
if (identifierEquals("WORK")) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -50,7 +50,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement;
|
||||
@@ -192,10 +191,6 @@ public interface MySqlASTVisitor extends SQLASTVisitor {
|
||||
|
||||
boolean visit(MySqlReplaceStatement x);
|
||||
|
||||
void endVisit(MySqlCommitStatement x);
|
||||
|
||||
boolean visit(MySqlCommitStatement x);
|
||||
|
||||
void endVisit(MySqlRollbackStatement x);
|
||||
|
||||
boolean visit(MySqlRollbackStatement x);
|
||||
|
||||
@@ -50,7 +50,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
@@ -282,17 +281,6 @@ public class MySqlASTVisitorAdapter extends SQLASTVisitorAdapter implements MySq
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCommitStatement x) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlRollbackStatement x) {
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
@@ -1224,38 +1223,6 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCommitStatement x) {
|
||||
print0(ucase ? "COMMIT" : "commit");
|
||||
|
||||
if (x.isWork()) {
|
||||
print0(ucase ? " WORK" : " work");
|
||||
}
|
||||
|
||||
if (x.getChain() != null) {
|
||||
if (x.getChain().booleanValue()) {
|
||||
print0(ucase ? " AND CHAIN" : " and chain");
|
||||
} else {
|
||||
print0(ucase ? " AND NO CHAIN" : " and no chain");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getRelease() != null) {
|
||||
if (x.getRelease().booleanValue()) {
|
||||
print0(ucase ? " AND RELEASE" : " and release");
|
||||
} else {
|
||||
print0(ucase ? " AND NO RELEASE" : " and no release");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlRollbackStatement x) {
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterTableOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAlterUserStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlAnalyzeStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlBinlogStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement.TableSpaceOption;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateUserStatement;
|
||||
@@ -411,17 +410,6 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCommitStatement x) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(MySqlRollbackStatement x) {
|
||||
|
||||
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2017 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.oracle.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
|
||||
public class OracleCommitStatement extends OracleStatementImpl {
|
||||
|
||||
private boolean write;
|
||||
private Boolean wait;
|
||||
private Boolean immediate;
|
||||
|
||||
@Override
|
||||
public void accept0(OracleASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public boolean isWrite() {
|
||||
return write;
|
||||
}
|
||||
|
||||
public void setWrite(boolean write) {
|
||||
this.write = write;
|
||||
}
|
||||
|
||||
public Boolean getWait() {
|
||||
return wait;
|
||||
}
|
||||
|
||||
public void setWait(Boolean wait) {
|
||||
this.wait = wait;
|
||||
}
|
||||
|
||||
public Boolean getImmediate() {
|
||||
return immediate;
|
||||
}
|
||||
|
||||
public void setImmediate(Boolean immediate) {
|
||||
this.immediate = immediate;
|
||||
}
|
||||
|
||||
}
|
||||
+26
-4
@@ -15,13 +15,23 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.oracle.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLArgument;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OracleExecuteImmediateStatement extends OracleStatementImpl {
|
||||
|
||||
private SQLCharExpr dynamicSql;
|
||||
private SQLExpr dynamicSql;
|
||||
|
||||
private final List<SQLArgument> arguments = new ArrayList<SQLArgument>();
|
||||
|
||||
private final List<SQLExpr> into = new ArrayList<SQLExpr>();
|
||||
|
||||
private final List<SQLExpr> returnInto = new ArrayList<SQLExpr>();
|
||||
|
||||
public OracleExecuteImmediateStatement(){
|
||||
}
|
||||
@@ -38,11 +48,11 @@ public class OracleExecuteImmediateStatement extends OracleStatementImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
public SQLCharExpr getDynamicSql() {
|
||||
public SQLExpr getDynamicSql() {
|
||||
return dynamicSql;
|
||||
}
|
||||
|
||||
public void setDynamicSql(SQLCharExpr dynamicSql) {
|
||||
public void setDynamicSql(SQLExpr dynamicSql) {
|
||||
if (dynamicSql != null) {
|
||||
dynamicSql.setParent(this);
|
||||
}
|
||||
@@ -52,4 +62,16 @@ public class OracleExecuteImmediateStatement extends OracleStatementImpl {
|
||||
public void setDynamicSql(String dynamicSql) {
|
||||
this.setDynamicSql(new SQLCharExpr(dynamicSql));
|
||||
}
|
||||
|
||||
public List<SQLArgument> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getInto() {
|
||||
return into;
|
||||
}
|
||||
|
||||
public List<SQLExpr> getReturnInto() {
|
||||
return returnInto;
|
||||
}
|
||||
}
|
||||
|
||||
+51
-5
@@ -402,7 +402,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
if (identifierEquals("WORK")) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
OracleCommitStatement stmt = new OracleCommitStatement();
|
||||
SQLCommitStatement stmt = new SQLCommitStatement();
|
||||
stmt.setParent(parent);
|
||||
|
||||
if (identifierEquals("WRITE")) {
|
||||
@@ -623,9 +623,54 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
lexer.nextToken();
|
||||
|
||||
OracleExecuteImmediateStatement stmt = new OracleExecuteImmediateStatement();
|
||||
String dyanmiacSql = lexer.stringVal();
|
||||
accept(Token.LITERAL_CHARS);
|
||||
|
||||
SQLExpr dyanmiacSql = this.exprParser.primary();
|
||||
stmt.setDynamicSql(dyanmiacSql);
|
||||
|
||||
if (lexer.token() == Token.INTO) {
|
||||
lexer.nextToken();
|
||||
|
||||
this.exprParser.exprList(stmt.getInto(), stmt);
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.USING) {
|
||||
lexer.nextToken();
|
||||
|
||||
for (;;) {
|
||||
SQLArgument arg = new SQLArgument();
|
||||
|
||||
if (lexer.token() == Token.IN) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.OUT) {
|
||||
lexer.nextToken();
|
||||
arg.setType(SQLParameter.ParameterType.INOUT);
|
||||
} else {
|
||||
arg.setType(SQLParameter.ParameterType.IN);
|
||||
}
|
||||
} else if (lexer.token() == Token.OUT) {
|
||||
lexer.nextToken();
|
||||
arg.setType(SQLParameter.ParameterType.OUT);
|
||||
}
|
||||
|
||||
arg.setExpr(this.exprParser.primary());
|
||||
arg.setParent(stmt);
|
||||
stmt.getArguments().add(arg);
|
||||
|
||||
if (lexer.token() == Token.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.RETURNING) {
|
||||
lexer.nextToken();
|
||||
accept(Token.INTO);
|
||||
|
||||
this.exprParser.exprList(stmt.getReturnInto(), stmt);
|
||||
}
|
||||
|
||||
return stmt;
|
||||
}
|
||||
throw new ParserException("TODO : " + lexer.info());
|
||||
@@ -1457,7 +1502,7 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
SQLParameter parameter = new SQLParameter();
|
||||
|
||||
SQLName name;
|
||||
SQLDataType dataType;
|
||||
SQLDataType dataType = null;
|
||||
if (lexer.token() == Token.CURSOR) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -1557,7 +1602,8 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
parameter.setDataType(dataType);
|
||||
|
||||
parameters.add(parameter);
|
||||
if (lexer.token() == Token.COMMA || lexer.token() == Token.SEMI) {
|
||||
Token token = lexer.token();
|
||||
if (token == Token.COMMA || token == Token.SEMI) {
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
@@ -345,10 +345,6 @@ public interface OracleASTVisitor extends SQLASTVisitor {
|
||||
|
||||
void endVisit(OracleLabelStatement x);
|
||||
|
||||
boolean visit(OracleCommitStatement x);
|
||||
|
||||
void endVisit(OracleCommitStatement x);
|
||||
|
||||
boolean visit(OracleAlterTriggerStatement x);
|
||||
|
||||
void endVisit(OracleAlterTriggerStatement x);
|
||||
|
||||
-10
@@ -827,16 +827,6 @@ public class OracleASTVisitorAdapter extends SQLASTVisitorAdapter implements Ora
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleCommitStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleAlterTriggerStatement x) {
|
||||
return true;
|
||||
|
||||
+18
-31
@@ -2240,37 +2240,6 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleCommitStatement x) {
|
||||
print0(ucase ? "COMMIT" : "commit");
|
||||
|
||||
if (x.isWrite()) {
|
||||
print0(ucase ? " WRITE" : " write");
|
||||
if (x.getWait() != null) {
|
||||
if (x.getWait().booleanValue()) {
|
||||
print0(ucase ? " WAIT" : " wait");
|
||||
} else {
|
||||
print0(ucase ? " NOWAIT" : " nowait");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getImmediate() != null) {
|
||||
if (x.getImmediate().booleanValue()) {
|
||||
print0(ucase ? " IMMEDIATE" : " immediate");
|
||||
} else {
|
||||
print0(ucase ? " BATCH" : " batch");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleAlterTriggerStatement x) {
|
||||
print0(ucase ? "ALTER TRIGGER " : "alter trigger ");
|
||||
@@ -3226,6 +3195,24 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
public boolean visit(OracleExecuteImmediateStatement x) {
|
||||
print0(ucase ? "EXECUTE IMMEDIATE " : "execute immediate ");
|
||||
x.getDynamicSql().accept(this);
|
||||
|
||||
List<SQLExpr> into = x.getInto();
|
||||
if (into.size() > 0) {
|
||||
print0(ucase ? " INTO " : " into ");
|
||||
printAndAccept(into, ", ");
|
||||
}
|
||||
|
||||
List<SQLArgument> using = x.getArguments();
|
||||
if (using.size() > 0) {
|
||||
print0(ucase ? " USING " : " using ");
|
||||
printAndAccept(using, ", ");
|
||||
}
|
||||
|
||||
List<SQLExpr> returnInto = x.getReturnInto();
|
||||
if (returnInto.size() > 0) {
|
||||
print0(ucase ? " RETURNNING INTO " : " returnning into ");
|
||||
printAndAccept(returnInto, ", ");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+69
-33
@@ -24,24 +24,13 @@ import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCheck;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateIndexStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeleteStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeInsertClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeUpdateClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelect;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnique;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeTimestamp;
|
||||
@@ -86,7 +75,6 @@ import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectPivot.Item;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectRestriction.CheckOption;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectRestriction.ReadOnly;
|
||||
import com.alibaba.druid.sql.parser.SQLParserUtils;
|
||||
import com.alibaba.druid.sql.visitor.SchemaStatVisitor;
|
||||
import com.alibaba.druid.stat.TableStat;
|
||||
import com.alibaba.druid.stat.TableStat.Column;
|
||||
@@ -280,19 +268,24 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
}
|
||||
|
||||
public boolean visit(SQLIdentifierExpr x) {
|
||||
if ("ROWNUM".equalsIgnoreCase(x.getName())) {
|
||||
String name = x.getName();
|
||||
if ("ROWNUM".equalsIgnoreCase(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("SYSDATE".equalsIgnoreCase(x.getName())) {
|
||||
if ("SYSDATE".equalsIgnoreCase(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("+".equalsIgnoreCase(x.getName())) {
|
||||
if ("+".equalsIgnoreCase(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("LEVEL".equals(x.getName())) {
|
||||
if ("LEVEL".equals(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("SQLCODE".equalsIgnoreCase(name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -910,7 +903,23 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
@Override
|
||||
public boolean visit(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExceptionStatement.Item x) {
|
||||
return true;
|
||||
SQLExpr when = x.getWhen();
|
||||
if (when instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr ident = (SQLIdentifierExpr) when;
|
||||
if (ident.getName().equalsIgnoreCase("OTHERS")) {
|
||||
// skip
|
||||
} else {
|
||||
this.visit(ident);
|
||||
}
|
||||
} else if (when != null) {
|
||||
when.accept(this);
|
||||
}
|
||||
|
||||
for (SQLStatement stmt : x.getStatements()) {
|
||||
stmt.accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1163,16 +1172,6 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleCommitStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(OracleCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleAlterTriggerStatement x) {
|
||||
return false;
|
||||
@@ -1453,11 +1452,48 @@ public class OracleSchemaStatVisitor extends SchemaStatVisitor implements Oracle
|
||||
|
||||
@Override
|
||||
public boolean visit(OracleExecuteImmediateStatement x) {
|
||||
String sql = x.getDynamicSql().getText();
|
||||
SQLExpr dynamicSql = x.getDynamicSql();
|
||||
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, getDbType());
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(this);
|
||||
String sql = null;
|
||||
|
||||
if (dynamicSql instanceof SQLIdentifierExpr) {
|
||||
String varName = ((SQLIdentifierExpr) dynamicSql).getName();
|
||||
|
||||
SQLExpr valueExpr = null;
|
||||
if (x.getParent() instanceof SQLBlockStatement) {
|
||||
List<SQLStatement> statementList = ((SQLBlockStatement) x.getParent()).getStatementList();
|
||||
for (int i = 0, size = statementList.size(); i < size; ++i) {
|
||||
SQLStatement stmt = statementList.get(i);
|
||||
if (stmt == x) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (stmt instanceof SQLSetStatement) {
|
||||
List<SQLAssignItem> items = ((SQLSetStatement) stmt).getItems();
|
||||
for (SQLAssignItem item : items) {
|
||||
if (item.getTarget().equals(dynamicSql)) {
|
||||
valueExpr = item.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (valueExpr != null) {
|
||||
dynamicSql = valueExpr;
|
||||
}
|
||||
}
|
||||
|
||||
if (dynamicSql instanceof SQLCharExpr) {
|
||||
sql = ((SQLCharExpr) dynamicSql).getText();
|
||||
}
|
||||
|
||||
if (sql != null) {
|
||||
List<SQLStatement> stmtList = SQLUtils.parseStatements(sql, getDbType());
|
||||
for (SQLStatement stmt : stmtList) {
|
||||
stmt.accept(this);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2017 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.postgresql.ast.stmt;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
public class PGBeginStatement extends SQLStatementImpl implements PGSQLStatement {
|
||||
public final boolean isBegin;
|
||||
|
||||
public PGBeginStatement(boolean isBegin) {
|
||||
super(JdbcConstants.POSTGRESQL);
|
||||
this.isBegin = isBegin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
if (visitor instanceof PGASTVisitor) {
|
||||
accept0((PGASTVisitor) visitor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(PGASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -20,11 +20,8 @@ import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
// 暂时不支持END命令
|
||||
public class PGCommitStatement extends SQLStatementImpl implements PGSQLStatement {
|
||||
|
||||
// COMMIT
|
||||
public PGCommitStatement() {
|
||||
public class PGStartTransactionStatement extends SQLStatementImpl implements PGSQLStatement {
|
||||
public PGStartTransactionStatement() {
|
||||
super(JdbcConstants.POSTGRESQL);
|
||||
}
|
||||
|
||||
+11
-23
@@ -39,14 +39,12 @@ import com.alibaba.druid.sql.parser.Token;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PGSQLStatementParser extends SQLStatementParser {
|
||||
public static final String TIME_ZONE = "TIME ZONE";
|
||||
public static final String TIME = "TIME";
|
||||
public static final String LOCAL = "LOCAL";
|
||||
public static final String TRANSACTION = "TRANSACTION";
|
||||
|
||||
|
||||
public PGSQLStatementParser(PGExprParser parser) {
|
||||
super(parser);
|
||||
}
|
||||
@@ -222,11 +220,14 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
|
||||
public boolean parseStatementListDialect(List<SQLStatement> statementList) {
|
||||
switch (lexer.token()) {
|
||||
case BEGIN:
|
||||
statementList.add(handleBegin());
|
||||
case START: {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("TRANSACTION");
|
||||
PGStartTransactionStatement stmt = new PGStartTransactionStatement();
|
||||
statementList.add(stmt);
|
||||
lexer.nextToken();
|
||||
return true;
|
||||
case START:
|
||||
return handleStart(statementList);
|
||||
}
|
||||
case WITH:
|
||||
statementList.add(parseWith());
|
||||
return true;
|
||||
@@ -235,21 +236,7 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
}
|
||||
}
|
||||
|
||||
private SQLStatement handleBegin() {
|
||||
SQLStatement statement = new PGBeginStatement(true);
|
||||
lexer.nextToken();
|
||||
return statement;
|
||||
}
|
||||
|
||||
private boolean handleStart(List<SQLStatement> statementList) {
|
||||
lexer.nextToken();
|
||||
if (lexer.token() == Token.IDENTIFIER && TRANSACTION.equalsIgnoreCase(lexer.stringVal())) {
|
||||
statementList.add(new PGBeginStatement(false));
|
||||
lexer.nextToken();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public PGWithClause parseWithClause() {
|
||||
lexer.nextToken();
|
||||
@@ -417,9 +404,10 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
|
||||
@Override
|
||||
public SQLStatement parseCommit() {
|
||||
SQLStatement statment = new PGCommitStatement();
|
||||
SQLCommitStatement stmt = new SQLCommitStatement();
|
||||
stmt.setDbType(this.dbType);
|
||||
lexer.nextToken();
|
||||
return statment;
|
||||
return stmt;
|
||||
}
|
||||
|
||||
private SQLStatement handleTimeZoneSet(String range) {
|
||||
|
||||
@@ -119,13 +119,9 @@ public interface PGASTVisitor extends SQLASTVisitor {
|
||||
|
||||
boolean visit(PGShowStatement x);
|
||||
|
||||
void endVisit(PGBeginStatement x);
|
||||
void endVisit(PGStartTransactionStatement x);
|
||||
|
||||
boolean visit(PGBeginStatement x);
|
||||
|
||||
void endVisit(PGCommitStatement x);
|
||||
|
||||
boolean visit(PGCommitStatement x);
|
||||
boolean visit(PGStartTransactionStatement x);
|
||||
|
||||
void endVisit(PGSetStatement x);
|
||||
|
||||
|
||||
+2
-12
@@ -282,22 +282,12 @@ public class PGASTVisitorAdapter extends SQLASTVisitorAdapter implements PGASTVi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGBeginStatement x) {
|
||||
public void endVisit(PGStartTransactionStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGBeginStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGCommitStatement x) {
|
||||
public boolean visit(PGStartTransactionStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+3
-14
@@ -637,24 +637,13 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGBeginStatement x) {
|
||||
public void endVisit(PGStartTransactionStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGBeginStatement x) {
|
||||
print0(x.isBegin ? "BEGIN" : "START TRANSACTION");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGCommitStatement x) {
|
||||
print0(ucase ? "COMMIT" : "commit");
|
||||
public boolean visit(PGStartTransactionStatement x) {
|
||||
print0(ucase ? "START TRANSACTION" : "start transaction");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+2
-12
@@ -396,22 +396,12 @@ public class PGSchemaStatVisitor extends SchemaStatVisitor implements PGASTVisit
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGBeginStatement x) {
|
||||
public void endVisit(PGStartTransactionStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGBeginStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(PGCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(PGCommitStatement x) {
|
||||
public boolean visit(PGStartTransactionStatement x) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2017 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.dialect.sqlserver.ast.SQLServerObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerStatementImpl;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.visitor.SQLServerASTVisitor;
|
||||
|
||||
public class SQLServerCommitStatement extends SQLServerStatementImpl implements SQLServerStatement {
|
||||
|
||||
private boolean work = false;
|
||||
|
||||
private SQLExpr transactionName;
|
||||
|
||||
private SQLExpr delayedDurability;
|
||||
|
||||
public boolean isWork() {
|
||||
return work;
|
||||
}
|
||||
|
||||
public void setWork(boolean work) {
|
||||
this.work = work;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept0(SQLServerASTVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
|
||||
visitor.endVisit(this);
|
||||
|
||||
}
|
||||
|
||||
public SQLExpr getTransactionName() {
|
||||
return transactionName;
|
||||
}
|
||||
|
||||
public void setTransactionName(SQLExpr transactionName) {
|
||||
this.transactionName = transactionName;
|
||||
}
|
||||
|
||||
public SQLExpr getDelayedDurability() {
|
||||
return delayedDurability;
|
||||
}
|
||||
|
||||
public void setDelayedDurability(SQLExpr delayedDurability) {
|
||||
this.delayedDurability = delayedDurability;
|
||||
}
|
||||
}
|
||||
+2
-3
@@ -28,7 +28,6 @@ import com.alibaba.druid.sql.ast.expr.SQLQueryExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
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.SQLServerCommitStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeclareStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement.SQLServerParameter;
|
||||
@@ -483,10 +482,10 @@ public class SQLServerStatementParser extends SQLStatementParser {
|
||||
return block;
|
||||
}
|
||||
|
||||
public SQLServerCommitStatement parseCommit() {
|
||||
public SQLStatement parseCommit() {
|
||||
acceptIdentifier("COMMIT");
|
||||
|
||||
SQLServerCommitStatement stmt = new SQLServerCommitStatement();
|
||||
SQLCommitStatement stmt = new SQLCommitStatement();
|
||||
|
||||
if (identifierEquals("WORK")) {
|
||||
lexer.nextToken();
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
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.SQLServerCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement.SQLServerParameter;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
@@ -72,11 +71,7 @@ public interface SQLServerASTVisitor extends SQLASTVisitor {
|
||||
boolean visit(SQLServerSelect x);
|
||||
|
||||
void endVisit(SQLServerSelect x);
|
||||
|
||||
boolean visit(SQLServerCommitStatement x);
|
||||
|
||||
void endVisit(SQLServerCommitStatement x);
|
||||
|
||||
boolean visit(SQLServerRollbackStatement x);
|
||||
|
||||
void endVisit(SQLServerRollbackStatement x);
|
||||
|
||||
-11
@@ -20,7 +20,6 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
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.SQLServerCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement.SQLServerParameter;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
@@ -133,16 +132,6 @@ public class SQLServerASTVisitorAdapter extends SQLASTVisitorAdapter implements
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerCommitStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerRollbackStatement x) {
|
||||
return true;
|
||||
|
||||
+1
-7
@@ -24,7 +24,6 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
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.SQLServerCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement.SQLServerParameter;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
@@ -464,7 +463,7 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerCommitStatement x) {
|
||||
public boolean visit(SQLCommitStatement x) {
|
||||
print0(ucase ? "COMMIT" : "commit");
|
||||
|
||||
if (x.isWork()) {
|
||||
@@ -485,11 +484,6 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerRollbackStatement x) {
|
||||
print0(ucase ? "ROLLBACK" : "rollback");
|
||||
|
||||
-11
@@ -24,7 +24,6 @@ import com.alibaba.druid.sql.dialect.sqlserver.ast.SQLServerSelect;
|
||||
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.SQLServerCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerExecStatement.SQLServerParameter;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerInsertStatement;
|
||||
@@ -160,16 +159,6 @@ public class SQLServerSchemaStatVisitor extends SchemaStatVisitor implements SQL
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerCommitStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLServerCommitStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLServerRollbackStatement x) {
|
||||
return true;
|
||||
|
||||
@@ -2097,6 +2097,10 @@ public class SQLExprParser extends SQLParser {
|
||||
item.setTarget(var);
|
||||
if (lexer.token() == Token.COLONEQ) {
|
||||
lexer.nextToken();
|
||||
} else if (lexer.token() == Token.TRUE || identifierEquals("TRUE")) {
|
||||
lexer.nextToken();
|
||||
item.setValue(new SQLBooleanExpr(true));
|
||||
return item;
|
||||
} else {
|
||||
accept(Token.EQ);
|
||||
}
|
||||
|
||||
@@ -4289,4 +4289,62 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLArgument x) {
|
||||
SQLParameter.ParameterType type = x.getType();
|
||||
if (type != null) {
|
||||
print0(type.name());
|
||||
print(' ');
|
||||
}
|
||||
|
||||
x.getExpr().accept(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCommitStatement x) {
|
||||
print0(ucase ? "COMMIT" : "commit");
|
||||
|
||||
if (x.isWrite()) {
|
||||
print0(ucase ? " WRITE" : " write");
|
||||
if (x.getWait() != null) {
|
||||
if (x.getWait().booleanValue()) {
|
||||
print0(ucase ? " WAIT" : " wait");
|
||||
} else {
|
||||
print0(ucase ? " NOWAIT" : " nowait");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getImmediate() != null) {
|
||||
if (x.getImmediate().booleanValue()) {
|
||||
print0(ucase ? " IMMEDIATE" : " immediate");
|
||||
} else {
|
||||
print0(ucase ? " BATCH" : " batch");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x.isWork()) {
|
||||
print0(ucase ? " WORK" : " work");
|
||||
}
|
||||
|
||||
if (x.getChain() != null) {
|
||||
if (x.getChain().booleanValue()) {
|
||||
print0(ucase ? " AND CHAIN" : " and chain");
|
||||
} else {
|
||||
print0(ucase ? " AND NO CHAIN" : " and no chain");
|
||||
}
|
||||
}
|
||||
|
||||
if (x.getRelease() != null) {
|
||||
if (x.getRelease().booleanValue()) {
|
||||
print0(ucase ? " AND RELEASE" : " and release");
|
||||
} else {
|
||||
print0(ucase ? " AND NO RELEASE" : " and no release");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLWhileStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeclareStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCommitStatement;
|
||||
|
||||
public interface SQLASTVisitor {
|
||||
|
||||
@@ -717,4 +718,12 @@ public interface SQLASTVisitor {
|
||||
boolean visit(SQLReturnStatement x);
|
||||
|
||||
void endVisit(SQLReturnStatement x);
|
||||
|
||||
boolean visit(SQLArgument x);
|
||||
|
||||
void endVisit(SQLArgument x);
|
||||
|
||||
boolean visit(SQLCommitStatement x);
|
||||
|
||||
void endVisit(SQLCommitStatement x);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeInsertClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeUpdateClause;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLWhileStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLDeclareStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCommitStatement;
|
||||
|
||||
public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
|
||||
@@ -1631,4 +1632,25 @@ public class SQLASTVisitorAdapter implements SQLASTVisitor {
|
||||
public void endVisit(SQLReturnStatement x) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLArgument x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLArgument x) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLCommitStatement x) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(SQLCommitStatement x) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,20 +24,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLDeclareItem;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.SQLParameter;
|
||||
import com.alibaba.druid.sql.ast.SQLPartition;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByHash;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByList;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionByRange;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionValue;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartition;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartitionByHash;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLArrayExpr;
|
||||
@@ -445,8 +432,11 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
x.getLeft().setParent(x);
|
||||
x.getRight().setParent(x);
|
||||
SQLObject parent = x.getParent();
|
||||
|
||||
if (parent instanceof SQLIfStatement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (x.getOperator()) {
|
||||
case Equality:
|
||||
@@ -1750,8 +1740,20 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
|
||||
SQLExpr name = param.getName();
|
||||
this.variants.put(name.toString(), name);
|
||||
|
||||
param.accept(this);
|
||||
}
|
||||
return true;
|
||||
|
||||
for (SQLStatement stmt : x.getStatementList()) {
|
||||
stmt.accept(this);
|
||||
}
|
||||
|
||||
SQLStatement exception = x.getException();
|
||||
if (exception != null) {
|
||||
exception.accept(this);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -52,7 +52,6 @@ import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOrderingExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlOutFileExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCommitStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlExplainStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlHintStatement;
|
||||
@@ -68,7 +67,6 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser;
|
||||
import com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement;
|
||||
import com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGShowStatement;
|
||||
import com.alibaba.druid.sql.dialect.sqlserver.ast.stmt.SQLServerCommitStatement;
|
||||
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;
|
||||
@@ -2477,7 +2475,7 @@ public class WallVisitorUtils {
|
||||
allow = config.isShowAllow();
|
||||
denyMessage = "show not allow";
|
||||
errorCode = ErrorCode.SHOW_NOT_ALLOW;
|
||||
} else if (x instanceof MySqlCommitStatement || x instanceof SQLServerCommitStatement) {
|
||||
} else if (x instanceof SQLCommitStatement) {
|
||||
allow = config.isCommitAllow();
|
||||
denyMessage = "commit not allow";
|
||||
errorCode = ErrorCode.COMMIT_NOT_ALLOW;
|
||||
|
||||
Reference in New Issue
Block a user