123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543 |
- # 2009 August 13
- #
- # The author disclaims copyright to this source code. In place of
- # a legal notice, here is a blessing:
- #
- # May you do good and not evil.
- # May you find forgiveness for yourself and forgive others.
- # May you share freely, never taking more than you give.
- #
- #***********************************************************************
- # This file implements regression tests for SQLite library. The
- # focus of this file is testing WHERE clause conditions with
- # subtle affinity issues.
- #
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- # For this set of tests:
- #
- # * t1.y holds an integer value with affinity NONE
- # * t2.b holds a text value with affinity TEXT
- #
- # These values are not equal and because neither affinity is NUMERIC
- # no type conversion occurs.
- #
- do_test whereB-1.1 {
- db eval {
- CREATE TABLE t1(x,y); -- affinity of t1.y is NONE
- INSERT INTO t1 VALUES(1,99);
- CREATE TABLE t2(a, b TEXT); -- affinity of t2.b is TEXT
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,99);
- SELECT x, a, y=b FROM t1, t2 ORDER BY +x, +a;
- }
- } {1 2 0}
- do_test whereB-1.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {}
- do_test whereB-1.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {}
- do_test whereB-1.4 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-1.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {}
- do_test whereB-1.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {}
- do_test whereB-1.102 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- # For this set of tests:
- #
- # * t1.y holds a text value with affinity TEXT
- # * t2.b holds an integer value with affinity NONE
- #
- # These values are not equal and because neither affinity is NUMERIC
- # no type conversion occurs.
- #
- do_test whereB-2.1 {
- db eval {
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(x, y TEXT); -- affinity of t1.y is TEXT
- INSERT INTO t1 VALUES(1,99);
- CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,99);
- SELECT x, a, y=b FROM t1, t2 ORDER BY +x, +a;
- }
- } {1 2 0}
- do_test whereB-2.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {}
- do_test whereB-2.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {}
- do_test whereB-2.4 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-2.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {}
- do_test whereB-2.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {}
- do_test whereB-2.102 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- # For this set of tests:
- #
- # * t1.y holds a text value with affinity NONE
- # * t2.b holds an integer value with affinity NONE
- #
- # These values are not equal and because neither affinity is NUMERIC
- # no type conversion occurs.
- #
- do_test whereB-3.1 {
- db eval {
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
- INSERT INTO t1 VALUES(1,99);
- CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,'99');
- SELECT x, a, y=b FROM t1, t2;
- }
- } {1 2 0}
- do_test whereB-3.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {}
- do_test whereB-3.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {}
- do_test whereB-3.4 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-3.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {}
- do_test whereB-3.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {}
- do_test whereB-3.102 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- # For this set of tests:
- #
- # * t1.y holds a text value with affinity NONE
- # * t2.b holds an integer value with affinity NUMERIC
- #
- # Because t2.b has a numeric affinity, type conversion should occur
- # and the two fields should be equal.
- #
- do_test whereB-4.1 {
- db eval {
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
- INSERT INTO t1 VALUES(1,'99');
- CREATE TABLE t2(a, b NUMERIC); -- affinity of t2.b is NUMERIC
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,99);
- SELECT x, a, y=b FROM t1, t2;
- }
- } {1 2 1}
- do_test whereB-4.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-4.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-4.4 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-4.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-4.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-4.102 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- # For this set of tests:
- #
- # * t1.y holds a text value with affinity NONE
- # * t2.b holds an integer value with affinity INTEGER
- #
- # Because t2.b has a numeric affinity, type conversion should occur
- # and the two fields should be equal.
- #
- do_test whereB-5.1 {
- db eval {
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
- INSERT INTO t1 VALUES(1,'99');
- CREATE TABLE t2(a, b INT); -- affinity of t2.b is INTEGER
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,99);
- SELECT x, a, y=b FROM t1, t2;
- }
- } {1 2 1}
- do_test whereB-5.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-5.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-5.4 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-5.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-5.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-5.102 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- # For this set of tests:
- #
- # * t1.y holds a text value with affinity NONE
- # * t2.b holds an integer value with affinity REAL
- #
- # Because t2.b has a numeric affinity, type conversion should occur
- # and the two fields should be equal.
- #
- do_test whereB-6.1 {
- db eval {
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
- INSERT INTO t1 VALUES(1,'99');
- CREATE TABLE t2(a, b REAL); -- affinity of t2.b is REAL
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,99.0);
- SELECT x, a, y=b FROM t1, t2;
- }
- } {1 2 1}
- do_test whereB-6.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-6.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-6.4 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-6.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-6.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-6.102 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- # For this set of tests:
- #
- # * t1.y holds an integer value with affinity NUMERIC
- # * t2.b holds a text value with affinity NONE
- #
- # Because t1.y has a numeric affinity, type conversion should occur
- # and the two fields should be equal.
- #
- do_test whereB-7.1 {
- db eval {
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(x, y NUMERIC); -- affinity of t1.y is NUMERIC
- INSERT INTO t1 VALUES(1,99);
- CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,'99');
- SELECT x, a, y=b FROM t1, t2;
- }
- } {1 2 1}
- do_test whereB-7.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-7.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-7.4 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-7.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-7.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-7.102 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- # For this set of tests:
- #
- # * t1.y holds an integer value with affinity INTEGER
- # * t2.b holds a text value with affinity NONE
- #
- # Because t1.y has a numeric affinity, type conversion should occur
- # and the two fields should be equal.
- #
- do_test whereB-8.1 {
- db eval {
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(x, y INT); -- affinity of t1.y is INTEGER
- INSERT INTO t1 VALUES(1,99);
- CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,'99');
- SELECT x, a, y=b FROM t1, t2;
- }
- } {1 2 1}
- do_test whereB-8.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-8.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-8.4 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-8.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-8.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-8.102 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- # For this set of tests:
- #
- # * t1.y holds an integer value with affinity REAL
- # * t2.b holds a text value with affinity NONE
- #
- # Because t1.y has a numeric affinity, type conversion should occur
- # and the two fields should be equal.
- #
- do_test whereB-9.1 {
- db eval {
- DROP TABLE t1;
- DROP TABLE t2;
- CREATE TABLE t1(x, y REAL); -- affinity of t1.y is REAL
- INSERT INTO t1 VALUES(1,99.0);
- CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
- CREATE INDEX t2b ON t2(b);
- INSERT INTO t2 VALUES(2,'99');
- SELECT x, a, y=b FROM t1, t2;
- }
- } {1 2 1}
- do_test whereB-9.2 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-9.3 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-9.4 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- do_test whereB-9.100 {
- db eval {
- DROP INDEX t2b;
- SELECT x, a, y=b FROM t1, t2 WHERE y=b;
- }
- } {1 2 1}
- do_test whereB-9.101 {
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE b=y;
- }
- } {1 2 1}
- do_test whereB-9.102 {
- # In this case the unary "+" operator removes the column affinity so
- # the columns compare false
- db eval {
- SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
- }
- } {}
- finish_test
|