/ Check-in [0593a2ba]
Login

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

Overview
Comment:Add the "sqlite3_imposter DB SCHEMA ROOT SQL" command to sqlite3_checker. Use it to fix the checkindex01.test module. There are still errors reported by the checkfreelist01.test module.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | checkindex
Files: files | file ages | folders
SHA3-256: 0593a2ba74c886afe8a65cea1310025bb9777c320d093278044719210c9f6ba2
User & Date: drh 2017-11-01 18:31:34
Context
2017-11-01
19:22
Adjust page numbers in the ext/repair/test/checkfreelist01.test module due to the fact that the pending-byte page is no longer shifted down to a low-numbered page but is in its rightful place. Closed-Leaf check-in: c1641aff user: drh tags: checkindex
18:31
Add the "sqlite3_imposter DB SCHEMA ROOT SQL" command to sqlite3_checker. Use it to fix the checkindex01.test module. There are still errors reported by the checkfreelist01.test module. check-in: 0593a2ba user: drh tags: checkindex
18:05
Move the test scripts for checkfreelist and checkindex over into the ext/repair/test directory. Run them now using the sqlite3_checker utility with the --test option. Some tests are currently failing due to an incomplete port. This is an incremental check-in. check-in: 17f8d5e1 user: drh tags: checkindex
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/repair/sqlite3_checker.c.in.

    14     14   #define SQLITE_DEFAULT_MEMSTATUS 0
    15     15   #define SQLITE_MAX_EXPR_DEPTH 0
    16     16   INCLUDE sqlite3.c
    17     17   INCLUDE $ROOT/src/tclsqlite.c
    18     18   INCLUDE $ROOT/ext/misc/btreeinfo.c
    19     19   INCLUDE $ROOT/ext/repair/checkindex.c
    20     20   INCLUDE $ROOT/ext/repair/checkfreelist.c
           21  +
           22  +/*
           23  +** Decode a pointer to an sqlite3 object.
           24  +*/
           25  +int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
           26  +  struct SqliteDb *p;
           27  +  Tcl_CmdInfo cmdInfo;
           28  +  if( Tcl_GetCommandInfo(interp, zA, &cmdInfo) ){
           29  +    p = (struct SqliteDb*)cmdInfo.objClientData;
           30  +    *ppDb = p->db;
           31  +    return TCL_OK;
           32  +  }else{
           33  +    *ppDb = 0;
           34  +    return TCL_ERROR;
           35  +  }
           36  +  return TCL_OK;
           37  +}
           38  +
           39  +/*
           40  +**   sqlite3_imposter db main rootpage {CREATE TABLE...}  ;# setup an imposter
           41  +**   sqlite3_imposter db main                             ;# rm all imposters
           42  +*/
           43  +static int sqlite3_imposter(
           44  +  void *clientData,
           45  +  Tcl_Interp *interp,
           46  +  int objc,
           47  +  Tcl_Obj *CONST objv[]
           48  +){
           49  +  sqlite3 *db;
           50  +  const char *zSchema;
           51  +  int iRoot;
           52  +  const char *zSql;
           53  +
           54  +  if( objc!=3 && objc!=5 ){
           55  +    Tcl_WrongNumArgs(interp, 1, objv, "DB SCHEMA [ROOTPAGE SQL]");
           56  +    return TCL_ERROR;
           57  +  }
           58  +  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
           59  +  zSchema = Tcl_GetString(objv[2]);
           60  +  if( objc==3 ){
           61  +    sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zSchema, 0, 1);
           62  +  }else{
           63  +    if( Tcl_GetIntFromObj(interp, objv[3], &iRoot) ) return TCL_ERROR;
           64  +    zSql = Tcl_GetString(objv[4]);
           65  +    sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zSchema, 1, iRoot);
           66  +    sqlite3_exec(db, zSql, 0, 0, 0);
           67  +    sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zSchema, 0, 0);
           68  +  }
           69  +  return TCL_OK;
           70  +}
    21     71   
    22     72   #include <stdio.h>
    23     73   
    24     74   const char *sqlite3_checker_init_proc(Tcl_Interp *interp){
           75  +  Tcl_CreateObjCommand(interp, "sqlite3_imposter", 
           76  +                       (Tcl_ObjCmdProc*)sqlite3_imposter, 0, 0);
    25     77     sqlite3_auto_extension((void(*)(void))sqlite3_btreeinfo_init);
    26     78     sqlite3_auto_extension((void(*)(void))sqlite3_checkindex_init);
    27     79     sqlite3_auto_extension((void(*)(void))sqlite3_checkfreelist_init);
    28     80     return
    29     81   BEGIN_STRING
    30     82   INCLUDE $ROOT/ext/repair/sqlite3_checker.tcl
    31     83   END_STRING
    32     84   ;
    33     85   }

Changes to ext/repair/test/checkindex01.test.

    67     67     {} 'one',1
    68     68     {} 'four',4
    69     69     {} 'five',5
    70     70   }
    71     71   
    72     72   do_test 1.5 {
    73     73     set tblroot [db one { SELECT rootpage FROM sqlite_master WHERE name='t1' }]
    74         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $tblroot
    75         -  db eval {CREATE TABLE xt1(a, b)}
    76         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
    77         -
    78         -  execsql {
           74  +  sqlite3_imposter db main $tblroot {CREATE TABLE xt1(a,b)}
           75  +  db eval {
    79     76       UPDATE xt1 SET a='six' WHERE rowid=3;
    80     77       DELETE FROM xt1 WHERE rowid = 5;
    81     78     }
    82         -
    83         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 1
           79  +  sqlite3_imposter db main
    84     80   } {}
    85     81   
    86     82   do_index_check_test 1.6 i1 {
    87     83     {row missing} 'five',5
    88     84     {} 'four',4
    89     85     {} 'one',1
    90     86     {row data mismatch} 'three',3
................................................................................
   207    203     {} 'AAA','CCC',2 
   208    204     {} 'aab','ddd',3 
   209    205     {} 'AAB','EEE',4
   210    206   }
   211    207   
   212    208   do_test 4.2 {
   213    209     set tblroot [db one { SELECT rootpage FROM sqlite_master WHERE name='t4' }]
   214         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $tblroot
   215         -  db eval {CREATE TABLE xt4(a INTEGER PRIMARY KEY, c1 TEXT, c2 TEXT)}
   216         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
          210  +  sqlite3_imposter db main $tblroot \
          211  +     {CREATE TABLE xt4(a INTEGER PRIMARY KEY, c1 TEXT, c2 TEXT)}
   217    212   
   218         -  execsql {
          213  +  db eval {
   219    214       UPDATE xt4 SET c1='hello' WHERE rowid=2;
   220    215       DELETE FROM xt4 WHERE rowid = 3;
   221    216     }
   222         -
   223         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 1
          217  +  sqlite3_imposter db main
   224    218   } {}
   225    219   
   226    220   do_index_check_test 4.3 t4cc {
   227    221     {} 'aaa','bbb',1 
   228    222     {row data mismatch} 'AAA','CCC',2 
   229    223     {row missing} 'aab','ddd',3 
   230    224     {} 'AAB','EEE',4
................................................................................
   259    253     {} {'{"x":2, "y":2}',2} 
   260    254     {} {'{"x":3, "y":3}',3} 
   261    255     {} {'{"x":5, "y":5}',5}
   262    256   }
   263    257   
   264    258   do_test 5.2 {
   265    259     set tblroot [db one { SELECT rootpage FROM sqlite_master WHERE name='t5' }]
   266         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $tblroot
   267         -  db eval {CREATE TABLE xt5(a INTEGER PRIMARY KEY, c1 TEXT);}
   268         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
   269         -  execsql {
          260  +  sqlite3_imposter db main $tblroot \
          261  +      {CREATE TABLE xt5(a INTEGER PRIMARY KEY, c1 TEXT);}
          262  +  db eval {
   270    263       UPDATE xt5 SET c1='{"x":22, "y":11}' WHERE rowid=1;
   271    264       DELETE FROM xt5 WHERE rowid = 4;
   272    265     }
   273         -  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 1
          266  +  sqlite3_imposter db main
   274    267   } {}
   275    268   
   276    269   do_index_check_test 5.3.1 t5x {
   277    270     {row missing} NULL,4 
   278    271     {row data mismatch} 1,1 
   279    272     {} 2,2 
   280    273     {} 3,3