You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/03/23 08:38:06 UTC
[shardingsphere] branch master updated: Make UTF8 as default charset in PostgreSQLSetCharsetExecutor (#16305)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 83beb32 Make UTF8 as default charset in PostgreSQLSetCharsetExecutor (#16305)
83beb32 is described below
commit 83beb32e94db99c5e1f7f35e9d67266f5527e5e8
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Wed Mar 23 16:36:49 2022 +0800
Make UTF8 as default charset in PostgreSQLSetCharsetExecutor (#16305)
* Refactor MySQLSetCharsetExecutor
* Consider setting charset to default in PostgreSQLSetCharsetExecutor
---
.../text/admin/mysql/executor/MySQLSetCharsetExecutor.java | 14 +++++++-------
.../postgresql/executor/PostgreSQLSetCharsetExecutor.java | 9 ++++++---
2 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/MySQLSetCharsetExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/MySQLSetCharsetExecutor.java
index 96d04ea..09ded68 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/MySQLSetCharsetExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/MySQLSetCharsetExecutor.java
@@ -54,14 +54,14 @@ public final class MySQLSetCharsetExecutor implements DatabaseSetCharsetExecutor
}
private Charset parseCharset(final String value) {
- String result = value.toLowerCase(Locale.ROOT);
- if ("default".equals(result)) {
- return MySQLServerInfo.DEFAULT_CHARSET.getCharset();
+ switch (value.toLowerCase(Locale.ROOT)) {
+ case "default":
+ return MySQLServerInfo.DEFAULT_CHARSET.getCharset();
+ case "utf8mb4":
+ return StandardCharsets.UTF_8;
+ default:
+ return Charset.forName(value);
}
- if ("utf8mb4".equals(result)) {
- return StandardCharsets.UTF_8;
- }
- return Charset.forName(value);
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
index c23e11a..ff02c48 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
@@ -54,10 +54,13 @@ public final class PostgreSQLSetCharsetExecutor implements DatabaseSetCharsetExe
private Charset parseCharset(final String value) {
String result = value.toLowerCase(Locale.ROOT);
- if ("unicode".equals(result)) {
- return StandardCharsets.UTF_8;
+ switch (result) {
+ case "default":
+ case "unicode":
+ return StandardCharsets.UTF_8;
+ default:
+ return Charset.forName(value);
}
- return Charset.forName(value);
}
@Override