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

106 lines · 2363 bytes Raw Blame History
1# 2014 October 21
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# This file contains tests for the RBU module.
13#
14
15
16source [file join [file dirname [info script]] rbu_common.tcl]
17if_no_rbu_support { finish_test ; return }
18set ::testprefix rbu7
19
20# Test index:
21#
22# 1.*: That affinities are correctly applied to values within the
23# RBU database.
24#
25# 2.*: Tests for multi-column primary keys.
26#
27
28do_test 1.0 {
29 execsql {
30 CREATE TABLE t1(a INT PRIMARY KEY, b) WITHOUT ROWID;
31 INSERT INTO t1 VALUES(1, 'abc');
32 INSERT INTO t1 VALUES(2, 'def');
33 }
34
35 forcedelete rbu.db
36 sqlite3 rbu rbu.db
37 rbu eval {
38 CREATE TABLE data_t1(a, b, rbu_control);
39 INSERT INTO data_t1 VALUES('1', NULL, 1);
40 }
41 rbu close
42} {}
43
44do_test 1.1 {
45 sqlite3rbu rbu test.db rbu.db
46 while { [rbu step]=="SQLITE_OK" } {}
47 rbu close
48} {SQLITE_DONE}
49
50sqlite3 db test.db
51do_execsql_test 1.2 {
52 SELECT * FROM t1
53} {2 def}
54
55#-------------------------------------------------------------------------
56#
57foreach {tn tbl} {
58 1 { CREATE TABLE t1(a, b, c, PRIMARY KEY(a, b)) WITHOUT ROWID }
59 2 { CREATE TABLE t1(a, b, c, PRIMARY KEY(a, b)) }
60} {
61 reset_db
62
63 execsql $tbl
64 do_execsql_test 2.$tn.1 {
65 CREATE INDEX t1c ON t1(c);
66 INSERT INTO t1 VALUES(1, 1, 'a');
67 INSERT INTO t1 VALUES(1, 2, 'b');
68 INSERT INTO t1 VALUES(2, 1, 'c');
69 INSERT INTO t1 VALUES(2, 2, 'd');
70 }
71
72 do_test 2.$tn.2 {
73 forcedelete rbu.db
74 sqlite3 rbu rbu.db
75 execsql {
76 CREATE TABLE data_t1(a, b, c, rbu_control);
77 INSERT INTO data_t1 VALUES(3, 1, 'e', 0);
78 INSERT INTO data_t1 VALUES(3, 2, 'f', 0);
79 INSERT INTO data_t1 VALUES(1, 2, NULL, 1);
80 INSERT INTO data_t1 VALUES(2, 1, 'X', '..x');
81 } rbu
82 rbu close
83 } {}
84
85 do_test 2.$tn.3 {
86 set rc "SQLITE_OK"
87 while {$rc == "SQLITE_OK"} {
88 sqlite3rbu rbu test.db rbu.db
89 rbu step
90 set rc [rbu close]
91 }
92 set rc
93 } {SQLITE_DONE}
94
95 do_execsql_test 2.$tn.1 {
96 SELECT * FROM t1 ORDER BY a, b
97 } {
98 1 1 a
99 2 1 X
100 2 2 d
101 3 1 e
102 3 2 f
103 }
104}
105
106finish_test