mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved sql server parser. for issue #2346
This commit is contained in:
@@ -18,6 +18,7 @@ package com.alibaba.druid.sql.ast.statement;
|
||||
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLPrimaryKeyImpl extends SQLUnique implements SQLPrimaryKey {
|
||||
protected boolean clustered = false; // sql server
|
||||
|
||||
@Override
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
@@ -33,4 +34,17 @@ public class SQLPrimaryKeyImpl extends SQLUnique implements SQLPrimaryKey {
|
||||
cloneTo(x);
|
||||
return x;
|
||||
}
|
||||
|
||||
public void cloneTo(SQLPrimaryKeyImpl x) {
|
||||
super.cloneTo(x);
|
||||
x.clustered = clustered;
|
||||
}
|
||||
|
||||
public boolean isClustered() {
|
||||
return clustered;
|
||||
}
|
||||
|
||||
public void setClustered(boolean clustered) {
|
||||
this.clustered = clustered;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2741,6 +2741,12 @@ public class SQLExprParser extends SQLParser {
|
||||
accept(Token.KEY);
|
||||
|
||||
SQLPrimaryKeyImpl pk = new SQLPrimaryKeyImpl();
|
||||
|
||||
if (lexer.identifierEquals(FnvHash.Constants.CLUSTERED)) {
|
||||
lexer.nextToken();
|
||||
pk.setClustered(true);
|
||||
}
|
||||
|
||||
accept(Token.LPAREN);
|
||||
orderBy(pk.getColumns(), pk);
|
||||
accept(Token.RPAREN);
|
||||
|
||||
@@ -3829,9 +3829,17 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
x.getName().accept(this);
|
||||
print(' ');
|
||||
}
|
||||
print0(ucase ? "PRIMARY KEY (" : "primary key (");
|
||||
|
||||
print0(ucase ? "PRIMARY KEY " : "primary key ");
|
||||
|
||||
if (x.isClustered()) {
|
||||
print0(ucase ? "CLUSTERED " : "clustered ");
|
||||
}
|
||||
|
||||
print('(');
|
||||
printAndAccept(x.getColumns(), ", ");
|
||||
print(')');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user