sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / rbu / rbugen.test
| 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 | |
| 17 | source [file join [file dirname [info script]] rbu_common.tcl] |
| 18 | if_no_rbu_support { finish_test ; return } |
| 19 | set ::testprefix rbugen |
| 20 | |
| 21 | foreach {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 | # |
| 74 | reset_db |
| 75 | do_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 | } |
| 88 | db close |
| 89 | |
| 90 | forcedelete rbu.db |
| 91 | sqlite3 db2 rbu.db |
| 92 | do_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 | } |
| 96 | db2 close |
| 97 | |
| 98 | do_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 | |
| 102 | sqlite3 db test.db |
| 103 | do_execsql_test 3.3 { |
| 104 | SELECT * FROM t1; |
| 105 | } {1 b c d e f g} |
| 106 | |
| 107 | finish_test |