blob: 75525f981c5755ad13cbd5896bcd010abd7dfc2c [file] [log] [blame]
drh9310ef22007-04-27 17:16:20 +00001# 2007 April 27
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.
12#
13# The focus of the tests in this file are to verify that the
14# underlying TEXT or BLOB representation of an sqlite3_value
15# changes appropriately when APIs from the following set are
16# called:
17#
18# sqlite3_value_text()
19# sqlite3_value_text16()
20# sqlite3_value_blob()
21# sqlite3_value_bytes()
22# sqlite3_value_bytes16()
23#
drhe8f52c52008-07-12 14:52:20 +000024# $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $
drh9310ef22007-04-27 17:16:20 +000025
26set testdir [file dirname $argv0]
27source $testdir/tester.tcl
28
danielk19774152e672007-09-12 17:01:45 +000029ifcapable !bloblit {
30 finish_test
31 return
32}
33
drh9310ef22007-04-27 17:16:20 +000034# Register the "pointer_change" SQL function.
35#
36sqlite3_create_function db
37
38do_test ptrchng-1.1 {
39 execsql {
40 CREATE TABLE t1(x INTEGER PRIMARY KEY, y BLOB);
41 INSERT INTO t1 VALUES(1, 'abc');
42 INSERT INTO t1 VALUES(2,
43 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789');
44 INSERT INTO t1 VALUES(3, x'626c6f62');
45 INSERT INTO t1 VALUES(4,
46 x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324'
47 );
48 SELECT count(*) FROM t1;
49 }
50} {4}
51
52# For the short entries that fit in the Mem.zBuf[], the pointer should
53# never change regardless of what type conversions occur.
54#
danielk1977a7a8e142008-02-13 18:25:27 +000055# UPDATE: No longer true, as Mem.zBuf[] has been removed.
56#
drh9310ef22007-04-27 17:16:20 +000057do_test ptrchng-2.1 {
58 execsql {
59 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
60 }
61} {0}
62do_test ptrchng-2.2 {
63 execsql {
64 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
65 }
danielk1977131b0ef2008-02-14 05:44:45 +000066} {0}
drh9310ef22007-04-27 17:16:20 +000067ifcapable utf16 {
68 do_test ptrchng-2.3 {
69 execsql {
70 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1
71 }
danielk1977a7a8e142008-02-13 18:25:27 +000072 } {1}
drh9310ef22007-04-27 17:16:20 +000073 do_test ptrchng-2.4 {
74 execsql {
75 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1
76 }
danielk1977a7a8e142008-02-13 18:25:27 +000077 } {1}
drh9310ef22007-04-27 17:16:20 +000078 do_test ptrchng-2.5 {
79 execsql {
80 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1
81 }
82 } {0}
83 do_test ptrchng-2.6 {
84 execsql {
85 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1
86 }
danielk1977a7a8e142008-02-13 18:25:27 +000087 } {1}
drh9310ef22007-04-27 17:16:20 +000088}
89do_test ptrchng-2.11 {
90 execsql {
91 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
92 }
93} {0}
94do_test ptrchng-2.12 {
95 execsql {
96 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
97 }
danielk1977131b0ef2008-02-14 05:44:45 +000098} {0}
drh9310ef22007-04-27 17:16:20 +000099ifcapable utf16 {
100 do_test ptrchng-2.13 {
101 execsql {
102 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3
103 }
danielk1977a7a8e142008-02-13 18:25:27 +0000104 } {1}
drh9310ef22007-04-27 17:16:20 +0000105 do_test ptrchng-2.14 {
106 execsql {
107 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3
108 }
danielk1977a7a8e142008-02-13 18:25:27 +0000109 } {1}
drh9310ef22007-04-27 17:16:20 +0000110 do_test ptrchng-2.15 {
111 execsql {
112 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3
113 }
114 } {0}
115 do_test ptrchng-2.16 {
drh9310ef22007-04-27 17:16:20 +0000116 execsql {
117 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
118 }
danielk1977a7a8e142008-02-13 18:25:27 +0000119 } {1}
drh9310ef22007-04-27 17:16:20 +0000120}
121
122# For the long entries that do not fit in the Mem.zBuf[], the pointer
123# should change sometimes.
124#
125do_test ptrchng-3.1 {
126 execsql {
127 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
128 }
129} {0}
130do_test ptrchng-3.2 {
131 execsql {
132 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
133 }
danielk1977131b0ef2008-02-14 05:44:45 +0000134} {0}
drh9310ef22007-04-27 17:16:20 +0000135ifcapable utf16 {
136 do_test ptrchng-3.3 {
137 execsql {
138 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2
139 }
140 } {1}
141 do_test ptrchng-3.4 {
142 execsql {
143 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2
144 }
145 } {1}
146 do_test ptrchng-3.5 {
147 execsql {
148 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2
149 }
150 } {0}
151 do_test ptrchng-3.6 {
152 execsql {
153 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2
154 }
155 } {1}
156}
157do_test ptrchng-3.11 {
158 execsql {
159 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
160 }
161} {0}
162do_test ptrchng-3.12 {
163 execsql {
164 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
165 }
danielk1977131b0ef2008-02-14 05:44:45 +0000166} {0}
drh9310ef22007-04-27 17:16:20 +0000167ifcapable utf16 {
168 do_test ptrchng-3.13 {
169 execsql {
170 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4
171 }
172 } {1}
173 do_test ptrchng-3.14 {
174 execsql {
175 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4
176 }
177 } {1}
178 do_test ptrchng-3.15 {
179 execsql {
180 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4
181 }
182 } {0}
183 do_test ptrchng-3.16 {
184 execsql {
185 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4
186 }
187 } {1}
188}
189
190# A call to _bytes() should never reformat a _text() or _blob().
191#
192do_test ptrchng-4.1 {
193 execsql {
194 SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
195 }
196} {0 0 0 0}
197do_test ptrchng-4.2 {
198 execsql {
199 SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
200 }
201} {0 0 0 0}
202
203# A call to _blob() should never trigger a reformat
204#
205do_test ptrchng-5.1 {
206 execsql {
207 SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
208 }
209} {0 0 0 0}
210ifcapable utf16 {
211 do_test ptrchng-5.2 {
212 execsql {
213 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
214 }
215 } {0 0 0 0}
216 do_test ptrchng-5.3 {
217 execsql {
218 SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1
219 }
220 } {0 0 0 0}
221}
222
223finish_test