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 6ec9209822914..1a365ba831e6b 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 @@ -54,14 +54,14 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供, | SQL State | Vendor Code | 错误信息 | |-----------|-------------|------------------------------------------| -| 42000 | 12000 | You have an error in your SQL syntax: %s | -| 42000 | 12001 | Can not accept SQL type '%s'. | -| 42000 | 12002 | SQL String can not be NULL or empty. | +| 42000 | 12000 | SQL String can not be NULL or empty. | | 42000 | 12010 | Can not support variable '%s'. | | HV008 | 12020 | Column index '%d' is out of range. | | 42S02 | 12021 | Can not find column label '%s'. | | HY000 | 12022 | Column '%s' in %s is ambiguous. | | 0A000 | 12100 | DROP TABLE ... CASCADE is not supported. | +| 42000 | 12100 | You have an error in your SQL syntax: %s | +| 42000 | 12101 | Can not accept SQL type '%s'. | | 42000 | 12200 | SQL audit failed, error message: %s. | | 42000 | 12201 | Hint datasource '%s' 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 61773bf6ef5bc..cbce522b4f4ae 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 @@ -54,14 +54,14 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi | SQL State | Vendor Code | Reason | |-----------|-------------|------------------------------------------| -| 42000 | 12000 | You have an error in your SQL syntax: %s | -| 42000 | 12001 | Can not accept SQL type '%s'. | -| 42000 | 12002 | SQL String can not be NULL or empty. | +| 42000 | 12000 | SQL String can not be NULL or empty. | | 42000 | 12010 | Can not support variable '%s'. | | HV008 | 12020 | Column index '%d' is out of range. | | 42S02 | 12021 | Can not find column label '%s'. | | HY000 | 12022 | Column '%s' in %s is ambiguous. | | 0A000 | 12100 | DROP TABLE ... CASCADE is not supported. | +| 42000 | 12100 | You have an error in your SQL syntax: %s | +| 42000 | 12101 | Can not accept SQL type '%s'. | | 42000 | 12200 | SQL audit failed, error message: %s. | | 42000 | 12201 | Hint datasource '%s' does not exist. | diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/syntax/EmptySQLException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/syntax/EmptySQLException.java index 40baba6010014..8afdf2d5cadb3 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/syntax/EmptySQLException.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/syntax/EmptySQLException.java @@ -28,6 +28,6 @@ public final class EmptySQLException extends SyntaxSQLException { private static final long serialVersionUID = -5723825491720138339L; public EmptySQLException() { - super(XOpenSQLState.SYNTAX_ERROR, 2, "SQL String can not be NULL or empty."); + super(XOpenSQLState.SYNTAX_ERROR, 0, "SQL String can not be NULL or empty."); } } diff --git a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/ParseSQLException.java b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/ParseSQLException.java new file mode 100644 index 0000000000000..48bc4232e94ea --- /dev/null +++ b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/ParseSQLException.java @@ -0,0 +1,41 @@ +/* + * 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.sql.parser.exception; + +import com.google.common.base.Preconditions; +import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.SQLState; +import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.SyntaxSQLException; + +/** + * Parse SQL exception. + */ +public abstract class ParseSQLException extends SyntaxSQLException { + + private static final long serialVersionUID = 1922421612933745823L; + + private static final int PARSE_CODE = 1; + + protected ParseSQLException(final SQLState sqlState, final int errorCode, final String reason, final Object... messageArgs) { + super(sqlState, getErrorCode(errorCode), reason, messageArgs); + } + + private static int getErrorCode(final int errorCode) { + Preconditions.checkArgument(errorCode >= 0 && errorCode < 100, "The value range of error code should be [0, 100)."); + return PARSE_CODE * 100 + errorCode; + } +} diff --git a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/SQLASTVisitorException.java b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/SQLASTVisitorException.java index 3dfcc2c0b4376..0fbfadbc447c0 100644 --- a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/SQLASTVisitorException.java +++ b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/SQLASTVisitorException.java @@ -19,12 +19,11 @@ import org.antlr.v4.runtime.tree.ParseTree; import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState; -import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.SyntaxSQLException; /** * SQL AST visitor exception. */ -public final class SQLASTVisitorException extends SyntaxSQLException { +public final class SQLASTVisitorException extends ParseSQLException { private static final long serialVersionUID = 8597155168000874870L; diff --git a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/SQLParsingException.java b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/SQLParsingException.java index 004158e21ddc8..295a901bd82f1 100644 --- a/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/SQLParsingException.java +++ b/parser/sql/engine/src/main/java/org/apache/shardingsphere/sql/parser/exception/SQLParsingException.java @@ -18,12 +18,11 @@ package org.apache.shardingsphere.sql.parser.exception; import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState; -import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.SyntaxSQLException; /** * SQL parsing exception. */ -public final class SQLParsingException extends SyntaxSQLException { +public final class SQLParsingException extends ParseSQLException { private static final long serialVersionUID = -6408790652103666096L;