/ Check-in [24e76997]
Login

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

Overview
Comment:Remove the dependency on the direct btree interface from as many test scripts as is practical. Fix a bug in the output limiter of the integrity_check pragma that came up while making this change. (CVS 4880)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 24e769972eb6052b82dc94d20444c186a213e104
User & Date: drh 2008-03-19 00:21:31
Context
2008-03-19
13:03
When a parse of the sqlite_master table fails, include the name of the object being parsed as part of the error message. (CVS 4881) check-in: 57805b58 user: drh tags: trunk
00:21
Remove the dependency on the direct btree interface from as many test scripts as is practical. Fix a bug in the output limiter of the integrity_check pragma that came up while making this change. (CVS 4880) check-in: 24e76997 user: drh tags: trunk
2008-03-18
13:47
Update the documentation to distinguish between protected and unprotected sqlite3_value objects. (CVS 4879) check-in: 074ee55f user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code used to implement the PRAGMA command.
    13     13   **
    14         -** $Id: pragma.c,v 1.170 2008/02/13 18:25:27 danielk1977 Exp $
           14  +** $Id: pragma.c,v 1.171 2008/03/19 00:21:31 drh Exp $
    15     15   */
    16     16   #include "sqliteInt.h"
    17     17   #include <ctype.h>
    18     18   
    19     19   /* Ignore this whole file if pragmas are disabled
    20     20   */
    21     21   #if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
................................................................................
   933    933               { OP_Rowid,       1,  4,  0},
   934    934               { OP_String8,     0,  5,  0},    /* 3 */
   935    935               { OP_String8,     0,  6,  0},    /* 4 */
   936    936               { OP_Concat,      4,  3,  3},
   937    937               { OP_Concat,      5,  3,  3},
   938    938               { OP_Concat,      6,  3,  3},
   939    939               { OP_ResultRow,   3,  1,  0},
          940  +            { OP_IfPos,       1,  0,  0},    /* 9 */
          941  +            { OP_Halt,        0,  0,  0},
   940    942             };
   941    943             sqlite3GenerateIndexKey(pParse, pIdx, 1, 3);
   942    944             jmp2 = sqlite3VdbeAddOp3(v, OP_Found, j+2, 0, 3);
   943    945             addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
   944    946             sqlite3VdbeChangeP4(v, addr+1, "rowid ", P4_STATIC);
   945    947             sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
   946    948             sqlite3VdbeChangeP4(v, addr+4, pIdx->zName, P4_STATIC);
          949  +          sqlite3VdbeJumpHere(v, addr+9);
   947    950             sqlite3VdbeJumpHere(v, jmp2);
   948    951           }
   949    952           sqlite3VdbeAddOp2(v, OP_Next, 1, loopTop+1);
   950    953           sqlite3VdbeJumpHere(v, loopTop);
   951    954           for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
   952    955             static const VdbeOpList cntIdx[] = {
   953    956                { OP_Integer,      0,  3,  0},

Changes to src/test2.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the pager.c module in SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test2.c,v 1.54 2008/03/07 19:51:14 drh Exp $
           16  +** $Id: test2.c,v 1.55 2008/03/19 00:21:31 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include <stdlib.h>
    21     21   #include <string.h>
    22     22   
    23     23   /*
................................................................................
   713    713        (char*)&sqlite3_io_error_hardhit, TCL_LINK_INT);
   714    714     Tcl_LinkVar(interp, "sqlite_diskfull_pending",
   715    715        (char*)&sqlite3_diskfull_pending, TCL_LINK_INT);
   716    716     Tcl_LinkVar(interp, "sqlite_diskfull",
   717    717        (char*)&sqlite3_diskfull, TCL_LINK_INT);
   718    718     Tcl_LinkVar(interp, "sqlite_pending_byte",
   719    719        (char*)&sqlite3_pending_byte, TCL_LINK_INT);
   720         -  Tcl_LinkVar(interp, "pager_pagesize",
   721         -     (char*)&test_pagesize, TCL_LINK_INT);
   722    720     Tcl_LinkVar(interp, "sqlite_pager_n_sort_bucket",
   723    721        (char*)&sqlite3_pager_n_sort_bucket, TCL_LINK_INT);
   724    722     return TCL_OK;
   725    723   }

Changes to test/alter2.test.

     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing that SQLite can handle a subtle 
    13     13   # file format change that may be used in the future to implement
    14     14   # "ALTER TABLE ... ADD COLUMN".
    15     15   #
    16         -# $Id: alter2.test,v 1.12 2007/11/28 13:43:17 drh Exp $
           16  +# $Id: alter2.test,v 1.13 2008/03/19 00:21:31 drh Exp $
    17     17   #
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # We have to have pragmas in order to do this test
    23     23   ifcapable {!pragma} return
    24     24   
    25         -# These tests do not work if there is a codec.  The
    26         -# btree_open command does not know how to handle codecs.
           25  +# These tests do not work if there is a codec. 
    27     26   #
    28     27   #if {[catch {sqlite3 -has_codec} r] || $r} return
    29     28   
    30     29   # The file format change affects the way row-records stored in tables (but 
    31     30   # not indices) are interpreted. Before version 3.1.3, a row-record for a 
    32     31   # table with N columns was guaranteed to contain exactly N fields. As
    33     32   # of version 3.1.3, the record may contain up to N fields. In this case
................................................................................
    38     37   # has columns, then the file-format meta value should be set to (at least) 2. 
    39     38   #
    40     39   
    41     40   # This procedure sets the value of the file-format in file 'test.db'
    42     41   # to $newval. Also, the schema cookie is incremented.
    43     42   # 
    44     43   proc set_file_format {newval} {
    45         -  set bt [btree_open test.db 10 0]
    46         -  btree_begin_transaction $bt
    47         -  set meta [btree_get_meta $bt]
    48         -  lset meta 2 $newval                    ;# File format
    49         -  lset meta 1 [expr [lindex $meta 1]+1]  ;# Schema cookie
    50         -  eval "btree_update_meta $bt $meta"
    51         -  btree_commit $bt
    52         -  btree_close $bt
           44  +  hexio_write test.db 44 [hexio_render_int32 $newval]
           45  +  set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
           46  +  incr schemacookie
           47  +  hexio_write test.db 40 [hexio_render_int32 $schemacookie]
           48  +  return {}
    53     49   }
    54     50   
    55     51   # This procedure returns the value of the file-format in file 'test.db'.
    56     52   # 
    57     53   proc get_file_format {{fname test.db}} {
    58         -  set bt [btree_open $fname 10 0]
    59         -  set meta [btree_get_meta $bt]
    60         -  btree_close $bt
    61         -  lindex $meta 2
           54  +  return [hexio_get_int [hexio_read $fname 44 4]]
    62     55   }
    63     56   
    64     57   # This procedure sets the SQL statement stored for table $tbl in the
    65     58   # sqlite_master table of file 'test.db' to $sql. Also set the file format
    66     59   # to the supplied value. This is 2 if the added column has a default that is
    67     60   # NULL, or 3 otherwise. 
    68     61   #
................................................................................
   232    225   #---------------------------------------------------------------------
   233    226   # Check that an error occurs if the database is upgraded to a file
   234    227   # format that SQLite does not support (in this case 5). Note: The 
   235    228   # file format is checked each time the schema is read, so changing the
   236    229   # file format requires incrementing the schema cookie.
   237    230   #
   238    231   do_test alter2-4.1 {
          232  +  db close
   239    233     set_file_format 5
          234  +  sqlite3 db test.db
   240    235   } {}
   241    236   do_test alter2-4.2 {
   242    237     # We have to run two queries here because the Tcl interface uses
   243    238     # sqlite3_prepare_v2(). In this case, the first query encounters an 
   244    239     # SQLITE_SCHEMA error. Then, when trying to recompile the statement, the
   245    240     # "unsupported file format" error is encountered. So the error code
   246    241     # returned is SQLITE_SCHEMA, not SQLITE_ERROR as required by the following
................................................................................
   251    246     # file format was detected during a call to sqlite3_prepare(), not
   252    247     # sqlite3_step().
   253    248     #
   254    249     catchsql { SELECT * FROM sqlite_master; }
   255    250     catchsql { SELECT * FROM sqlite_master; }
   256    251   } {1 {unsupported file format}}
   257    252   do_test alter2-4.3 {
   258         -  sqlite3_errcode $::DB
          253  +  sqlite3_errcode db
   259    254   } {SQLITE_ERROR}
   260    255   do_test alter2-4.4 {
   261    256     set ::DB [sqlite3_connection_pointer db]
   262    257     catchsql {
   263    258       SELECT * FROM sqlite_master;
   264    259     }
   265    260   } {1 {unsupported file format}}
   266    261   do_test alter2-4.5 {
   267         -  sqlite3_errcode $::DB
          262  +  sqlite3_errcode db
   268    263   } {SQLITE_ERROR}
   269    264   
   270    265   #---------------------------------------------------------------------
   271    266   # Check that executing VACUUM on a file with file-format version 2
   272    267   # resets the file format to 1.
   273    268   #
   274    269   set default_file_format [expr $SQLITE_DEFAULT_FILE_FORMAT==4 ? 4 : 1]
   275    270   ifcapable vacuum {
   276    271     do_test alter2-5.1 {
   277    272       set_file_format 2
          273  +    db close
          274  +    sqlite3 db test.db
   278    275       execsql {SELECT 1 FROM sqlite_master LIMIT 1;}
   279    276       get_file_format
   280    277     } {2}
   281    278     do_test alter2-5.2 {
   282    279       execsql {    
   283    280         VACUUM;
   284    281       }
................................................................................
   292    289   # Test that when a database with file-format 2 is opened, new 
   293    290   # databases are still created with file-format 1.
   294    291   #
   295    292   do_test alter2-6.1 {
   296    293     db close
   297    294     set_file_format 2
   298    295     sqlite3 db test.db
   299         -  set ::DB [sqlite3_connection_pointer db]
   300    296     get_file_format
   301    297   } {2}
   302    298   ifcapable attach {
   303    299     do_test alter2-6.2 {
   304    300       file delete -force test2.db-journal
   305    301       file delete -force test2.db
   306    302       execsql {

Changes to test/alter3.test.

     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is testing that SQLite can handle a subtle 
    13     13   # file format change that may be used in the future to implement
    14     14   # "ALTER TABLE ... ADD COLUMN".
    15     15   #
    16         -# $Id: alter3.test,v 1.10 2007/10/09 08:29:32 danielk1977 Exp $
           16  +# $Id: alter3.test,v 1.11 2008/03/19 00:21:31 drh Exp $
    17     17   #
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   
    21     21   source $testdir/tester.tcl
    22     22   
    23     23   # If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
................................................................................
    46     46   # alter3-6.*: Test that temp triggers are not accidentally dropped.
    47     47   # alter3-7.*: Test that VACUUM resets the file-format.
    48     48   #
    49     49   
    50     50   # This procedure returns the value of the file-format in file 'test.db'.
    51     51   # 
    52     52   proc get_file_format {{fname test.db}} {
    53         -  set bt [btree_open $fname 10 0]
    54         -  set meta [btree_get_meta $bt]
    55         -  btree_close $bt
    56         -  lindex $meta 2
           53  +  return [hexio_get_int [hexio_read $fname 44 4]]
    57     54   }
    58     55   
    59     56   do_test alter3-1.1 {
    60     57     execsql {
    61     58       CREATE TABLE abc(a, b, c);
    62     59       SELECT sql FROM sqlite_master;
    63     60     }

Changes to test/capi3.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script testing the callback-free C/C++ API.
    13     13   #
    14         -# $Id: capi3.test,v 1.59 2008/02/21 21:30:07 drh Exp $
           14  +# $Id: capi3.test,v 1.60 2008/03/19 00:21:31 drh Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    21     21   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
   630    630     sqlite3_finalize $STMT
   631    631   } {SQLITE_OK}
   632    632   do_test capi3-6.4-misuse {
   633    633     db cache flush
   634    634     sqlite3_close $DB
   635    635   } {SQLITE_OK}
   636    636   db close
          637  +
          638  +# This procedure sets the value of the file-format in file 'test.db'
          639  +# to $newval. Also, the schema cookie is incremented.
          640  +# 
          641  +proc set_file_format {newval} {
          642  +  hexio_write test.db 44 [hexio_render_int32 $newval]
          643  +  set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
          644  +  incr schemacookie
          645  +  hexio_write test.db 40 [hexio_render_int32 $schemacookie]
          646  +  return {}
          647  +}
          648  +
          649  +# This procedure returns the value of the file-format in file 'test.db'.
          650  +# 
          651  +proc get_file_format {{fname test.db}} {
          652  +  return [hexio_get_int [hexio_read $fname 44 4]]
          653  +}
   637    654   
   638    655   if {![sqlite3 -has-codec]} {
   639    656     # Test what happens when the library encounters a newer file format.
   640         -  # Do this by updating the file format via the btree layer.
   641    657     do_test capi3-7.1 {
   642         -    set ::bt [btree_open test.db 10 0]
   643         -    btree_begin_transaction $::bt
   644         -    set meta [btree_get_meta $::bt]
   645         -    lset meta 2 5
   646         -    eval [concat btree_update_meta $::bt [lrange $meta 0 end]]
   647         -    btree_commit $::bt
   648         -    btree_close $::bt
          658  +    set_file_format 5
   649    659     } {}
   650    660     do_test capi3-7.2 {
   651    661       sqlite3 db test.db
   652    662       catchsql {
   653    663         SELECT * FROM sqlite_master;
   654    664       }
   655    665     } {1 {unsupported file format}}
................................................................................
   656    666     db close
   657    667   }
   658    668   
   659    669   if {![sqlite3 -has-codec]} {
   660    670     # Now test that the library correctly handles bogus entries in the
   661    671     # sqlite_master table (schema corruption).
   662    672     do_test capi3-8.1 {
   663         -    file delete -force test.db
   664         -    file delete -force test.db-journal
          673  +    file delete -force test.db test.db-journal
   665    674       sqlite3 db test.db
   666    675       execsql {
   667    676         CREATE TABLE t1(a);
   668    677       }
   669    678       db close
   670    679     } {}
   671    680     do_test capi3-8.2 {
   672         -    set ::bt [btree_open test.db 10 0]
   673         -    btree_begin_transaction $::bt
   674         -    set ::bc [btree_cursor $::bt 1 1]
   675         -
   676         -    # Build a 5-field row record consisting of 5 null records. This is
   677         -    # officially black magic.
   678         -    catch {unset data}
   679         -    set data [binary format c6 {6 0 0 0 0 0}]
   680         -    btree_insert $::bc 5 $data
   681         -
   682         -    btree_close_cursor $::bc
   683         -    btree_commit $::bt
   684         -    btree_close $::bt
          681  +    sqlite3 db test.db
          682  +    execsql {
          683  +      PRAGMA writable_schema=ON;
          684  +      INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
          685  +    }
          686  +    db close
   685    687     } {}
   686    688     do_test capi3-8.3 {
   687    689       sqlite3 db test.db
   688    690       catchsql {
   689    691         SELECT * FROM sqlite_master;
   690    692       }
   691    693     } {1 {malformed database schema}}
   692    694     do_test capi3-8.4 {
   693         -    set ::bt [btree_open test.db 10 0]
   694         -    btree_begin_transaction $::bt
   695         -    set ::bc [btree_cursor $::bt 1 1]
   696         -  
   697    695       # Build a 5-field row record. The first field is a string 'table', and
   698         -    # subsequent fields are all NULL. Replace the other broken record with
   699         -    # this one and try to read the schema again. The broken record uses
   700         -    # either UTF-8 or native UTF-16 (if this file is being run by
   701         -    # utf16.test).
   702         -    if { [string match UTF-16* $::ENC] } {
   703         -      set data [binary format c6a10 {6 33 0 0 0 0} [utf16 table]]
   704         -    } else {
   705         -      set data [binary format c6a5 {6 23 0 0 0 0} table]
          696  +    # subsequent fields are all NULL.
          697  +    db close
          698  +    file delete -force test.db test.db-journal
          699  +    sqlite3 db test.db
          700  +    execsql {
          701  +      CREATE TABLE t1(a);
          702  +      PRAGMA writable_schema=ON;
          703  +      INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
   706    704       }
   707         -    btree_insert $::bc 5 $data
   708         -  
   709         -    btree_close_cursor $::bc
   710         -    btree_commit $::bt
   711         -    btree_close $::bt
          705  +    db close
   712    706     } {};
   713    707     do_test capi3-8.5 {
   714         -    db close 
   715    708       sqlite3 db test.db
   716    709       catchsql {
   717    710         SELECT * FROM sqlite_master;
   718    711       }
   719    712     } {1 {malformed database schema}}
   720    713     db close
   721    714   }

Changes to test/capi3c.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  
    12     12   #
    13     13   # This is a copy of the capi3.test file that has been adapted to
    14     14   # test the new sqlite3_prepare_v2 interface.
    15     15   #
    16         -# $Id: capi3c.test,v 1.14 2008/01/19 23:50:26 drh Exp $
           16  +# $Id: capi3c.test,v 1.15 2008/03/19 00:21:31 drh Exp $
    17     17   #
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    23     23   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
   590    590   } SQLITE_OK
   591    591   
   592    592   
   593    593   set ::ENC [execsql {pragma encoding}]
   594    594   db close
   595    595   
   596    596   do_test capi3c-6.0 {
   597         -btree_breakpoint
   598    597     sqlite3 db test.db
   599    598     set DB [sqlite3_connection_pointer db]
   600         -btree_breakpoint
   601    599     sqlite3_key $DB xyzzy
   602    600     set sql {SELECT a FROM t1 order by rowid}
   603    601     set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]
   604    602     expr 0
   605    603   } {0}
   606    604   do_test capi3c-6.1 {
   607    605     db cache flush
................................................................................
   617    615   do_test capi3c-6.4 {
   618    616     db cache flush
   619    617     sqlite3_close $DB
   620    618   } {SQLITE_OK}
   621    619   do_test capi3c-6.99-misuse {
   622    620     db close
   623    621   } {}
          622  +
          623  +# This procedure sets the value of the file-format in file 'test.db'
          624  +# to $newval. Also, the schema cookie is incremented.
          625  +# 
          626  +proc set_file_format {newval} {
          627  +  hexio_write test.db 44 [hexio_render_int32 $newval]
          628  +  set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
          629  +  incr schemacookie
          630  +  hexio_write test.db 40 [hexio_render_int32 $schemacookie]
          631  +  return {}
          632  +}
          633  +
          634  +# This procedure returns the value of the file-format in file 'test.db'.
          635  +# 
          636  +proc get_file_format {{fname test.db}} {
          637  +  return [hexio_get_int [hexio_read $fname 44 4]]
          638  +}
   624    639   
   625    640   if {![sqlite3 -has-codec]} {
   626    641     # Test what happens when the library encounters a newer file format.
   627         -  # Do this by updating the file format via the btree layer.
   628    642     do_test capi3c-7.1 {
   629         -    set ::bt [btree_open test.db 10 0]
   630         -    btree_begin_transaction $::bt
   631         -    set meta [btree_get_meta $::bt]
   632         -    lset meta 2 5
   633         -    eval [concat btree_update_meta $::bt [lrange $meta 0 end]]
   634         -    btree_commit $::bt
   635         -    btree_close $::bt
          643  +    set_file_format 5
   636    644     } {}
   637    645     do_test capi3c-7.2 {
   638    646       sqlite3 db test.db
   639    647       catchsql {
   640    648         SELECT * FROM sqlite_master;
   641    649       }
   642    650     } {1 {unsupported file format}}
................................................................................
   643    651     db close
   644    652   }
   645    653   
   646    654   if {![sqlite3 -has-codec]} {
   647    655     # Now test that the library correctly handles bogus entries in the
   648    656     # sqlite_master table (schema corruption).
   649    657     do_test capi3c-8.1 {
   650         -    file delete -force test.db
   651         -    file delete -force test.db-journal
          658  +    file delete -force test.db test.db-journal
   652    659       sqlite3 db test.db
   653    660       execsql {
   654    661         CREATE TABLE t1(a);
   655    662       }
   656    663       db close
   657    664     } {}
   658    665     do_test capi3c-8.2 {
   659         -    set ::bt [btree_open test.db 10 0]
   660         -    btree_begin_transaction $::bt
   661         -    set ::bc [btree_cursor $::bt 1 1]
   662         -
   663         -    # Build a 5-field row record consisting of 5 null records. This is
   664         -    # officially black magic.
   665         -    catch {unset data}
   666         -    set data [binary format c6 {6 0 0 0 0 0}]
   667         -    btree_insert $::bc 5 $data
   668         -
   669         -    btree_close_cursor $::bc
   670         -    btree_commit $::bt
   671         -    btree_close $::bt
          666  +    sqlite3 db test.db
          667  +    execsql {
          668  +      PRAGMA writable_schema=ON;
          669  +      INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
          670  +    }
          671  +    db close
   672    672     } {}
   673    673     do_test capi3c-8.3 {
   674    674       sqlite3 db test.db
   675    675       catchsql {
   676    676         SELECT * FROM sqlite_master;
   677    677       }
   678    678     } {1 {malformed database schema}}
   679    679     do_test capi3c-8.4 {
   680         -    set ::bt [btree_open test.db 10 0]
   681         -    btree_begin_transaction $::bt
   682         -    set ::bc [btree_cursor $::bt 1 1]
   683         -  
   684    680       # Build a 5-field row record. The first field is a string 'table', and
   685         -    # subsequent fields are all NULL. Replace the other broken record with
   686         -    # this one and try to read the schema again. The broken record uses
   687         -    # either UTF-8 or native UTF-16 (if this file is being run by
   688         -    # utf16.test).
   689         -    if { [string match UTF-16* $::ENC] } {
   690         -      set data [binary format c6a10 {6 33 0 0 0 0} [utf16 table]]
   691         -    } else {
   692         -      set data [binary format c6a5 {6 23 0 0 0 0} table]
          681  +    # subsequent fields are all NULL.
          682  +    db close
          683  +    file delete -force test.db test.db-journal
          684  +    sqlite3 db test.db
          685  +    execsql {
          686  +      CREATE TABLE t1(a);
          687  +      PRAGMA writable_schema=ON;
          688  +      INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
   693    689       }
   694         -    btree_insert $::bc 5 $data
   695         -  
   696         -    btree_close_cursor $::bc
   697         -    btree_commit $::bt
   698         -    btree_close $::bt
          690  +    db close
   699    691     } {};
   700    692     do_test capi3c-8.5 {
   701         -    db close 
   702    693       sqlite3 db test.db
   703    694       catchsql {
   704    695         SELECT * FROM sqlite_master;
   705    696       }
   706    697     } {1 {malformed database schema}}
   707    698     db close
   708    699   }

Changes to test/descidx1.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is descending indices.
    13     13   #
    14         -# $Id: descidx1.test,v 1.9 2007/11/28 13:43:17 drh Exp $
           14  +# $Id: descidx1.test,v 1.10 2008/03/19 00:21:31 drh Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   db eval {PRAGMA legacy_file_format=OFF}
    21     21   
    22     22   # This procedure sets the value of the file-format in file 'test.db'
    23     23   # to $newval. Also, the schema cookie is incremented.
    24     24   # 
    25     25   proc set_file_format {newval} {
    26         -  set bt [btree_open test.db 10 0]
    27         -  btree_begin_transaction $bt
    28         -  set meta [btree_get_meta $bt]
    29         -  lset meta 2 $newval                    ;# File format
    30         -  lset meta 1 [expr [lindex $meta 1]+1]  ;# Schema cookie
    31         -  eval "btree_update_meta $bt $meta"
    32         -  btree_commit $bt
    33         -  btree_close $bt
           26  +  hexio_write test.db 44 [hexio_render_int32 $newval]
           27  +  set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
           28  +  incr schemacookie
           29  +  hexio_write test.db 40 [hexio_render_int32 $schemacookie]
           30  +  return {}
    34     31   }
    35     32   
    36     33   # This procedure returns the value of the file-format in file 'test.db'.
    37     34   # 
    38     35   proc get_file_format {{fname test.db}} {
    39         -  set bt [btree_open $fname 10 0]
    40         -  set meta [btree_get_meta $bt]
    41         -  btree_close $bt
    42         -  lindex $meta 2
           36  +  return [hexio_get_int [hexio_read $fname 44 4]]
    43     37   }
           38  +
    44     39   
    45     40   # Verify that the file format starts as 4.
    46     41   #
    47     42   do_test descidx1-1.1 {
    48     43     execsql {
    49     44       CREATE TABLE t1(a,b);
    50     45       CREATE INDEX i1 ON t1(b ASC);

Changes to test/descidx2.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is descending indices.
    13     13   #
    14         -# $Id: descidx2.test,v 1.4 2006/07/11 14:17:52 drh Exp $
           14  +# $Id: descidx2.test,v 1.5 2008/03/19 00:21:31 drh Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   db eval {PRAGMA legacy_file_format=OFF}
    21     21   
    22     22   # This procedure sets the value of the file-format in file 'test.db'
    23     23   # to $newval. Also, the schema cookie is incremented.
    24     24   # 
    25     25   proc set_file_format {newval} {
    26         -  set bt [btree_open test.db 10 0]
    27         -  btree_begin_transaction $bt
    28         -  set meta [btree_get_meta $bt]
    29         -  lset meta 2 $newval                    ;# File format
    30         -  lset meta 1 [expr [lindex $meta 1]+1]  ;# Schema cookie
    31         -  eval "btree_update_meta $bt $meta"
    32         -  btree_commit $bt
    33         -  btree_close $bt
           26  +  hexio_write test.db 44 [hexio_render_int32 $newval]
           27  +  set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
           28  +  incr schemacookie
           29  +  hexio_write test.db 40 [hexio_render_int32 $schemacookie]
           30  +  return {}
    34     31   }
    35     32   
    36     33   # This procedure returns the value of the file-format in file 'test.db'.
    37     34   # 
    38     35   proc get_file_format {{fname test.db}} {
    39         -  set bt [btree_open $fname 10 0]
    40         -  set meta [btree_get_meta $bt]
    41         -  btree_close $bt
    42         -  lindex $meta 2
           36  +  return [hexio_get_int [hexio_read $fname 44 4]]
    43     37   }
           38  +
    44     39   
    45     40   # Verify that the file format starts as 4
    46     41   #
    47     42   do_test descidx2-1.1 {
    48     43     execsql {
    49     44       CREATE TABLE t1(a,b);
    50     45       CREATE INDEX i1 ON t1(b ASC);

Changes to test/descidx3.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #*************************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script is descending indices.
    13     13   #
    14         -# $Id: descidx3.test,v 1.5 2006/07/11 14:17:52 drh Exp $
           14  +# $Id: descidx3.test,v 1.6 2008/03/19 00:21:31 drh Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   ifcapable !bloblit {
    21     21     finish_test
................................................................................
    23     23   }
    24     24   db eval {PRAGMA legacy_file_format=OFF}
    25     25   
    26     26   # This procedure sets the value of the file-format in file 'test.db'
    27     27   # to $newval. Also, the schema cookie is incremented.
    28     28   # 
    29     29   proc set_file_format {newval} {
    30         -  set bt [btree_open test.db 10 0]
    31         -  btree_begin_transaction $bt
    32         -  set meta [btree_get_meta $bt]
    33         -  lset meta 2 $newval                    ;# File format
    34         -  lset meta 1 [expr [lindex $meta 1]+1]  ;# Schema cookie
    35         -  eval "btree_update_meta $bt $meta"
    36         -  btree_commit $bt
    37         -  btree_close $bt
           30  +  hexio_write test.db 44 [hexio_render_int32 $newval]
           31  +  set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
           32  +  incr schemacookie
           33  +  hexio_write test.db 40 [hexio_render_int32 $schemacookie]
           34  +  return {}
    38     35   }
    39     36   
    40     37   # This procedure returns the value of the file-format in file 'test.db'.
    41     38   # 
    42     39   proc get_file_format {{fname test.db}} {
    43         -  set bt [btree_open $fname 10 0]
    44         -  set meta [btree_get_meta $bt]
    45         -  btree_close $bt
    46         -  lindex $meta 2
           40  +  return [hexio_get_int [hexio_read $fname 44 4]]
    47     41   }
    48     42   
    49     43   # Verify that the file format starts as 4.
    50     44   #
    51     45   do_test descidx3-1.1 {
    52     46     execsql {
    53     47       CREATE TABLE t1(i INTEGER PRIMARY KEY,a,b,c,d);

Changes to test/minmax3.test.

     4      4   # a legal notice, here is a blessing:
     5      5   #
     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11         -# $Id: minmax3.test,v 1.1 2008/01/05 17:39:30 danielk1977 Exp $
           11  +# $Id: minmax3.test,v 1.2 2008/03/19 00:21:31 drh Exp $
    12     12   
    13     13   set testdir [file dirname $argv0]
    14     14   source $testdir/tester.tcl
    15     15   
    16     16   # Do an SQL statement.  Append the search count to the end of the result.
    17     17   #
    18     18   proc count sql {
................................................................................
    20     20     return [concat [execsql $sql] $::sqlite_search_count]
    21     21   }
    22     22   
    23     23   # This procedure sets the value of the file-format in file 'test.db'
    24     24   # to $newval. Also, the schema cookie is incremented.
    25     25   # 
    26     26   proc set_file_format {newval} {
    27         -  set bt [btree_open test.db 10 0]
    28         -  btree_begin_transaction $bt
    29         -  set meta [btree_get_meta $bt]
    30         -  lset meta 2 $newval                    ;# File format
    31         -  lset meta 1 [expr [lindex $meta 1]+1]  ;# Schema cookie
    32         -  eval "btree_update_meta $bt $meta"
    33         -  btree_commit $bt
    34         -  btree_close $bt
           27  +  hexio_write test.db 44 [hexio_render_int32 $newval]
           28  +  set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
           29  +  incr schemacookie
           30  +  hexio_write test.db 40 [hexio_render_int32 $schemacookie]
           31  +  return {}
    35     32   }
    36     33   
    37         -# Create the file as file-format 4 (DESC index support). This is 
    38         -# required to exercise a few cases in where.c.
    39         -#
    40         -execsql { select * from sqlite_master }
    41         -set_file_format 4
    42         -
    43     34   do_test minmax3-1.0 {
    44     35     execsql {
    45         -    BEGIN;
    46     36       CREATE TABLE t1(x, y, z);
           37  +  }
           38  +  db close
           39  +  set_file_format 4
           40  +  sqlite3 db test.db
           41  +  execsql {
           42  +    BEGIN;
    47     43       INSERT INTO t1 VALUES('1', 'I',   'one');
    48     44       INSERT INTO t1 VALUES('2', 'IV',  'four');
    49     45       INSERT INTO t1 VALUES('2', NULL,  'three');
    50     46       INSERT INTO t1 VALUES('2', 'II',  'two');
    51     47       INSERT INTO t1 VALUES('2', 'V',   'five');
    52     48       INSERT INTO t1 VALUES('3', 'VI',  'six');
    53     49       COMMIT;
................................................................................
   137    133   } {VI 0}
   138    134   do_test minmax3-1.4.4 {
   139    135     execsql { DROP INDEX i1 }
   140    136   } {}
   141    137   
   142    138   
   143    139   finish_test
   144         -

Changes to test/pragma.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for the PRAGMA command.
    14     14   #
    15         -# $Id: pragma.test,v 1.58 2008/03/18 13:46:53 drh Exp $
           15  +# $Id: pragma.test,v 1.59 2008/03/19 00:21:31 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Test organization:
    21     21   #
    22     22   # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
................................................................................
   258    258       COMMIT;
   259    259       SELECT rowid, * from t2;
   260    260     }
   261    261   } {1 11 2 3 2 22 3 4}
   262    262   ifcapable attach {
   263    263     if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
   264    264       do_test pragma-3.2 {
   265         -      set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}]
   266         -      set db [btree_open test.db 100 0]
   267         -      btree_begin_transaction $db
   268         -      set c [btree_cursor $db $rootpage 1]
   269         -      btree_first $c
   270         -      btree_delete $c
   271         -      btree_commit $db
   272         -      btree_close $db
          265  +      db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break
          266  +      set pgsz [db eval {PRAGMA page_size}]
          267  +      # overwrite the header on the rootpage of the index in order to
          268  +      # make the index appear to be empty.
          269  +      #
          270  +      set offset [expr {$pgsz*($rootpage-1)}]
          271  +      hexio_write test.db $offset 0a00000000040000000000
          272  +      db close
          273  +      sqlite3 db test.db
   273    274         execsql {PRAGMA integrity_check}
   274         -    } {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
          275  +    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
   275    276       do_test pragma-3.3 {
   276    277         execsql {PRAGMA integrity_check=1}
   277    278       } {{rowid 1 missing from index i2}}
   278    279       do_test pragma-3.4 {
   279    280         execsql {
   280    281           ATTACH DATABASE 'test.db' AS t2;
   281    282           PRAGMA integrity_check
   282    283         }
   283         -    } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
          284  +    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
   284    285       do_test pragma-3.5 {
   285    286         execsql {
   286         -        PRAGMA integrity_check=3
          287  +        PRAGMA integrity_check=4
   287    288         }
   288         -    } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
          289  +    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
   289    290       do_test pragma-3.6 {
   290    291         execsql {
   291    292           PRAGMA integrity_check=xyz
   292    293         }
   293         -    } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
          294  +    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
   294    295       do_test pragma-3.7 {
   295    296         execsql {
   296    297           PRAGMA integrity_check=0
   297    298         }
   298         -    } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
          299  +    } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
   299    300     
   300    301       # Add additional corruption by appending unused pages to the end of
   301    302       # the database file testerr.db
   302    303       #
   303    304       do_test pragma-3.8 {
   304    305         execsql {DETACH t2}
   305    306         file delete -force testerr.db testerr.db-journal
................................................................................
   322    323         execsql {
   323    324           ATTACH 'testerr.db' AS t2;
   324    325           PRAGMA integrity_check
   325    326         }
   326    327       } {{*** in database t2 ***
   327    328   Page 4 is never used
   328    329   Page 5 is never used
   329         -Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
          330  +Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
   330    331       do_test pragma-3.10 {
   331    332         execsql {
   332    333           PRAGMA integrity_check=1
   333    334         }
   334    335       } {{*** in database t2 ***
   335    336   Page 4 is never used}}
   336    337       do_test pragma-3.11 {
   337    338         execsql {
   338    339           PRAGMA integrity_check=5
   339    340         }
   340    341       } {{*** in database t2 ***
   341    342   Page 4 is never used
   342    343   Page 5 is never used
   343         -Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
          344  +Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2}}
   344    345       do_test pragma-3.12 {
   345    346         execsql {
   346    347           PRAGMA integrity_check=4
   347    348         }
   348    349       } {{*** in database t2 ***
   349    350   Page 4 is never used
   350    351   Page 5 is never used
................................................................................
   368    369         execsql {
   369    370           ATTACH 'testerr.db' AS t3;
   370    371           PRAGMA integrity_check
   371    372         }
   372    373       } {{*** in database t2 ***
   373    374   Page 4 is never used
   374    375   Page 5 is never used
   375         -Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
          376  +Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
   376    377   Page 4 is never used
   377    378   Page 5 is never used
   378         -Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
          379  +Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}}
   379    380       do_test pragma-3.16 {
   380    381         execsql {
   381         -        PRAGMA integrity_check(9)
          382  +        PRAGMA integrity_check(10)
   382    383         }
   383    384       } {{*** in database t2 ***
   384    385   Page 4 is never used
   385    386   Page 5 is never used
   386         -Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
          387  +Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
   387    388   Page 4 is never used
   388    389   Page 5 is never used
   389    390   Page 6 is never used} {rowid 1 missing from index i2}}
   390    391       do_test pragma-3.17 {
   391    392         execsql {
   392         -        PRAGMA integrity_check=7
          393  +        PRAGMA integrity_check=8
   393    394         }
   394    395       } {{*** in database t2 ***
   395    396   Page 4 is never used
   396    397   Page 5 is never used
   397         -Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
          398  +Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
   398    399   Page 4 is never used
   399    400   Page 5 is never used}}
   400    401       do_test pragma-3.18 {
   401    402         execsql {
   402    403           PRAGMA integrity_check=4
   403    404         }
   404    405       } {{*** in database t2 ***