SQLite

Check-in [0593a2ba74]
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
Timelines: family | ancestors | descendants | both | checkindex
Files: files | file ages | folders
SHA3-256: 0593a2ba74c886afe8a65cea1310025bb9777c320d093278044719210c9f6ba2
User & Date: drh 2017-11-01 18:31:34.119
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: c1641affae 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: 0593a2ba74 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: 17f8d5e111 user: drh tags: checkindex)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to ext/repair/sqlite3_checker.c.in.
14
15
16
17
18
19
20
21


















































22
23
24


25
26
27
28
29
30
31
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83








+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



+
+







#define SQLITE_DEFAULT_MEMSTATUS 0
#define SQLITE_MAX_EXPR_DEPTH 0
INCLUDE sqlite3.c
INCLUDE $ROOT/src/tclsqlite.c
INCLUDE $ROOT/ext/misc/btreeinfo.c
INCLUDE $ROOT/ext/repair/checkindex.c
INCLUDE $ROOT/ext/repair/checkfreelist.c

/*
** Decode a pointer to an sqlite3 object.
*/
int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
  struct SqliteDb *p;
  Tcl_CmdInfo cmdInfo;
  if( Tcl_GetCommandInfo(interp, zA, &cmdInfo) ){
    p = (struct SqliteDb*)cmdInfo.objClientData;
    *ppDb = p->db;
    return TCL_OK;
  }else{
    *ppDb = 0;
    return TCL_ERROR;
  }
  return TCL_OK;
}

/*
**   sqlite3_imposter db main rootpage {CREATE TABLE...}  ;# setup an imposter
**   sqlite3_imposter db main                             ;# rm all imposters
*/
static int sqlite3_imposter(
  void *clientData,
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  sqlite3 *db;
  const char *zSchema;
  int iRoot;
  const char *zSql;

  if( objc!=3 && objc!=5 ){
    Tcl_WrongNumArgs(interp, 1, objv, "DB SCHEMA [ROOTPAGE SQL]");
    return TCL_ERROR;
  }
  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  zSchema = Tcl_GetString(objv[2]);
  if( objc==3 ){
    sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zSchema, 0, 1);
  }else{
    if( Tcl_GetIntFromObj(interp, objv[3], &iRoot) ) return TCL_ERROR;
    zSql = Tcl_GetString(objv[4]);
    sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zSchema, 1, iRoot);
    sqlite3_exec(db, zSql, 0, 0, 0);
    sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, db, zSchema, 0, 0);
  }
  return TCL_OK;
}

#include <stdio.h>

const char *sqlite3_checker_init_proc(Tcl_Interp *interp){
  Tcl_CreateObjCommand(interp, "sqlite3_imposter", 
                       (Tcl_ObjCmdProc*)sqlite3_imposter, 0, 0);
  sqlite3_auto_extension((void(*)(void))sqlite3_btreeinfo_init);
  sqlite3_auto_extension((void(*)(void))sqlite3_checkindex_init);
  sqlite3_auto_extension((void(*)(void))sqlite3_checkfreelist_init);
  return
BEGIN_STRING
INCLUDE $ROOT/ext/repair/sqlite3_checker.tcl
END_STRING
Changes to ext/repair/test/checkindex01.test.
67
68
69
70
71
72
73
74
75


76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
67
68
69
70
71
72
73


74
75



76
77
78

79

80
81
82
83
84
85
86







-
-
+
+
-
-
-



-
+
-







  {} 'one',1
  {} 'four',4
  {} 'five',5
}

do_test 1.5 {
  set tblroot [db one { SELECT rootpage FROM sqlite_master WHERE name='t1' }]
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $tblroot
  db eval {CREATE TABLE xt1(a, b)}
  sqlite3_imposter db main $tblroot {CREATE TABLE xt1(a,b)}
  db eval {
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0

  execsql {
    UPDATE xt1 SET a='six' WHERE rowid=3;
    DELETE FROM xt1 WHERE rowid = 5;
  }

  sqlite3_imposter db main
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 1
} {}

do_index_check_test 1.6 i1 {
  {row missing} 'five',5
  {} 'four',4
  {} 'one',1
  {row data mismatch} 'three',3
207
208
209
210
211
212
213
214
215


216
217
218

219
220
221
222

223
224
225
226
227
228
229
230
203
204
205
206
207
208
209


210
211

212

213
214
215
216

217

218
219
220
221
222
223
224







-
-
+
+
-

-
+



-
+
-







  {} 'AAA','CCC',2 
  {} 'aab','ddd',3 
  {} 'AAB','EEE',4
}

do_test 4.2 {
  set tblroot [db one { SELECT rootpage FROM sqlite_master WHERE name='t4' }]
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $tblroot
  db eval {CREATE TABLE xt4(a INTEGER PRIMARY KEY, c1 TEXT, c2 TEXT)}
  sqlite3_imposter db main $tblroot \
     {CREATE TABLE xt4(a INTEGER PRIMARY KEY, c1 TEXT, c2 TEXT)}
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0

  execsql {
  db eval {
    UPDATE xt4 SET c1='hello' WHERE rowid=2;
    DELETE FROM xt4 WHERE rowid = 3;
  }

  sqlite3_imposter db main
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 1
} {}

do_index_check_test 4.3 t4cc {
  {} 'aaa','bbb',1 
  {row data mismatch} 'AAA','CCC',2 
  {row missing} 'aab','ddd',3 
  {} 'AAB','EEE',4
259
260
261
262
263
264
265
266
267


268
269

270
271
272
273

274
275
276
277
278
279
280
253
254
255
256
257
258
259


260
261


262
263
264
265

266
267
268
269
270
271
272
273







-
-
+
+
-
-
+



-
+







  {} {'{"x":2, "y":2}',2} 
  {} {'{"x":3, "y":3}',3} 
  {} {'{"x":5, "y":5}',5}
}

do_test 5.2 {
  set tblroot [db one { SELECT rootpage FROM sqlite_master WHERE name='t5' }]
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 1 $tblroot
  db eval {CREATE TABLE xt5(a INTEGER PRIMARY KEY, c1 TEXT);}
  sqlite3_imposter db main $tblroot \
      {CREATE TABLE xt5(a INTEGER PRIMARY KEY, c1 TEXT);}
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 0
  execsql {
  db eval {
    UPDATE xt5 SET c1='{"x":22, "y":11}' WHERE rowid=1;
    DELETE FROM xt5 WHERE rowid = 4;
  }
  sqlite3_test_control SQLITE_TESTCTRL_IMPOSTER db main 0 1
  sqlite3_imposter db main
} {}

do_index_check_test 5.3.1 t5x {
  {row missing} NULL,4 
  {row data mismatch} 1,1 
  {} 2,2 
  {} 3,3