aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/zeroblob.test
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/zeroblob.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/zeroblob.test213
1 files changed, 213 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/zeroblob.test b/libraries/sqlite/unix/sqlite-3.5.1/test/zeroblob.test
new file mode 100644
index 0000000..04a6f63
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/zeroblob.test
@@ -0,0 +1,213 @@
1# 2007 May 02
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 of the zero-filled blob functionality
13# including the sqlite3_bind_zeroblob(), sqlite3_result_zeroblob(),
14# and the built-in zeroblob() SQL function.
15#
16# $Id: zeroblob.test,v 1.10 2007/09/12 17:01:45 danielk1977 Exp $
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21ifcapable !incrblob {
22 finish_test
23 return
24}
25
26# When zeroblob() is used for the last field of a column, then the
27# content of the zeroblob is never instantiated on the VDBE stack.
28# But it does get inserted into the database correctly.
29#
30do_test zeroblob-1.1 {
31 execsql {
32 CREATE TABLE t1(a,b,c,d);
33 }
34 set ::sqlite3_max_blobsize 0
35 execsql {
36 INSERT INTO t1 VALUES(2,3,4,zeroblob(10000));
37 }
38 set ::sqlite3_max_blobsize
39} {10}
40do_test zeroblob-1.2 {
41 execsql {
42 SELECT length(d) FROM t1
43 }
44} {10000}
45
46# If a non-NULL column follows the zeroblob, then the content of
47# the zeroblob must be instantiated.
48#
49do_test zeroblob-1.3 {
50 set ::sqlite3_max_blobsize 0
51 execsql {
52 INSERT INTO t1 VALUES(3,4,zeroblob(10000),5);
53 }
54 set ::sqlite3_max_blobsize
55} {10010}
56do_test zeroblob-1.4 {
57 execsql {
58 SELECT length(c), length(d) FROM t1
59 }
60} {1 10000 10000 1}
61
62# Multiple zeroblobs can appear at the end of record. No instantiation
63# of the blob content occurs on the stack.
64#
65do_test zeroblob-1.5 {
66 set ::sqlite3_max_blobsize 0
67 execsql {
68 INSERT INTO t1 VALUES(4,5,zeroblob(10000),zeroblob(10000));
69 }
70 set ::sqlite3_max_blobsize
71} {11}
72do_test zeroblob-1.6 {
73 execsql {
74 SELECT length(c), length(d) FROM t1
75 }
76} {1 10000 10000 1 10000 10000}
77
78# NULLs can follow the zeroblob() or be intermixed with zeroblobs and
79# no instantiation of the zeroblobs occurs on the stack.
80#
81do_test zeroblob-1.7 {
82 set ::sqlite3_max_blobsize 0
83 execsql {
84 INSERT INTO t1 VALUES(5,zeroblob(10000),NULL,zeroblob(10000));
85 }
86 set ::sqlite3_max_blobsize
87} {10}
88do_test zeroblob-1.8 {
89 execsql {
90 SELECT length(b), length(d) FROM t1 WHERE a=5
91 }
92} {10000 10000}
93
94# Comparisons against zeroblobs work.
95#
96do_test zeroblob-2.1 {
97 execsql {
98 SELECT a FROM t1 WHERE b=zeroblob(10000)
99 }
100} {5}
101
102# Comparisons against zeroblobs work even when indexed.
103#
104do_test zeroblob-2.2 {
105 execsql {
106 CREATE INDEX i1_1 ON t1(b);
107 SELECT a FROM t1 WHERE b=zeroblob(10000);
108 }
109} {5}
110
111# DISTINCT works for zeroblobs
112#
113ifcapable bloblit&&subquery&&compound {
114 do_test zeroblob-3.1 {
115 execsql {
116 SELECT count(DISTINCT a) FROM (
117 SELECT x'00000000000000000000' AS a
118 UNION ALL
119 SELECT zeroblob(10) AS a
120 )
121 }
122 } {1}
123}
124
125# Concatentation works with zeroblob
126#
127ifcapable bloblit {
128 do_test zeroblob-4.1 {
129 execsql {
130 SELECT hex(zeroblob(2) || x'61')
131 }
132 } {000061}
133}
134
135# Check various CAST(...) operations on zeroblob.
136#
137do_test zeroblob-5.1 {
138 execsql {
139 SELECT CAST (zeroblob(100) AS REAL);
140 }
141} {0.0}
142do_test zeroblob-5.2 {
143 execsql {
144 SELECT CAST (zeroblob(100) AS INTEGER);
145 }
146} {0}
147do_test zeroblob-5.3 {
148 execsql {
149 SELECT CAST (zeroblob(100) AS TEXT);
150 }
151} {{}}
152do_test zeroblob-5.4 {
153 execsql {
154 SELECT CAST(zeroblob(100) AS BLOB);
155 }
156} [execsql {SELECT zeroblob(100)}]
157
158
159# Check for malicious use of zeroblob. Make sure nothing crashes.
160#
161do_test zeroblob-6.1.1 {
162 execsql {select zeroblob(-1)}
163} {{}}
164do_test zeroblob-6.1.2 {
165 execsql {select zeroblob(-10)}
166} {{}}
167do_test zeroblob-6.1.3 {
168 execsql {select zeroblob(-100)}
169} {{}}
170do_test zeroblob-6.2 {
171 execsql {select length(zeroblob(-1))}
172} {0}
173do_test zeroblob-6.3 {
174 execsql {select zeroblob(-1)|1}
175} {1}
176do_test zeroblob-6.4 {
177 catchsql {select length(zeroblob(2147483648))}
178} {1 {string or blob too big}}
179do_test zeroblob-6.5 {
180 catchsql {select zeroblob(2147483648)}
181} {1 {string or blob too big}}
182do_test zeroblob-6.6 {
183 execsql {select hex(zeroblob(-1))}
184} {{}}
185do_test zeroblob-6.7 {
186 execsql {select typeof(zeroblob(-1))}
187} {blob}
188
189# Test bind_zeroblob()
190#
191do_test zeroblob-7.1 {
192 set ::STMT [sqlite3_prepare $::DB "SELECT length(?)" -1 DUMMY]
193 sqlite3_bind_zeroblob $::STMT 1 450
194 sqlite3_step $::STMT
195} {SQLITE_ROW}
196do_test zeroblob-7.2 {
197 sqlite3_column_int $::STMT 0
198} {450}
199do_test zeroblob-7.3 {
200 sqlite3_finalize $::STMT
201} {SQLITE_OK}
202
203# Test that MakeRecord can handle a value with some real content
204# and a zero-blob tail.
205#
206do_test zeroblob-8.1 {
207 llength [execsql {
208 SELECT 'hello' AS a, zeroblob(10) as b from t1 ORDER BY a, b;
209 }]
210} {8}
211
212
213finish_test