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:
@@ -700,27 +700,8 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean apply(SQLAlterTableAddIndex item) {
|
||||
if (item.isKey()) {
|
||||
MySqlPrimaryKey x = new MySqlPrimaryKey();
|
||||
item.cloneTo(x);
|
||||
x.setParent(this);
|
||||
this.tableElementList.add(x);
|
||||
return true;
|
||||
}
|
||||
if (item.isUnique()) {
|
||||
MySqlUnique x = new MySqlUnique();
|
||||
item.cloneTo(x);
|
||||
x.setParent(this);
|
||||
this.tableElementList.add(x);
|
||||
return true;
|
||||
}
|
||||
|
||||
MySqlTableIndex x = new MySqlTableIndex();
|
||||
item.cloneTo(x);
|
||||
x.setParent(this);
|
||||
this.tableElementList.add(x);
|
||||
return true;
|
||||
protected boolean apply(SQLAlterTableAddIndex item) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean apply(SQLAlterTableAddColumn item) {
|
||||
|
||||
@@ -135,4 +135,16 @@ public class SQLUnionQuery extends SQLObjectImpl implements SQLSelectQuery {
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public SQLSelectQueryBlock getFirstQueryBlock() {
|
||||
if (left instanceof SQLSelectQueryBlock) {
|
||||
return (SQLSelectQueryBlock) left;
|
||||
}
|
||||
|
||||
if (left instanceof SQLUnionQuery) {
|
||||
return ((SQLUnionQuery) left).getFirstQueryBlock();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+20
-8
@@ -29,6 +29,8 @@ import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.SQLPartitionBy;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlObjectImpl;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor;
|
||||
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlShowColumnOutpuVisitor;
|
||||
@@ -211,16 +213,26 @@ public class MySqlCreateTableStatement extends SQLCreateTableStatement implement
|
||||
return super.alterApply(item);
|
||||
}
|
||||
|
||||
public boolean apply(SQLAlterTableAddIndex x) {
|
||||
MySqlTableIndex index = new MySqlTableIndex();
|
||||
|
||||
index.setName(x.getName());
|
||||
for (SQLSelectOrderByItem orderByItem : x.getItems()) {
|
||||
index.addColumn(orderByItem.clone());
|
||||
public boolean apply(SQLAlterTableAddIndex item) {
|
||||
if (item.isKey()) {
|
||||
MySqlPrimaryKey x = new MySqlPrimaryKey();
|
||||
item.cloneTo(x);
|
||||
x.setParent(this);
|
||||
this.tableElementList.add(x);
|
||||
return true;
|
||||
}
|
||||
if (item.isUnique()) {
|
||||
MySqlUnique x = new MySqlUnique();
|
||||
item.cloneTo(x);
|
||||
x.setParent(this);
|
||||
this.tableElementList.add(x);
|
||||
return true;
|
||||
}
|
||||
index.setParent(this);
|
||||
this.tableElementList.add(index);
|
||||
|
||||
MySqlTableIndex x = new MySqlTableIndex();
|
||||
item.cloneTo(x);
|
||||
x.setParent(this);
|
||||
this.tableElementList.add(x);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +196,14 @@ public class Schema {
|
||||
select.accept(
|
||||
repository.createResolveVisitor());
|
||||
|
||||
SQLSelectQueryBlock queryBlock = select.getQueryBlock();
|
||||
SQLSelectQuery query = select.getQuery();
|
||||
SQLSelectQueryBlock queryBlock = null;
|
||||
if (query instanceof SQLSelectQueryBlock) {
|
||||
queryBlock = (SQLSelectQueryBlock) query;
|
||||
} else if (query instanceof SQLUnionQuery) {
|
||||
queryBlock = ((SQLUnionQuery) query).getFirstQueryBlock();
|
||||
}
|
||||
|
||||
if (queryBlock != null) {
|
||||
List<SQLSelectItem> selectList = queryBlock.getSelectList();
|
||||
for (SQLSelectItem selectItem : selectList) {
|
||||
|
||||
Reference in New Issue
Block a user