提交 c99b31fe authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use custom error code

上级 d071dcec
...@@ -402,6 +402,17 @@ public class ErrorCode { ...@@ -402,6 +402,17 @@ public class ErrorCode {
*/ */
public static final int COLUMN_NOT_FOUND_1 = 42122; public static final int COLUMN_NOT_FOUND_1 = 42122;
/**
* The error with code <code>42123</code> is thrown when
* identical expressions should be used, but different
* exceptions were found.
* Example:
* <pre>
* SELECT MODE(A ORDER BY B) FROM TEST;
* </pre>
*/
public static final int IDENTICAL_EXPRESSIONS_SHOULD_BE_USED = 42131;
// 0A: feature not supported // 0A: feature not supported
// HZ: remote database access // HZ: remote database access
...@@ -2068,6 +2079,7 @@ public class ErrorCode { ...@@ -2068,6 +2079,7 @@ public class ErrorCode {
case INDEX_NOT_FOUND_1: return "42S12"; case INDEX_NOT_FOUND_1: return "42S12";
case DUPLICATE_COLUMN_NAME_1: return "42S21"; case DUPLICATE_COLUMN_NAME_1: return "42S21";
case COLUMN_NOT_FOUND_1: return "42S22"; case COLUMN_NOT_FOUND_1: return "42S22";
case IDENTICAL_EXPRESSIONS_SHOULD_BE_USED: return "42S31";
// 0A: feature not supported // 0A: feature not supported
......
...@@ -2983,14 +2983,10 @@ public class Parser { ...@@ -2983,14 +2983,10 @@ public class Parser {
if (readIf(ORDER)) { if (readIf(ORDER)) {
read("BY"); read("BY");
Expression expr2 = readExpression(); Expression expr2 = readExpression();
String sql = expr.getSQL(); String sql = expr.getSQL(), sql2 = expr2.getSQL();
if (!sql.equals(expr2.getSQL())) { if (!sql.equals(sql2)) {
parseIndex = lastParseIndex; throw DbException.getSyntaxError(ErrorCode.IDENTICAL_EXPRESSIONS_SHOULD_BE_USED, sqlCommand,
if (expectedList != null) { lastParseIndex, sql, sql2);
expectedList.clear();
expectedList.add(sql);
}
throw getSyntaxError();
} }
setModeAggOrder(r, expr); setModeAggOrder(r, expr);
} }
......
...@@ -237,6 +237,22 @@ public class DbException extends RuntimeException { ...@@ -237,6 +237,22 @@ public class DbException extends RuntimeException {
null, sql, message)); null, sql, message));
} }
/**
* Create a syntax error exception for a specific error code.
*
* @param errorCode the error code
* @param sql the SQL statement
* @param index the position of the error in the SQL statement
* @param params the list of parameters of the message
* @return the exception
*/
public static DbException getSyntaxError(int errorCode, String sql, int index, String... params) {
sql = StringUtils.addAsterisk(sql, index);
String sqlstate = ErrorCode.getState(errorCode);
String message = translate(sqlstate, params);
return new DbException(getJdbcSQLException(message, sql, sqlstate, errorCode, null, null));
}
/** /**
* Gets a SQL exception meaning this feature is not supported. * Gets a SQL exception meaning this feature is not supported.
* *
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=Index {0} nenalezen 42S12=Index {0} nenalezen
42S21=Duplicitní název sloupce {0} 42S21=Duplicitní název sloupce {0}
42S22=Sloupec {0} nenalezen 42S22=Sloupec {0} nenalezen
42S32=Nastavení {0} nenalezeno 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=Příkaz byl zrušen nebo připojení vypršelo 57014=Příkaz byl zrušen nebo připojení vypršelo
90000=Funkce {0} musí vracet výsledek 90000=Funkce {0} musí vracet výsledek
90001=Metoda neumožňuje dotazování. Použijte execute nebo executeQuery namísto executeUpdate 90001=Metoda neumožňuje dotazování. Použijte execute nebo executeQuery namísto executeUpdate
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=Index {0} nicht gefunden 42S12=Index {0} nicht gefunden
42S21=Doppelter Feldname {0} 42S21=Doppelter Feldname {0}
42S22=Feld {0} nicht gefunden 42S22=Feld {0} nicht gefunden
42S32=Einstellung {0} nicht gefunden 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=Befehl wurde abgebrochen oder das Session-Timeout ist abgelaufen 57014=Befehl wurde abgebrochen oder das Session-Timeout ist abgelaufen
90000=Funktion {0} muss Zeilen zurückgeben 90000=Funktion {0} muss Zeilen zurückgeben
90001=Methode nicht zulässig für eine Abfrage. Erlaubt sind execute oder executeQuery, nicht jedoch executeUpdate 90001=Methode nicht zulässig für eine Abfrage. Erlaubt sind execute oder executeQuery, nicht jedoch executeUpdate
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=Index {0} not found 42S12=Index {0} not found
42S21=Duplicate column name {0} 42S21=Duplicate column name {0}
42S22=Column {0} not found 42S22=Column {0} not found
42S32=Setting {0} not found 42S31=Identical expressions should be used; expected {0}, found {1}
57014=Statement was canceled or the session timed out 57014=Statement was canceled or the session timed out
90000=Function {0} must return a result set 90000=Function {0} must return a result set
90001=Method is not allowed for a query. Use execute or executeQuery instead of executeUpdate 90001=Method is not allowed for a query. Use execute or executeQuery instead of executeUpdate
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=Indice {0} no encontrado 42S12=Indice {0} no encontrado
42S21=Nombre de columna Duplicada {0} 42S21=Nombre de columna Duplicada {0}
42S22=Columna {0} no encontrada 42S22=Columna {0} no encontrada
42S32=Setting {0} no encontrado 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=Ls sentencia fue cancelado ó la sesión expiró por tiempo vencido 57014=Ls sentencia fue cancelado ó la sesión expiró por tiempo vencido
90000=Función {0} debe devolver un set de resultados (ResultSet) 90000=Función {0} debe devolver un set de resultados (ResultSet)
90001=Metodo no permitido en un query. Use execute ó executeQuery en lugar de executeUpdate 90001=Metodo no permitido en un query. Use execute ó executeQuery en lugar de executeUpdate
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=Index {0} non trouvé 42S12=Index {0} non trouvé
42S21=Duplication du nom de colonnes {0} 42S21=Duplication du nom de colonnes {0}
42S22=Colonne {0} non trouvée 42S22=Colonne {0} non trouvée
42S32=Paramètre {0} non trouvé 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=L'instruction a été annulée ou la session a expiré 57014=L'instruction a été annulée ou la session a expiré
90000=La fonction {0} doit retourner résultat 90000=La fonction {0} doit retourner résultat
90001=Methode non autorisée pour une requête. Utilisez execute ou executeQuery à la place d'executeUpdate 90001=Methode non autorisée pour une requête. Utilisez execute ou executeQuery à la place d'executeUpdate
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=インデックス {0} が見つかりません 42S12=インデックス {0} が見つかりません
42S21=列名 {0} が重複しています 42S21=列名 {0} が重複しています
42S22=列 {0} が見つかりません 42S22=列 {0} が見つかりません
42S32=設定 {0} が見つかりません 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=ステートメントがキャンセルされたか、セッションがタイムアウトしました 57014=ステートメントがキャンセルされたか、セッションがタイムアウトしました
90000=関数 {0} はリザルトセットを返さなければなりません 90000=関数 {0} はリザルトセットを返さなければなりません
90001=メソッドはクエリをサポートしていません。executeUpdateのかわりに、excute、またはexecuteQueryを使用してください 90001=メソッドはクエリをサポートしていません。executeUpdateのかわりに、excute、またはexecuteQueryを使用してください
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=Indeks {0} nie istnieje 42S12=Indeks {0} nie istnieje
42S21=Zduplikowana nazwa kolumny {0} 42S21=Zduplikowana nazwa kolumny {0}
42S22=Kolumna {0} nie istnieje 42S22=Kolumna {0} nie istnieje
42S32=Ustawienie {0} nie istnieje 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=Kwerenda została anulowana albo sesja wygasła 57014=Kwerenda została anulowana albo sesja wygasła
90000=Funkcja {0} musi zwrócić dane 90000=Funkcja {0} musi zwrócić dane
90001=Metoda nie jest dozwolona w kwerendzie 90001=Metoda nie jest dozwolona w kwerendzie
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=índice {0} não foi encontrado 42S12=índice {0} não foi encontrado
42S21=Nome duplicado da coluna {0} 42S21=Nome duplicado da coluna {0}
42S22=Coluna {0} não foi encontrada 42S22=Coluna {0} não foi encontrada
42S32=Definição {0} não foi encontrada 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=#Statement was canceled or the session timed out 57014=#Statement was canceled or the session timed out
90000=Função {0} deve retornar algum resultado 90000=Função {0} deve retornar algum resultado
90001=O método não esta hábilitado para consulta. Use o execute ou o executeQuery em vez de executeUpdate 90001=O método não esta hábilitado para consulta. Use o execute ou o executeQuery em vez de executeUpdate
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=Индекс {0} не найден 42S12=Индекс {0} не найден
42S21=Повтор имени столбца {0} 42S21=Повтор имени столбца {0}
42S22=Столбец {0} не найден 42S22=Столбец {0} не найден
42S32=Настройка {0} не найдена 42S31=Должны использоваться идентичные выражения; ожидалось {0}, получено {1}
57014=Запрос был отменен или закончилось время ожидания сессии 57014=Запрос был отменен или закончилось время ожидания сессии
90000=Функция {0} должна возвращать набор записей 90000=Функция {0} должна возвращать набор записей
90001=Метод не разрешен для запросов. Используйте execute или executeQuery вместо executeUpdate 90001=Метод не разрешен для запросов. Используйте execute или executeQuery вместо executeUpdate
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=Index {0} nenájdený 42S12=Index {0} nenájdený
42S21=Duplicitné meno stĺpca {0} 42S21=Duplicitné meno stĺpca {0}
42S22=Stĺpec {0} nenájdený 42S22=Stĺpec {0} nenájdený
42S32=Nastavenie {0} nenájdené 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=Príkaz bol zrušený alebo vypršal časový limit sedenia 57014=Príkaz bol zrušený alebo vypršal časový limit sedenia
90000=Funkcia {0} musí vracať výsledok (result set) 90000=Funkcia {0} musí vracať výsledok (result set)
90001=Metóda nie je povolená pre dopyt (query). Použite execute alebo executeQuery namiesto executeUpdate 90001=Metóda nie je povolená pre dopyt (query). Použite execute alebo executeQuery namiesto executeUpdate
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
42S12=找不到索引 {0} 42S12=找不到索引 {0}
42S21=重复的字段: {0} 42S21=重复的字段: {0}
42S22=找不到字段 {0} 42S22=找不到字段 {0}
42S32=找不到设置 {0} 42S31=#Identical expressions should be used; expected {0}, found {1}
57014=语句已取消执行或会话已过期 57014=语句已取消执行或会话已过期
90000={0} 函数必须返回一个结果集 90000={0} 函数必须返回一个结果集
90001=不允许在查询内使用的方法,使用execute 或 executeQuery 代替 executeUpdate 90001=不允许在查询内使用的方法,使用execute 或 executeQuery 代替 executeUpdate
......
...@@ -44,7 +44,7 @@ SELECT MODE(V ORDER BY V DESC) FROM TEST; ...@@ -44,7 +44,7 @@ SELECT MODE(V ORDER BY V DESC) FROM TEST;
>> 3 >> 3
SELECT MODE(V ORDER BY V + 1) FROM TEST; SELECT MODE(V ORDER BY V + 1) FROM TEST;
> exception SYNTAX_ERROR_2 > exception IDENTICAL_EXPRESSIONS_SHOULD_BE_USED
SELECT MODE() WITHIN GROUP(ORDER BY V) FROM TEST; SELECT MODE() WITHIN GROUP(ORDER BY V) FROM TEST;
>> 1 >> 1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论