1467c1c70Sdrh# 2015-06-02 2467c1c70Sdrh# 3467c1c70Sdrh# The author disclaims copyright to this source code. In place of 4467c1c70Sdrh# a legal notice, here is a blessing: 5467c1c70Sdrh# 6467c1c70Sdrh# May you do good and not evil. 7467c1c70Sdrh# May you find forgiveness for yourself and forgive others. 8467c1c70Sdrh# May you share freely, never taking more than you give. 9467c1c70Sdrh# 10467c1c70Sdrh#*********************************************************************** 11467c1c70Sdrh# This file implements regression tests for SQLite library. The 12467c1c70Sdrh# focus of this file is type affinity in comparison operations. 13467c1c70Sdrh# 14467c1c70Sdrh 15467c1c70Sdrhset testdir [file dirname $argv0] 16467c1c70Sdrhsource $testdir/tester.tcl 17b6ce71bdSdanset testprefix affinity2 18467c1c70Sdrh 19467c1c70Sdrhdo_execsql_test affinity2-100 { 20467c1c70Sdrh CREATE TABLE t1( 21467c1c70Sdrh xi INTEGER, 22467c1c70Sdrh xr REAL, 23467c1c70Sdrh xb BLOB, 24467c1c70Sdrh xn NUMERIC, 25467c1c70Sdrh xt TEXT 26467c1c70Sdrh ); 27467c1c70Sdrh INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(1,1,1,1,1,1); 28467c1c70Sdrh INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(2,'2','2','2','2','2'); 29467c1c70Sdrh INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(3,'03','03','03','03','03'); 30467c1c70Sdrh 31467c1c70Sdrh} {} 32467c1c70Sdrhdo_execsql_test affinity2-110 { 33467c1c70Sdrh SELECT xi, typeof(xi) FROM t1 ORDER BY rowid; 34467c1c70Sdrh} {1 integer 2 integer 3 integer} 35467c1c70Sdrhdo_execsql_test affinity2-120 { 36467c1c70Sdrh SELECT xr, typeof(xr) FROM t1 ORDER BY rowid; 37467c1c70Sdrh} {1.0 real 2.0 real 3.0 real} 38467c1c70Sdrhdo_execsql_test affinity2-130 { 39467c1c70Sdrh SELECT xb, typeof(xb) FROM t1 ORDER BY rowid; 40467c1c70Sdrh} {1 integer 2 text 03 text} 41467c1c70Sdrhdo_execsql_test affinity2-140 { 42467c1c70Sdrh SELECT xn, typeof(xn) FROM t1 ORDER BY rowid; 43467c1c70Sdrh} {1 integer 2 integer 3 integer} 44467c1c70Sdrhdo_execsql_test affinity2-150 { 45467c1c70Sdrh SELECT xt, typeof(xt) FROM t1 ORDER BY rowid; 46467c1c70Sdrh} {1 text 2 text 03 text} 47467c1c70Sdrh 48467c1c70Sdrhdo_execsql_test affinity2-200 { 49467c1c70Sdrh SELECT rowid, xi==xt, xi==xb, xi==+xt FROM t1 ORDER BY rowid; 50467c1c70Sdrh} {1 1 1 1 2 1 1 1 3 1 1 1} 51467c1c70Sdrhdo_execsql_test affinity2-210 { 52467c1c70Sdrh SELECT rowid, xr==xt, xr==xb, xr==+xt FROM t1 ORDER BY rowid; 53467c1c70Sdrh} {1 1 1 1 2 1 1 1 3 1 1 1} 54467c1c70Sdrhdo_execsql_test affinity2-220 { 55467c1c70Sdrh SELECT rowid, xn==xt, xn==xb, xn==+xt FROM t1 ORDER BY rowid; 56467c1c70Sdrh} {1 1 1 1 2 1 1 1 3 1 1 1} 57467c1c70Sdrh 58467c1c70Sdrhdo_execsql_test affinity2-300 { 59467c1c70Sdrh SELECT rowid, xt==+xi, xt==xi, xt==xb FROM t1 ORDER BY rowid; 60467c1c70Sdrh} {1 1 1 0 2 1 1 1 3 0 1 1} 61467c1c70Sdrh 62b6ce71bdSdan#------------------------------------------------------------------------- 63b6ce71bdSdando_execsql_test 400 { 64b6ce71bdSdan CREATE TABLE ttt(c0, c1); 65b6ce71bdSdan CREATE INDEX ii ON ttt(CAST(c0 AS NUMERIC)); 66b6ce71bdSdan INSERT INTO ttt VALUES('abc', '-1'); 67b6ce71bdSdan} 68b6ce71bdSdando_execsql_test 410 { 69b6ce71bdSdan SELECT * FROM ttt WHERE CAST(c0 AS NUMERIC) > c1 GROUP BY rowid; 70b6ce71bdSdan} {abc -1} 71b6ce71bdSdando_execsql_test 420 { 72b6ce71bdSdan SELECT * FROM ttt INDEXED BY ii WHERE CAST(c0 AS NUMERIC) > c1 GROUP BY rowid; 73b6ce71bdSdan} {abc -1} 74b6ce71bdSdan 75b6ce71bdSdando_execsql_test 430 { 76b6ce71bdSdan CREATE TABLE t3(a, b, c INTEGER); 77b6ce71bdSdan CREATE INDEX t3ac ON t3(a, c-1); 78b6ce71bdSdan INSERT INTO t3 VALUES(1, 1, 1); 79b6ce71bdSdan INSERT INTO t3 VALUES(2, 1, 0); 80b6ce71bdSdan INSERT INTO t3 VALUES(3, 1, 1); 81b6ce71bdSdan INSERT INTO t3 VALUES(4, 1, 0); 82b6ce71bdSdan INSERT INTO t3 VALUES(5, 1, 1); 83b6ce71bdSdan} 84b6ce71bdSdando_execsql_test 440 { 85b6ce71bdSdan SELECT * FROM t3 WHERE c='0' ORDER BY a; 86b6ce71bdSdan} {2 1 0 4 1 0} 87b6ce71bdSdan 88af866402Sdrh# 2019-08-22 ticket https://sqlite.org/src/info/d99f1ffe836c591ac57f 89af866402Sdrh# False positive in sqlite3ExprNeedsNoAffinityChange() 90af866402Sdrh# 91af866402Sdrhdo_execsql_test 500 { 92af866402Sdrh DROP TABLE IF EXISTS t0; 93af866402Sdrh CREATE TABLE t0(c0 TEXT UNIQUE, c1); 94af866402Sdrh INSERT INTO t0(c0) VALUES (-1); 95af866402Sdrh SELECT quote(- x'ce'), quote(t0.c0), quote(- x'ce' >= t0.c0) FROM t0; 96af866402Sdrh} {0 '-1' 1} 97af866402Sdrhdo_execsql_test 501 { 98af866402Sdrh SELECT * FROM t0 WHERE - x'ce' >= t0.c0; 99af866402Sdrh} {-1 {}} 100af866402Sdrhdo_execsql_test 502 { 101af866402Sdrh SELECT quote(+-+x'ce'), quote(t0.c0), quote(+-+x'ce' >= t0.c0) FROM t0; 102af866402Sdrh} {0 '-1' 1} 103af866402Sdrhdo_execsql_test 503 { 104af866402Sdrh SELECT * FROM t0 WHERE +-+x'ce' >= t0.c0; 105af866402Sdrh} {-1 {}} 106af866402Sdrhdo_execsql_test 504 { 107af866402Sdrh SELECT quote(- 'ce'), quote(t0.c0), quote(- 'ce' >= t0.c0) FROM t0; 108af866402Sdrh} {0 '-1' 1} 109af866402Sdrhdo_execsql_test 505 { 110af866402Sdrh SELECT * FROM t0 WHERE - 'ce' >= t0.c0; 111af866402Sdrh} {-1 {}} 112af866402Sdrhdo_execsql_test 506 { 113af866402Sdrh SELECT quote(+-+'ce'), quote(t0.c0), quote(+-+'ce' >= t0.c0) FROM t0; 114af866402Sdrh} {0 '-1' 1} 115af866402Sdrhdo_execsql_test 507 { 116af866402Sdrh SELECT * FROM t0 WHERE +-+'ce' >= t0.c0; 117af866402Sdrh} {-1 {}} 118af866402Sdrh 1197314495fSdrh# 2019-08-30 ticket https://www.sqlite.org/src/info/40812aea1fde9594 1207314495fSdrh# 121*6117a173Sdan# Due to some differences in floating point computations, these tests do not 122*6117a173Sdan# work under valgrind. 123*6117a173Sdan# 124*6117a173Sdanif {![info exists ::G(valgrind)]} { 1257314495fSdrh do_execsql_test 600 { 1267314495fSdrh DROP TABLE IF EXISTS t0; 1277314495fSdrh CREATE TABLE t0(c0 REAL UNIQUE); 1287314495fSdrh INSERT INTO t0(c0) VALUES (3175546974276630385); 1297314495fSdrh SELECT 3175546974276630385 < c0 FROM t0; 1307314495fSdrh } {1} 1317314495fSdrh do_execsql_test 601 { 1327314495fSdrh SELECT 1 FROM t0 WHERE 3175546974276630385 < c0; 1337314495fSdrh } {1} 134*6117a173Sdan} 135af866402Sdrh 136467c1c70Sdrhfinish_test 137