blob: 176e61e67caa5ffd6c8c8e8ad9c513b7e6a82390 [file] [log] [blame]
danielk1977b4e9af92007-05-01 17:49:49 +00001# 2007 May 1
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#
danielk1977d04417962007-05-02 13:16:30 +000012# $Id: incrblob.test,v 1.2 2007/05/02 13:16:31 danielk1977 Exp $
danielk1977b4e9af92007-05-01 17:49:49 +000013
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16
17do_test incrblob-1.1 {
18 execsql {
19 CREATE TABLE blobs(k PRIMARY KEY, v BLOB);
20 INSERT INTO blobs VALUES('one', X'0102030405060708090A');
21 INSERT INTO blobs VALUES('two', X'0A090807060504030201');
22 }
23} {}
24
25do_test incrblob-1.2.1 {
26 set ::blob [db incrblob blobs v 1]
27} {incrblob_1}
28do_test incrblob-1.2.2 {
29 binary scan [read $::blob] c* data
30 set data
31} {1 2 3 4 5 6 7 8 9 10}
32do_test incrblob-1.2.3 {
33 seek $::blob 0
34 puts -nonewline $::blob "1234567890"
35 flush $::blob
36} {}
37do_test incrblob-1.2.4 {
38 seek $::blob 0
39 binary scan [read $::blob] c* data
40 set data
41} {49 50 51 52 53 54 55 56 57 48}
42do_test incrblob-1.2.5 {
43 close $::blob
44} {}
45do_test incrblob-1.2.6 {
46 execsql {
47 SELECT v FROM blobs WHERE rowid = 1;
48 }
49} {1234567890}
50
danielk1977d04417962007-05-02 13:16:30 +000051#--------------------------------------------------------------------
52# Test cases incrblob-2.X check that it is possible to read and write
53# regions of a blob that lie on overflow pages.
54do_test incrblob-2.1 {
55 set ::str "[string repeat . 10000]"
56 execsql {
57 INSERT INTO blobs(rowid, k, v) VALUES(3, 'three', $::str);
58 }
59} {}
danielk1977b4e9af92007-05-01 17:49:49 +000060
danielk1977d04417962007-05-02 13:16:30 +000061do_test incrblob-2.2 {
62 set ::blob [db incrblob blobs v 3]
63 seek $::blob 8500
64 read $::blob 10
65} {..........}
66
67do_test incrblob-2.3 {
68 seek $::blob 8500
69 puts -nonewline $::blob 1234567890
70} {}
71
72do_test incrblob-2.4 {
73 seek $::blob 8496
74 read $::blob 10
75} {....123456}
76
77do_test incrblob-2.10 {
78 close $::blob
79} {}
80
81finish_test
danielk1977b4e9af92007-05-01 17:49:49 +000082