sql parser add refactor api.

This commit is contained in:
wenshao
2018-04-23 01:15:35 +08:00
parent 28ac367003
commit 236226991b
6 changed files with 123 additions and 1 deletions
@@ -292,4 +292,13 @@ public class SQLDeleteStatement extends SQLStatementImpl implements SQLReplaceab
return false;
}
public boolean addWhere(SQLExpr where) {
if (where == null) {
return false;
}
this.addCondition(where);
return true;
}
}
@@ -20,6 +20,7 @@ import java.util.List;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.*;
import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr;
import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObject;
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@@ -321,4 +322,26 @@ public class SQLSelect extends SQLObjectImpl {
return null;
}
public boolean addWhere(SQLExpr where) {
if (where == null) {
return false;
}
if (query instanceof SQLSelectQueryBlock) {
((SQLSelectQueryBlock) query).addWhere(where);
return true;
}
if (query instanceof SQLUnionQuery) {
SQLSelectQueryBlock queryBlock = new SQLSelectQueryBlock();
queryBlock.setFrom(new SQLSelect(query), "u");
queryBlock.addSelectItem(new SQLAllColumnExpr());
queryBlock.setParent(queryBlock);
query = queryBlock;
return true;
}
return false;
}
}
@@ -16,6 +16,7 @@
package com.alibaba.druid.sql.ast.statement;
import com.alibaba.druid.sql.ast.SQLCommentHint;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
@@ -85,4 +86,8 @@ public class SQLSelectStatement extends SQLStatementImpl {
public List<SQLObject> getChildren() {
return Collections.<SQLObject>singletonList(select);
}
public boolean addWhere(SQLExpr where) {
return select.addWhere(where);
}
}
@@ -312,4 +312,13 @@ public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceab
result = 31 * result + (hints != null ? hints.hashCode() : 0);
return result;
}
public boolean addWhere(SQLExpr where) {
if (where == null) {
return false;
}
this.addCondition(where);
return true;
}
}
@@ -104,7 +104,7 @@ public class MySqlUtils {
e.printStackTrace();
}
} else if (major == 6) {
} else if (major == 6 || major == 8) {
if (method_6_getValue == null && !method_6_getValue_error) {
try {
class_6_connection = Class.forName("com.mysql.cj.api.jdbc.JdbcConnection");