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.2 2007/05/02 16:51:59 drh Exp $ 17 18set testdir [file dirname $argv0] 19source $testdir/tester.tcl 20 21# When zeroblob() is used for the last field of a column, then the 22# content of the zeroblob is never instantiated on the VDBE stack. 23# But it does get inserted into the database correctly. 24# 25do_test zeroblob-1.1 { 26 execsql { 27 CREATE TABLE t1(a,b,c,d); 28 } 29 set ::sqlite3_max_blobsize 0 30 execsql { 31 INSERT INTO t1 VALUES(2,3,4,zeroblob(10000)); 32 } 33 set ::sqlite3_max_blobsize 34} {10} 35do_test zeroblob-1.2 { 36 execsql { 37 SELECT length(d) FROM t1 38 } 39} {10000} 40 41# If a non-NULL column follows the zeroblob, then the content of 42# the zeroblob must be instantiated. 43# 44do_test zeroblob-1.3 { 45 set ::sqlite3_max_blobsize 0 46 execsql { 47 INSERT INTO t1 VALUES(3,4,zeroblob(10000),5); 48 } 49 set ::sqlite3_max_blobsize 50} {10010} 51do_test zeroblob-1.4 { 52 execsql { 53 SELECT length(c), length(d) FROM t1 54 } 55} {1 10000 10000 1} 56 57# Multiple zeroblobs can appear at the end of record. No instantiation 58# of the blob content occurs on the stack. 59# 60do_test zeroblob-1.5 { 61 set ::sqlite3_max_blobsize 0 62 execsql { 63 INSERT INTO t1 VALUES(4,5,zeroblob(10000),zeroblob(10000)); 64 } 65 set ::sqlite3_max_blobsize 66} {11} 67do_test zeroblob-1.6 { 68 execsql { 69 SELECT length(c), length(d) FROM t1 70 } 71} {1 10000 10000 1 10000 10000} 72 73# NULLs can follow the zeroblob() or be intermixed with zeroblobs and 74# no instantiation of the zeroblobs occurs on the stack. 75# 76do_test zeroblob-1.7 { 77 set ::sqlite3_max_blobsize 0 78 execsql { 79 INSERT INTO t1 VALUES(5,zeroblob(10000),NULL,zeroblob(10000)); 80 } 81 set ::sqlite3_max_blobsize 82} {10} 83do_test zeroblob-1.8 { 84 execsql { 85 SELECT length(b), length(d) FROM t1 WHERE a=5 86 } 87} {10000 10000} 88 89# Comparisons against zeroblobs work. 90# 91do_test zeroblob-2.1 { 92 execsql { 93 SELECT a FROM t1 WHERE b=zeroblob(10000) 94 } 95} {5} 96 97# Comparisons against zeroblobs work even when indexed. 98# 99do_test zeroblob-2.2 { 100 execsql { 101 CREATE INDEX i1_1 ON t1(b); 102 SELECT a FROM t1 WHERE b=zeroblob(10000); 103 } 104} {5} 105 106# DISTINCT works for zeroblobs 107# 108do_test zeroblob-3.1 { 109 execsql { 110 SELECT count(DISTINCT a) FROM ( 111 SELECT x'00000000000000000000' AS a 112 UNION ALL 113 SELECT zeroblob(10) AS a 114 ) 115 } 116} {1} 117 118 119finish_test 120