blob: 35a5cae83d750f7b47994b116b3068974a0bd692 [file] [log] [blame]
drh82a48512003-09-06 22:45:20 +00001# 2003 September 6
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 script testing the sqlite_bind API.
13#
danielk197751e3d8e2004-05-20 01:12:34 +000014# $Id: bind.test,v 1.2 2004/05/20 01:12:35 danielk1977 Exp $
drh82a48512003-09-06 22:45:20 +000015#
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20do_test bind-1.1 {
21 db close
22 set DB [sqlite db test.db]
23 execsql {CREATE TABLE t1(a,b,c)}
24 set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
25 set TAIL
26} {}
27do_test bind-1.2 {
28 sqlite_step $VM N VALUES COLNAMES
29} {SQLITE_DONE}
30do_test bind-1.3 {
31 execsql {SELECT rowid, * FROM t1}
32} {1 {} {} {}}
33do_test bind-1.4 {
34 sqlite_reset $VM
35 sqlite_bind $VM 1 {test value 1} normal
36 sqlite_step $VM N VALUES COLNAMES
37} SQLITE_DONE
38do_test bind-1.5 {
39 execsql {SELECT rowid, * FROM t1}
40} {1 {} {} {} 2 {test value 1} {} {}}
41do_test bind-1.6 {
42 sqlite_reset $VM
43 sqlite_bind $VM 3 {'test value 2'} normal
44 sqlite_step $VM N VALUES COLNAMES
45} SQLITE_DONE
46do_test bind-1.7 {
47 execsql {SELECT rowid, * FROM t1}
48} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}}
49do_test bind-1.8 {
50 sqlite_reset $VM
51 set sqlite_static_bind_value 123
52 sqlite_bind $VM 1 {} static
53 sqlite_bind $VM 2 {abcdefg} normal
54 sqlite_bind $VM 3 {} null
55 execsql {DELETE FROM t1}
56 sqlite_step $VM N VALUES COLNAMES
57 execsql {SELECT rowid, * FROM t1}
58} {1 123 abcdefg {}}
59do_test bind-1.9 {
60 sqlite_reset $VM
61 sqlite_bind $VM 1 {456} normal
62 sqlite_step $VM N VALUES COLNAMES
63 execsql {SELECT rowid, * FROM t1}
64} {1 123 abcdefg {} 2 456 abcdefg {}}
65
drh82a48512003-09-06 22:45:20 +000066do_test bind-1.99 {
67 sqlite_finalize $VM
68} {}
69
danielk197751e3d8e2004-05-20 01:12:34 +000070do_test bind-2.1 {
71 execsql {
72 DELETE FROM t1;
73 }
74 set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(?,?,?)} TAIL]
75 set TAIL
76} {}
77
78# 32 bit Integers
79do_test bind-2.2 {
80 sqlite3_bind_int32 $VM 1 123
81 sqlite3_bind_int32 $VM 2 456
82 sqlite3_bind_int32 $VM 3 789
83 sqlite_step $VM N VALUES COLNAMES
84 sqlite_reset $VM
85 execsql {SELECT rowid, * FROM t1}
86} {1 123 456 789}
87do_test bind-2.3 {
88 sqlite3_bind_int32 $VM 2 -2000000000
89 sqlite3_bind_int32 $VM 3 2000000000
90 sqlite_step $VM N VALUES COLNAMES
91 sqlite_reset $VM
92 execsql {SELECT rowid, * FROM t1}
93} {1 123 456 789 2 123 -2000000000 2000000000}
94do_test bind-2.4 {
95 execsql {SELECT classof(a), classof(b), classof(c) FROM t1}
96} {INTEGER INTEGER INTEGER INTEGER INTEGER INTEGER}
97do_test bind-2.5 {
98 execsql {
99 DELETE FROM t1;
100 }
101} {}
102
103# 64 bit Integers
104do_test bind-3.1 {
105 sqlite3_bind_int64 $VM 1 32
106 sqlite3_bind_int64 $VM 2 -2000000000000
107 sqlite3_bind_int64 $VM 3 2000000000000
108 sqlite_step $VM N VALUES COLNAMES
109 sqlite_reset $VM
110 execsql {SELECT rowid, * FROM t1}
111} {1 32 -2000000000000 2000000000000}
112do_test bind-3.2 {
113 execsql {SELECT classof(a), classof(b), classof(c) FROM t1}
114} {INTEGER INTEGER INTEGER}
115do_test bind-3.3 {
116 execsql {
117 DELETE FROM t1;
118 }
119} {}
120
121# Doubles
122do_test bind-4.1 {
123 sqlite3_bind_double $VM 1 1234.1234
124 sqlite3_bind_double $VM 2 0.00001
125 sqlite3_bind_double $VM 3 123456789
126 sqlite_step $VM N VALUES COLNAMES
127 sqlite_reset $VM
128 execsql {SELECT rowid, * FROM t1}
129} {1 1234.1234 1e-05 123456789}
130do_test bind-4.2 {
131 execsql {SELECT classof(a), classof(b), classof(c) FROM t1}
132} {REAL REAL REAL}
133do_test bind-4.3 {
134 execsql {
135 DELETE FROM t1;
136 }
137} {}
138
139# NULL
140do_test bind-5.1 {
141 sqlite3_bind_null $VM 1
142 sqlite3_bind_null $VM 2
143 sqlite3_bind_null $VM 3
144 sqlite_step $VM N VALUES COLNAMES
145 sqlite_reset $VM
146 execsql {SELECT rowid, * FROM t1}
147} {1 {} {} {}}
148do_test bind-5.2 {
149 execsql {SELECT classof(a), classof(b), classof(c) FROM t1}
150} {NULL NULL NULL}
151do_test bind-5.3 {
152 execsql {
153 DELETE FROM t1;
154 }
155} {}
156
157# UTF-8 text
158do_test bind-6.1 {
159 sqlite3_bind_text $VM 1 hellothere 5
160 sqlite3_bind_text $VM 2 "." 2
161 sqlite3_bind_text $VM 3 world -1
162 sqlite_step $VM N VALUES COLNAMES
163 sqlite_reset $VM
164 execsql {SELECT rowid, * FROM t1}
165} {1 hello . world}
166do_test bind-6.2 {
167 execsql {SELECT classof(a), classof(b), classof(c) FROM t1}
168} {TEXT TEXT TEXT}
169do_test bind-6.3 {
170 execsql {
171 DELETE FROM t1;
172 }
173} {}
174
175# UTF-16 text
176do_test bind-7.1 {
177 sqlite3_bind_text16 $VM 1 [encoding convertto unicode hellothere] 10
178 sqlite3_bind_text16 $VM 2 [encoding convertto unicode ""] 0
179 sqlite3_bind_text16 $VM 3 [encoding convertto unicode world] 10
180 sqlite_step $VM N VALUES COLNAMES
181 sqlite_reset $VM
182 execsql {SELECT rowid, * FROM t1}
183} {1 hello {} world}
184do_test bind-7.2 {
185 execsql {SELECT classof(a), classof(b), classof(c) FROM t1}
186} {TEXT TEXT TEXT}
187do_test bind-7.3 {
188 execsql {
189 DELETE FROM t1;
190 }
191} {}
192
193do_test bind-8.99 {
194 sqlite_finalize $VM
195} {}
196
197
drh82a48512003-09-06 22:45:20 +0000198
199finish_test