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 if {![info exists testdir]} {
14 set testdir [file join [file dirname [info script]] .. .. test]
16 source $testdir/tester.tcl
17 set ::testprefix rbu10
20 #--------------------------------------------------------------------
21 # Test that UPDATE commands work even if the input columns are in a
22 # different order to the output columns.
25 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
26 INSERT INTO t1 VALUES(1, 'b', 'c');
29 proc apply_rbu {sql} {
34 sqlite3rbu rbu test.db rbu.db
35 while { [rbu step]=="SQLITE_OK" } {}
41 CREATE TABLE data_t1(a, c, b, rbu_control);
42 INSERT INTO data_t1 VALUES(1, 'xxx', NULL, '.x.');
44 db eval { SELECT * FROM t1 }
47 #--------------------------------------------------------------------
48 # Test that the hidden languageid column of an fts4 table can be
53 CREATE VIRTUAL TABLE ft USING fts4(a, b, languageid='langid');
57 CREATE TABLE data_ft(a, b, rbu_rowid, langid, rbu_control);
58 INSERT INTO data_ft VALUES('a', 'b', 22, 1, 0); -- insert
59 INSERT INTO data_ft VALUES('a', 'b', 23, 10, 0); -- insert
60 INSERT INTO data_ft VALUES('a', 'b', 24, 100, 0); -- insert
62 db eval { SELECT a, b, rowid, langid FROM ft }
69 # Or not - this data_xxx table has no langid column, so langid
74 CREATE TABLE data_ft(a, b, rbu_rowid, rbu_control);
75 INSERT INTO data_ft VALUES('a', 'b', 25, 0); -- insert
77 db eval { SELECT a, b, rowid, langid FROM ft }
89 CREATE TABLE data_ft(a, b, rbu_rowid, langid, rbu_control);
90 INSERT INTO data_ft VALUES(NULL, NULL, 23, 50, '..x');
91 INSERT INTO data_ft VALUES(NULL, NULL, 25, 500, '..x');
93 db eval { SELECT a, b, rowid, langid FROM ft }
102 #--------------------------------------------------------------------
103 # Test that if writing a hidden virtual table column is an error,
104 # attempting to do so via rbu is also an error.
107 do_execsql_test 3.0 {
108 CREATE VIRTUAL TABLE xt USING fts4(a);
113 CREATE TABLE data_xt(a, xt, rbu_rowid, rbu_control);
114 INSERT INTO data_xt VALUES('a', 'b', 1, 0);
117 } {1 {SQLITE_ERROR - SQL logic error or missing database}}
120 #--------------------------------------------------------------------
121 # Test that it is not possible to violate a NOT NULL constraint by
122 # applying an RBU update.
124 do_execsql_test 4.1 {
125 CREATE TABLE t2(a INTEGER NOT NULL, b TEXT NOT NULL, c PRIMARY KEY);
126 CREATE TABLE t3(a INTEGER NOT NULL, b TEXT NOT NULL, c INTEGER PRIMARY KEY);
127 CREATE TABLE t4(a, b, PRIMARY KEY(a, b)) WITHOUT ROWID;
129 INSERT INTO t2 VALUES(10, 10, 10);
130 INSERT INTO t3 VALUES(10, 10, 10);
131 INSERT INTO t4 VALUES(10, 10);
134 foreach {tn error rbu} {
135 2 {SQLITE_CONSTRAINT - NOT NULL constraint failed: t2.a} {
136 INSERT INTO data_t2 VALUES(NULL, 'abc', 1, 0);
138 3 {SQLITE_CONSTRAINT - NOT NULL constraint failed: t2.b} {
139 INSERT INTO data_t2 VALUES(2, NULL, 1, 0);
141 4 {SQLITE_CONSTRAINT - NOT NULL constraint failed: t2.c} {
142 INSERT INTO data_t2 VALUES(1, 'abc', NULL, 0);
145 5 {SQLITE_MISMATCH - datatype mismatch} {
146 INSERT INTO data_t3 VALUES(1, 'abc', NULL, 0);
149 6 {SQLITE_CONSTRAINT - NOT NULL constraint failed: t4.b} {
150 INSERT INTO data_t4 VALUES('a', NULL, 0);
152 7 {SQLITE_CONSTRAINT - NOT NULL constraint failed: t4.a} {
153 INSERT INTO data_t4 VALUES(NULL, 'a', 0);
155 8 {SQLITE_CONSTRAINT - NOT NULL constraint failed: t2.a} {
156 INSERT INTO data_t2 VALUES(NULL, 0, 10, 'x..');
158 9 {SQLITE_CONSTRAINT - NOT NULL constraint failed: t3.b} {
159 INSERT INTO data_t3 VALUES(10, NULL, 10, '.x.');
162 10 {SQLITE_MISMATCH - datatype mismatch} {
163 INSERT INTO data_t3 VALUES(1, 'abc', 'text', 0);
167 CREATE TABLE data_t2(a, b, c, rbu_control);
168 CREATE TABLE data_t3(a, b, c, rbu_control);
169 CREATE TABLE data_t4(a, b, rbu_control);
173 list [catch { apply_rbu $rbu } msg] $msg
179 CREATE TABLE data_t3(a, b, c, rbu_control);
180 INSERT INTO data_t3 VALUES(1, 'abc', '5', 0);
181 INSERT INTO data_t3 VALUES(1, 'abc', '-6.0', 0);
183 list [catch { apply_rbu $rbu } msg] $msg