3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file contains tests for the "truncate" option in the multiplexor.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set ::testprefix multiplex4
21 sqlite3_multiplex_initialize {} 0
23 # delete all filesl with the base name of $basename
25 proc multiplex_delete_db {basename} {
26 foreach file [glob -nocomplain $basename.*] {
31 # Return a sorted list of all files with the base name of $basename.
32 # Except, delete all text from the end of $basename through the NNN
33 # suffix on the end of the filename.
35 proc multiplex_file_list {basename} {
37 foreach file [glob -nocomplain $basename.*] {
38 regsub "^$basename\\..*(\\d\\d\\d)\$" $file $basename.\\1 file
44 do_test multiplex4-1.0 {
45 multiplex_delete_db mx4test
46 sqlite3 db {file:mx4test.db?chunksize=10&truncate=1} -uri 1 -vfs multiplex
49 INSERT INTO t1(x) VALUES(randomblob(250000));
51 multiplex_file_list mx4test
52 } {mx4test.001 mx4test.db}
54 do_test multiplex4-1.1 {
59 multiplex_file_list mx4test
62 # NB: The PRAGMA multiplex_truncate command is implemented using the
63 # SQLITE_FCNTL_PRAGMA file-control...
65 # EVIDENCE-OF: R-12238-55120 Whenever a PRAGMA statement is parsed, an
66 # SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
67 # object corresponding to the database file to which the pragma
70 do_test multiplex4-1.2 {
71 db eval {PRAGMA multiplex_truncate}
73 do_test multiplex4-1.3 {
74 db eval {PRAGMA multiplex_truncate=off}
76 do_test multiplex4-1.4 {
77 db eval {PRAGMA multiplex_truncate}
79 do_test multiplex4-1.5 {
80 db eval {PRAGMA multiplex_truncate=on}
82 do_test multiplex4-1.6 {
83 db eval {PRAGMA multiplex_truncate}
85 do_test multiplex4-1.7 {
86 db eval {PRAGMA multiplex_truncate=0}
88 do_test multiplex4-1.8 {
89 db eval {PRAGMA multiplex_truncate=1}
91 do_test multiplex4-1.9 {
92 db eval {PRAGMA multiplex_truncate=0}
95 # EVIDENCE-OF: R-26188-08449 If the SQLITE_FCNTL_PRAGMA file control
96 # returns SQLITE_OK, then the parser assumes that the VFS has handled
97 # the PRAGMA itself and the parser generates a no-op prepared statement
98 # if result string is NULL, or that returns a copy of the result string
99 # if the string is non-NULL.
101 do_test multiplex4-1.9-explain {
102 db eval {EXPLAIN PRAGMA multiplex_truncate=0;}
103 } {/String8 \d \d \d off/}
105 do_test multiplex4-1.10 {
107 INSERT INTO t1(x) VALUES(randomblob(250000));
109 multiplex_file_list mx4test
110 } {mx4test.001 mx4test.db}
112 do_test multiplex4-1.11 {
117 multiplex_file_list mx4test
118 } {mx4test.001 mx4test.db}
120 do_test multiplex4-1.12 {
122 PRAGMA multiplex_truncate=ON;
126 multiplex_file_list mx4test
130 forcedelete mx4test.db
131 sqlite3_multiplex_shutdown