AryaWu/sqlite
0
1# 2007 April 272#3# The author disclaims copyright to this source code. In place of4# 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 the14# underlying TEXT or BLOB representation of an sqlite3_value15# changes appropriately when APIs from the following set are16# called:17#18# sqlite3_value_text()19# sqlite3_value_text16()20# sqlite3_value_blob()21# sqlite3_value_bytes()22# sqlite3_value_bytes16()23#24# $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $25 26set testdir [file dirname $argv0]27source $testdir/tester.tcl28 29ifcapable !bloblit {30 finish_test31 return32}33 34# Register the "pointer_change" SQL function.35#36sqlite3_create_function db37 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 should53# never change regardless of what type conversions occur.54#55# UPDATE: No longer true, as Mem.zBuf[] has been removed.56#57do_test ptrchng-2.1 {58 execsql {59 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=160 }61} {0}62do_test ptrchng-2.2 {63 execsql {64 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=165 }66} {0}67ifcapable utf16 {68 do_test ptrchng-2.3 {69 execsql {70 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=171 }72 } {1}73 do_test ptrchng-2.4 {74 execsql {75 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=176 }77 } {1}78 do_test ptrchng-2.5 {79 execsql {80 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=181 }82 } {0}83 do_test ptrchng-2.6 {84 execsql {85 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=186 }87 } {1}88}89do_test ptrchng-2.11 {90 execsql {91 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=392 }93} {0}94do_test ptrchng-2.12 {95 execsql {96 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=397 }98} {0}99ifcapable utf16 {100 do_test ptrchng-2.13 {101 execsql {102 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3103 }104 } {1}105 do_test ptrchng-2.14 {106 execsql {107 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3108 }109 } {1}110 do_test ptrchng-2.15 {111 execsql {112 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3113 }114 } {0}115 do_test ptrchng-2.16 {116 execsql {117 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3118 }119 } {1}120}121 122# For the long entries that do not fit in the Mem.zBuf[], the pointer123# should change sometimes.124#125do_test ptrchng-3.1 {126 execsql {127 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2128 }129} {0}130do_test ptrchng-3.2 {131 execsql {132 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2133 }134} {0}135ifcapable utf16 {136 do_test ptrchng-3.3 {137 execsql {138 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2139 }140 } {1}141 do_test ptrchng-3.4 {142 execsql {143 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2144 }145 } {1}146 do_test ptrchng-3.5 {147 execsql {148 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2149 }150 } {0}151 do_test ptrchng-3.6 {152 execsql {153 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2154 }155 } {1}156}157do_test ptrchng-3.11 {158 execsql {159 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4160 }161} {0}162do_test ptrchng-3.12 {163 execsql {164 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4165 }166} {0}167ifcapable utf16 {168 do_test ptrchng-3.13 {169 execsql {170 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4171 }172 } {1}173 do_test ptrchng-3.14 {174 execsql {175 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4176 }177 } {1}178 do_test ptrchng-3.15 {179 execsql {180 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4181 }182 } {0}183 do_test ptrchng-3.16 {184 execsql {185 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4186 }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 t1195 }196} {0 0 0 0}197do_test ptrchng-4.2 {198 execsql {199 SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1200 }201} {0 0 0 0}202 203# A call to _blob() should never trigger a reformat204#205do_test ptrchng-5.1 {206 execsql {207 SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1208 }209} {0 0 0 0}210ifcapable utf16 {211 do_test ptrchng-5.2 {212 execsql {213 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1214 }215 } {0 0 0 0}216 do_test ptrchng-5.3 {217 execsql {218 SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1219 }220 } {0 0 0 0}221}222 223finish_test224 