xref: /sqlite-3.40.0/test/incrblob4.test (revision e0a04a36)
1# 2012 March 23
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#
12#
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15ifcapable {!incrblob} { finish_test ; return }
16set testprefix incrblob4
17
18proc create_t1 {} {
19  execsql {
20    PRAGMA page_size = 1024;
21    CREATE TABLE t1(k INTEGER PRIMARY KEY, v);
22  }
23}
24
25proc 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  }
31}
32
33
34do_test 1.1 {
35  create_t1
36  populate_t1
37} {}
38
39do_test 1.2 {
40  set blob [db incrblob t1 v 5]
41  read $blob 10
42} {eeeeeeeeee}
43
44do_test 1.3 {
45  execsql { DELETE FROM t1 }
46  populate_t1
47} {}
48
49
50
51do_test 2.1 {
52  reset_db
53  create_t1
54  populate_t1
55} {}
56
57do_test 2.2 {
58  set blob [db incrblob t1 v 10]
59  read $blob 10
60} {jjjjjjjjjj}
61
62do_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} {}
68
69
70
71do_test 3.1 {
72  reset_db
73  create_t1
74  populate_t1
75} {}
76
77do_test 3.2 {
78  set blob [db incrblob t1 v 20]
79  read $blob 10
80} {tttttttttt}
81
82do_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} {}
88
89#-------------------------------------------------------------------------
90# Test that it is not possible to DROP a table with an incremental blob
91# cursor open on it.
92#
93do_execsql_test 4.1 {
94  CREATE TABLE t2(a INTEGER PRIMARY KEY, b);
95  INSERT INTO t2 VALUES(456, '0123456789');
96}
97do_test 4.2 {
98  set blob [db incrblob -readonly t2 b 456]
99  read $blob 5
100} {01234}
101do_catchsql_test 4.3 {
102  DROP TABLE t2
103} {1 {database table is locked}}
104do_test 4.4 {
105  sqlite3_extended_errcode db
106} {SQLITE_LOCKED}
107close $blob
108
109finish_test
110