You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2022/09/05 15:54:45 UTC

[shardingsphere] branch master updated: Add UnsupportedStreamCharsetConversionException (#20807)

This is an automated email from the ASF dual-hosted git repository.

menghaoran 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 88ba12230fe Add UnsupportedStreamCharsetConversionException (#20807)
88ba12230fe is described below

commit 88ba12230fef5a42d6a02494b215078415821dca
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Sep 5 23:54:32 2022 +0800

    Add UnsupportedStreamCharsetConversionException (#20807)
---
 .../content/user-manual/error-code/sql-error-code.cn.md      |  3 ++-
 .../content/user-manual/error-code/sql-error-code.en.md      |  3 ++-
 .../UnsupportedDataTypeConversionException.java              |  2 +-
 .../UnsupportedStreamCharsetConversionException.java         | 12 ++++++------
 .../impl/driver/jdbc/type/stream/JDBCStreamQueryResult.java  |  6 ++++--
 .../query/impl/driver/jdbc/type/util/ResultSetUtil.java      |  1 +
 .../query/impl/driver/jdbc/type/util/ResultSetUtilTest.java  |  1 +
 .../driver/jdbc/exception/EmptySQLException.java             |  2 +-
 8 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 294e0adcbc8..4b7d6eca173 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -15,7 +15,8 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42000     | 10002       | Can not support 3-tier structure for actual data node \`%s\` with JDBC \`%s\` |
 | 42000     | 10003       | Unsupported SQL node conversion for SQL statement \`%s\` |
 | HY004     | 10004       | Unsupported conversion data type \`%s\` for value \`%s\` |
-| HY004     | 10005       | SQL String can not be NULL or empty |
+| HY004     | 10005       | Unsupported conversion stream charset \`%s\` |
+| HY004     | 10006       | SQL String can not be NULL or empty |
 | HY004     | 10100       | Can not register driver, reason is: %s |
 | 34000     | 10200       | Can not get cursor name from fetch statement |
 | HY000     | 10300       | Could not support variable \`%s\` |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 2f1eeceb4c1..1139e889803 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -15,7 +15,8 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
 | 42000     | 10002       | Can not support 3-tier structure for actual data node \`%s\` with JDBC \`%s\` |
 | 42000     | 10003       | Unsupported SQL node conversion for SQL statement \`%s\` |
 | HY004     | 10004       | Unsupported conversion data type \`%s\` for value \`%s\` |
-| HY004     | 10005       | SQL String can not be NULL or empty |
+| HY004     | 10005       | Unsupported conversion stream charset \`%s\` |
+| HY004     | 10006       | SQL String can not be NULL or empty |
 | HY004     | 10100       | Can not register driver, reason is: %s |
 | 34000     | 10200       | Can not get cursor name from fetch statement |
 | HY000     | 10300       | Could not support variable \`%s\` |
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/UnsupportedDataTypeConversionException.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/exception/UnsupportedDataTypeConversionException.java
similarity index 93%
rename from shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/UnsupportedDataTypeConversionException.java
rename to shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/exception/UnsupportedDataTypeConversionException.java
index fce3215ceed..6bf594eab3d 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/UnsupportedDataTypeConversionException.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/exception/UnsupportedDataTypeConversionException.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.util;
+package org.apache.shardingsphere.infra.executor.exception;
 
 import org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException;
 import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/exception/UnsupportedStreamCharsetConversionException.java
similarity index 67%
copy from shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java
copy to shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/exception/UnsupportedStreamCharsetConversionException.java
index 03d26d0ca22..a917e86b916 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/exception/UnsupportedStreamCharsetConversionException.java
@@ -15,19 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.driver.jdbc.exception;
+package org.apache.shardingsphere.infra.executor.exception;
 
 import org.apache.shardingsphere.infra.util.exception.external.sql.ShardingSphereSQLException;
 import org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
 
 /**
- * Empty SQL exception.
+ * Unsupported stream charset conversion exception.
  */
-public final class EmptySQLException extends ShardingSphereSQLException {
+public final class UnsupportedStreamCharsetConversionException extends ShardingSphereSQLException {
     
-    private static final long serialVersionUID = -5723825491720138339L;
+    private static final long serialVersionUID = 4577091201937095156L;
     
-    public EmptySQLException() {
-        super(XOpenSQLState.GENERAL_ERROR.getValue(), 10005, "SQL String can not be NULL or empty");
+    public UnsupportedStreamCharsetConversionException(final String charsetType) {
+        super(XOpenSQLState.INVALID_DATA_TYPE, 10005, "Unsupported conversion stream charset `%s`", charsetType);
     }
 }
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/stream/JDBCStreamQueryResult.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/stream/JDBCStreamQueryResult.java
index 534a58124bb..d3b5efc52f3 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/stream/JDBCStreamQueryResult.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/stream/JDBCStreamQueryResult.java
@@ -18,6 +18,8 @@
 package org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream;
 
 import lombok.Getter;
+import org.apache.shardingsphere.infra.executor.exception.UnsupportedDataTypeConversionException;
+import org.apache.shardingsphere.infra.executor.exception.UnsupportedStreamCharsetConversionException;
 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.metadata.JDBCQueryResultMetaData;
 import org.apache.shardingsphere.infra.executor.sql.execute.result.query.type.stream.AbstractStreamQueryResult;
 
@@ -101,7 +103,7 @@ public final class JDBCStreamQueryResult extends AbstractStreamQueryResult {
         if (Timestamp.class == type) {
             return resultSet.getTimestamp(columnIndex, calendar);
         }
-        throw new SQLException(String.format("Unsupported type: %s", type));
+        throw new UnsupportedDataTypeConversionException(type, calendar).toSQLException();
     }
     
     @SuppressWarnings("deprecation")
@@ -115,7 +117,7 @@ public final class JDBCStreamQueryResult extends AbstractStreamQueryResult {
             case "Binary":
                 return resultSet.getBinaryStream(columnIndex);
             default:
-                throw new SQLException(String.format("Unsupported type: %s", type));
+                throw new UnsupportedStreamCharsetConversionException(type).toSQLException();
         }
     }
     
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
index e01e97a2065..761d4a18bf7 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtil.java
@@ -22,6 +22,7 @@ import com.google.common.primitives.Longs;
 import com.google.common.primitives.Shorts;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.executor.exception.UnsupportedDataTypeConversionException;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilTest.java
index 806b9fd8291..e9b29cc5c06 100644
--- a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilTest.java
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilTest.java
@@ -21,6 +21,7 @@ import com.google.common.primitives.Ints;
 import com.google.common.primitives.Longs;
 import com.google.common.primitives.Shorts;
 import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.executor.exception.UnsupportedDataTypeConversionException;
 import org.junit.Test;
 
 import java.math.BigDecimal;
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java
index 03d26d0ca22..e8aaff46780 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/exception/EmptySQLException.java
@@ -28,6 +28,6 @@ public final class EmptySQLException extends ShardingSphereSQLException {
     private static final long serialVersionUID = -5723825491720138339L;
     
     public EmptySQLException() {
-        super(XOpenSQLState.GENERAL_ERROR.getValue(), 10005, "SQL String can not be NULL or empty");
+        super(XOpenSQLState.GENERAL_ERROR.getValue(), 10006, "SQL String can not be NULL or empty");
     }
 }