blob: 53d8d871d8138622037b4607ad6aef439eccd080 (
plain)
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
|
# 2015 November 13
#
# 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 SQLite library. The
# focus of this file is testing the test_sqllog.c module.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix sqllog
ifcapable !sqllog {
finish_test
return
}
proc readfile {f} {
set fd [open $f]
set txt [read $fd]
close $fd
set txt
}
proc delete_all_sqllog_files {} {
forcedelete {*}[glob -nocomplain sqllog_*.sql]
forcedelete {*}[glob -nocomplain sqllog_*.db]
forcedelete {*}[glob -nocomplain sqllog_*.idx]
}
proc touch {f} {
set fd [open $f w+]
close $fd
}
db close
sqlite3_shutdown
set ::env(SQLITE_SQLLOG_DIR) [pwd]
delete_all_sqllog_files
sqlite3 db test.db
set a a
set b b
do_execsql_test 1.0 {
CREATE TABLE t1(x, y);
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES($a, $b);
SELECT * FROM t1;
} {1 2 a b}
db close
do_test 1.1 {
readfile [lindex [glob sqllog_*.sql] 0]
} [string trimleft {
/-- Main database is '.*/sqllog_.*_0.db'
CREATE TABLE t1\(x, y\);; -- clock=0
INSERT INTO t1 VALUES\(1, 2\);; -- clock=1
INSERT INTO t1 VALUES\('a', 'b'\);; -- clock=2
SELECT . FROM t1;; -- clock=3
/}]
do_test 1.2 {
file size [lindex [glob sqllog_*_0.db] 0]
} 1024
#-------------------------------------------------------------------------
catch { db close }
sqlite3_shutdown
delete_all_sqllog_files
forcedelete test.db-sqllog
set ::env(SQLITE_SQLLOG_CONDITIONAL) 1
sqlite3 db test.db
do_execsql_test 2.1 {
INSERT INTO t1 VALUES(4, 5);
SELECT * FROM t1;
} {1 2 a b 4 5}
do_test 2.2 {
glob -nocomplain sqllog_*
} {}
db close
touch test.db-sqllog
sqlite3 db test.db
do_execsql_test 2.3 {
INSERT INTO t1 VALUES(6, 7);
SELECT * FROM t1;
} {1 2 a b 4 5 6 7}
db close
do_test 2.4 {
readfile [lindex [glob sqllog_*.sql] 0]
} [string trimleft {
/-- Main database is '.*/sqllog_.*_0.db'
INSERT INTO t1 VALUES\(6, 7\);; -- clock=0
SELECT . FROM t1;; -- clock=1
/}]
catch { db close }
sqlite3_shutdown
unset ::env(SQLITE_SQLLOG_DIR)
unset ::env(SQLITE_SQLLOG_CONDITIONAL)
sqlite3_config_sqllog
sqlite3_initialize
finish_test
|