xref: /sqlite-3.40.0/test/tableapi.test (revision daffd0e5)
1# Copyright (c) 2001 D. Richard Hipp
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public
5# License as published by the Free Software Foundation; either
6# version 2 of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11# General Public License for more details.
12#
13# You should have received a copy of the GNU General Public
14# License along with this library; if not, write to the
15# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16# Boston, MA  02111-1307, USA.
17#
18# Author contact information:
19#   [email protected]
20#   http://www.hwaci.com/drh/
21#
22#***********************************************************************
23# This file implements regression tests for SQLite library.  The
24# focus of this file is testing the sqlite_exec_printf() and
25# sqlite_get_table_printf() APIs.
26#
27# $Id: tableapi.test,v 1.2 2001/04/11 14:28:43 drh Exp $
28
29set testdir [file dirname $argv0]
30source $testdir/tester.tcl
31
32do_test tableapi-1.0 {
33  set ::dbx [sqlite_open testdb]
34  catch {sqlite_exec_printf $::dbx {DROP TABLE xyz} {}}
35  sqlite_exec_printf $::dbx {CREATE TABLE %s(a int, b text)} xyz
36} {0 {}}
37do_test tableapi-1.1 {
38  sqlite_exec_printf $::dbx {
39    INSERT INTO xyz VALUES(1,'%q')
40  } {Hi Y'all}
41} {0 {}}
42do_test tableapi-1.2 {
43  sqlite_exec_printf $::dbx {SELECT * FROM xyz} {}
44} {0 {a b 1 {Hi Y'all}}}
45
46do_test tableapi-2.1 {
47  sqlite_get_table_printf $::dbx {
48    SELECT * FROM xyz WHERE b='%q'
49  } {Hi Y'all}
50} {0 1 2 a b 1 {Hi Y'all}}
51do_test tableapi-2.2 {
52  sqlite_get_table_printf $::dbx {
53    SELECT * FROM xyz
54  } {}
55} {0 1 2 a b 1 {Hi Y'all}}
56do_test tableapi-2.3 {
57  for {set i 2} {$i<=50} {incr i} {
58    sqlite_get_table_printf $::dbx \
59       "INSERT INTO xyz VALUES($i,'(%s)')" $i
60  }
61  sqlite_get_table_printf $::dbx {
62    SELECT * FROM xyz ORDER BY a
63  } {}
64} {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)}
65do_test tableapi-2.3.1 {
66  sqlite_get_table_printf $::dbx {
67    SELECT * FROM xyz  WHERE a>49 ORDER BY a
68  } {}
69} {0 1 2 a b 50 (50)}
70do_test tableapi-2.3.2 {
71  sqlite_get_table_printf $::dbx {
72    SELECT * FROM xyz WHERE a>47 ORDER BY a
73  } {}
74} {0 3 2 a b 48 (48) 49 (49) 50 (50)}
75do_test tableapi-2.4 {
76  set ::big_str [sqlite_mprintf_str {%500'* Hello %500'*} 0 0 {}]
77  sqlite_get_table_printf $::dbx {
78    INSERT INTO xyz VALUES(51,'%q')
79  } $::big_str
80} {0 0 0}
81do_test tableapi-2.5 {
82  sqlite_get_table_printf $::dbx {
83    SELECT * FROM xyz WHERE a>49 ORDER BY a;
84  } {}
85} "0 2 2 a b 50 (50) 51 \173$::big_str\175"
86do_test tableapi-2.6 {
87  sqlite_get_table_printf $::dbx {
88    INSERT INTO xyz VALUES(52,NULL)
89  } {}
90  sqlite_get_table_printf $::dbx {
91    SELECT * FROM xyz WHERE a IN (42,50,52) ORDER BY a DESC
92  } {}
93} {0 3 2 a b 52 NULL 50 (50) 42 (42)}
94
95do_test tableapi-99.0 {
96  sqlite_close $::dbx
97} {}
98
99finish_test
100