3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
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
18 # sqlite3_value_text()
19 # sqlite3_value_text16()
20 # sqlite3_value_blob()
21 # sqlite3_value_bytes()
22 # sqlite3_value_bytes16()
24 # $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $
26 set testdir [file dirname $argv0]
27 source $testdir/tester.tcl
34 # Register the "pointer_change" SQL function.
36 sqlite3_create_function db
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'
48 SELECT count(*) FROM t1;
52 # For the short entries that fit in the Mem.zBuf[], the pointer should
53 # never change regardless of what type conversions occur.
55 # UPDATE: No longer true, as Mem.zBuf[] has been removed.
59 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
64 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
70 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1
75 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1
80 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1
85 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1
89 do_test ptrchng-2.11 {
91 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
94 do_test ptrchng-2.12 {
96 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
100 do_test ptrchng-2.13 {
102 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3
105 do_test ptrchng-2.14 {
107 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3
110 do_test ptrchng-2.15 {
112 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3
115 do_test ptrchng-2.16 {
117 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
122 # For the long entries that do not fit in the Mem.zBuf[], the pointer
123 # should change sometimes.
125 do_test ptrchng-3.1 {
127 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
130 do_test ptrchng-3.2 {
132 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
136 do_test ptrchng-3.3 {
138 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2
141 do_test ptrchng-3.4 {
143 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2
146 do_test ptrchng-3.5 {
148 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2
151 do_test ptrchng-3.6 {
153 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2
157 do_test ptrchng-3.11 {
159 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
162 do_test ptrchng-3.12 {
164 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
168 do_test ptrchng-3.13 {
170 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4
173 do_test ptrchng-3.14 {
175 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4
178 do_test ptrchng-3.15 {
180 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4
183 do_test ptrchng-3.16 {
185 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4
190 # A call to _bytes() should never reformat a _text() or _blob().
192 do_test ptrchng-4.1 {
194 SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
197 do_test ptrchng-4.2 {
199 SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
203 # A call to _blob() should never trigger a reformat
205 do_test ptrchng-5.1 {
207 SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
211 do_test ptrchng-5.2 {
213 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
216 do_test ptrchng-5.3 {
218 SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1