xref: /sqlite-3.40.0/test/multiplex4.test (revision 8dd7a6a9)
13b8fea9eSdrh# 2014-09-25
23b8fea9eSdrh#
33b8fea9eSdrh# The author disclaims copyright to this source code.  In place of
43b8fea9eSdrh# a legal notice, here is a blessing:
53b8fea9eSdrh#
63b8fea9eSdrh#    May you do good and not evil.
73b8fea9eSdrh#    May you find forgiveness for yourself and forgive others.
83b8fea9eSdrh#    May you share freely, never taking more than you give.
93b8fea9eSdrh#
103b8fea9eSdrh#***********************************************************************
113b8fea9eSdrh#
123b8fea9eSdrh# This file contains tests for the "truncate" option in the multiplexor.
133b8fea9eSdrh#
143b8fea9eSdrh
153b8fea9eSdrhset testdir [file dirname $argv0]
163b8fea9eSdrhsource $testdir/tester.tcl
173b8fea9eSdrhset ::testprefix multiplex4
183b8fea9eSdrh
193b8fea9eSdrhdb close
203b8fea9eSdrhsqlite3_shutdown
213b8fea9eSdrhsqlite3_multiplex_initialize {} 0
223b8fea9eSdrh
233b8fea9eSdrh# delete all filesl with the base name of $basename
243b8fea9eSdrh#
253b8fea9eSdrhproc multiplex_delete_db {basename} {
263b8fea9eSdrh  foreach file [glob -nocomplain $basename.*] {
273b8fea9eSdrh    forcedelete $file
283b8fea9eSdrh  }
293b8fea9eSdrh}
303b8fea9eSdrh
313b8fea9eSdrh# Return a sorted list of all files with the base name of $basename.
323b8fea9eSdrh# Except, delete all text from the end of $basename through the NNN
333b8fea9eSdrh# suffix on the end of the filename.
343b8fea9eSdrh#
353b8fea9eSdrhproc multiplex_file_list {basename} {
363b8fea9eSdrh  set x {}
373b8fea9eSdrh  foreach file [glob -nocomplain $basename.*] {
383b8fea9eSdrh    regsub "^$basename\\..*(\\d\\d\\d)\$" $file $basename.\\1 file
393b8fea9eSdrh    lappend x $file
403b8fea9eSdrh  }
413b8fea9eSdrh  return [lsort $x]
423b8fea9eSdrh}
433b8fea9eSdrh
443b8fea9eSdrhdo_test multiplex4-1.0 {
453b8fea9eSdrh  multiplex_delete_db mx4test
463b8fea9eSdrh  sqlite3 db {file:mx4test.db?chunksize=10&truncate=1} -uri 1 -vfs multiplex
473b8fea9eSdrh  db eval {
483b8fea9eSdrh    CREATE TABLE t1(x);
493b8fea9eSdrh    INSERT INTO t1(x) VALUES(randomblob(250000));
503b8fea9eSdrh  }
513b8fea9eSdrh  multiplex_file_list mx4test
523b8fea9eSdrh} {mx4test.001 mx4test.db}
533b8fea9eSdrh
543b8fea9eSdrhdo_test multiplex4-1.1 {
553b8fea9eSdrh  db eval {
563b8fea9eSdrh    DELETE FROM t1;
573b8fea9eSdrh    VACUUM;
583b8fea9eSdrh  }
593b8fea9eSdrh  multiplex_file_list mx4test
603b8fea9eSdrh} {mx4test.db}
613b8fea9eSdrh
62*8dd7a6a9Sdrh# NB:  The PRAGMA multiplex_truncate command is implemented using the
63*8dd7a6a9Sdrh# SQLITE_FCNTL_PRAGMA file-control...
64*8dd7a6a9Sdrh#
65*8dd7a6a9Sdrh# EVIDENCE-OF: R-12238-55120 Whenever a PRAGMA statement is parsed, an
66*8dd7a6a9Sdrh# SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file
67*8dd7a6a9Sdrh# object corresponding to the database file to which the pragma
68*8dd7a6a9Sdrh# statement refers.
69*8dd7a6a9Sdrh#
703b8fea9eSdrhdo_test multiplex4-1.2 {
713b8fea9eSdrh  db eval {PRAGMA multiplex_truncate}
723b8fea9eSdrh} {on}
733b8fea9eSdrhdo_test multiplex4-1.3 {
743b8fea9eSdrh  db eval {PRAGMA multiplex_truncate=off}
753b8fea9eSdrh} {off}
763b8fea9eSdrhdo_test multiplex4-1.4 {
773b8fea9eSdrh  db eval {PRAGMA multiplex_truncate}
783b8fea9eSdrh} {off}
793b8fea9eSdrhdo_test multiplex4-1.5 {
803b8fea9eSdrh  db eval {PRAGMA multiplex_truncate=on}
813b8fea9eSdrh} {on}
823b8fea9eSdrhdo_test multiplex4-1.6 {
833b8fea9eSdrh  db eval {PRAGMA multiplex_truncate}
843b8fea9eSdrh} {on}
853b8fea9eSdrhdo_test multiplex4-1.7 {
863b8fea9eSdrh  db eval {PRAGMA multiplex_truncate=0}
873b8fea9eSdrh} {off}
883b8fea9eSdrhdo_test multiplex4-1.8 {
893b8fea9eSdrh  db eval {PRAGMA multiplex_truncate=1}
903b8fea9eSdrh} {on}
913b8fea9eSdrhdo_test multiplex4-1.9 {
923b8fea9eSdrh  db eval {PRAGMA multiplex_truncate=0}
933b8fea9eSdrh} {off}
943b8fea9eSdrh
95*8dd7a6a9Sdrh# EVIDENCE-OF: R-26188-08449 If the SQLITE_FCNTL_PRAGMA file control
96*8dd7a6a9Sdrh# returns SQLITE_OK, then the parser assumes that the VFS has handled
97*8dd7a6a9Sdrh# the PRAGMA itself and the parser generates a no-op prepared statement
98*8dd7a6a9Sdrh# if result string is NULL, or that returns a copy of the result string
99*8dd7a6a9Sdrh# if the string is non-NULL.
100*8dd7a6a9Sdrh#
101*8dd7a6a9Sdrhdo_test multiplex4-1.9-explain {
102*8dd7a6a9Sdrh  db eval {EXPLAIN PRAGMA multiplex_truncate=0;}
103*8dd7a6a9Sdrh} {/String8 \d \d \d off/}
104*8dd7a6a9Sdrh
1053b8fea9eSdrhdo_test multiplex4-1.10 {
1063b8fea9eSdrh  db eval {
1073b8fea9eSdrh    INSERT INTO t1(x) VALUES(randomblob(250000));
1083b8fea9eSdrh  }
1093b8fea9eSdrh  multiplex_file_list mx4test
1103b8fea9eSdrh} {mx4test.001 mx4test.db}
1113b8fea9eSdrh
1123b8fea9eSdrhdo_test multiplex4-1.11 {
1133b8fea9eSdrh  db eval {
1143b8fea9eSdrh    DELETE FROM t1;
1153b8fea9eSdrh    VACUUM;
1163b8fea9eSdrh  }
1173b8fea9eSdrh  multiplex_file_list mx4test
1183b8fea9eSdrh} {mx4test.001 mx4test.db}
1193b8fea9eSdrh
1203b8fea9eSdrhdo_test multiplex4-1.12 {
1213b8fea9eSdrh  db eval {
1223b8fea9eSdrh    PRAGMA multiplex_truncate=ON;
1233b8fea9eSdrh    DROP TABLE t1;
1243b8fea9eSdrh    VACUUM;
1253b8fea9eSdrh  }
1263b8fea9eSdrh  multiplex_file_list mx4test
1273b8fea9eSdrh} {mx4test.db}
1283b8fea9eSdrh
1293b8fea9eSdrhcatch { db close }
1303b8fea9eSdrhforcedelete mx4test.db
1313b8fea9eSdrhsqlite3_multiplex_shutdown
1323b8fea9eSdrhfinish_test
133