diff options
author | danielk1977 <danielk1977@noemail.net> | 2004-05-27 13:55:27 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2004-05-27 13:55:27 +0000 |
commit | 49e4643ee8e59265bcc7d28218234f9000a85e65 (patch) | |
tree | 243bd998797b95931d10da52ab53c4cae48da32b /test/blob.test | |
parent | 3fd0a736bfa81524e7bba6152e5b868c5925aba8 (diff) | |
download | sqlite-49e4643ee8e59265bcc7d28218234f9000a85e65.tar.gz sqlite-49e4643ee8e59265bcc7d28218234f9000a85e65.zip |
Test sqlite3_bind_blob(). (CVS 1475)
FossilOrigin-Name: 42247b2fb0c94e75a432b3e067fff9a1be328fc8
Diffstat (limited to 'test/blob.test')
-rw-r--r-- | test/blob.test | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/test/blob.test b/test/blob.test new file mode 100644 index 000000000..5eb876146 --- /dev/null +++ b/test/blob.test @@ -0,0 +1,120 @@ +# 2001 September 15 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# $Id: blob.test,v 1.1 2004/05/27 13:55:27 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc bin_to_hex {blob} { + set bytes {} + binary scan $blob \c* bytes + set bytes2 [list] + foreach b $bytes {lappend bytes2 [format %02X [expr $b & 0xFF]]} + join $bytes2 {} +} + +# Simplest possible case. Specify a blob literal +do_test blob-1.0 { + set blob [execsql {SELECT X'01020304'}] + bin_to_hex [lindex $blob 0] +} {01020304} +do_test blob-1.1 { + set blob [execsql {SELECT x'ABCDEF'}] + bin_to_hex [lindex $blob 0] +} {ABCDEF} +do_test blob-1.2 { + set blob [execsql {SELECT x''}] + bin_to_hex [lindex $blob 0] +} {} +do_test blob-1.3 { + set blob [execsql {SELECT x'abcdEF12'}] + bin_to_hex [lindex $blob 0] +} {ABCDEF12} + +# Try some syntax errors in blob literals. +do_test blob-1.4 { + catchsql {SELECT X'01020k304', 100} +} {1 {unrecognized token: "X'01020"}} +do_test blob-1.5 { + catchsql {SELECT X'01020, 100} +} {1 {unrecognized token: "X'01020"}} +do_test blob-1.6 { + catchsql {SELECT X'01020 100'} +} {1 {unrecognized token: "X'01020"}} +do_test blob-1.7 { + catchsql {SELECT X'01001'} +} {1 {unrecognized token: "X'01001'"}} + +# Insert a blob into a table and retrieve it. +do_test blob-2.0 { + execsql { + CREATE TABLE t1(a BLOB, b BLOB); + INSERT INTO t1 VALUES(X'123456', x'7890ab'); + INSERT INTO t1 VALUES(X'CDEF12', x'345678'); + } + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB CDEF12 345678} + +# An index on a blob column +do_test blob-2.1 { + execsql { + CREATE INDEX i1 ON t1(a); + } + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB CDEF12 345678} +do_test blob-2.2 { + set blobs [execsql {SELECT * FROM t1 where a = X'123456'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB} +do_test blob-2.3 { + set blobs [execsql {SELECT * FROM t1 where a = X'CDEF12'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {CDEF12 345678} +do_test blob-2.4 { + set blobs [execsql {SELECT * FROM t1 where a = X'CD12'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {} + +# Try to bind a blob value to a prepared statement. +do_test blob-3.0 { + set DB [sqlite db2 test.db] + set STMT [sqlite3_prepare $DB "DELETE FROM t1 WHERE a = ?" -1 DUMMY] + sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3 + sqlite3_step $STMT +} {SQLITE_DONE} +do_test blob-3.1 { + sqlite3_finalize $STMT + db2 close +} {} +do_test blob-2.3 { + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {CDEF12 345678} + +finish_test + + |