This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new c20d36a Set charset key unified for PostgreSQL (#15795)
c20d36a is described below
commit c20d36a60842bf13f01622363501110e838563fc
Author: gin <[email protected]>
AuthorDate: Fri Mar 4 19:30:12 2022 +0800
Set charset key unified for PostgreSQL (#15795)
* Set charset key unified for PostgreSQL
* Test completed
---
.../text/admin/postgresql/PostgreSQLAdminExecutorFactory.java | 6 +-----
.../visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java | 2 +-
.../src/main/resources/case/dal/set.xml | 9 +++++++--
.../src/main/resources/sql/supported/dal/set.xml | 3 ++-
4 files changed, 11 insertions(+), 9 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactory.java
index b7334c7..d1641e8 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactory.java
@@ -101,11 +101,7 @@ public final class PostgreSQLAdminExecutorFactory
implements DatabaseAdminExecut
private boolean isSetClientEncoding(final SetStatement setStatement) {
Iterator<VariableAssignSegment> iterator =
setStatement.getVariableAssigns().iterator();
- return iterator.hasNext() &&
containsKey(iterator.next().getVariable().getVariable());
- }
-
- private boolean containsKey(final String key) {
- return "charset".equalsIgnoreCase(key) ||
"client_encoding".equalsIgnoreCase(key);
+ return iterator.hasNext() &&
"client_encoding".equalsIgnoreCase(iterator.next().getVariable().getVariable());
}
@Override
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java
index db645cb..202d51c 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLDALStatementSQLVisitor.java
@@ -81,7 +81,7 @@ public final class PostgreSQLDALStatementSQLVisitor extends
PostgreSQLStatementS
if (null != ctx.encoding()) {
VariableAssignSegment variableAssignSegment = new
VariableAssignSegment();
VariableSegment variableSegment = new VariableSegment();
- variableSegment.setVariable("charset");
+ variableSegment.setVariable("client_encoding");
variableAssignSegment.setVariable(variableSegment);
String value = ctx.encoding().getText();
variableAssignSegment.setAssignValue(value);
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/set.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/set.xml
index 8072b00..9059358 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/set.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/set.xml
@@ -83,11 +83,16 @@
<set-resource-group sql-case-id="set_resource_group">
<group name="rg" />
</set-resource-group>
- <set-parameter sql-case-id="set_charset" >
- <parameter-assign value="'UTF8'" >
+ <set-parameter sql-case-id="set_charset_mysql" >
+ <parameter-assign value="'utf8'" >
<parameter name="charset" />
</parameter-assign>
</set-parameter>
+ <set-parameter sql-case-id="set_charset_postgresql" >
+ <parameter-assign value="'UTF8'" >
+ <parameter name="client_encoding" />
+ </parameter-assign>
+ </set-parameter>
<set-parameter sql-case-id="set_client_encoding" >
<parameter-assign value="'UTF8'" >
<parameter name="CLIENT_ENCODING" />
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/set.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/set.xml
index 47693d4..ab253f7 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/set.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/set.xml
@@ -37,6 +37,7 @@
<sql-case id="set_parameter_equal_number_with_signal" value="SET
extra_float_digits = -10.5" db-types="PostgreSQL,openGauss" />
<sql-case id="set_names" value="SET NAMES 'utf8' COLLATE
'utf8_general_ci'" db-types="MySQL" />
<sql-case id="set_resource_group" value="SET RESOURCE GROUP rg"
db-types="MySQL"/>
- <sql-case id="set_charset" value="SET NAMES 'UTF8'"
db-types="MySQL,PostgreSQL" />
+ <sql-case id="set_charset_mysql" value="SET NAMES 'utf8'" db-types="MySQL"
/>
+ <sql-case id="set_charset_postgresql" value="SET NAMES 'UTF8'"
db-types="PostgreSQL" />
<sql-case id="set_client_encoding" value="SET CLIENT_ENCODING TO 'UTF8'"
db-types="PostgreSQL" />
</sql-cases>