Convert the implementation of the ".dbstat" dot-command of the command-line
[sqlite.git] / test / tkt2332.test
blob2d09dda6e3aae1ffcdcfd19f24d7bbbdcb3a6304
1 # 2007 May 3
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 #***********************************************************************
12 # $Id: tkt2332.test,v 1.4 2007/09/12 17:01:45 danielk1977 Exp $
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 ifcapable !incrblob||!tclvar {
19   finish_test
20   return
23 do_test tkt2332.1 {
24   execsql {
25     CREATE TABLE blobs (k INTEGER PRIMARY KEY, v BLOB);
26     PRAGMA cache_size = 100;
27   }
28 } {}
30 set ::iKey 1
31 foreach Len [list 10000 100000 1000000] {
32   do_test tkt2332.$Len.1 {
33     set val "[expr rand()][expr rand()][expr rand()][expr rand()][expr rand()]"
34     set ::blobstr [string range \
35       [string repeat $val [expr ($Len/[string length $val])+1]] 0 [expr $Len-1]
36     ]
38     db eval { INSERT INTO blobs VALUES($::iKey, zeroblob($Len)) }
39   } {}
41   do_test tkt2332.$Len.2 {
42     execsql {
43       SELECT length(v) FROM blobs WHERE k = $::iKey;
44     }
45   } $Len
47   do_test tkt2332.$Len.3 {
48     set ::fd [db incrblob blobs v $::iKey]
49     puts -nonewline $::fd $::blobstr
50     close $::fd
51   } {}
53   do_test tkt2332.$Len.4 {
54     execsql { SELECT length(v) FROM blobs WHERE k = $::iKey; }
55   } $Len
57   do_test tkt2332.$Len.5 {
58     lindex [execsql {SELECT v FROM blobs WHERE k = $::iKey}] 0
59   } $::blobstr
61   incr ::iKey
64 # Free memory:
65 unset ::blobstr
67 finish_test