1# 2001 September 15 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#*********************************************************************** 11# This file implements regression tests for SQLite library. The 12# focus of this file is testing the sqlite_exec_printf() and 13# sqlite_get_table_printf() APIs. 14# 15# $Id: tableapi.test,v 1.3 2001/09/16 00:13:28 drh Exp $ 16 17set testdir [file dirname $argv0] 18source $testdir/tester.tcl 19 20do_test tableapi-1.0 { 21 set ::dbx [sqlite_open testdb] 22 catch {sqlite_exec_printf $::dbx {DROP TABLE xyz} {}} 23 sqlite_exec_printf $::dbx {CREATE TABLE %s(a int, b text)} xyz 24} {0 {}} 25do_test tableapi-1.1 { 26 sqlite_exec_printf $::dbx { 27 INSERT INTO xyz VALUES(1,'%q') 28 } {Hi Y'all} 29} {0 {}} 30do_test tableapi-1.2 { 31 sqlite_exec_printf $::dbx {SELECT * FROM xyz} {} 32} {0 {a b 1 {Hi Y'all}}} 33 34do_test tableapi-2.1 { 35 sqlite_get_table_printf $::dbx { 36 SELECT * FROM xyz WHERE b='%q' 37 } {Hi Y'all} 38} {0 1 2 a b 1 {Hi Y'all}} 39do_test tableapi-2.2 { 40 sqlite_get_table_printf $::dbx { 41 SELECT * FROM xyz 42 } {} 43} {0 1 2 a b 1 {Hi Y'all}} 44do_test tableapi-2.3 { 45 for {set i 2} {$i<=50} {incr i} { 46 sqlite_get_table_printf $::dbx \ 47 "INSERT INTO xyz VALUES($i,'(%s)')" $i 48 } 49 sqlite_get_table_printf $::dbx { 50 SELECT * FROM xyz ORDER BY a 51 } {} 52} {0 50 2 a b 1 {Hi Y'all} 2 (2) 3 (3) 4 (4) 5 (5) 6 (6) 7 (7) 8 (8) 9 (9) 10 (10) 11 (11) 12 (12) 13 (13) 14 (14) 15 (15) 16 (16) 17 (17) 18 (18) 19 (19) 20 (20) 21 (21) 22 (22) 23 (23) 24 (24) 25 (25) 26 (26) 27 (27) 28 (28) 29 (29) 30 (30) 31 (31) 32 (32) 33 (33) 34 (34) 35 (35) 36 (36) 37 (37) 38 (38) 39 (39) 40 (40) 41 (41) 42 (42) 43 (43) 44 (44) 45 (45) 46 (46) 47 (47) 48 (48) 49 (49) 50 (50)} 53do_test tableapi-2.3.1 { 54 sqlite_get_table_printf $::dbx { 55 SELECT * FROM xyz WHERE a>49 ORDER BY a 56 } {} 57} {0 1 2 a b 50 (50)} 58do_test tableapi-2.3.2 { 59 sqlite_get_table_printf $::dbx { 60 SELECT * FROM xyz WHERE a>47 ORDER BY a 61 } {} 62} {0 3 2 a b 48 (48) 49 (49) 50 (50)} 63do_test tableapi-2.4 { 64 set ::big_str [sqlite_mprintf_str {%500'* Hello %500'*} 0 0 {}] 65 sqlite_get_table_printf $::dbx { 66 INSERT INTO xyz VALUES(51,'%q') 67 } $::big_str 68} {0 0 0} 69do_test tableapi-2.5 { 70 sqlite_get_table_printf $::dbx { 71 SELECT * FROM xyz WHERE a>49 ORDER BY a; 72 } {} 73} "0 2 2 a b 50 (50) 51 \173$::big_str\175" 74do_test tableapi-2.6 { 75 sqlite_get_table_printf $::dbx { 76 INSERT INTO xyz VALUES(52,NULL) 77 } {} 78 sqlite_get_table_printf $::dbx { 79 SELECT * FROM xyz WHERE a IN (42,50,52) ORDER BY a DESC 80 } {} 81} {0 3 2 a b 52 NULL 50 (50) 42 (42)} 82 83do_test tableapi-99.0 { 84 sqlite_close $::dbx 85} {} 86 87finish_test 88