3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is testing WHERE clause conditions with
13 # subtle affinity issues.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 # For this set of tests:
21 # * t1.y holds an integer value with affinity NONE
22 # * t2.b holds a text value with affinity TEXT
24 # These values are not equal and because neither affinity is NUMERIC
25 # no type conversion occurs.
29 CREATE TABLE t1(x,y); -- affinity of t1.y is NONE
30 INSERT INTO t1 VALUES(1,99);
32 CREATE TABLE t2(a, b TEXT); -- affinity of t2.b is TEXT
33 CREATE INDEX t2b ON t2(b);
34 INSERT INTO t2 VALUES(2,99);
36 SELECT x, a, y=b FROM t1, t2 ORDER BY +x, +a;
41 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
46 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
51 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
54 do_test whereB-1.100 {
57 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
60 do_test whereB-1.101 {
62 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
65 do_test whereB-1.102 {
67 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
71 # For this set of tests:
73 # * t1.y holds a text value with affinity TEXT
74 # * t2.b holds an integer value with affinity NONE
76 # These values are not equal and because neither affinity is NUMERIC
77 # no type conversion occurs.
84 CREATE TABLE t1(x, y TEXT); -- affinity of t1.y is TEXT
85 INSERT INTO t1 VALUES(1,99);
87 CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
88 CREATE INDEX t2b ON t2(b);
89 INSERT INTO t2 VALUES(2,99);
91 SELECT x, a, y=b FROM t1, t2 ORDER BY +x, +a;
96 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
101 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
106 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
109 do_test whereB-2.100 {
112 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
115 do_test whereB-2.101 {
117 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
120 do_test whereB-2.102 {
122 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
126 # For this set of tests:
128 # * t1.y holds a text value with affinity NONE
129 # * t2.b holds an integer value with affinity NONE
131 # These values are not equal and because neither affinity is NUMERIC
132 # no type conversion occurs.
139 CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
140 INSERT INTO t1 VALUES(1,99);
142 CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
143 CREATE INDEX t2b ON t2(b);
144 INSERT INTO t2 VALUES(2,'99');
146 SELECT x, a, y=b FROM t1, t2;
151 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
156 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
161 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
164 do_test whereB-3.100 {
167 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
170 do_test whereB-3.101 {
172 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
175 do_test whereB-3.102 {
177 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
182 # For this set of tests:
184 # * t1.y holds a text value with affinity NONE
185 # * t2.b holds an integer value with affinity NUMERIC
187 # Because t2.b has a numeric affinity, type conversion should occur
188 # and the two fields should be equal.
195 CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
196 INSERT INTO t1 VALUES(1,'99');
198 CREATE TABLE t2(a, b NUMERIC); -- affinity of t2.b is NUMERIC
199 CREATE INDEX t2b ON t2(b);
200 INSERT INTO t2 VALUES(2,99);
202 SELECT x, a, y=b FROM t1, t2;
207 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
212 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
216 # In this case the unary "+" operator removes the column affinity so
217 # the columns compare false
219 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
222 do_test whereB-4.100 {
225 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
228 do_test whereB-4.101 {
230 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
233 do_test whereB-4.102 {
234 # In this case the unary "+" operator removes the column affinity so
235 # the columns compare false
237 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
243 # For this set of tests:
245 # * t1.y holds a text value with affinity NONE
246 # * t2.b holds an integer value with affinity INTEGER
248 # Because t2.b has a numeric affinity, type conversion should occur
249 # and the two fields should be equal.
256 CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
257 INSERT INTO t1 VALUES(1,'99');
259 CREATE TABLE t2(a, b INT); -- affinity of t2.b is INTEGER
260 CREATE INDEX t2b ON t2(b);
261 INSERT INTO t2 VALUES(2,99);
263 SELECT x, a, y=b FROM t1, t2;
268 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
273 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
277 # In this case the unary "+" operator removes the column affinity so
278 # the columns compare false
280 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
283 do_test whereB-5.100 {
286 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
289 do_test whereB-5.101 {
291 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
294 do_test whereB-5.102 {
295 # In this case the unary "+" operator removes the column affinity so
296 # the columns compare false
298 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
303 # For this set of tests:
305 # * t1.y holds a text value with affinity NONE
306 # * t2.b holds an integer value with affinity REAL
308 # Because t2.b has a numeric affinity, type conversion should occur
309 # and the two fields should be equal.
316 CREATE TABLE t1(x, y BLOB); -- affinity of t1.y is NONE
317 INSERT INTO t1 VALUES(1,'99');
319 CREATE TABLE t2(a, b REAL); -- affinity of t2.b is REAL
320 CREATE INDEX t2b ON t2(b);
321 INSERT INTO t2 VALUES(2,99.0);
323 SELECT x, a, y=b FROM t1, t2;
328 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
333 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
337 # In this case the unary "+" operator removes the column affinity so
338 # the columns compare false
340 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
343 do_test whereB-6.100 {
346 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
349 do_test whereB-6.101 {
351 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
354 do_test whereB-6.102 {
355 # In this case the unary "+" operator removes the column affinity so
356 # the columns compare false
358 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
363 # For this set of tests:
365 # * t1.y holds an integer value with affinity NUMERIC
366 # * t2.b holds a text value with affinity NONE
368 # Because t1.y has a numeric affinity, type conversion should occur
369 # and the two fields should be equal.
376 CREATE TABLE t1(x, y NUMERIC); -- affinity of t1.y is NUMERIC
377 INSERT INTO t1 VALUES(1,99);
379 CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
380 CREATE INDEX t2b ON t2(b);
381 INSERT INTO t2 VALUES(2,'99');
383 SELECT x, a, y=b FROM t1, t2;
388 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
393 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
397 # In this case the unary "+" operator removes the column affinity so
398 # the columns compare false
400 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
403 do_test whereB-7.100 {
406 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
409 do_test whereB-7.101 {
411 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
414 do_test whereB-7.102 {
415 # In this case the unary "+" operator removes the column affinity so
416 # the columns compare false
418 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
422 # For this set of tests:
424 # * t1.y holds an integer value with affinity INTEGER
425 # * t2.b holds a text value with affinity NONE
427 # Because t1.y has a numeric affinity, type conversion should occur
428 # and the two fields should be equal.
435 CREATE TABLE t1(x, y INT); -- affinity of t1.y is INTEGER
436 INSERT INTO t1 VALUES(1,99);
438 CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
439 CREATE INDEX t2b ON t2(b);
440 INSERT INTO t2 VALUES(2,'99');
442 SELECT x, a, y=b FROM t1, t2;
447 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
452 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
456 # In this case the unary "+" operator removes the column affinity so
457 # the columns compare false
459 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
462 do_test whereB-8.100 {
465 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
468 do_test whereB-8.101 {
470 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
473 do_test whereB-8.102 {
474 # In this case the unary "+" operator removes the column affinity so
475 # the columns compare false
477 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
481 # For this set of tests:
483 # * t1.y holds an integer value with affinity REAL
484 # * t2.b holds a text value with affinity NONE
486 # Because t1.y has a numeric affinity, type conversion should occur
487 # and the two fields should be equal.
494 CREATE TABLE t1(x, y REAL); -- affinity of t1.y is REAL
495 INSERT INTO t1 VALUES(1,99.0);
497 CREATE TABLE t2(a, b BLOB); -- affinity of t2.b is NONE
498 CREATE INDEX t2b ON t2(b);
499 INSERT INTO t2 VALUES(2,'99');
501 SELECT x, a, y=b FROM t1, t2;
506 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
511 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
515 # In this case the unary "+" operator removes the column affinity so
516 # the columns compare false
518 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;
521 do_test whereB-9.100 {
524 SELECT x, a, y=b FROM t1, t2 WHERE y=b;
527 do_test whereB-9.101 {
529 SELECT x, a, y=b FROM t1, t2 WHERE b=y;
532 do_test whereB-9.102 {
533 # In this case the unary "+" operator removes the column affinity so
534 # the columns compare false
536 SELECT x, a, y=b FROM t1, t2 WHERE +y=+b;