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:
@@ -94,6 +94,14 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
return name;
|
||||
}
|
||||
|
||||
public long nameHashCode64() {
|
||||
if (name == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return name.hashCode64();
|
||||
}
|
||||
|
||||
public String getNameAsString() {
|
||||
if (name == null) {
|
||||
return null;
|
||||
@@ -379,8 +387,10 @@ public class SQLColumnDefinition extends SQLObjectImpl implements SQLTableElemen
|
||||
if (this.name instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) this.name;
|
||||
String columnName = identExpr.getName();
|
||||
columnName = SQLUtils.normalize(columnName, dbType);
|
||||
this.setName(columnName);
|
||||
String normalized = SQLUtils.normalize(columnName, dbType);
|
||||
if (normalized != columnName) {
|
||||
this.setName(normalized);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,8 +110,11 @@ public abstract class SQLConstraintImpl extends SQLObjectImpl implements SQLCons
|
||||
if (this.name instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) this.name;
|
||||
String columnName = identExpr.getName();
|
||||
columnName = SQLUtils.normalize(columnName, dbType);
|
||||
this.setName(columnName);
|
||||
|
||||
String normalized = SQLUtils.normalize(columnName, dbType);
|
||||
if (columnName != normalized) {
|
||||
this.setName(normalized);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,15 +573,21 @@ public class SQLCreateTableStatement extends SQLStatementImpl implements SQLDDLS
|
||||
if (name instanceof SQLPropertyExpr) {
|
||||
String tableName = ((SQLPropertyExpr) name).getName();
|
||||
tableName = SQLUtils.normalize(tableName);
|
||||
setName(tableName);
|
||||
name = getName();
|
||||
|
||||
String normalized = SQLUtils.normalize(tableName, dbType);
|
||||
if (tableName != normalized) {
|
||||
this.setName(normalized);
|
||||
name = getName();
|
||||
}
|
||||
}
|
||||
|
||||
if (name instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) name;
|
||||
String tableName = identExpr.getName();
|
||||
tableName = SQLUtils.normalize(tableName, dbType);
|
||||
setName(tableName);
|
||||
String normalized = SQLUtils.normalize(tableName, dbType);
|
||||
if (normalized != tableName) {
|
||||
setName(normalized);
|
||||
}
|
||||
}
|
||||
|
||||
for (SQLTableElement element : this.tableElementList) {
|
||||
|
||||
@@ -97,8 +97,10 @@ public class SQLUnique extends SQLConstraintImpl implements SQLUniqueConstraint,
|
||||
if (column instanceof SQLIdentifierExpr) {
|
||||
SQLIdentifierExpr identExpr = (SQLIdentifierExpr) column;
|
||||
String columnName = identExpr.getName();
|
||||
columnName = SQLUtils.normalize(columnName, dbType);
|
||||
item.setExpr(new SQLIdentifierExpr(columnName));
|
||||
String normalized = SQLUtils.normalize(columnName, dbType);
|
||||
if (normalized != columnName) {
|
||||
item.setExpr(new SQLIdentifierExpr(columnName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.SQLObjectImpl;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
@@ -70,4 +71,12 @@ public class SQLUpdateSetItem extends SQLObjectImpl {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean columnMatch(long columnHash) {
|
||||
if (this.column instanceof SQLName) {
|
||||
return ((SQLName) this.column).nameHashCode64() == columnHash;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user