OLD | NEW |
(Empty) | |
| 1 # 2014-09-25 |
| 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 "truncate" option in the multiplexor. |
| 13 # |
| 14 |
| 15 set testdir [file dirname $argv0] |
| 16 source $testdir/tester.tcl |
| 17 set ::testprefix multiplex4 |
| 18 |
| 19 db close |
| 20 sqlite3_shutdown |
| 21 sqlite3_multiplex_initialize {} 0 |
| 22 |
| 23 # delete all filesl with the base name of $basename |
| 24 # |
| 25 proc multiplex_delete_db {basename} { |
| 26 foreach file [glob -nocomplain $basename.*] { |
| 27 forcedelete $file |
| 28 } |
| 29 } |
| 30 |
| 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. |
| 34 # |
| 35 proc multiplex_file_list {basename} { |
| 36 set x {} |
| 37 foreach file [glob -nocomplain $basename.*] { |
| 38 regsub "^$basename\\..*(\\d\\d\\d)\$" $file $basename.\\1 file |
| 39 lappend x $file |
| 40 } |
| 41 return [lsort $x] |
| 42 } |
| 43 |
| 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 |
| 47 db eval { |
| 48 CREATE TABLE t1(x); |
| 49 INSERT INTO t1(x) VALUES(randomblob(250000)); |
| 50 } |
| 51 multiplex_file_list mx4test |
| 52 } {mx4test.001 mx4test.db} |
| 53 |
| 54 do_test multiplex4-1.1 { |
| 55 db eval { |
| 56 DELETE FROM t1; |
| 57 VACUUM; |
| 58 } |
| 59 multiplex_file_list mx4test |
| 60 } {mx4test.db} |
| 61 |
| 62 # NB: The PRAGMA multiplex_truncate command is implemented using the |
| 63 # SQLITE_FCNTL_PRAGMA file-control... |
| 64 # |
| 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 |
| 68 # statement refers. |
| 69 # |
| 70 do_test multiplex4-1.2 { |
| 71 db eval {PRAGMA multiplex_truncate} |
| 72 } {on} |
| 73 do_test multiplex4-1.3 { |
| 74 db eval {PRAGMA multiplex_truncate=off} |
| 75 } {off} |
| 76 do_test multiplex4-1.4 { |
| 77 db eval {PRAGMA multiplex_truncate} |
| 78 } {off} |
| 79 do_test multiplex4-1.5 { |
| 80 db eval {PRAGMA multiplex_truncate=on} |
| 81 } {on} |
| 82 do_test multiplex4-1.6 { |
| 83 db eval {PRAGMA multiplex_truncate} |
| 84 } {on} |
| 85 do_test multiplex4-1.7 { |
| 86 db eval {PRAGMA multiplex_truncate=0} |
| 87 } {off} |
| 88 do_test multiplex4-1.8 { |
| 89 db eval {PRAGMA multiplex_truncate=1} |
| 90 } {on} |
| 91 do_test multiplex4-1.9 { |
| 92 db eval {PRAGMA multiplex_truncate=0} |
| 93 } {off} |
| 94 |
| 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. |
| 100 # |
| 101 do_test multiplex4-1.9-explain { |
| 102 db eval {EXPLAIN PRAGMA multiplex_truncate=0;} |
| 103 } {/String8 \d \d \d off/} |
| 104 |
| 105 do_test multiplex4-1.10 { |
| 106 db eval { |
| 107 INSERT INTO t1(x) VALUES(randomblob(250000)); |
| 108 } |
| 109 multiplex_file_list mx4test |
| 110 } {mx4test.001 mx4test.db} |
| 111 |
| 112 do_test multiplex4-1.11 { |
| 113 db eval { |
| 114 DELETE FROM t1; |
| 115 VACUUM; |
| 116 } |
| 117 multiplex_file_list mx4test |
| 118 } {mx4test.001 mx4test.db} |
| 119 |
| 120 do_test multiplex4-1.12 { |
| 121 db eval { |
| 122 PRAGMA multiplex_truncate=ON; |
| 123 DROP TABLE t1; |
| 124 VACUUM; |
| 125 } |
| 126 multiplex_file_list mx4test |
| 127 } {mx4test.db} |
| 128 |
| 129 catch { db close } |
| 130 forcedelete mx4test.db |
| 131 sqlite3_multiplex_shutdown |
| 132 finish_test |
OLD | NEW |