Enhance the command-line completion extension to return the names of
[sqlite.git] / test / incrblob4.test
blobdbff8eb7d58c74eed3dfb3543affae11e2330983
1 # 2012 March 23
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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 ifcapable {!incrblob} { finish_test ; return }
16 set testprefix incrblob4
18 proc create_t1 {} {
19   execsql {
20     PRAGMA page_size = 1024;
21     CREATE TABLE t1(k INTEGER PRIMARY KEY, v);
22   }
25 proc populate_t1 {} {
26   set data [list a b c d e f g h i j k l m n o p q r s t u v w x y z]
27   foreach d $data {
28     set blob [string repeat $d 900]
29     execsql { INSERT INTO t1(v) VALUES($blob) }
30   }
34 do_test 1.1 { 
35   create_t1
36   populate_t1 
37 } {}
39 do_test 1.2 {
40   set blob [db incrblob t1 v 5]
41   read $blob 10
42 } {eeeeeeeeee}
44 do_test 1.3 {
45   execsql { DELETE FROM t1 }
46   populate_t1
47 } {}
51 do_test 2.1 { 
52   reset_db
53   create_t1
54   populate_t1 
55 } {}
57 do_test 2.2 {
58   set blob [db incrblob t1 v 10]
59   read $blob 10
60 } {jjjjjjjjjj}
62 do_test 2.3 {
63   set new [string repeat % 900]
64   execsql { DELETE FROM t1 WHERE k=10 }
65   execsql { DELETE FROM t1 WHERE k=9 }
66   execsql { INSERT INTO t1(v) VALUES($new) }
67 } {}
71 do_test 3.1 {
72   reset_db
73   create_t1
74   populate_t1 
75 } {}
77 do_test 3.2 {
78   set blob [db incrblob t1 v 20]
79   read $blob 10
80 } {tttttttttt}
82 do_test 3.3 {
83   set new [string repeat % 900]
84   execsql { UPDATE t1 SET v = $new WHERE k = 20 }
85   execsql { DELETE FROM t1 WHERE k=19 }
86   execsql { INSERT INTO t1(v) VALUES($new) }
87 } {}
89 #-------------------------------------------------------------------------
90 # Test that it is not possible to DROP a table with an incremental blob
91 # cursor open on it.
93 do_execsql_test 4.1 {
94   CREATE TABLE t2(a INTEGER PRIMARY KEY, b);
95   INSERT INTO t2 VALUES(456, '0123456789');
97 do_test 4.2 {
98   set blob [db incrblob -readonly t2 b 456]
99   read $blob 5
100 } {01234}
101 do_catchsql_test 4.3 {
102   DROP TABLE t2
103 } {1 {database table is locked}}
104 do_test 4.4 {
105   sqlite3_extended_errcode db
106 } {SQLITE_LOCKED}
107 close $blob
109 finish_test