/ Check-in [d2962a5f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the "multiplex_truncate" PRAGMA to the multiplexor extension, for querying and setting the truncate flag on a database connection.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d2962a5f388f30a02429e0c8b87399f482b5604c
User & Date: drh 2014-09-23 18:30:00
Context
2014-09-23
21:25
Simplify the CellInfo structure for a size reduction and performance improvement. check-in: bf59df66 user: drh tags: trunk
18:30
Add the "multiplex_truncate" PRAGMA to the multiplexor extension, for querying and setting the truncate flag on a database connection. check-in: d2962a5f user: drh tags: trunk
01:40
Adjust skip-scan cost estimates slightly so that a full table scan is preferred over a skip-scan to a column with only two distinct values. check-in: ae9a42b2 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_multiplex.c.

   998    998         rc = SQLITE_OK;
   999    999         break;
  1000   1000       case SQLITE_FCNTL_SIZE_HINT:
  1001   1001       case SQLITE_FCNTL_CHUNK_SIZE:
  1002   1002         /* no-op these */
  1003   1003         rc = SQLITE_OK;
  1004   1004         break;
         1005  +    case SQLITE_FCNTL_PRAGMA: {
         1006  +      char **aFcntl = (char**)pArg;
         1007  +      if( aFcntl[1] && sqlite3_stricmp(aFcntl[1],"multiplex_truncate")==0 ){
         1008  +        if( aFcntl[2] && aFcntl[2][0] ){
         1009  +          if( sqlite3_stricmp(aFcntl[2], "on")==0
         1010  +           || sqlite3_stricmp(aFcntl[2], "1")==0 ){
         1011  +            pGroup->bTruncate = 1;
         1012  +          }else
         1013  +          if( sqlite3_stricmp(aFcntl[2], "off")==0
         1014  +           || sqlite3_stricmp(aFcntl[2], "0")==0 ){
         1015  +            pGroup->bTruncate = 0;
         1016  +          }
         1017  +        }
         1018  +        aFcntl[0] = sqlite3_mprintf(pGroup->bTruncate ? "on" : "off");
         1019  +        rc = SQLITE_OK;
         1020  +        break;
         1021  +      }
         1022  +      /* If the multiplexor does not handle the pragma, pass it through
         1023  +      ** into the default case. */
         1024  +    }
  1005   1025       default:
  1006   1026         pSubOpen = multiplexSubOpen(pGroup, 0, &rc, NULL, 0);
  1007   1027         if( pSubOpen ){
  1008   1028           rc = pSubOpen->pMethods->xFileControl(pSubOpen, op, pArg);
  1009   1029           if( op==SQLITE_FCNTL_VFSNAME && rc==SQLITE_OK ){
  1010   1030            *(char**)pArg = sqlite3_mprintf("multiplex/%z", *(char**)pArg);
  1011   1031           }

Added test/multiplex4.test.

            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  +do_test multiplex4-1.2 {
           63  +  db eval {PRAGMA multiplex_truncate}
           64  +} {on}
           65  +do_test multiplex4-1.3 {
           66  +  db eval {PRAGMA multiplex_truncate=off}
           67  +} {off}
           68  +do_test multiplex4-1.4 {
           69  +  db eval {PRAGMA multiplex_truncate}
           70  +} {off}
           71  +do_test multiplex4-1.5 {
           72  +  db eval {PRAGMA multiplex_truncate=on}
           73  +} {on}
           74  +do_test multiplex4-1.6 {
           75  +  db eval {PRAGMA multiplex_truncate}
           76  +} {on}
           77  +do_test multiplex4-1.7 {
           78  +  db eval {PRAGMA multiplex_truncate=0}
           79  +} {off}
           80  +do_test multiplex4-1.8 {
           81  +  db eval {PRAGMA multiplex_truncate=1}
           82  +} {on}
           83  +do_test multiplex4-1.9 {
           84  +  db eval {PRAGMA multiplex_truncate=0}
           85  +} {off}
           86  +
           87  +do_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  +
           94  +do_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  +
          102  +do_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  +
          111  +catch { db close }
          112  +forcedelete mx4test.db
          113  +sqlite3_multiplex_shutdown
          114  +finish_test