mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor sql parser.
This commit is contained in:
+2
-2
@@ -28,7 +28,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitorUtils;
|
||||
|
||||
public class DB2ExportParameterVisitor extends DB2ParameterizedOutputVisitor implements ExportParameterVisitor {
|
||||
public class DB2ExportParameterVisitor extends DB2OutputVisitor implements ExportParameterVisitor {
|
||||
|
||||
|
||||
/**
|
||||
@@ -37,7 +37,7 @@ public class DB2ExportParameterVisitor extends DB2ParameterizedOutputVisitor imp
|
||||
private final boolean requireParameterizedOutput;
|
||||
|
||||
public DB2ExportParameterVisitor(final List<Object> parameters,final Appendable appender,final boolean wantParameterizedOutput){
|
||||
super(appender);
|
||||
super(appender, true);
|
||||
this.parameters = parameters;
|
||||
this.requireParameterizedOutput = wantParameterizedOutput;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ public class DB2OutputVisitor extends SQLASTOutputVisitor implements DB2ASTVisit
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public DB2OutputVisitor(Appendable appender, boolean parameterized){
|
||||
super(appender, parameterized);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(DB2SelectQueryBlock x) {
|
||||
this.visit((SQLSelectQueryBlock) x);
|
||||
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.db2.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
|
||||
public class DB2ParameterizedOutputVisitor extends DB2OutputVisitor implements ParameterizedVisitor {
|
||||
|
||||
private int replaceCount;
|
||||
|
||||
public DB2ParameterizedOutputVisitor(){
|
||||
this(new StringBuilder());
|
||||
}
|
||||
|
||||
public DB2ParameterizedOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public int getReplaceCount() {
|
||||
return this.replaceCount;
|
||||
}
|
||||
|
||||
public void incrementReplaceCunt() {
|
||||
replaceCount++;
|
||||
}
|
||||
|
||||
public boolean visit(SQLInListExpr x) {
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
x = ParameterizedOutputVisitorUtils.merge(this, x);
|
||||
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLIntegerExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNumberExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNullExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -29,7 +29,7 @@ import com.alibaba.druid.sql.ast.SQLLimit;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitorUtils;
|
||||
|
||||
public class MySqlExportParameterVisitor extends MySqlParameterizedOutputVisitor implements ExportParameterVisitor {
|
||||
public class MySqlExportParameterVisitor extends MySqlOutputVisitor implements ExportParameterVisitor {
|
||||
|
||||
/**
|
||||
* true= if require parameterized sql output
|
||||
@@ -38,7 +38,7 @@ public class MySqlExportParameterVisitor extends MySqlParameterizedOutputVisitor
|
||||
|
||||
|
||||
public MySqlExportParameterVisitor(List<Object> parameters, Appendable appender, boolean wantParameterizedOutput){
|
||||
super(appender);
|
||||
super(appender, true);
|
||||
this.parameters = parameters;
|
||||
this.requireParameterizedOutput = wantParameterizedOutput;
|
||||
}
|
||||
|
||||
+115
-23
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package com.alibaba.druid.sql.dialect.mysql.visitor;
|
||||
|
||||
import java.security.AccessControlException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLCommentHint;
|
||||
import com.alibaba.druid.sql.ast.SQLDataType;
|
||||
@@ -27,25 +29,8 @@ import com.alibaba.druid.sql.ast.SQLParameter;
|
||||
import com.alibaba.druid.sql.ast.SQLSetQuantifier;
|
||||
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLSubPartitionBy;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLAggregateExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableAddColumn;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLBlockStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCharacterDataType;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition;
|
||||
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.SQLLoopStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLShowTablesStatement;
|
||||
import com.alibaba.druid.sql.ast.expr.*;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey;
|
||||
@@ -163,6 +148,7 @@ import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatem
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateTableSource;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
|
||||
import com.alibaba.druid.util.JdbcConstants;
|
||||
|
||||
@@ -172,10 +158,94 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
this.dbType = JdbcConstants.MYSQL;
|
||||
}
|
||||
|
||||
private boolean shardingSupport = true;
|
||||
|
||||
public MySqlOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public MySqlOutputVisitor(Appendable appender, boolean parameterized){
|
||||
super(appender, parameterized);
|
||||
|
||||
try {
|
||||
configFromProperty(System.getProperties());
|
||||
} catch (AccessControlException e) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
|
||||
public void configFromProperty(Properties properties) {
|
||||
if (parameterized) {
|
||||
String property = properties.getProperty("druid.parameterized.shardingSupport");
|
||||
if ("true".equals(property)) {
|
||||
this.setShardingSupport(true);
|
||||
} else if ("false".equals(property)) {
|
||||
this.setShardingSupport(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isShardingSupport() {
|
||||
return shardingSupport;
|
||||
}
|
||||
|
||||
public void setShardingSupport(boolean shardingSupport) {
|
||||
this.shardingSupport = shardingSupport;
|
||||
}
|
||||
|
||||
public boolean visit(SQLIdentifierExpr x) {
|
||||
if (!parameterized) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
final String name = x.getName();
|
||||
boolean computeSharding = isShardingSupport();
|
||||
if (computeSharding) {
|
||||
SQLObject parent = x.getParent();
|
||||
computeSharding = parent instanceof SQLExprTableSource || parent instanceof SQLPropertyExpr;
|
||||
}
|
||||
|
||||
if (computeSharding) {
|
||||
int pos = name.lastIndexOf('_');
|
||||
if (pos != -1 && pos != name.length() - 1) {
|
||||
boolean isNumber = true;
|
||||
for (int i = pos + 1; i < name.length(); ++i) {
|
||||
char ch = name.charAt(i);
|
||||
if (ch < '0' || ch > '9') {
|
||||
isNumber = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isNumber) {
|
||||
String realName = name.substring(0, pos);
|
||||
print0(realName);
|
||||
incrementReplaceCunt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int numberCount = 0;
|
||||
for (int i = name.length() - 1; i >= 0; --i) {
|
||||
char ch = name.charAt(i);
|
||||
if (ch < '0' || ch > '9') {
|
||||
break;
|
||||
} else {
|
||||
numberCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberCount > 1) {
|
||||
int numPos = name.length() - numberCount;
|
||||
String realName = name.substring(0, numPos);
|
||||
print0(realName);
|
||||
incrementReplaceCunt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
print0(name);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visit(SQLSelectQueryBlock select) {
|
||||
if (select instanceof MySqlSelectQueryBlock) {
|
||||
@@ -617,6 +687,11 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
public boolean visit(SQLCharExpr x) {
|
||||
if (this.parameterized
|
||||
&& ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
print('\'');
|
||||
|
||||
String text = x.getText();
|
||||
@@ -1014,18 +1089,31 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
}
|
||||
|
||||
protected void printValuesList(MySqlInsertStatement x) {
|
||||
List<SQLInsertStatement.ValuesClause> valuesList = x.getValuesList();
|
||||
|
||||
if (parameterized) {
|
||||
print0(ucase ? "VALUES " : "values ");
|
||||
incrementIndent();
|
||||
valuesList.get(0).accept(this);
|
||||
decrementIndent();
|
||||
if (valuesList.size() > 1) {
|
||||
this.incrementReplaceCunt();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
print0(ucase ? "VALUES " : "values ");
|
||||
if (x.getValuesList().size() > 1) {
|
||||
incrementIndent();
|
||||
}
|
||||
for (int i = 0, size = x.getValuesList().size(); i < size; ++i) {
|
||||
for (int i = 0, size = valuesList.size(); i < size; ++i) {
|
||||
if (i != 0) {
|
||||
print(',');
|
||||
println();
|
||||
}
|
||||
x.getValuesList().get(i).accept(this);
|
||||
valuesList.get(i).accept(this);
|
||||
}
|
||||
if (x.getValuesList().size() > 1) {
|
||||
if (valuesList.size() > 1) {
|
||||
decrementIndent();
|
||||
}
|
||||
}
|
||||
@@ -2457,7 +2545,7 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
} else {
|
||||
print0(ucase ? "ALTER TABLE " : "alter table ");
|
||||
}
|
||||
x.getName().accept(this);
|
||||
printTableSourceExpr(x.getName());
|
||||
incrementIndent();
|
||||
for (int i = 0; i < x.getItems().size(); ++i) {
|
||||
SQLAlterTableItem item = x.getItems().get(i);
|
||||
@@ -2827,6 +2915,10 @@ public class MySqlOutputVisitor extends SQLASTOutputVisitor implements MySqlASTV
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlCharExpr x) {
|
||||
if (parameterized && ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
print0(x.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
-213
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.visitor;
|
||||
|
||||
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.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.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.expr.MySqlCharExpr;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
|
||||
import java.security.AccessControlException;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MySqlParameterizedOutputVisitor extends MySqlOutputVisitor implements ParameterizedVisitor {
|
||||
|
||||
private boolean shardingSupport = true;
|
||||
|
||||
private int replaceCount;
|
||||
|
||||
public MySqlParameterizedOutputVisitor(){
|
||||
this(new StringBuilder());
|
||||
}
|
||||
|
||||
public MySqlParameterizedOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
|
||||
try {
|
||||
configFromProperty(System.getProperties());
|
||||
} catch (AccessControlException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void configFromProperty(Properties properties) {
|
||||
{
|
||||
String property = properties.getProperty("druid.parameterized.shardingSupport");
|
||||
if ("true".equals(property)) {
|
||||
this.setShardingSupport(true);
|
||||
} else if ("false".equals(property)) {
|
||||
this.setShardingSupport(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isShardingSupport() {
|
||||
return shardingSupport;
|
||||
}
|
||||
|
||||
public void setShardingSupport(boolean shardingSupport) {
|
||||
this.shardingSupport = shardingSupport;
|
||||
}
|
||||
|
||||
public int getReplaceCount() {
|
||||
return this.replaceCount;
|
||||
}
|
||||
|
||||
public void incrementReplaceCunt() {
|
||||
replaceCount++;
|
||||
}
|
||||
|
||||
public boolean visit(SQLInListExpr x) {
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLIdentifierExpr x) {
|
||||
final String name = x.getName();
|
||||
boolean computeSharding = isShardingSupport();
|
||||
if (computeSharding) {
|
||||
SQLObject parent = x.getParent();
|
||||
computeSharding = parent instanceof SQLExprTableSource || parent instanceof SQLPropertyExpr;
|
||||
}
|
||||
|
||||
if (computeSharding) {
|
||||
int pos = name.lastIndexOf('_');
|
||||
if (pos != -1 && pos != name.length() - 1) {
|
||||
boolean isNumber = true;
|
||||
for (int i = pos + 1; i < name.length(); ++i) {
|
||||
char ch = name.charAt(i);
|
||||
if (ch < '0' || ch > '9') {
|
||||
isNumber = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isNumber) {
|
||||
String realName = name.substring(0, pos);
|
||||
print0(realName);
|
||||
incrementReplaceCunt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int numberCount = 0;
|
||||
for (int i = name.length() - 1; i >= 0; --i) {
|
||||
char ch = name.charAt(i);
|
||||
if (ch < '0' || ch > '9') {
|
||||
break;
|
||||
} else {
|
||||
numberCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (numberCount > 1) {
|
||||
int numPos = name.length() - numberCount;
|
||||
String realName = name.substring(0, numPos);
|
||||
print0(realName);
|
||||
incrementReplaceCunt();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
print0(name);
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
x = ParameterizedOutputVisitorUtils.merge(this, x);
|
||||
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLIntegerExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNumberExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNullExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLHexExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(MySqlCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
protected void printValuesList(MySqlInsertStatement x) {
|
||||
List<ValuesClause> valuesList = x.getValuesList();
|
||||
print0(ucase ? "VALUES " : "values ");
|
||||
incrementIndent();
|
||||
valuesList.get(0).accept(this);
|
||||
decrementIndent();
|
||||
if (valuesList.size() > 1) {
|
||||
this.incrementReplaceCunt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -901,6 +901,12 @@ public class OracleStatementParser extends SQLStatementParser {
|
||||
OracleAlterTableDropPartition item = new OracleAlterTableDropPartition();
|
||||
item.setName(this.exprParser.name());
|
||||
stmt.addItem(item);
|
||||
} else if (lexer.token() == Token.INDEX) {
|
||||
lexer.nextToken();
|
||||
SQLName indexName = this.exprParser.name();
|
||||
SQLAlterTableDropIndex item = new SQLAlterTableDropIndex();
|
||||
item.setIndexName(indexName);
|
||||
stmt.addItem(item);
|
||||
} else {
|
||||
throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
|
||||
}
|
||||
|
||||
@@ -1695,7 +1695,7 @@ public class OracleOutputVisitor extends SQLASTOutputVisitor implements OracleAS
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableStatement x) {
|
||||
print0(ucase ? "ALTER TABLE " : "alter table ");
|
||||
x.getName().accept(this);
|
||||
printTableSourceExpr(x.getName());
|
||||
incrementIndent();
|
||||
for (SQLAlterTableItem item : x.getItems()) {
|
||||
println();
|
||||
|
||||
+2
-10
@@ -27,28 +27,20 @@ import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
|
||||
public class OracleParameterizedOutputVisitor extends OracleOutputVisitor implements ParameterizedVisitor {
|
||||
|
||||
private int replaceCount;
|
||||
|
||||
public OracleParameterizedOutputVisitor(){
|
||||
this(new StringBuilder());
|
||||
this.parameterized = true;
|
||||
}
|
||||
|
||||
public OracleParameterizedOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
this.parameterized = true;
|
||||
}
|
||||
|
||||
public OracleParameterizedOutputVisitor(Appendable appender, boolean printPostSemi){
|
||||
super(appender, printPostSemi);
|
||||
}
|
||||
|
||||
public int getReplaceCount() {
|
||||
return this.replaceCount;
|
||||
}
|
||||
|
||||
public void incrementReplaceCunt() {
|
||||
replaceCount++;
|
||||
}
|
||||
|
||||
public boolean visit(SQLInListExpr x) {
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
@@ -24,4 +24,8 @@ public class PhoenixOutputVisitor extends SQLASTOutputVisitor implements Phoenix
|
||||
public PhoenixOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public PhoenixOutputVisitor(Appendable appender, boolean parameterized){
|
||||
super(appender, parameterized);
|
||||
}
|
||||
}
|
||||
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.phoenix.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
|
||||
/**
|
||||
* Created by wenshao on 16/9/13.
|
||||
*/
|
||||
public class PhoenixParameterizedOutputVisitor extends PhoenixOutputVisitor implements ParameterizedVisitor {
|
||||
private int replaceCount;
|
||||
|
||||
public PhoenixParameterizedOutputVisitor(){
|
||||
this(new StringBuilder());
|
||||
}
|
||||
|
||||
public PhoenixParameterizedOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public int getReplaceCount() {
|
||||
return this.replaceCount;
|
||||
}
|
||||
|
||||
public void incrementReplaceCunt() {
|
||||
replaceCount++;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -28,7 +28,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitorUtils;
|
||||
|
||||
public class PGExportParameterVisitor extends PGParameterizedOutputVisitor implements ExportParameterVisitor {
|
||||
public class PGExportParameterVisitor extends PGOutputVisitor implements ExportParameterVisitor {
|
||||
|
||||
/**
|
||||
* true= if require parameterized sql output
|
||||
@@ -36,7 +36,7 @@ public class PGExportParameterVisitor extends PGParameterizedOutputVisitor imple
|
||||
private final boolean requireParameterizedOutput;
|
||||
|
||||
public PGExportParameterVisitor(final List<Object> parameters,final Appendable appender,final boolean wantParameterizedOutput){
|
||||
super(appender);
|
||||
super(appender, true);
|
||||
this.parameters = parameters;
|
||||
this.requireParameterizedOutput = wantParameterizedOutput;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ public class PGOutputVisitor extends SQLASTOutputVisitor implements PGASTVisitor
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public PGOutputVisitor(Appendable appender, boolean parameterized){
|
||||
super(appender, parameterized);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVisit(WindowClause x) {
|
||||
|
||||
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.visitor;
|
||||
|
||||
import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLInListExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNCharExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
|
||||
public class PGParameterizedOutputVisitor extends PGOutputVisitor implements ParameterizedVisitor {
|
||||
|
||||
private int replaceCount;
|
||||
|
||||
public PGParameterizedOutputVisitor(){
|
||||
this(new StringBuilder());
|
||||
}
|
||||
|
||||
public PGParameterizedOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public int getReplaceCount() {
|
||||
return this.replaceCount;
|
||||
}
|
||||
|
||||
public void incrementReplaceCunt() {
|
||||
replaceCount++;
|
||||
}
|
||||
|
||||
public boolean visit(SQLInListExpr x) {
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
x = ParameterizedOutputVisitorUtils.merge(this, x);
|
||||
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLIntegerExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNumberExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNullExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -28,7 +28,7 @@ import com.alibaba.druid.sql.ast.statement.SQLSelectItem;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitor;
|
||||
import com.alibaba.druid.sql.visitor.ExportParameterVisitorUtils;
|
||||
|
||||
public class MSSQLServerExportParameterVisitor extends SQLServerParameterizedOutputVisitor implements ExportParameterVisitor {
|
||||
public class MSSQLServerExportParameterVisitor extends SQLServerOutputVisitor implements ExportParameterVisitor {
|
||||
|
||||
/**
|
||||
* true= if require parameterized sql output
|
||||
@@ -36,7 +36,7 @@ public class MSSQLServerExportParameterVisitor extends SQLServerParameterizedOut
|
||||
private final boolean requireParameterizedOutput;
|
||||
|
||||
public MSSQLServerExportParameterVisitor(final List<Object> parameters,final Appendable appender,final boolean wantParameterizedOutput){
|
||||
super(appender);
|
||||
super(appender, true);
|
||||
this.parameters = parameters;
|
||||
this.requireParameterizedOutput = wantParameterizedOutput;
|
||||
}
|
||||
|
||||
+4
@@ -47,6 +47,10 @@ public class SQLServerOutputVisitor extends SQLASTOutputVisitor implements SQLSe
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public SQLServerOutputVisitor(Appendable appender, boolean parameterized){
|
||||
super(appender, parameterized);
|
||||
}
|
||||
|
||||
public boolean visit(SQLServerSelectQueryBlock x) {
|
||||
print0(ucase ? "SELECT " : "select ");
|
||||
|
||||
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2101 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.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;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNullExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLNumberExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedOutputVisitorUtils;
|
||||
import com.alibaba.druid.sql.visitor.ParameterizedVisitor;
|
||||
|
||||
public class SQLServerParameterizedOutputVisitor extends SQLServerOutputVisitor implements ParameterizedVisitor {
|
||||
|
||||
private int replaceCount;
|
||||
|
||||
public SQLServerParameterizedOutputVisitor(Appendable appender){
|
||||
super(appender);
|
||||
}
|
||||
|
||||
public int getReplaceCount() {
|
||||
return this.replaceCount;
|
||||
}
|
||||
|
||||
public void incrementReplaceCunt() {
|
||||
replaceCount++;
|
||||
}
|
||||
|
||||
public boolean visit(SQLInListExpr x) {
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLBinaryOpExpr x) {
|
||||
x = ParameterizedOutputVisitorUtils.merge(this, x);
|
||||
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLIntegerExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNumberExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNCharExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLNullExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLVariantRefExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x) || x.getName().equalsIgnoreCase("?")) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
public boolean visit(SQLHexExpr x) {
|
||||
if (!ParameterizedOutputVisitorUtils.checkParameterize(x)) {
|
||||
return super.visit(x);
|
||||
}
|
||||
|
||||
return ParameterizedOutputVisitorUtils.visit(this, x);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user