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 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17set ::testprefix multiplex4 18 19db close 20sqlite3_shutdown 21sqlite3_multiplex_initialize {} 0 22 23# delete all filesl with the base name of $basename 24# 25proc 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# 35proc 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 44do_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 54do_test multiplex4-1.1 { 55 db eval { 56 DELETE FROM t1; 57 VACUUM; 58 } 59 multiplex_file_list mx4test 60} {mx4test.db} 61 62do_test multiplex4-1.2 { 63 db eval {PRAGMA multiplex_truncate} 64} {on} 65do_test multiplex4-1.3 { 66 db eval {PRAGMA multiplex_truncate=off} 67} {off} 68do_test multiplex4-1.4 { 69 db eval {PRAGMA multiplex_truncate} 70} {off} 71do_test multiplex4-1.5 { 72 db eval {PRAGMA multiplex_truncate=on} 73} {on} 74do_test multiplex4-1.6 { 75 db eval {PRAGMA multiplex_truncate} 76} {on} 77do_test multiplex4-1.7 { 78 db eval {PRAGMA multiplex_truncate=0} 79} {off} 80do_test multiplex4-1.8 { 81 db eval {PRAGMA multiplex_truncate=1} 82} {on} 83do_test multiplex4-1.9 { 84 db eval {PRAGMA multiplex_truncate=0} 85} {off} 86 87do_test multiplex4-1.10 { 88 db eval { 89 INSERT INTO t1(x) VALUES(randomblob(250000)); 90 } 91 multiplex_file_list mx4test 92} {mx4test.001 mx4test.db} 93 94do_test multiplex4-1.11 { 95 db eval { 96 DELETE FROM t1; 97 VACUUM; 98 } 99 multiplex_file_list mx4test 100} {mx4test.001 mx4test.db} 101 102do_test multiplex4-1.12 { 103 db eval { 104 PRAGMA multiplex_truncate=ON; 105 DROP TABLE t1; 106 VACUUM; 107 } 108 multiplex_file_list mx4test 109} {mx4test.db} 110 111catch { db close } 112forcedelete mx4test.db 113sqlite3_multiplex_shutdown 114finish_test 115