mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for sql parser.
This commit is contained in:
@@ -915,7 +915,7 @@ public class SQLUtils {
|
||||
}
|
||||
|
||||
tableName = normalize(tableName);
|
||||
long hash = Utils.fnv_64_lower(tableName);
|
||||
long hash = Utils.fnv_32_lower(tableName);
|
||||
return Utils.hex_t(hash);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,18 @@ public class SQLUnique extends SQLConstraintImpl implements SQLUniqueConstraint,
|
||||
}
|
||||
|
||||
public void addColumn(SQLExpr column) {
|
||||
if (column == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
addColumn(new SQLSelectOrderByItem(column));
|
||||
}
|
||||
|
||||
public void addColumn(SQLSelectOrderByItem column) {
|
||||
if (column != null) {
|
||||
column.setParent(this);
|
||||
}
|
||||
this.columns.add(new SQLSelectOrderByItem(column));
|
||||
this.columns.add(column);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-11
@@ -21,15 +21,7 @@ import com.alibaba.druid.sql.ast.SQLName;
|
||||
import com.alibaba.druid.sql.ast.SQLObject;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
|
||||
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLAlterTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLExprTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLSelectStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLStartTransactionStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLTableSource;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUnionQuery;
|
||||
import com.alibaba.druid.sql.ast.statement.SQLUpdateStatement;
|
||||
import com.alibaba.druid.sql.ast.statement.*;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint;
|
||||
import com.alibaba.druid.sql.dialect.mysql.ast.MySqlKey;
|
||||
@@ -257,8 +249,9 @@ public class MySqlSchemaStatVisitor extends SchemaStatVisitor implements MySqlAS
|
||||
|
||||
@Override
|
||||
public boolean visit(MySqlPrimaryKey x) {
|
||||
for (SQLObject item : x.getColumns()) {
|
||||
item.accept(this);
|
||||
for (SQLSelectOrderByItem item : x.getColumns()) {
|
||||
SQLExpr expr = item.getExpr();
|
||||
expr.accept(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1764,10 +1764,17 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
}
|
||||
|
||||
public boolean visit(SQLDropTableStatement x) {
|
||||
print0(ucase ? "DROP " : "drop ");
|
||||
List<SQLCommentHint> hints = x.getHints();
|
||||
if (hints != null) {
|
||||
printAndAccept(hints, " ");
|
||||
print(' ');
|
||||
};
|
||||
|
||||
if (x.isTemporary()) {
|
||||
print0(ucase ? "DROP TEMPORARY TABLE " : "drop temporary table ");
|
||||
print0(ucase ? "TEMPORARY TABLE " : "temporary table ");
|
||||
} else {
|
||||
print0(ucase ? "DROP TABLE " : "drop table ");
|
||||
print0(ucase ? "TABLE " : "table ");
|
||||
}
|
||||
|
||||
if (x.isIfExists()) {
|
||||
|
||||
@@ -1056,6 +1056,9 @@ public class SchemaStatVisitor extends SQLASTVisitorAdapter {
|
||||
}
|
||||
if (column != null) {
|
||||
SQLObject parent = x.getParent();
|
||||
if (parent instanceof SQLSelectOrderByItem) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (parent instanceof SQLPrimaryKey) {
|
||||
column.setPrimaryKey(true);
|
||||
} else if (parent instanceof SQLUnique) {
|
||||
|
||||
@@ -442,6 +442,25 @@ public class Utils {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public static long fnv_32_lower(String key) {
|
||||
long hashCode = 0x811c9dc5;
|
||||
for (int i = 0; i < key.length(); ++i) {
|
||||
char ch = key.charAt(i);
|
||||
if (ch == '_' || ch == '-') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch >= 'A' && ch <= 'Z') {
|
||||
ch = (char) (ch + 32);
|
||||
}
|
||||
|
||||
hashCode ^= ch;
|
||||
hashCode *= 0x01000193;
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public static void loadFromFile(String path, Set<String> set) {
|
||||
InputStream is = null;
|
||||
BufferedReader reader = null;
|
||||
|
||||
Reference in New Issue
Block a user