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 / rbustrict.test

115 lines · 3248 bytes Raw Blame History
1# 2026 October 29
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# Tests for RBU updates and RBU vacuums of STRICT tables. In particular,
13# that values stored in columns of type ANY are not subjected to
14# NUMERIC affinity by the imposter tables RBU uses to write to the
15# target database.
16#
17
18source [file join [file dirname [info script]] rbu_common.tcl]
19if_no_rbu_support { finish_test ; return }
20set ::testprefix rbustrict
21
22#-------------------------------------------------------------------------
23# RBU vacuum.
24#
25foreach {tn bIndex} {1 0 2 1} {
26reset_db
27do_execsql_test 1.$tn.0 {
28 CREATE TABLE t1(id INTEGER PRIMARY KEY, v ANY) STRICT;
29 INSERT INTO t1 VALUES(1, '01'), (2, '1.0'), (3, '-0'), (4, ' 7');
30 INSERT INTO t1 VALUES(5, '1e5'), (6, 'abc'), (7, '9223372036854775808');
31 INSERT INTO t1 VALUES(8, 8), (9, NULL);
32
33 CREATE TABLE w1(k ANY PRIMARY KEY, n INT) STRICT, WITHOUT ROWID;
34 INSERT INTO w1 VALUES('007', 1), (8, 2), ('8', 3);
35}
36if {$bIndex} {
37 do_execsql_test 1.$tn.0.1 {
38 CREATE INDEX i1 ON t1(v);
39 CREATE INDEX w1n ON w1(n, k);
40 }
41}
42
43set t1_res {
44 1 text '01' 2 text '1.0' 3 text '-0' 4 text {' 7'}
45 5 text '1e5' 6 text 'abc' 7 text '9223372036854775808'
46 8 integer 8 9 null NULL
47}
48set w1_res {
49 integer 8 2 text '007' 1 text '8' 3
50}
51
52do_rbu_vacuum_test 1.$tn.1 1
53
54do_execsql_test 1.$tn.2 {
55 SELECT id, typeof(v), quote(v) FROM t1 ORDER BY id;
56} $t1_res
57do_execsql_test 1.$tn.3 {
58 SELECT typeof(k), quote(k), n FROM w1 ORDER BY k;
59} $w1_res
60do_execsql_test 1.$tn.4 {
61 SELECT id FROM t1 WHERE v='01';
62 SELECT n FROM w1 WHERE k='007';
63} {1 1}
64}
65
66#-------------------------------------------------------------------------
67# RBU update.
68#
69reset_db
70do_execsql_test 2.0 {
71 CREATE TABLE t1(id INTEGER PRIMARY KEY, v ANY) STRICT;
72 CREATE INDEX i1 ON t1(v);
73 INSERT INTO t1 VALUES(6, 'abc'), (7, NULL);
74
75 CREATE TABLE w1(k ANY PRIMARY KEY, n INT) STRICT, WITHOUT ROWID;
76 CREATE INDEX w1n ON w1(n, k);
77 INSERT INTO w1 VALUES('xyz', 1);
78}
79
80do_test 2.1 {
81 forcedelete rbu.db
82 sqlite3 rbu rbu.db
83 rbu eval {
84 CREATE TABLE data_t1(id, v, rbu_control);
85 INSERT INTO data_t1 VALUES(10, '0042', 0);
86 INSERT INTO data_t1 VALUES(11, '5.50', 0);
87 INSERT INTO data_t1 VALUES(12, NULL, 0);
88 INSERT INTO data_t1 VALUES(6, '007', '.x');
89
90 CREATE TABLE data_w1(k, n, rbu_control);
91 INSERT INTO data_w1 VALUES('007', 2, 0);
92 INSERT INTO data_w1 VALUES(8, 3, 0);
93 INSERT INTO data_w1 VALUES('xyz', 4, '.x');
94 }
95 rbu close
96 step_rbu test.db rbu.db
97} {SQLITE_DONE}
98
99do_execsql_test 2.2 {
100 SELECT id, typeof(v), quote(v) FROM t1 ORDER BY id;
101} {
102 6 text '007' 7 null NULL 10 text '0042' 11 text '5.50' 12 null NULL
103}
104do_execsql_test 2.3 {
105 SELECT typeof(k), quote(k), n FROM w1 ORDER BY k;
106} {
107 integer 8 3 text '007' 2 text 'xyz' 4
108}
109do_execsql_test 2.4 {
110 SELECT id FROM t1 WHERE v='0042';
111 SELECT n FROM w1 WHERE k='007';
112 PRAGMA integrity_check;
113} {10 2 ok}
114
115finish_test