mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
sql parser improved pg support, fix #4128
This commit is contained in:
@@ -53,6 +53,8 @@ public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
protected int buckets;
|
||||
protected int shards;
|
||||
|
||||
private boolean ifExists = false;
|
||||
|
||||
public SQLAlterTableStatement(){
|
||||
|
||||
}
|
||||
@@ -85,6 +87,14 @@ public class SQLAlterTableStatement extends SQLStatementImpl implements SQLDDLSt
|
||||
this.offline = offline;
|
||||
}
|
||||
|
||||
public boolean isIfExists() {
|
||||
return ifExists;
|
||||
}
|
||||
|
||||
public void setIfExists(boolean ifExists) {
|
||||
this.ifExists = ifExists;
|
||||
}
|
||||
|
||||
public boolean isRemovePatiting() {
|
||||
return removePatiting;
|
||||
}
|
||||
|
||||
+4
@@ -557,6 +557,10 @@ public class PGSQLStatementParser extends SQLStatementParser {
|
||||
values.add(new SQLCharExpr(lexer.stringVal()));
|
||||
} else if (lexer.token() == Token.LITERAL_INT) {
|
||||
values.add(new SQLIdentifierExpr(lexer.numberString()));
|
||||
} else if (lexer.identifierEquals(FnvHash.Constants.JSON_SET)
|
||||
|| lexer.identifierEquals(FnvHash.Constants.JSONB_SET)) {
|
||||
SQLExpr json_set = this.exprParser.expr();
|
||||
values.add(json_set);
|
||||
} else {
|
||||
values.add(new SQLIdentifierExpr(lexer.stringVal()));
|
||||
}
|
||||
|
||||
@@ -1763,6 +1763,13 @@ public class SQLStatementParser extends SQLParser {
|
||||
lexer.nextToken();
|
||||
|
||||
SQLAlterTableStatement stmt = new SQLAlterTableStatement(getDbType());
|
||||
|
||||
if (lexer.token == Token.IF) {
|
||||
lexer.nextToken();
|
||||
accept(Token.EXISTS);
|
||||
stmt.setIfExists(true);
|
||||
}
|
||||
|
||||
stmt.setName(this.exprParser.name());
|
||||
|
||||
for (;;) {
|
||||
|
||||
@@ -5405,6 +5405,11 @@ public class SQLASTOutputVisitor extends SQLASTVisitorAdapter implements Paramet
|
||||
@Override
|
||||
public boolean visit(SQLAlterTableStatement x) {
|
||||
print0(ucase ? "ALTER TABLE " : "alter table ");
|
||||
|
||||
if (x.isIfExists()) {
|
||||
print0(ucase ? "IF EXISTS " : "if exists ");
|
||||
}
|
||||
|
||||
printTableSourceExpr(x.getName());
|
||||
this.indentCount++;
|
||||
for (int i = 0; i < x.getItems().size(); ++i) {
|
||||
|
||||
@@ -1117,5 +1117,7 @@ public final class FnvHash {
|
||||
long RESTART = fnv1a_64_lower("RESTART");
|
||||
|
||||
long ASOF = fnv1a_64_lower("ASOF");
|
||||
long JSON_SET = fnv1a_64_lower("JSON_SET");
|
||||
long JSONB_SET = fnv1a_64_lower("JSONB_SET");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user