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 / session / sessionA.test

106 lines · 2283 bytes Raw Blame History
1# 2013 July 04
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 tests that filter callbacks work as required.
13#
14
15if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
17}
18source [file join [file dirname [info script]] session_common.tcl]
19source $testdir/tester.tcl
20ifcapable !session {finish_test; return}
21set testprefix sessionA
22
23
24forcedelete test.db2
25sqlite3 db2 test.db2
26foreach {tn db} {1 db 2 db2} {
27 do_test 1.$tn.1 {
28 execsql {
29 CREATE TABLE t1(a PRIMARY KEY, b);
30 CREATE TABLE t2(a PRIMARY KEY, b);
31 CREATE TABLE t3(a PRIMARY KEY, b);
32 } $db
33 } {}
34}
35
36proc tbl_filter {zTbl} {
37 return $::table_filter($zTbl)
38}
39
40do_test 2.1 {
41 set ::table_filter(t1) 1
42 set ::table_filter(t2) 0
43 set ::table_filter(t3) 1
44
45 sqlite3session S db main
46 S table_filter tbl_filter
47
48 execsql {
49 INSERT INTO t1 VALUES('a', 'b');
50 INSERT INTO t2 VALUES('c', 'd');
51 INSERT INTO t3 VALUES('e', 'f');
52 }
53
54 set changeset [S changeset]
55 S delete
56 sqlite3changeset_apply db2 $changeset xConflict
57
58 execsql {
59 SELECT * FROM t1;
60 SELECT * FROM t2;
61 SELECT * FROM t3;
62 } db2
63} {a b e f}
64
65#-------------------------------------------------------------------------
66# Test that filter callbacks passed to sqlite3changeset_apply() are
67# invoked correctly.
68#
69reset_db
70do_execsql_test 3.1 {
71 CREATE TABLE t1(a PRIMARY KEY, b);
72 CREATE TABLE t2(x PRIMARY KEY, y);
73}
74
75do_test 3.2 {
76 execsql BEGIN
77 set ::cs [changeset_from_sql {
78 INSERT INTO t1 VALUES(1, 2);
79 INSERT INTO t2 VALUES('x', 'y');
80 }]
81 execsql ROLLBACK
82 set {} {}
83} {}
84
85proc filter {x y} {
86 return [string equal $x $y]
87}
88
89do_test 3.3 {
90 sqlite3changeset_apply db $::cs {} [list filter t1]
91 execsql {
92 SELECT * FROM t1;
93 SELECT * FROM t2;
94 }
95} {1 2}
96
97do_test 3.4 {
98 execsql { DELETE FROM t1 }
99 sqlite3changeset_apply db $::cs {} [list filter t2]
100 execsql {
101 SELECT * FROM t1;
102 SELECT * FROM t2;
103 }
104} {x y}
105
106finish_test