CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
multiplex4.test133 linesDownload Raw Back to test
1# 2014-09-252#3# The author disclaims copyright to this source code.  In place of4# 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.tcl17set ::testprefix multiplex418 19db close20sqlite3_shutdown21sqlite3_multiplex_initialize {} 022 23# delete all filesl with the base name of $basename24#25proc multiplex_delete_db {basename} {26  foreach file [glob -nocomplain $basename.*] {27    forcedelete $file28  }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 NNN33# 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 file39    lappend x $file40  }41  return [lsort $x]42}43 44do_test multiplex4-1.0 {45  multiplex_delete_db mx4test46  sqlite3 db {file:mx4test.db?chunksize=10&truncate=1} -uri 1 -vfs multiplex47  db eval {48    CREATE TABLE t1(x);49    INSERT INTO t1(x) VALUES(randomblob(250000));50  }51  multiplex_file_list mx4test52} {mx4test.001 mx4test.db}53 54do_test multiplex4-1.1 {55  db eval {56    DELETE FROM t1;57    VACUUM;58  }59  multiplex_file_list mx4test60} {mx4test.db}61 62# NB:  The PRAGMA multiplex_truncate command is implemented using the63# SQLITE_FCNTL_PRAGMA file-control...64#65# EVIDENCE-OF: R-12238-55120 Whenever a PRAGMA statement is parsed, an66# SQLITE_FCNTL_PRAGMA file control is sent to the open sqlite3_file67# object corresponding to the database file to which the pragma68# statement refers.69#70do_test multiplex4-1.2 {71  db eval {PRAGMA multiplex_truncate}72} {on}73do_test multiplex4-1.3 {74  db eval {PRAGMA multiplex_truncate=off}75} {off}76do_test multiplex4-1.4 {77  db eval {PRAGMA multiplex_truncate}78} {off}79do_test multiplex4-1.5 {80  db eval {PRAGMA multiplex_truncate=on}81} {on}82do_test multiplex4-1.6 {83  db eval {PRAGMA multiplex_truncate}84} {on}85do_test multiplex4-1.7 {86  db eval {PRAGMA multiplex_truncate=0}87} {off}88do_test multiplex4-1.8 {89  db eval {PRAGMA multiplex_truncate=1}90} {on}91do_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 control96# returns SQLITE_OK, then the parser assumes that the VFS has handled97# the PRAGMA itself and the parser generates a no-op prepared statement98# if result string is NULL, or that returns a copy of the result string99# if the string is non-NULL.100#101do_test multiplex4-1.9-explain {102  db eval {EXPLAIN PRAGMA multiplex_truncate=0;}103} {/String8 \d \d \d off/}104 105do_test multiplex4-1.10 {106  db eval {107    INSERT INTO t1(x) VALUES(randomblob(250000));108  }109  multiplex_file_list mx4test110} {mx4test.001 mx4test.db}111 112do_test multiplex4-1.11 {113  db eval {114    DELETE FROM t1;115    VACUUM;116  }117  multiplex_file_list mx4test118} {mx4test.001 mx4test.db}119 120do_test multiplex4-1.12 {121  db eval {122    PRAGMA multiplex_truncate=ON;123    DROP TABLE t1;124    VACUUM;125  }126  multiplex_file_list mx4test127} {mx4test.db}128 129catch { db close }130forcedelete mx4test.db131sqlite3_multiplex_shutdown132finish_test133