mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser improved support db2 truncate syntax. for issue #1324
This commit is contained in:
@@ -24,20 +24,28 @@ import com.alibaba.druid.sql.visitor.SQLASTVisitor;
|
||||
|
||||
public class SQLTruncateStatement extends SQLStatementImpl {
|
||||
|
||||
protected List<SQLExprTableSource> tableSources = new ArrayList<SQLExprTableSource>(2);
|
||||
protected List<SQLExprTableSource> tableSources = new ArrayList<SQLExprTableSource>(2);
|
||||
|
||||
private boolean purgeSnapshotLog = false;
|
||||
private boolean purgeSnapshotLog = false;
|
||||
|
||||
private boolean only;
|
||||
private Boolean restartIdentity;
|
||||
private Boolean cascade;
|
||||
|
||||
public SQLTruncateStatement() {
|
||||
|
||||
|
||||
// db2
|
||||
private boolean dropStorage = false;
|
||||
private boolean reuseStorage = false;
|
||||
private boolean immediate = false;
|
||||
private boolean ignoreDeleteTriggers = false;
|
||||
private boolean restrictWhenDeleteTriggers = false;
|
||||
private boolean continueIdentity = false;
|
||||
|
||||
public SQLTruncateStatement(){
|
||||
|
||||
}
|
||||
|
||||
public SQLTruncateStatement(String dbType) {
|
||||
super (dbType);
|
||||
|
||||
public SQLTruncateStatement(String dbType){
|
||||
super(dbType);
|
||||
}
|
||||
|
||||
public List<SQLExprTableSource> getTableSources() {
|
||||
@@ -93,4 +101,53 @@ public class SQLTruncateStatement extends SQLStatementImpl {
|
||||
public void setCascade(Boolean cascade) {
|
||||
this.cascade = cascade;
|
||||
}
|
||||
|
||||
public boolean isDropStorage() {
|
||||
return dropStorage;
|
||||
}
|
||||
|
||||
public void setDropStorage(boolean dropStorage) {
|
||||
this.dropStorage = dropStorage;
|
||||
}
|
||||
|
||||
public boolean isReuseStorage() {
|
||||
return reuseStorage;
|
||||
}
|
||||
|
||||
public void setReuseStorage(boolean reuseStorage) {
|
||||
this.reuseStorage = reuseStorage;
|
||||
}
|
||||
|
||||
public boolean isImmediate() {
|
||||
return immediate;
|
||||
}
|
||||
|
||||
public void setImmediate(boolean immediate) {
|
||||
this.immediate = immediate;
|
||||
}
|
||||
|
||||
public boolean isIgnoreDeleteTriggers() {
|
||||
return ignoreDeleteTriggers;
|
||||
}
|
||||
|
||||
public void setIgnoreDeleteTriggers(boolean ignoreDeleteTriggers) {
|
||||
this.ignoreDeleteTriggers = ignoreDeleteTriggers;
|
||||
}
|
||||
|
||||
public boolean isRestrictWhenDeleteTriggers() {
|
||||
return restrictWhenDeleteTriggers;
|
||||
}
|
||||
|
||||
public void setRestrictWhenDeleteTriggers(boolean restrictWhenDeleteTriggers) {
|
||||
this.restrictWhenDeleteTriggers = restrictWhenDeleteTriggers;
|
||||
}
|
||||
|
||||
public boolean isContinueIdentity() {
|
||||
return continueIdentity;
|
||||
}
|
||||
|
||||
public void setContinueIdentity(boolean continueIdentity) {
|
||||
this.continueIdentity = continueIdentity;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ public class DB2Lexer extends Lexer {
|
||||
map.put("OPTIMIZE", Token.OPTIMIZE);
|
||||
map.put("OF", Token.OF);
|
||||
map.put("CONCAT", Token.CONCAT);
|
||||
map.put("CONTINUE", Token.CONTINUE);
|
||||
map.put("IDENTITY", Token.IDENTITY);
|
||||
|
||||
DEFAULT_DB2_KEYWORDS = new Keywords(map);
|
||||
}
|
||||
|
||||
@@ -1430,6 +1430,49 @@ public class SQLStatementParser extends SQLParser {
|
||||
stmt.setCascade(Boolean.FALSE);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.DROP) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("STORAGE");
|
||||
stmt.setDropStorage(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("REUSE")) {
|
||||
lexer.nextToken();
|
||||
acceptIdentifier("STORAGE");
|
||||
stmt.setReuseStorage(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("IGNORE")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.DELETE);
|
||||
acceptIdentifier("TRIGGERS");
|
||||
stmt.setIgnoreDeleteTriggers(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("RESTRICT")) {
|
||||
lexer.nextToken();
|
||||
accept(Token.WHEN);
|
||||
accept(Token.DELETE);
|
||||
acceptIdentifier("TRIGGERS");
|
||||
stmt.setRestrictWhenDeleteTriggers(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lexer.token() == Token.CONTINUE) {
|
||||
lexer.nextToken();
|
||||
accept(Token.IDENTITY);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (identifierEquals("IMMEDIATE")) {
|
||||
lexer.nextToken();
|
||||
stmt.setImmediate(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1449,6 +1449,31 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Printab
|
||||
public boolean visit(SQLTruncateStatement x) {
|
||||
print0(ucase ? "TRUNCATE TABLE " : "truncate table ");
|
||||
printAndAccept(x.getTableSources(), ", ");
|
||||
|
||||
if (x.isDropStorage()) {
|
||||
print0(ucase ? " DROP STORAGE" : " drop storage");
|
||||
}
|
||||
|
||||
if (x.isReuseStorage()) {
|
||||
print0(ucase ? " REUSE STORAGE" : " reuse storage");
|
||||
}
|
||||
|
||||
if (x.isIgnoreDeleteTriggers()) {
|
||||
print0(ucase ? " IGNORE DELETE TRIGGERS" : " ignore delete triggers");
|
||||
}
|
||||
|
||||
if (x.isRestrictWhenDeleteTriggers()) {
|
||||
print0(ucase ? " RESTRICT WHEN DELETE TRIGGERS" : " restrict when delete triggers");
|
||||
}
|
||||
|
||||
if (x.isContinueIdentity()) {
|
||||
print0(ucase ? " CONTINUE IDENTITY" : " continue identity");
|
||||
}
|
||||
|
||||
if (x.isImmediate()) {
|
||||
print0(ucase ? " IMMEDIATE" : " immediate");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user