improved sql server parser. for issue #2346

This commit is contained in:
wenshao
2018-02-20 13:07:40 +08:00
parent 87ee1fa6dc
commit 30be97f0b0
3 changed files with 29 additions and 1 deletions
@@ -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;
}