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

zhonghongsheng 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 6cd28d80c1f Add CursorNameNotFoundException (#20539)
6cd28d80c1f is described below

commit 6cd28d80c1f7fb900e533f878cd385573f759a82
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 26 12:29:03 2022 +0800

    Add CursorNameNotFoundException (#20539)
---
 .../user-manual/error-code/sql-error-code.cn.md    |  1 +
 .../user-manual/error-code/sql-error-code.en.md    |  1 +
 .../exception/CursorNameNotFoundException.java     | 33 ++++++++++++++++++++++
 .../merge/ddl/fetch/FetchStreamMergedResult.java   |  5 ++--
 .../util/exception/sql/sqlstate/XOpenSQLState.java |  2 ++
 5 files changed, 39 insertions(+), 3 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 37d4490de72..592ae8a904a 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
@@ -14,6 +14,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
 | 42000     | 10003       | Unsupported SQL node conversion for SQL statement 
\`%s\` |
 | HY004     | 10004       | Unsupported conversion data type \`%s\` for value 
\`%s\` |
 | HY004     | 10100       | Can not register driver, reason is: %s |
+| 34000     | 10200       | Can not get cursor name from fetch statement |
 | 42000     | 11000       | You have an error in your SQL syntax: %s |
 | 42000     | 11001       | configuration error |
 | 42000     | 11002       | Resource does not exist |
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 0792665abc3..be17827fd97 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
@@ -14,6 +14,7 @@ SQL error codes provide by standard `SQL State`, `Vendor 
Code` and `Reason`, whi
 | 42000     | 10003       | Unsupported SQL node conversion for SQL statement 
\`%s\` |
 | HY004     | 10004       | Unsupported conversion data type \`%s\` for value 
\`%s\` |
 | HY004     | 10100       | Can not register driver, reason is: %s |
+| 34000     | 10200       | Can not get cursor name from fetch statement |
 | 42000     | 11000       | You have an error in your SQL syntax: %s |
 | 42000     | 11001       | configuration error |
 | 42000     | 11002       | Resource does not exist |
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/CursorNameNotFoundException.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/CursorNameNotFoundException.java
new file mode 100644
index 00000000000..aa73c9d47da
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/exception/CursorNameNotFoundException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shardingsphere.sharding.exception;
+
+import 
org.apache.shardingsphere.infra.util.exception.sql.ShardingSphereSQLException;
+import 
org.apache.shardingsphere.infra.util.exception.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Cursor name not found exception.
+ */
+public final class CursorNameNotFoundException extends 
ShardingSphereSQLException {
+    
+    private static final long serialVersionUID = 3124329832945598311L;
+    
+    public CursorNameNotFoundException() {
+        super(XOpenSQLState.INVALID_CURSOR_NAME, 10200, "Can not get cursor 
name from fetch statement");
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResult.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResult.java
index 47ee5b76464..e62100bd76c 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResult.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResult.java
@@ -23,12 +23,12 @@ import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementConte
 import org.apache.shardingsphere.infra.context.ConnectionContext;
 import org.apache.shardingsphere.infra.context.cursor.FetchGroup;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.memory.JDBCMemoryQueryResult;
 import 
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.stream.JDBCStreamQueryResult;
 import 
org.apache.shardingsphere.infra.merge.result.impl.stream.StreamMergedResult;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
+import 
org.apache.shardingsphere.sharding.exception.CursorNameNotFoundException;
 import org.apache.shardingsphere.sharding.merge.dql.orderby.OrderByValue;
 import org.apache.shardingsphere.sql.parser.sql.common.constant.DirectionType;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.cursor.DirectionSegment;
@@ -61,8 +61,7 @@ public final class FetchStreamMergedResult extends 
StreamMergedResult {
         directionType = 
fetchStatementContext.getSqlStatement().getDirection().flatMap(DirectionSegment::getDirectionType).orElse(DirectionType.NEXT);
         fetchCount = 
fetchStatementContext.getSqlStatement().getDirection().flatMap(DirectionSegment::getCount).orElse(1L);
         SelectStatementContext selectStatementContext = 
fetchStatementContext.getCursorStatementContext().getSelectStatementContext();
-        String cursorName = fetchStatementContext.getCursorName().map(optional 
-> optional.getIdentifier().getValue().toLowerCase())
-                .orElseThrow(() -> new ShardingSphereException("Can not get 
cursorName from fetchStatementContext."));
+        String cursorName = fetchStatementContext.getCursorName().map(optional 
-> 
optional.getIdentifier().getValue().toLowerCase()).orElseThrow(CursorNameNotFoundException::new);
         List<FetchOrderByValueGroup> fetchOrderByValueGroups = 
getFetchOrderByValueGroups(queryResults, selectStatementContext, schema, 
cursorName, connectionContext);
         addOrderedResultSetsToQueue(fetchOrderByValueGroups, queryResults);
         setMinResultSetRowCount(cursorName, connectionContext);
diff --git 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/sqlstate/XOpenSQLState.java
 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/sqlstate/XOpenSQLState.java
index 49b46fd5b37..1d05bb1d18e 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/sqlstate/XOpenSQLState.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-util/src/main/java/org/apache/shardingsphere/infra/util/exception/sql/sqlstate/XOpenSQLState.java
@@ -45,6 +45,8 @@ public enum XOpenSQLState implements SQLState {
     
     INVALID_AUTHORIZATION_SPECIFICATION("28000"),
     
+    INVALID_CURSOR_NAME("34000"),
+    
     INVALID_CATALOG_NAME("3D000"),
     
     SYNTAX_ERROR("42000"),

Reply via email to