Skip to content

Commit

Permalink
Add ParseSQLException (#30763)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Apr 3, 2024
1 parent 10b2cb5 commit 4798f7d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 4798f7d

Please sign in to comment.