mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for sql parser. for issue #1910
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
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.SQLStatement;
|
||||
import com.alibaba.druid.sql.ast.SQLStatementImpl;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
@@ -26,7 +27,7 @@ public class SQLCommentStatement extends SQLStatementImpl {
|
||||
TABLE, COLUMN
|
||||
}
|
||||
|
||||
private SQLExpr on;
|
||||
private SQLName on;
|
||||
private Type type;
|
||||
private SQLExpr comment;
|
||||
|
||||
@@ -46,11 +47,11 @@ public class SQLCommentStatement extends SQLStatementImpl {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public SQLExpr getOn() {
|
||||
public SQLName getOn() {
|
||||
return on;
|
||||
}
|
||||
|
||||
public void setOn(SQLExpr on) {
|
||||
public void setOn(SQLName on) {
|
||||
this.on = on;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,16 +33,18 @@ import com.alibaba.druid.util.lang.Consumer;
|
||||
|
||||
public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLStatement {
|
||||
|
||||
protected boolean ifNotExiists = false;
|
||||
protected Type type;
|
||||
protected SQLExprTableSource tableSource;
|
||||
protected boolean ifNotExiists = false;
|
||||
protected Type type;
|
||||
protected SQLExprTableSource tableSource;
|
||||
|
||||
protected List<SQLTableElement> tableElementList = new ArrayList<SQLTableElement>();
|
||||
|
||||
// for postgresql
|
||||
private SQLExprTableSource inherits;
|
||||
private SQLExprTableSource inherits;
|
||||
|
||||
protected SQLSelect select;
|
||||
protected SQLSelect select;
|
||||
|
||||
protected SQLExpr comment;
|
||||
|
||||
public SQLCreateTableStatement(){
|
||||
|
||||
@@ -52,6 +54,17 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
super(dbType);
|
||||
}
|
||||
|
||||
public SQLExpr getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(SQLExpr comment) {
|
||||
if (comment != null) {
|
||||
comment.setParent(this);
|
||||
}
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public SQLName getName() {
|
||||
if (tableSource == null) {
|
||||
return null;
|
||||
@@ -586,6 +599,38 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean apply(SQLCommentStatement x) {
|
||||
SQLName on = x.getOn();
|
||||
SQLExpr comment = x.getComment();
|
||||
if (comment == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SQLCommentStatement.Type type = x.getType();
|
||||
if (type == SQLCommentStatement.Type.TABLE) {
|
||||
if (!SQLUtils.nameEquals(getName(), on)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setComment(comment.clone());
|
||||
|
||||
return true;
|
||||
} else if (type == SQLCommentStatement.Type.COLUMN) {
|
||||
SQLPropertyExpr propertyExpr = (SQLPropertyExpr) on;
|
||||
if (!SQLUtils.nameEquals(getName(), (SQLName) propertyExpr.getOwner())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SQLColumnDefinition column = this.findColumn(propertyExpr.getName());
|
||||
if (column != null) {
|
||||
column.setComment(comment.clone());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean apply(SQLAlterTableStatement alter) {
|
||||
if (!SQLUtils.nameEquals(alter.getName(), this.getName())) {
|
||||
return false;
|
||||
@@ -842,6 +887,9 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
if (select != null) {
|
||||
x.setSelect(select.clone());
|
||||
}
|
||||
if (comment != null) {
|
||||
x.setComment(comment.clone());
|
||||
}
|
||||
}
|
||||
|
||||
public SQLCreateTableStatement clone() {
|
||||
|
||||
Reference in New Issue
Block a user