interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / rbu / rbugen.test

107 lines · 2993 bytes Raw Blame History
1# 2026 September 25
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# RBU does not support tables with GENERATED columns. This file tests
13# that attempting to update such a table, or to RBU vacuum a database
14# that contains one, fails with an error.
15#
16
17source [file join [file dirname [info script]] rbu_common.tcl]
18if_no_rbu_support { finish_test ; return }
19set ::testprefix rbugen
20
21foreach {tn schema} {
22 1 { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c AS (b*2) STORED) }
23 2 { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c AS (b*2) VIRTUAL) }
24} {
25 set errmsg "SQLITE_ERROR - generated columns not supported: t1.c"
26
27 # Attempt to apply an RBU update to table t1. Test both with and
28 # without the generated column in the data_t1 table.
29 #
30 foreach {tn2 data} {
31 1 {
32 CREATE TABLE data_t1(a, b, rbu_control);
33 INSERT INTO data_t1 VALUES(3, 3, 0);
34 }
35 2 {
36 CREATE TABLE data_t1(a, b, c, rbu_control);
37 INSERT INTO data_t1 VALUES(3, 3, 6, 0);
38 }
39 } {
40 reset_db
41 execsql $schema
42 execsql { INSERT INTO t1(a, b) VALUES(1, 1), (2, 2) }
43 db close
44
45 forcedelete rbu.db
46 sqlite3 db2 rbu.db
47 db2 eval $data
48 db2 close
49
50 do_test $tn.$tn2.1 {
51 list [catch { run_rbu test.db rbu.db } msg] $msg
52 } [list 1 $errmsg]
53
54 sqlite3 db test.db
55 do_execsql_test $tn.$tn2.2 { SELECT * FROM t1 } {1 1 2 2 2 4}
56 }
57
58 # Attempt to RBU vacuum a database that contains table t1.
59 #
60 db close
61 do_test $tn.3 {
62 forcedelete state.db
63 sqlite3rbu_vacuum rbu test.db state.db
64 while {[rbu step]=="SQLITE_OK"} {}
65 list [catch { rbu close } msg] $msg
66 } [list 1 $errmsg]
67}
68
69#-------------------------------------------------------------------------
70# Test case from forum post 297b9c4103. An index on a generated column
71# with a large column number used to cause RBU to write past the end
72# of a heap buffer.
73#
74reset_db
75do_execsql_test 3.0 {
76 CREATE TABLE t1(
77 a INTEGER PRIMARY KEY,
78 b TEXT GENERATED ALWAYS AS ('b') STORED,
79 c TEXT GENERATED ALWAYS AS ('c') STORED,
80 d TEXT GENERATED ALWAYS AS ('d') STORED,
81 e TEXT GENERATED ALWAYS AS ('e') STORED,
82 f TEXT GENERATED ALWAYS AS ('f') STORED,
83 g TEXT GENERATED ALWAYS AS ('g') STORED
84 );
85 CREATE INDEX idx1 ON t1(g);
86 INSERT INTO t1(a) VALUES(1);
87}
88db close
89
90forcedelete rbu.db
91sqlite3 db2 rbu.db
92do_execsql_test -db db2 3.1 {
93 CREATE TABLE data_t1(a INTEGER PRIMARY KEY, rbu_control TEXT);
94 INSERT INTO data_t1 VALUES(2, 0);
95}
96db2 close
97
98do_test 3.2 {
99 list [catch { run_rbu test.db rbu.db } msg] $msg
100} {1 {SQLITE_ERROR - generated columns not supported: t1.b}}
101
102sqlite3 db test.db
103do_execsql_test 3.3 {
104 SELECT * FROM t1;
105} {1 b c d e f g}
106
107finish_test