1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
# 2015 June 02
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file implements regression tests for the sessions module.
# Specifically, it tests that tables appear in the correct order
# within changesets and patchsets.
#
if {![info exists testdir]} {
set testdir [file join [file dirname [info script]] .. .. test]
}
source [file join [file dirname [info script]] session_common.tcl]
source $testdir/tester.tcl
ifcapable !session {finish_test; return}
set testprefix sessionF
#
# Test plan:
#
# 1.*: Test that sqlite3session_changeset() and sqlite3session_patchset()
# output tables in the right order.
#
# 2.*: Test that sqlite3session_invert() does not modify the order of
# tables within a changeset.
#
# 3.*: Test that sqlite3session_concat outputs tables in the right order.
#
# Create a db schema to use.
#
do_execsql_test 1.0 {
CREATE TABLE t3(e PRIMARY KEY, f);
CREATE TABLE t1(a PRIMARY KEY, b);
CREATE TABLE t2(c PRIMARY KEY, d);
}
#-----------------------------------------------------------------------
# 1.* - changeset() and patchset().
#
foreach {tn setup result} {
1 {
S attach *
} {
{INSERT t2 0 X. {} {i 2 t two}}
{INSERT t1 0 X. {} {i 1 t one}}
{INSERT t3 0 X. {} {i 3 t three}}
}
2 {
S attach t1
S attach *
} {
{INSERT t1 0 X. {} {i 1 t one}}
{INSERT t2 0 X. {} {i 2 t two}}
{INSERT t3 0 X. {} {i 3 t three}}
}
3 {
S attach t3
S attach t2
S attach t1
} {
{INSERT t3 0 X. {} {i 3 t three}}
{INSERT t2 0 X. {} {i 2 t two}}
{INSERT t1 0 X. {} {i 1 t one}}
}
} {
execsql {
DELETE FROM t1;
DELETE FROM t2;
DELETE FROM t3;
}
sqlite3session S db main
eval $setup
do_execsql_test 1.$tn.1 {
INSERT INTO t2 VALUES(2, 'two');
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t3 VALUES(3, 'three');
}
do_changeset_test 1.1.$tn.2 S $result
do_patchset_test 1.1.$tn.3 S $result
S delete
}
foreach {tn setup result} {
1 {
S attach *
} {
{INSERT t2 0 X. {} {i 4 t four}}
{INSERT t2 0 X. {} {i 5 t five}}
{INSERT t1 0 X. {} {i 1 t one}}
{INSERT t3 0 X. {} {i 6 t six}}
}
2 {
S attach t1
S attach *
} {
{INSERT t1 0 X. {} {i 1 t one}}
{INSERT t2 0 X. {} {i 4 t four}}
{INSERT t2 0 X. {} {i 5 t five}}
{INSERT t3 0 X. {} {i 6 t six}}
}
3 {
S attach t3
S attach t2
S attach t1
} {
{INSERT t3 0 X. {} {i 6 t six}}
{INSERT t2 0 X. {} {i 4 t four}}
{INSERT t2 0 X. {} {i 5 t five}}
{INSERT t1 0 X. {} {i 1 t one}}
}
} {
execsql {
DELETE FROM t1;
DELETE FROM t2;
DELETE FROM t3;
}
sqlite3session S db main
eval $setup
do_execsql_test 1.$tn.1 {
INSERT INTO t2 VALUES(2, 'two');
INSERT INTO t1 VALUES(1, 'one');
DELETE FROM t2;
INSERT INTO t2 VALUES(4, 'four');
INSERT INTO t2 VALUES(5, 'five');
INSERT INTO t3 VALUES(6, 'six');
}
do_changeset_test 1.2.$tn.2 S $result
do_patchset_test 1.2.$tn.2 S $result
S delete
}
#-------------------------------------------------------------------------
# 2.* - invert()
#
foreach {tn setup result} {
1 {
S attach *
} {
{DELETE t2 0 X. {i 4 t four} {}}
{DELETE t2 0 X. {i 5 t five} {}}
{DELETE t1 0 X. {i 1 t one} {}}
{DELETE t3 0 X. {i 6 t six} {}}
}
2 {
S attach t1
S attach *
} {
{DELETE t1 0 X. {i 1 t one} {}}
{DELETE t2 0 X. {i 4 t four} {}}
{DELETE t2 0 X. {i 5 t five} {}}
{DELETE t3 0 X. {i 6 t six} {}}
}
3 {
S attach t3
S attach t2
S attach t1
} {
{DELETE t3 0 X. {i 6 t six} {}}
{DELETE t2 0 X. {i 4 t four} {}}
{DELETE t2 0 X. {i 5 t five} {}}
{DELETE t1 0 X. {i 1 t one} {}}
}
} {
execsql {
DELETE FROM t1;
DELETE FROM t2;
DELETE FROM t3;
}
sqlite3session S db main
eval $setup
do_execsql_test 1.$tn.1 {
INSERT INTO t2 VALUES(2, 'two');
INSERT INTO t1 VALUES(1, 'one');
DELETE FROM t2;
INSERT INTO t2 VALUES(4, 'four');
INSERT INTO t2 VALUES(5, 'five');
INSERT INTO t3 VALUES(6, 'six');
}
do_changeset_invert_test 2.$tn.2 S $result
S delete
}
#-------------------------------------------------------------------------
# 3.* - concat()
#
foreach {tn setup1 sql1 setup2 sql2 result} {
1 {
S attach *
} {
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t2 VALUES(2, 'two');
} {
S attach t2
S attach t1
} {
INSERT INTO t1 VALUES(3, 'three');
INSERT INTO t2 VALUES(4, 'four');
} {
{INSERT t1 0 X. {} {i 1 t one}}
{INSERT t1 0 X. {} {i 3 t three}}
{INSERT t2 0 X. {} {i 2 t two}}
{INSERT t2 0 X. {} {i 4 t four}}
}
1 {
S attach t2
S attach t1
} {
INSERT INTO t1 VALUES(1, 'one');
INSERT INTO t2 VALUES(2, 'two');
} {
S attach *
} {
INSERT INTO t1 VALUES(3, 'three');
INSERT INTO t2 VALUES(4, 'four');
} {
{INSERT t2 0 X. {} {i 2 t two}}
{INSERT t2 0 X. {} {i 4 t four}}
{INSERT t1 0 X. {} {i 1 t one}}
{INSERT t1 0 X. {} {i 3 t three}}
}
1 {
S attach *
} {
INSERT INTO t2 VALUES(2, 'two');
} {
S attach *
} {
INSERT INTO t1 VALUES(3, 'three');
INSERT INTO t2 VALUES(4, 'four');
INSERT INTO t3 VALUES(5, 'five');
} {
{INSERT t2 0 X. {} {i 2 t two}}
{INSERT t2 0 X. {} {i 4 t four}}
{INSERT t1 0 X. {} {i 3 t three}}
{INSERT t3 0 X. {} {i 5 t five}}
}
} {
execsql {
DELETE FROM t1;
DELETE FROM t2;
DELETE FROM t3;
}
sqlite3session S db main
eval $setup1
execsql $sql1
set c1 [S changeset]
S delete
sqlite3session S db main
eval $setup2
execsql $sql2
set c2 [S changeset]
S delete
set res [list]
sqlite3session_foreach x [sqlite3changeset_concat $c1 $c2] {
lappend res $x
}
do_test 3.$tn { set res } [list {*}$result]
}
finish_test
|