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:
@@ -17,9 +17,10 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLAssignItem extends SQLObjectImpl {
|
||||
public class SQLAssignItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
|
||||
private SQLExpr target;
|
||||
private SQLExpr value;
|
||||
@@ -69,4 +70,17 @@ public class SQLAssignItem extends SQLObjectImpl {
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (this.target == expr) {
|
||||
setTarget(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this.value == expr) {
|
||||
setValue(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
return null;
|
||||
}
|
||||
|
||||
public SQLTableElement findKey(String columnName) {
|
||||
public SQLTableElement findIndex(String columnName) {
|
||||
for (SQLTableElement element : tableElementList) {
|
||||
List<SQLExpr> keyColumns = null;
|
||||
if (element instanceof SQLUniqueConstraint) {
|
||||
|
||||
@@ -17,11 +17,12 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLDeleteStatement extends SQLStatementImpl {
|
||||
public class SQLDeleteStatement extends SQLStatementImpl implements SQLReplaceable {
|
||||
|
||||
protected SQLTableSource tableSource;
|
||||
protected SQLExpr where;
|
||||
@@ -121,4 +122,13 @@ public class SQLDeleteStatement extends SQLStatementImpl {
|
||||
}
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (where == expr) {
|
||||
setWhere(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLJoinTableSource extends SQLTableSourceImpl {
|
||||
public class SQLJoinTableSource extends SQLTableSourceImpl implements SQLReplaceable {
|
||||
|
||||
protected SQLTableSource left;
|
||||
protected JoinType joinType;
|
||||
@@ -139,6 +140,16 @@ public class SQLJoinTableSource extends SQLTableSourceImpl {
|
||||
return using != null ? using.equals(that.using) : that.using == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (condition == expr) {
|
||||
setCondition(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum JoinType {
|
||||
COMMA(","), //
|
||||
JOIN("JOIN"), //
|
||||
|
||||
@@ -18,11 +18,12 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import com.alibaba.druid.sql.SQLUtils;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLSelectItem extends SQLObjectImpl {
|
||||
public class SQLSelectItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
|
||||
protected SQLExpr expr;
|
||||
protected String alias;
|
||||
@@ -146,4 +147,14 @@ public class SQLSelectItem extends SQLObjectImpl {
|
||||
x.connectByRoot = connectByRoot;
|
||||
return x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (expr == expr) {
|
||||
setExpr(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,10 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderingSpecification;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLSelectOrderByItem extends SQLObjectImpl {
|
||||
public class SQLSelectOrderByItem extends SQLObjectImpl implements SQLReplaceable {
|
||||
|
||||
protected SQLExpr expr;
|
||||
protected String collate;
|
||||
@@ -104,6 +105,15 @@ public class SQLSelectOrderByItem extends SQLObjectImpl {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (this.expr == expr) {
|
||||
this.setExpr(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static enum NullsOrderType {
|
||||
NullsFirst, NullsLast;
|
||||
|
||||
|
||||
@@ -18,13 +18,10 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLLimit;
|
||||
import com.alibaba.druid.sql.ast.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.SQLOrderBy;
|
||||
import com.alibaba.druid.sql.ast.*;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery {
|
||||
public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery, SQLReplaceable {
|
||||
private boolean bracket = false;
|
||||
protected int distionOption;
|
||||
protected final List<SQLSelectItem> selectList = new ArrayList<SQLSelectItem>();
|
||||
@@ -415,4 +412,13 @@ public class SQLSelectQueryBlock extends SQLObjectImpl implements SQLSelectQuery
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (where == expr) {
|
||||
setWhere(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,11 @@ import java.util.List;
|
||||
|
||||
import com.alibaba.druid.sql.ast.SQLExpr;
|
||||
import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLReplaceable;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLUpdateStatement extends SQLStatementImpl {
|
||||
public class SQLUpdateStatement extends SQLStatementImpl implements SQLReplaceable {
|
||||
|
||||
protected final List<SQLUpdateSetItem> items = new ArrayList<SQLUpdateSetItem>();
|
||||
protected SQLExpr where;
|
||||
@@ -131,4 +132,13 @@ public class SQLUpdateStatement extends SQLStatementImpl {
|
||||
}
|
||||
visitor.endVisit(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replace(SQLExpr expr, SQLExpr target) {
|
||||
if (where == expr) {
|
||||
setWhere(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user