sl@0
|
1 |
# 2007 April 27
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# The focus of the tests in this file are to verify that the
|
sl@0
|
14 |
# underlying TEXT or BLOB representation of an sqlite3_value
|
sl@0
|
15 |
# changes appropriately when APIs from the following set are
|
sl@0
|
16 |
# called:
|
sl@0
|
17 |
#
|
sl@0
|
18 |
# sqlite3_value_text()
|
sl@0
|
19 |
# sqlite3_value_text16()
|
sl@0
|
20 |
# sqlite3_value_blob()
|
sl@0
|
21 |
# sqlite3_value_bytes()
|
sl@0
|
22 |
# sqlite3_value_bytes16()
|
sl@0
|
23 |
#
|
sl@0
|
24 |
# $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $
|
sl@0
|
25 |
|
sl@0
|
26 |
set testdir [file dirname $argv0]
|
sl@0
|
27 |
source $testdir/tester.tcl
|
sl@0
|
28 |
|
sl@0
|
29 |
ifcapable !bloblit {
|
sl@0
|
30 |
finish_test
|
sl@0
|
31 |
return
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
# Register the "pointer_change" SQL function.
|
sl@0
|
35 |
#
|
sl@0
|
36 |
sqlite3_create_function db
|
sl@0
|
37 |
|
sl@0
|
38 |
do_test ptrchng-1.1 {
|
sl@0
|
39 |
execsql {
|
sl@0
|
40 |
CREATE TABLE t1(x INTEGER PRIMARY KEY, y BLOB);
|
sl@0
|
41 |
INSERT INTO t1 VALUES(1, 'abc');
|
sl@0
|
42 |
INSERT INTO t1 VALUES(2,
|
sl@0
|
43 |
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789');
|
sl@0
|
44 |
INSERT INTO t1 VALUES(3, x'626c6f62');
|
sl@0
|
45 |
INSERT INTO t1 VALUES(4,
|
sl@0
|
46 |
x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324'
|
sl@0
|
47 |
);
|
sl@0
|
48 |
SELECT count(*) FROM t1;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
} {4}
|
sl@0
|
51 |
|
sl@0
|
52 |
# For the short entries that fit in the Mem.zBuf[], the pointer should
|
sl@0
|
53 |
# never change regardless of what type conversions occur.
|
sl@0
|
54 |
#
|
sl@0
|
55 |
# UPDATE: No longer true, as Mem.zBuf[] has been removed.
|
sl@0
|
56 |
#
|
sl@0
|
57 |
do_test ptrchng-2.1 {
|
sl@0
|
58 |
execsql {
|
sl@0
|
59 |
SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
|
sl@0
|
60 |
}
|
sl@0
|
61 |
} {0}
|
sl@0
|
62 |
do_test ptrchng-2.2 {
|
sl@0
|
63 |
execsql {
|
sl@0
|
64 |
SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
|
sl@0
|
65 |
}
|
sl@0
|
66 |
} {0}
|
sl@0
|
67 |
ifcapable utf16 {
|
sl@0
|
68 |
do_test ptrchng-2.3 {
|
sl@0
|
69 |
execsql {
|
sl@0
|
70 |
SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1
|
sl@0
|
71 |
}
|
sl@0
|
72 |
} {1}
|
sl@0
|
73 |
do_test ptrchng-2.4 {
|
sl@0
|
74 |
execsql {
|
sl@0
|
75 |
SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1
|
sl@0
|
76 |
}
|
sl@0
|
77 |
} {1}
|
sl@0
|
78 |
do_test ptrchng-2.5 {
|
sl@0
|
79 |
execsql {
|
sl@0
|
80 |
SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1
|
sl@0
|
81 |
}
|
sl@0
|
82 |
} {0}
|
sl@0
|
83 |
do_test ptrchng-2.6 {
|
sl@0
|
84 |
execsql {
|
sl@0
|
85 |
SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1
|
sl@0
|
86 |
}
|
sl@0
|
87 |
} {1}
|
sl@0
|
88 |
}
|
sl@0
|
89 |
do_test ptrchng-2.11 {
|
sl@0
|
90 |
execsql {
|
sl@0
|
91 |
SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
|
sl@0
|
92 |
}
|
sl@0
|
93 |
} {0}
|
sl@0
|
94 |
do_test ptrchng-2.12 {
|
sl@0
|
95 |
execsql {
|
sl@0
|
96 |
SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
|
sl@0
|
97 |
}
|
sl@0
|
98 |
} {0}
|
sl@0
|
99 |
ifcapable utf16 {
|
sl@0
|
100 |
do_test ptrchng-2.13 {
|
sl@0
|
101 |
execsql {
|
sl@0
|
102 |
SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3
|
sl@0
|
103 |
}
|
sl@0
|
104 |
} {1}
|
sl@0
|
105 |
do_test ptrchng-2.14 {
|
sl@0
|
106 |
execsql {
|
sl@0
|
107 |
SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3
|
sl@0
|
108 |
}
|
sl@0
|
109 |
} {1}
|
sl@0
|
110 |
do_test ptrchng-2.15 {
|
sl@0
|
111 |
execsql {
|
sl@0
|
112 |
SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3
|
sl@0
|
113 |
}
|
sl@0
|
114 |
} {0}
|
sl@0
|
115 |
do_test ptrchng-2.16 {
|
sl@0
|
116 |
execsql {
|
sl@0
|
117 |
SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
|
sl@0
|
118 |
}
|
sl@0
|
119 |
} {1}
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
# For the long entries that do not fit in the Mem.zBuf[], the pointer
|
sl@0
|
123 |
# should change sometimes.
|
sl@0
|
124 |
#
|
sl@0
|
125 |
do_test ptrchng-3.1 {
|
sl@0
|
126 |
execsql {
|
sl@0
|
127 |
SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
|
sl@0
|
128 |
}
|
sl@0
|
129 |
} {0}
|
sl@0
|
130 |
do_test ptrchng-3.2 {
|
sl@0
|
131 |
execsql {
|
sl@0
|
132 |
SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
|
sl@0
|
133 |
}
|
sl@0
|
134 |
} {0}
|
sl@0
|
135 |
ifcapable utf16 {
|
sl@0
|
136 |
do_test ptrchng-3.3 {
|
sl@0
|
137 |
execsql {
|
sl@0
|
138 |
SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2
|
sl@0
|
139 |
}
|
sl@0
|
140 |
} {1}
|
sl@0
|
141 |
do_test ptrchng-3.4 {
|
sl@0
|
142 |
execsql {
|
sl@0
|
143 |
SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2
|
sl@0
|
144 |
}
|
sl@0
|
145 |
} {1}
|
sl@0
|
146 |
do_test ptrchng-3.5 {
|
sl@0
|
147 |
execsql {
|
sl@0
|
148 |
SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2
|
sl@0
|
149 |
}
|
sl@0
|
150 |
} {0}
|
sl@0
|
151 |
do_test ptrchng-3.6 {
|
sl@0
|
152 |
execsql {
|
sl@0
|
153 |
SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2
|
sl@0
|
154 |
}
|
sl@0
|
155 |
} {1}
|
sl@0
|
156 |
}
|
sl@0
|
157 |
do_test ptrchng-3.11 {
|
sl@0
|
158 |
execsql {
|
sl@0
|
159 |
SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
|
sl@0
|
160 |
}
|
sl@0
|
161 |
} {0}
|
sl@0
|
162 |
do_test ptrchng-3.12 {
|
sl@0
|
163 |
execsql {
|
sl@0
|
164 |
SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
|
sl@0
|
165 |
}
|
sl@0
|
166 |
} {0}
|
sl@0
|
167 |
ifcapable utf16 {
|
sl@0
|
168 |
do_test ptrchng-3.13 {
|
sl@0
|
169 |
execsql {
|
sl@0
|
170 |
SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4
|
sl@0
|
171 |
}
|
sl@0
|
172 |
} {1}
|
sl@0
|
173 |
do_test ptrchng-3.14 {
|
sl@0
|
174 |
execsql {
|
sl@0
|
175 |
SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4
|
sl@0
|
176 |
}
|
sl@0
|
177 |
} {1}
|
sl@0
|
178 |
do_test ptrchng-3.15 {
|
sl@0
|
179 |
execsql {
|
sl@0
|
180 |
SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4
|
sl@0
|
181 |
}
|
sl@0
|
182 |
} {0}
|
sl@0
|
183 |
do_test ptrchng-3.16 {
|
sl@0
|
184 |
execsql {
|
sl@0
|
185 |
SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4
|
sl@0
|
186 |
}
|
sl@0
|
187 |
} {1}
|
sl@0
|
188 |
}
|
sl@0
|
189 |
|
sl@0
|
190 |
# A call to _bytes() should never reformat a _text() or _blob().
|
sl@0
|
191 |
#
|
sl@0
|
192 |
do_test ptrchng-4.1 {
|
sl@0
|
193 |
execsql {
|
sl@0
|
194 |
SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
|
sl@0
|
195 |
}
|
sl@0
|
196 |
} {0 0 0 0}
|
sl@0
|
197 |
do_test ptrchng-4.2 {
|
sl@0
|
198 |
execsql {
|
sl@0
|
199 |
SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
|
sl@0
|
200 |
}
|
sl@0
|
201 |
} {0 0 0 0}
|
sl@0
|
202 |
|
sl@0
|
203 |
# A call to _blob() should never trigger a reformat
|
sl@0
|
204 |
#
|
sl@0
|
205 |
do_test ptrchng-5.1 {
|
sl@0
|
206 |
execsql {
|
sl@0
|
207 |
SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
|
sl@0
|
208 |
}
|
sl@0
|
209 |
} {0 0 0 0}
|
sl@0
|
210 |
ifcapable utf16 {
|
sl@0
|
211 |
do_test ptrchng-5.2 {
|
sl@0
|
212 |
execsql {
|
sl@0
|
213 |
SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
|
sl@0
|
214 |
}
|
sl@0
|
215 |
} {0 0 0 0}
|
sl@0
|
216 |
do_test ptrchng-5.3 {
|
sl@0
|
217 |
execsql {
|
sl@0
|
218 |
SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1
|
sl@0
|
219 |
}
|
sl@0
|
220 |
} {0 0 0 0}
|
sl@0
|
221 |
}
|
sl@0
|
222 |
|
sl@0
|
223 |
finish_test
|