-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
支持 PG DDL 语句若干,MySQL 支持 create/alter database ... collate 语句 (#6276)
* 1. 支持 PG create schema ... create table 连体写法。 2. 修复 PG insert ... with ... select 被分解为两条语句的问题。 * 1. 支持 PG create database ... owner 2. 支持 PG create database ... template 3. 支持 PG alter database ... allow_connections 4. 支持 PG alter database ... is_template * 1. fix code style. * 1. 支持 pg drop database ... force 2. 移除 guava 依赖。 * 1. 修复 pg create schema ... create ... 多个元素。 * 1. 支持 pg drop schema 多名称. * 1. 使用新方式编写单侧。 * 1. 优化 PG 新语句支持的实现逻辑。 2. 支持 MySQL alter schema abc default collate utf8mb4_unicode_ci; 语句 3. 支持 MySQL create database abc collate utf8mb4_unicode_ci; 语句 * 1. fix code style. * 1. add test case. * 1. format code.
- Loading branch information
Showing
20 changed files
with
729 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
core/src/main/java/com/alibaba/druid/sql/dialect/postgresql/ast/expr/PGAttrExpr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright 1999-2017 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.druid.sql.dialect.postgresql.ast.expr; | ||
|
||
import com.alibaba.druid.sql.ast.SQLExpr; | ||
import com.alibaba.druid.sql.ast.SQLObject; | ||
import com.alibaba.druid.sql.ast.SQLReplaceable; | ||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class PGAttrExpr extends PGExprImpl implements SQLReplaceable { | ||
private SQLExpr name; | ||
private SQLExpr value; | ||
private PGExprMode mode; | ||
|
||
public static enum PGExprMode { | ||
EMPTY, | ||
EQ | ||
} | ||
|
||
public PGAttrExpr clone() { | ||
PGAttrExpr x = new PGAttrExpr(); | ||
if (value != null) { | ||
x.setName(name.clone()); | ||
x.setValue(value.clone()); | ||
x.setMode(this.mode); | ||
} | ||
return x; | ||
} | ||
|
||
public SQLExpr getName() { | ||
return name; | ||
} | ||
|
||
public void setName(SQLExpr name) { | ||
this.name = name; | ||
} | ||
|
||
public SQLExpr getValue() { return value; } | ||
|
||
public void setValue(SQLExpr value) { this.value = value; } | ||
|
||
public PGExprMode getMode() { return this.mode; } | ||
|
||
public void setMode(PGExprMode mode) { this.mode = mode; } | ||
|
||
@Override | ||
public void accept0(PGASTVisitor visitor) { | ||
if (visitor.visit(this)) { | ||
acceptChild(visitor, value); | ||
} | ||
visitor.endVisit(this); | ||
} | ||
|
||
@Override | ||
public boolean replace(SQLExpr expr, SQLExpr target) { | ||
if (this.value == expr) { | ||
setValue(target); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public List<SQLObject> getChildren() { | ||
return Collections.singletonList(value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((name == null) ? 0 : name.hashCode()); | ||
result = prime * result + ((value == null) ? 0 : value.hashCode()); | ||
result = prime * result + ((mode == null) ? 0 : mode.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
PGAttrExpr other = (PGAttrExpr) obj; | ||
|
||
return Objects.equals(this.name, other.name) && | ||
Objects.equals(this.value, other.value) && | ||
Objects.equals(this.mode, other.mode); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...ain/java/com/alibaba/druid/sql/dialect/postgresql/ast/stmt/PGCreateDatabaseStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 1999-2017 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.druid.sql.dialect.postgresql.ast.stmt; | ||
|
||
import com.alibaba.druid.DbType; | ||
import com.alibaba.druid.sql.ast.SQLName; | ||
import com.alibaba.druid.sql.ast.SQLStatementImpl; | ||
import com.alibaba.druid.sql.ast.statement.SQLCreateStatement; | ||
import com.alibaba.druid.sql.dialect.postgresql.ast.expr.PGAttrExpr; | ||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor; | ||
import com.alibaba.druid.sql.visitor.SQLASTVisitor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class PGCreateDatabaseStatement extends SQLStatementImpl implements PGSQLStatement, SQLCreateStatement { | ||
private SQLName name; | ||
private boolean haveWith; | ||
private List<PGAttrExpr> stats = new ArrayList<>(); | ||
|
||
public PGCreateDatabaseStatement(DbType dbType) { | ||
super(dbType); | ||
} | ||
|
||
@Override | ||
public SQLName getName() { return this.name; } | ||
|
||
public void setName(SQLName dbName) { this.name = dbName; } | ||
|
||
public boolean isHaveWith() { return haveWith; } | ||
|
||
public void setHaveWith(boolean haveWith) { this.haveWith = haveWith; } | ||
|
||
public List<PGAttrExpr> getStats() { return stats; } | ||
|
||
public void setStats(List<PGAttrExpr> stats) { this.stats = stats; } | ||
|
||
protected void accept0(SQLASTVisitor visitor) { | ||
if (visitor instanceof PGASTVisitor) { | ||
accept0((PGASTVisitor) visitor); | ||
} | ||
} | ||
|
||
@Override | ||
public void accept0(PGASTVisitor visitor) { | ||
if (visitor.visit(this)) { | ||
acceptChild(visitor, this.name); | ||
acceptChild(visitor, this.stats); | ||
} | ||
|
||
visitor.endVisit(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
.../main/java/com/alibaba/druid/sql/dialect/postgresql/ast/stmt/PGDropDatabaseStatement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 1999-2017 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.druid.sql.dialect.postgresql.ast.stmt; | ||
|
||
import com.alibaba.druid.DbType; | ||
import com.alibaba.druid.sql.ast.statement.SQLDropCatalogStatement; | ||
import com.alibaba.druid.sql.dialect.postgresql.visitor.PGASTVisitor; | ||
import com.alibaba.druid.sql.visitor.SQLASTVisitor; | ||
|
||
public class PGDropDatabaseStatement extends SQLDropCatalogStatement implements PGSQLStatement { | ||
private boolean usingWith; | ||
private boolean force; | ||
|
||
public PGDropDatabaseStatement(DbType dbType) { | ||
super(dbType); | ||
} | ||
|
||
public boolean isUsingWith() { | ||
return usingWith; | ||
} | ||
|
||
public void setUsingWith(boolean usingWith) { | ||
this.usingWith = usingWith; | ||
} | ||
|
||
public boolean isForce() { return force; } | ||
|
||
public void setForce(boolean force) { this.force = force; } | ||
|
||
protected void accept0(SQLASTVisitor visitor) { | ||
if (visitor instanceof PGASTVisitor) { | ||
accept0((PGASTVisitor) visitor); | ||
} | ||
} | ||
|
||
@Override | ||
public void accept0(PGASTVisitor visitor) { | ||
if (visitor.visit(this)) { | ||
acceptChild(visitor, this.getName()); | ||
} | ||
visitor.endVisit(this); | ||
} | ||
} |
Oops, something went wrong.