1bc622bc0Sdrh# 2014-08-24 2bc622bc0Sdrh# 3bc622bc0Sdrh# The author disclaims copyright to this source code. In place of 4bc622bc0Sdrh# a legal notice, here is a blessing: 5bc622bc0Sdrh# 6bc622bc0Sdrh# May you do good and not evil. 7bc622bc0Sdrh# May you find forgiveness for yourself and forgive others. 8bc622bc0Sdrh# May you share freely, never taking more than you give. 9bc622bc0Sdrh# 10bc622bc0Sdrh#*********************************************************************** 11bc622bc0Sdrh# This file implements regression tests for SQLite library. 12bc622bc0Sdrh# The focus of this script is testing details of the SQL language parser. 13bc622bc0Sdrh# 14bc622bc0Sdrh 15bc622bc0Sdrhset testdir [file dirname $argv0] 16bc622bc0Sdrhsource $testdir/tester.tcl 17bc622bc0Sdrh 18bc622bc0Sdrhdo_catchsql_test parser1-1.1 { 19bc622bc0Sdrh CREATE TABLE t1( 20bc622bc0Sdrh a TEXT PRIMARY KEY, 21bc622bc0Sdrh b TEXT, 22bc622bc0Sdrh FOREIGN KEY(b COLLATE nocase DESC) REFERENCES t1(a COLLATE binary ASC) 23bc622bc0Sdrh ); 24*108aa00aSdrh} {1 {syntax error after column name "b"}} 25*108aa00aSdrh 26*108aa00aSdrh 27*108aa00aSdrh# Verify that a legacy schema in the sqlite_master file is allowed to have 28*108aa00aSdrh# COLLATE, ASC, and DESC keywords on the id list of a FK constraint, and that 29*108aa00aSdrh# those keywords are silently ignored. 30*108aa00aSdrh# 31bc622bc0Sdrhdo_execsql_test parser1-1.2 { 32bc622bc0Sdrh CREATE TABLE t1( 33bc622bc0Sdrh a TEXT PRIMARY KEY, 34bc622bc0Sdrh b TEXT, 35bc622bc0Sdrh FOREIGN KEY(b) REFERENCES t1(a) 36bc622bc0Sdrh ); 37bc622bc0Sdrh INSERT INTO t1 VALUES('abc',NULL),('xyz','abc'); 38bc622bc0Sdrh PRAGMA writable_schema=on; 39bc622bc0Sdrh UPDATE sqlite_master SET sql='CREATE TABLE t1( 40bc622bc0Sdrh a TEXT PRIMARY KEY, 41bc622bc0Sdrh b TEXT, 42bc622bc0Sdrh FOREIGN KEY(b COLLATE nocase) REFERENCES t1(a) 43bc622bc0Sdrh )' WHERE name='t1'; 44bc622bc0Sdrh SELECT name FROM sqlite_master WHERE sql LIKE '%collate%'; 45bc622bc0Sdrh} {t1} 46bc622bc0Sdrhsqlite3 db2 test.db 47bc622bc0Sdrhdo_test parser1-1.3 { 48bc622bc0Sdrh sqlite3 db2 test.db 49bc622bc0Sdrh db2 eval {SELECT * FROM t1 ORDER BY 1} 50bc622bc0Sdrh} {abc {} xyz abc} 51*108aa00aSdrhdb2 close 52bc622bc0Sdrh 53*108aa00aSdrhdo_execsql_test parser1-1.4 { 54*108aa00aSdrh UPDATE sqlite_master SET sql='CREATE TABLE t1( 55*108aa00aSdrh a TEXT PRIMARY KEY, 56*108aa00aSdrh b TEXT, 57*108aa00aSdrh FOREIGN KEY(b ASC) REFERENCES t1(a) 58*108aa00aSdrh )' WHERE name='t1'; 59*108aa00aSdrh SELECT name FROM sqlite_master WHERE sql LIKE '%ASC%'; 60*108aa00aSdrh} {t1} 61*108aa00aSdrhsqlite3 db2 test.db 62*108aa00aSdrhdo_test parser1-1.5 { 63*108aa00aSdrh sqlite3 db2 test.db 64*108aa00aSdrh db2 eval {SELECT * FROM t1 ORDER BY 1} 65*108aa00aSdrh} {abc {} xyz abc} 66*108aa00aSdrhdb2 close 67bc622bc0Sdrh 68bc622bc0Sdrhdo_catchsql_test parser1-2.1 { 69bc622bc0Sdrh WITH RECURSIVE 70bc622bc0Sdrh c(x COLLATE binary) AS (VALUES(1) UNION SELECT x+1 FROM c WHERE x<5) 71bc622bc0Sdrh SELECT x FROM c; 72bc622bc0Sdrh} {1 {syntax error after column name "x"}} 73bc622bc0Sdrhdo_catchsql_test parser1-2.2 { 74bc622bc0Sdrh WITH RECURSIVE 75bc622bc0Sdrh c(x ASC) AS (VALUES(1) UNION SELECT x+1 FROM c WHERE x<5) 76bc622bc0Sdrh SELECT x FROM c; 77bc622bc0Sdrh} {1 {syntax error after column name "x"}} 78bc622bc0Sdrh 79bc622bc0Sdrhfinish_test 80