提交 6fa531aa authored 作者: Noel Grandin's avatar Noel Grandin

issue #873: No error when `=` in equal condition when column is not of array type

上级 6d54fb23
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #873: No error when `=` in equal condition when column is not of array type
</li>
<li>Issue #1069: Failed to add DATETIME(3) column since 1.4.197
</li>
<li>Issue #456: H2 table privileges referring to old schema after schema rename
......
......@@ -140,6 +140,7 @@
90107=Cannot drop {0} because {1} depends on it
90108=Out of memory.
90109=View {0} is invalid: {1}
90110=Comparing ARRAY to scalar value
90111=Error accessing linked table with SQL statement {0}, cause: {1}
90112=Row not found when trying to delete from index {0}
90113=Unsupported connection setting {0}
......
......@@ -1628,6 +1628,17 @@ public class ErrorCode {
*/
public static final int VIEW_IS_INVALID_2 = 90109;
/**
* The error with code <code>90110</code> is thrown when
* trying to compare an array value against a non-array value.
* Example:
* <pre>
* CREATE TABLE test (id INT NOT NULL, name VARCHAR);
* select * from test where id = (1, 2);
* </pre>
*/
public static final int COMPARING_ARRAY_TO_SCALAR = 90110;
/**
* The error with code <code>90111</code> is thrown when
* an exception occurred while accessing a linked table.
......@@ -1979,7 +1990,7 @@ public class ErrorCode {
*/
public static final int ROW_NOT_FOUND_IN_PRIMARY_INDEX = 90143;
// next are 90110, 90122, 90144
// next are 90122, 90144
private ErrorCode() {
// utility class
......
......@@ -7,6 +7,7 @@ package org.h2.expression;
import java.util.ArrayList;
import java.util.Arrays;
import org.h2.api.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Session;
import org.h2.engine.SysProperties;
......@@ -16,7 +17,11 @@ import org.h2.table.Column;
import org.h2.table.ColumnResolver;
import org.h2.table.TableFilter;
import org.h2.util.MathUtils;
import org.h2.value.*;
import org.h2.value.Value;
import org.h2.value.ValueBoolean;
import org.h2.value.ValueEnum;
import org.h2.value.ValueGeometry;
import org.h2.value.ValueNull;
/**
* Example comparison expressions are ID=1, NAME=NAME, NAME IS NULL.
......@@ -177,6 +182,9 @@ public class Comparison extends Condition {
left = left.optimize(session);
if (right != null) {
right = right.optimize(session);
if (right.getType() == Value.ARRAY && left.getType() != Value.ARRAY) {
throw DbException.get(ErrorCode.COMPARING_ARRAY_TO_SCALAR);
}
if (right instanceof ExpressionColumn) {
if (left.isConstant() || left instanceof Parameter) {
Expression temp = left;
......
......@@ -140,6 +140,7 @@
90107=Nelze odstranit {0}, protože {1} na něm závisí
90108=Nedostatek paměti.
90109=Pohled {0} je neplatný: {1}
90110=#Comparing ARRAY to scalar value
90111=Chyba přístupu propojené tabulky s SQL příkazem {0}, příčina: {1}
90112=Řádek nebyl nalezen při pokusu o smazání z indexu {0}
90113=Nepodporované nastavení připojení {0}
......
......@@ -140,6 +140,7 @@
90107=Kann {0} nicht löschen weil {1} davon abhängt
90108=Nicht genug Hauptspeicher.
90109=View {0} ist ungültig: {1}
90110=#Comparing ARRAY to scalar value
90111=Fehler beim Zugriff auf eine verknüpfte Tabelle mit SQL Befehl {0}, Grund: {1}
90112=Zeile nicht gefunden beim Löschen von Index {0}
90113=Datenbank-Verbindungs Option {0} nicht unterstützt
......
......@@ -140,6 +140,7 @@
90107=Cannot drop {0} because {1} depends on it
90108=Out of memory.
90109=View {0} is invalid: {1}
90110=Comparing ARRAY to scalar value
90111=Error accessing linked table with SQL statement {0}, cause: {1}
90112=Row not found when trying to delete from index {0}
90113=Unsupported connection setting {0}
......
......@@ -140,6 +140,7 @@
90107=Imposible eliminar {0} debido a que {1} depende de él.
90108=Memoria Insuficiente - Out of memory. Tamaño: {0}
90109=La Vista {0} es invalida: {1}
90110=#Comparing ARRAY to scalar value
90111=Error accediendo Linked Table con sentencia SQL {0}, causa: {1}
90112=Fila no encontrada mientras se intentaba borrar del indice {0}
90113=Parametro de conexión No soportado {0}
......
......@@ -140,6 +140,7 @@
90107=Impossible de supprimer {0} car {1} dépend de lui
90108=Mémoire insuffisante.
90109=La vue {0} est invalide: {1}
90110=#Comparing ARRAY to scalar value
90111=Erreur lors de l'accès à la table liée à l'aide de l'instruction SQL {0}, cause: {1}
90112=Ligne non trouvée lors de la tentative de suppression à partir de l'index {0}
90113=Paramétrage de connexion non pris en charge {0}
......
......@@ -140,6 +140,7 @@
90107={1} が依存しているため、{0} をドロップすることはできません
90108=メモリが不足しています
90109=ビュー {0} は無効です: {1}
90110=#Comparing ARRAY to scalar value
90111=SQLステートメント {0} による結合テーブルアクセスエラー
90112=インデックス {0} から削除を試みましたが、行が見つかりません
90113=未サポートの接続設定 {0}
......
......@@ -140,6 +140,7 @@
90107=Nie można skasować {0} ponieważ zależy od {1}
90108=Brak pamięci.
90109=Widok {0} jest nieprawidłowy
90110=#Comparing ARRAY to scalar value
90111=Błąd dostępu do tabeli skrzyżowań przy pomocy zapytania SQL {0}, błąd: {1}
90112=Rekord nie znaleziony przy probie kasowania z indeksu {0}
90113=Nie wspierana opcja połączenia {0}
......
......@@ -140,6 +140,7 @@
90107=Não pode apagar {0} por que depende de {1}
90108=#Out of memory.
90109=Vista {0} é inválida: {1}
90110=#Comparing ARRAY to scalar value
90111=Erro ao acessar a tabela lincada com a instrução SQL {0}, causa: {1}
90112=A linha não foi encontrada ao tentar eliminar apartir do índice {0}
90113=Não suporta a definição de conecção {0}
......
......@@ -140,6 +140,7 @@
90107=Невозможно удалить {0}, пока существует зависимый объект {1}
90108=Ошибка нехватки памяти
90109=Представление {0} содержит ошибки: {1}
90110=#Comparing ARRAY to scalar value
90111=Ошибка при обращении к линкованной таблице SQL запросом {0}, причина: {1}
90112=Запись не найдена при удалении из индекса {0}
90113=Неподдерживаемая опция соединения {0}
......
......@@ -140,6 +140,7 @@
90107=Nemôžem zmazať {0} lebo {1} zavisí na {0}
90108=Nedostatok pamäte.
90109=Pohľad (view) {0} je nesprávny: {1}
90110=#Comparing ARRAY to scalar value
90111=Chyba prístupu k linkovanej tabuľke SQL príkazom {0}, dôvod: {1}
90112=Riadok nenájdený pri pokuse o vymazanie cez index {0}
90113=Nepodporované nastavenie spojenia {0}
......
......@@ -140,6 +140,7 @@
90107=不能删除 {0} ,因为 {1} 依赖着它
90108=内存不足.
90109=视图 {0} 无效: {1}
90110=#Comparing ARRAY to scalar value
90111=SQL语句访问表连接错误 {0}, 原因: {1}
90112=尝试从索引中删除 {0}的时候找不到行
90113=不支持的连接设置 {0}
......
......@@ -19,7 +19,6 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Random;
import org.h2.engine.SysProperties;
import org.h2.test.TestAll;
import org.h2.test.TestBase;
......@@ -108,7 +107,8 @@ public class TestScript extends TestBase {
"dropSchema" }) {
testScript("ddl/" + s + ".sql");
}
for (String s : new String[] { "insertIgnore", "mergeUsing", "script", "with" }) {
for (String s : new String[] { "error_reporting", "insertIgnore",
"mergeUsing", "script", "with" }) {
testScript("dml/" + s + ".sql");
}
for (String s : new String[] { "avg", "bit-and", "bit-or", "count",
......
-- Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
-- and the EPL 1.0 (http://h2database.com/html/license.html).
-- Initial Developer: H2 Group
--
CREATE TABLE test (id INT NOT NULL, name VARCHAR);
> ok
select * from test where id = (1, 2);
> exception
drop table test;
> ok
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论