SQLite

Check-in [3212733cb6]
Login

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

Overview
Comment:Add the SQLITE_DEFAULT_DEFENSIVE compile-time option. Fix up test cases so that they work with DEFENSIVE enabled.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | read-only-shadow
Files: files | file ages | folders
SHA3-256: 3212733cb6d1a59516d67a86df7c7b1d2456a1b2e5d7080c26b0e87b2609c65d
User & Date: drh 2018-11-07 02:17:01.958
Context
2018-11-07
13:41
Merge the permutations fix from trunk. (check-in: b753d849fe user: drh tags: read-only-shadow)
02:17
Add the SQLITE_DEFAULT_DEFENSIVE compile-time option. Fix up test cases so that they work with DEFENSIVE enabled. (check-in: 3212733cb6 user: drh tags: read-only-shadow)
2018-11-06
19:26
Enable DEFENSIVE mode by default for tests. This requires lots of case of turning DEFENSIVE off in order to dodgy things to the database for testing purposes. No all of those cases are yet handled, so "make test" does not run to completion. (check-in: a1d6c6712c user: drh tags: read-only-shadow)
Changes
Unified Diff Ignore Whitespace Patch
Changes to ext/fts5/test/fts5connect.test.
240
241
242
243
244
245
246
247

  do_execsql_test 4.$tn.3 {
    INSERT INTO ft3(ft3) VALUES('integrity-check');
  }
}

finish_test








<
240
241
242
243
244
245
246


  do_execsql_test 4.$tn.3 {
    INSERT INTO ft3(ft3) VALUES('integrity-check');
  }
}

finish_test

Changes to ext/fts5/test/fts5first.test.
89
90
91
92
93
94
95
96
  SELECT * FROM x2('a + b');
} {1 {fts5: phrase queries are not supported (detail!=full)}}

do_catchsql_test 3.3 {
  SELECT * FROM x2('^a');
} {1 {fts5: phrase queries are not supported (detail!=full)}}
finish_test








<
89
90
91
92
93
94
95

  SELECT * FROM x2('a + b');
} {1 {fts5: phrase queries are not supported (detail!=full)}}

do_catchsql_test 3.3 {
  SELECT * FROM x2('^a');
} {1 {fts5: phrase queries are not supported (detail!=full)}}
finish_test

Changes to ext/fts5/test/fts5rank.test.
159
160
161
162
163
164
165
166
}

do_execsql_test 5.1 {
  SELECT rowid FROM ttt('word') WHERE rowid BETWEEN 30 AND 40 ORDER BY rank;
} {30 31 32 33 34 35 36 37 38 39 40}

finish_test








<
159
160
161
162
163
164
165

}

do_execsql_test 5.1 {
  SELECT rowid FROM ttt('word') WHERE rowid BETWEEN 30 AND 40 ORDER BY rank;
} {30 31 32 33 34 35 36 37 38 39 40}

finish_test

Changes to ext/fts5/test/fts5rebuild.test.
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  INSERT INTO f1(f1) VALUES('integrity-check');
} {}

sqlite3_db_config db DEFENSIVE 0
do_execsql_test 1.5 {
  DELETE FROM f1_data;
} {}
sqlite3_db_config db DEFENSIVE 1

do_catchsql_test 1.6 {
  INSERT INTO f1(f1) VALUES('integrity-check');
} {1 {database disk image is malformed}}

do_execsql_test 1.7 {
  INSERT INTO f1(f1) VALUES('rebuild');







<







39
40
41
42
43
44
45

46
47
48
49
50
51
52
  INSERT INTO f1(f1) VALUES('integrity-check');
} {}

sqlite3_db_config db DEFENSIVE 0
do_execsql_test 1.5 {
  DELETE FROM f1_data;
} {}


do_catchsql_test 1.6 {
  INSERT INTO f1(f1) VALUES('integrity-check');
} {1 {database disk image is malformed}}

do_execsql_test 1.7 {
  INSERT INTO f1(f1) VALUES('rebuild');
Changes to ext/fts5/test/fts5rowid.test.
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  SELECT count(fts5_decode(rowid, block)) FROM x1_data;
} $res
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 2.4 {
  UPDATE x1_data SET block = X'';
  SELECT count(fts5_decode(rowid, block)) FROM x1_data;
} $res
sqlite3_db_config db DEFENSIVE 1

do_execsql_test 2.5 {
  INSERT INTO x1(x1, rank) VALUES('pgsz', 1024);
  INSERT INTO x1(x1) VALUES('rebuild');
}

set res [db one {SELECT count(*) FROM x1_data}]







<







71
72
73
74
75
76
77

78
79
80
81
82
83
84
  SELECT count(fts5_decode(rowid, block)) FROM x1_data;
} $res
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 2.4 {
  UPDATE x1_data SET block = X'';
  SELECT count(fts5_decode(rowid, block)) FROM x1_data;
} $res


do_execsql_test 2.5 {
  INSERT INTO x1(x1, rank) VALUES('pgsz', 1024);
  INSERT INTO x1(x1) VALUES('rebuild');
}

set res [db one {SELECT count(*) FROM x1_data}]
Changes to ext/fts5/test/fts5vocab2.test.
202
203
204
205
206
207
208
209
do_execsql_test 3.5 {
  DELETE FROM t1;
  SELECT * FROM v1;
} {
}

finish_test








<
202
203
204
205
206
207
208

do_execsql_test 3.5 {
  DELETE FROM t1;
  SELECT * FROM v1;
} {
}

finish_test

Changes to ext/rbu/rbu1.test.
666
667
668
669
670
671
672
673

  catch { db close }
  eval $destroy_vfs
}


finish_test








<
666
667
668
669
670
671
672


  catch { db close }
  eval $destroy_vfs
}


finish_test

Changes to ext/rbu/rbu10.test.
181
182
183
184
185
186
187
188
    INSERT INTO data_t3 VALUES(1, 'abc', '-6.0', 0);
  }
  list [catch { apply_rbu $rbu } msg] $msg
} {0 SQLITE_DONE}


finish_test








<
181
182
183
184
185
186
187

    INSERT INTO data_t3 VALUES(1, 'abc', '-6.0', 0);
  }
  list [catch { apply_rbu $rbu } msg] $msg
} {0 SQLITE_DONE}


finish_test

Changes to ext/rbu/rbu11.test.
191
192
193
194
195
196
197
198
  rbu step
} {SQLITE_ERROR}
do_test 4.7.2 {
  list [catch {rbu close} msg] $msg
} {1 {SQLITE_ERROR - rbu_state mismatch error}}

finish_test








<
191
192
193
194
195
196
197

  rbu step
} {SQLITE_ERROR}
do_test 4.7.2 {
  list [catch {rbu close} msg] $msg
} {1 {SQLITE_ERROR - rbu_state mismatch error}}

finish_test

Changes to ext/rbu/rbu12.test.
228
229
230
231
232
233
234
235
  do_test 2.$tn.6 {
    list [sql1 {PRAGMA data_version}] [sql2 {PRAGMA data_version}]
  } [list $V1 $V2]

}

finish_test








<
228
229
230
231
232
233
234

  do_test 2.$tn.6 {
    list [sql1 {PRAGMA data_version}] [sql2 {PRAGMA data_version}]
  } [list $V1 $V2]

}

finish_test

Changes to ext/rbu/rbu13.test.
58
59
60
61
62
63
64
65
do_execsql_test 1.4 {
  SELECT count(*) FROM t1 WHERE
  a == ( (b<<6) + (c<<5) + (d<<4) + (e<<3) + (f<<2) + (g<<1) + (h<<0) )
} {128}


finish_test








<
58
59
60
61
62
63
64

do_execsql_test 1.4 {
  SELECT count(*) FROM t1 WHERE
  a == ( (b<<6) + (c<<5) + (d<<4) + (e<<3) + (f<<2) + (g<<1) + (h<<0) )
} {128}


finish_test

Changes to ext/rbu/rbu14.test.
88
89
90
91
92
93
94
95
  } {4 5 6 50 50 50}

  integrity_check $tn.4
}


finish_test








<
88
89
90
91
92
93
94

  } {4 5 6 50 50 50}

  integrity_check $tn.4
}


finish_test

Changes to ext/rbu/rbu3.test.
199
200
201
202
203
204
205
206
207
do_test 5.3 {
  expr {[file size test.db-wal] > (1024 * 1200)}
} 1

do_test 6.1 { sqlite3rbu_internal_test } {}

finish_test









<
<
199
200
201
202
203
204
205


do_test 5.3 {
  expr {[file size test.db-wal] > (1024 * 1200)}
} 1

do_test 6.1 { sqlite3rbu_internal_test } {}

finish_test


Changes to ext/rbu/rbu5.test.
296
297
298
299
300
301
302
303
304
305
306

    db close
  }
}


finish_test











<
<
<
<
296
297
298
299
300
301
302





    db close
  }
}


finish_test




Changes to ext/rbu/rbu6.test.
96
97
98
99
100
101
102
103
  do_execsql_test 1.$nStep.5 {
    SELECT * FROM t1;
  } {1 t1 5 hello}
}


finish_test








<
96
97
98
99
100
101
102

  do_execsql_test 1.$nStep.5 {
    SELECT * FROM t1;
  } {1 t1 5 hello}
}


finish_test

Changes to ext/rbu/rbu7.test.
102
103
104
105
106
107
108
109
110
    2 2 d
    3 1 e
    3 2 f
  }
}

finish_test









<
<
102
103
104
105
106
107
108


    2 2 d
    3 1 e
    3 2 f
  }
}

finish_test


Changes to ext/rbu/rbu8.test.
68
69
70
71
72
73
74
75
  {}   2 2
  _iii 3 three-III
}
integrity_check 1.3.3


finish_test








<
68
69
70
71
72
73
74

  {}   2 2
  _iii 3 three-III
}
integrity_check 1.3.3


finish_test

Changes to ext/rbu/rbu9.test.
121
122
123
124
125
126
127
128
  }
  
  integrity_check 2.$tn.4
}


finish_test








<
121
122
123
124
125
126
127

  }
  
  integrity_check 2.$tn.4
}


finish_test

Changes to ext/rbu/rbuA.test.
76
77
78
79
80
81
82
83

do_test 2.2 {
  list [catch { rbu close } msg] $msg
} {1 {SQLITE_ERROR - cannot update wal mode database}}


finish_test








<
76
77
78
79
80
81
82


do_test 2.2 {
  list [catch { rbu close } msg] $msg
} {1 {SQLITE_ERROR - cannot update wal mode database}}


finish_test

Changes to ext/rbu/rbuB.test.
55
56
57
58
59
60
61
62
} {1 2 3 4 5 6 7 8 9}

db close
sqlite3_shutdown
test_sqlite3_log 
sqlite3_initialize
finish_test








<
55
56
57
58
59
60
61

} {1 2 3 4 5 6 7 8 9}

db close
sqlite3_shutdown
test_sqlite3_log 
sqlite3_initialize
finish_test

Changes to ext/rbu/rbuC.test.
135
136
137
138
139
140
141
142
  
  integrity_check 3.$tn.4
}



finish_test








<
135
136
137
138
139
140
141

  
  integrity_check 3.$tn.4
}



finish_test

Changes to ext/rbu/rbucollate.test.
56
57
58
59
60
61
62
63
  }
  rbu close
  db eval { SELECT * FROM t1 }
} {a one 1 b two 2 c three 3}

#forcedelete testrbu.db
finish_test








<
56
57
58
59
60
61
62

  }
  rbu close
  db eval { SELECT * FROM t1 }
} {a one 1 b two 2 c three 3}

#forcedelete testrbu.db
finish_test

Changes to ext/rbu/rbucrash.test.
141
142
143
144
145
146
147
148
for {set nPre 0} {$nPre < $rbu_num_steps} {incr nPre} {
  for {set is 1} {$is <= ($rbu_num_steps - $nPre)} {incr is} {
    do_rbu_crash_test 2.pre=$nPre.step=$is $nPre $is
  }
}

finish_test








<
141
142
143
144
145
146
147

for {set nPre 0} {$nPre < $rbu_num_steps} {incr nPre} {
  for {set is 1} {$is <= ($rbu_num_steps - $nPre)} {incr is} {
    do_rbu_crash_test 2.pre=$nPre.step=$is $nPre $is
  }
}

finish_test

Changes to ext/rbu/rbucrash2.test.
99
100
101
102
103
104
105
106
      sqlite3rbu rbu test.db test.db2
    }
    rbu close
  }
}

finish_test








<
99
100
101
102
103
104
105

      sqlite3rbu rbu test.db test.db2
    }
    rbu close
  }
}

finish_test

Changes to ext/rbu/rbudiff.test.
296
297
298
299
300
301
302
303
    db close
    db2 close
  }
}


finish_test








<
296
297
298
299
300
301
302

    db close
    db2 close
  }
}


finish_test

Changes to ext/rbu/rbudor.test.
52
53
54
55
56
57
58
59
} {SQLITE_DONE}

do_execsql_test 1.4 {
  SELECT * FROM t1 
} [list 1 $bigA 2 $bigB]

finish_test








<
52
53
54
55
56
57
58

} {SQLITE_DONE}

do_execsql_test 1.4 {
  SELECT * FROM t1 
} [list 1 $bigA 2 $bigB]

finish_test

Changes to ext/rbu/rbufault.test.
230
231
232
233
234
235
236
237
        }
      }
    }
  }
}

finish_test








<
230
231
232
233
234
235
236

        }
      }
    }
  }
}

finish_test

Changes to ext/rbu/rbufault2.test.
51
52
53
54
55
56
57
58
      {1 {SQLITE_NOMEM - out of memory}} 
}




finish_test








<
51
52
53
54
55
56
57

      {1 {SQLITE_NOMEM - out of memory}} 
}




finish_test

Changes to ext/rbu/rbufault3.test.
91
92
93
94
95
96
97
98
  } -test {
    eval [list faultsim_test_result {0 SQLITE_OK} {*}$::errlist]
  }

}

finish_test








<
91
92
93
94
95
96
97

  } -test {
    eval [list faultsim_test_result {0 SQLITE_OK} {*}$::errlist]
  }

}

finish_test

Changes to ext/rbu/rbufault4.test.
59
60
61
62
63
64
65
66
    if {$rc!="ok"} { error "Got $rc instead of ok!" }
  }
}



finish_test








<
59
60
61
62
63
64
65

    if {$rc!="ok"} { error "Got $rc instead of ok!" }
  }
}



finish_test

Changes to ext/rbu/rbufts.test.
127
128
129
130
131
132
133
134
    INSERT INTO data_ft VALUES('7 8 9', 1, 'x');
  } } msg] $msg]
} {1 {SQLITE_ERROR - SQL logic error]}}



finish_test








<
127
128
129
130
131
132
133

    INSERT INTO data_ft VALUES('7 8 9', 1, 'x');
  } } msg] $msg]
} {1 {SQLITE_ERROR - SQL logic error]}}



finish_test

Changes to ext/rbu/rbumulti.test.
168
169
170
171
172
173
174
175
    sqlite3rbu_destroy_vfs myrbu
  }

}


finish_test








<
168
169
170
171
172
173
174

    sqlite3rbu_destroy_vfs myrbu
  }

}


finish_test

Changes to ext/rbu/rbuprogress.test.
412
413
414
415
416
417
418
419
      do_sp_test 5.$tn.$bReopen.$tn2.1 $bReopen test.db rbu.db $R($tn)
    }
  }
}


finish_test








<
412
413
414
415
416
417
418

      do_sp_test 5.$tn.$bReopen.$tn2.1 $bReopen test.db rbu.db $R($tn)
    }
  }
}


finish_test

Changes to ext/rbu/rburesume.test.
247
248
249
250
251
252
253
254
      PRAGMA integrity_check;
    }
  } {60 ok}
  db2 close
}

finish_test








<
247
248
249
250
251
252
253

      PRAGMA integrity_check;
    }
  } {60 ok}
  db2 close
}

finish_test

Changes to ext/rbu/rbusave.test.
98
99
100
101
102
103
104
105

do_execsql_test 1.5 {
  SELECT * FROM t1;
  SELECT * FROM t2;
} {1 one 1 3 3 3 4 4 4 1 one 1 3 3 3 4 4 4}

finish_test








<
98
99
100
101
102
103
104


do_execsql_test 1.5 {
  SELECT * FROM t1;
  SELECT * FROM t2;
} {1 one 1 3 3 3 4 4 4 1 one 1 3 3 3 4 4 4}

finish_test

Changes to ext/rbu/rbusplit.test.
88
89
90
91
92
93
94
95
    1 1 1 2 2 2 3 3 3 4 4 4
    5 5 5 6 6 6 7 7 7 8 8 8
    9 9 9
  }
}

finish_test








<
88
89
90
91
92
93
94

    1 1 1 2 2 2 3 3 3 4 4 4
    5 5 5 6 6 6 7 7 7 8 8 8
    9 9 9
  }
}

finish_test

Changes to ext/rbu/rbutemplimit.test.
122
123
124
125
126
127
128
129
  setup_databases
  unset -nocomplain ::A
  step_rbu_cachesize test.db test.db2 1000 10 1400000
} {1 SQLITE_FULL}
do_test 1.6.2 { info commands rbu } {}

finish_test








<
122
123
124
125
126
127
128

  setup_databases
  unset -nocomplain ::A
  step_rbu_cachesize test.db test.db2 1000 10 1400000
} {1 SQLITE_FULL}
do_test 1.6.2 { info commands rbu } {}

finish_test

Changes to ext/rbu/rbuvacuum.test.
393
394
395
396
397
398
399
400

  while {[rbu step]=="SQLITE_OK"} {}
  list [catch { rbu close } msg] $msg
} {0 SQLITE_DONE}

catch { db close }
finish_test








<
393
394
395
396
397
398
399


  while {[rbu step]=="SQLITE_OK"} {}
  list [catch { rbu close } msg] $msg
} {0 SQLITE_DONE}

catch { db close }
finish_test

Changes to ext/rbu/rbuvacuum2.test.
228
229
230
231
232
233
234
235
  sqlite3rbu_vacuum rbu test.db test.db2
  while {[rbu step]!="SQLITE_DONE"} { rbu step }
  rbu close
  execsql { PRAGMA integrity_check }
} {ok}

finish_test








<
228
229
230
231
232
233
234

  sqlite3rbu_vacuum rbu test.db test.db2
  while {[rbu step]!="SQLITE_DONE"} { rbu step }
  rbu close
  execsql { PRAGMA integrity_check }
} {ok}

finish_test

Changes to ext/repair/test/checkindex01.test.
343
344
345
346
347
348
349
350
351
}
do_index_check_test 7.3 t7i3 {
  {} 1,1 {} 3,3
}
do_index_check_test 7.4 t7i4 {
  {} 1,1 {} 3,3
}









<
<
343
344
345
346
347
348
349


}
do_index_check_test 7.3 t7i3 {
  {} 1,1 {} 3,3
}
do_index_check_test 7.4 t7i4 {
  {} 1,1 {} 3,3
}


Changes to ext/rtree/rtree8.test.
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# level, but the contents of the various tables used internally by an
# r-tree table are inconsistent.
#
populate_t1 50
do_execsql_test rtree8-2.1.1 { SELECT max(nodeno) FROM t1_node } {5}
sqlite3_db_config db DEFENSIVE 0
do_execsql_test rtree8-2.1.2 { DELETE FROM t1_node } {}
sqlite3_db_config db DEFENSIVE 1
for {set i 1} {$i <= 50} {incr i} {
  do_catchsql_test rtree8-2.1.3.$i { 
    SELECT * FROM t1 WHERE id = $i 
  } {1 {database disk image is malformed}}
}
do_catchsql_test rtree8-2.1.4 { 
  SELECT * FROM t1







<







99
100
101
102
103
104
105

106
107
108
109
110
111
112
# level, but the contents of the various tables used internally by an
# r-tree table are inconsistent.
#
populate_t1 50
do_execsql_test rtree8-2.1.1 { SELECT max(nodeno) FROM t1_node } {5}
sqlite3_db_config db DEFENSIVE 0
do_execsql_test rtree8-2.1.2 { DELETE FROM t1_node } {}

for {set i 1} {$i <= 50} {incr i} {
  do_catchsql_test rtree8-2.1.3.$i { 
    SELECT * FROM t1 WHERE id = $i 
  } {1 {database disk image is malformed}}
}
do_catchsql_test rtree8-2.1.4 { 
  SELECT * FROM t1
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137


populate_t1 50
sqlite3_db_config db DEFENSIVE 0
do_execsql_test rtree8-2.2.1 {
  DELETE FROM t1_parent
} {}
sqlite3_db_config db DEFENSIVE 1
do_catchsql_test rtree8-2.2.2 {
  DELETE FROM t1 WHERE id=25
} {1 {database disk image is malformed}}
do_execsql_test rtree8-2.2.3 { 
  DROP TABLE t1;
  CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
} {}







<







122
123
124
125
126
127
128

129
130
131
132
133
134
135


populate_t1 50
sqlite3_db_config db DEFENSIVE 0
do_execsql_test rtree8-2.2.1 {
  DELETE FROM t1_parent
} {}

do_catchsql_test rtree8-2.2.2 {
  DELETE FROM t1 WHERE id=25
} {1 {database disk image is malformed}}
do_execsql_test rtree8-2.2.3 { 
  DROP TABLE t1;
  CREATE VIRTUAL TABLE t1 USING rtree_i32(id, x1, x2);
} {}
Changes to ext/session/sessionC.test.
191
192
193
194
195
196
197
198
    SELECT * FROM t3;
  }
} {1 1 3 3}



finish_test








<
191
192
193
194
195
196
197

    SELECT * FROM t3;
  }
} {1 1 3 3}



finish_test

Changes to ext/session/sessionD.test.
251
252
253
254
255
256
257
258
} {0 {}}
S delete
do_catchsql_test 4.5.2 {
  SELECT * FROM ixua.i8;
} {1 {no such table: ixua.i8}}

finish_test








<
251
252
253
254
255
256
257

} {0 {}}
S delete
do_catchsql_test 4.5.2 {
  SELECT * FROM ixua.i8;
} {1 {no such table: ixua.i8}}

finish_test

Changes to ext/session/sessionE.test.
107
108
109
110
111
112
113
114
115
  {INSERT t2 0 X. {} {i 7 i 8}}
}


S delete

finish_test









<
<
107
108
109
110
111
112
113


  {INSERT t2 0 X. {} {i 7 i 8}}
}


S delete

finish_test


Changes to ext/session/sessionF.test.
288
289
290
291
292
293
294
295
  }

  do_test 3.$tn { set res } [list {*}$result]
}


finish_test








<
288
289
290
291
292
293
294

  }

  do_test 3.$tn { set res } [list {*}$result]
}


finish_test

Changes to ext/session/sessionG.test.
244
245
246
247
248
249
250
251
  SELECT count(*) FROM t1 WHERE number_name(a+1) IS NOT b; 
} {0}

# db eval { SELECT * FROM t1 } { puts "$a || $b" }


finish_test








<
244
245
246
247
248
249
250

  SELECT count(*) FROM t1 WHERE number_name(a+1) IS NOT b; 
} {0}

# db eval { SELECT * FROM t1 } { puts "$a || $b" }


finish_test

Changes to ext/session/sessionH.test.
32
33
34
35
36
37
38
39
    INSERT INTO t1 SELECT 'abcde', randomblob(16), i FROM s;
  }
  compare_db db db2
} {}


finish_test








<
32
33
34
35
36
37
38

    INSERT INTO t1 SELECT 'abcde', randomblob(16), i FROM s;
  }
  compare_db db db2
} {}


finish_test

Changes to ext/session/sessionfault2.test.
278
279
280
281
282
283
284
285
} -test {
  catch { R delete } 
  faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}


finish_test








<
278
279
280
281
282
283
284

} -test {
  catch { R delete } 
  faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
}


finish_test

Changes to ext/session/sessionrebase.test.
470
471
472
473
474
475
476
477
    R configure $::rebase
    expr [catch {R rebase $P}]==0
  } $rebasable

  catch { R delete }
}
finish_test








<
470
471
472
473
474
475
476

    R configure $::rebase
    expr [catch {R rebase $P}]==0
  } $rebasable

  catch { R delete }
}
finish_test

Changes to ext/session/sessionstat1.test.
304
305
306
307
308
309
310
311
    return "REPLACE"
  }
  sqlite3changeset_apply db2 $C xConflict
  execsql { SELECT * FROM sqlite_stat1 ORDER BY 1,2 } db2
} {t3 null 3}

finish_test








<
304
305
306
307
308
309
310

    return "REPLACE"
  }
  sqlite3changeset_apply db2 $C xConflict
  execsql { SELECT * FROM sqlite_stat1 ORDER BY 1,2 } db2
} {t3 null 3}

finish_test

Changes to ext/session/sessionwor.test.
50
51
52
53
54
55
56
57
do_iterator_test 1.3 t1 {
  DELETE FROM t1;
} {
  {DELETE t1 0 X. {t one t three} {}}
}

finish_test








<
50
51
52
53
54
55
56

do_iterator_test 1.3 t1 {
  DELETE FROM t1;
} {
  {DELETE t1 0 X. {t one t three} {}}
}

finish_test

Changes to src/main.c.
3058
3059
3060
3061
3062
3063
3064



3065
3066
3067
3068
3069
3070
3071
                 | SQLITE_CellSizeCk
#endif
#if defined(SQLITE_ENABLE_FTS3_TOKENIZER)
                 | SQLITE_Fts3Tokenizer
#endif
#if defined(SQLITE_ENABLE_QPSG)
                 | SQLITE_EnableQPSG



#endif
      ;
  sqlite3HashInit(&db->aCollSeq);
#ifndef SQLITE_OMIT_VIRTUALTABLE
  sqlite3HashInit(&db->aModule);
#endif








>
>
>







3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
                 | SQLITE_CellSizeCk
#endif
#if defined(SQLITE_ENABLE_FTS3_TOKENIZER)
                 | SQLITE_Fts3Tokenizer
#endif
#if defined(SQLITE_ENABLE_QPSG)
                 | SQLITE_EnableQPSG
#endif
#if defined(SQLITE_DEFAULT_DEFENSIVE)
                 | SQLITE_Defensive
#endif
      ;
  sqlite3HashInit(&db->aCollSeq);
#ifndef SQLITE_OMIT_VIRTUALTABLE
  sqlite3HashInit(&db->aModule);
#endif

Changes to test/alter2.test.
60
61
62
63
64
65
66

67
68
69
70
71
72
73
# to the supplied value. This is 2 if the added column has a default that is
# NULL, or 3 otherwise. 
#
proc alter_table {tbl sql {file_format 2}} {
  sqlite3 dbat test.db
  set s [string map {' ''} $sql]
  set t [string map {' ''} $tbl]

  dbat eval [subst {
    PRAGMA writable_schema = 1;
    UPDATE sqlite_master SET sql = '$s' WHERE name = '$t' AND type = 'table';
    PRAGMA writable_schema = 0;
  }]
  dbat close
  set_file_format 2







>







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# to the supplied value. This is 2 if the added column has a default that is
# NULL, or 3 otherwise. 
#
proc alter_table {tbl sql {file_format 2}} {
  sqlite3 dbat test.db
  set s [string map {' ''} $sql]
  set t [string map {' ''} $tbl]
  sqlite3_db_config dbat DEFENSIVE 0
  dbat eval [subst {
    PRAGMA writable_schema = 1;
    UPDATE sqlite_master SET sql = '$s' WHERE name = '$t' AND type = 'table';
    PRAGMA writable_schema = 0;
  }]
  dbat close
  set_file_format 2
87
88
89
90
91
92
93

94
95
96
97
98
99
100
  catchsql {SELECT substr('abcdefg',1,3)}
} {1 {bad function}}


#-----------------------------------------------------------------------
# Some basic tests to make sure short rows are handled.
#

do_test alter2-1.1 {
  execsql {
    CREATE TABLE abc(a, b);
    INSERT INTO abc VALUES(1, 2);
    INSERT INTO abc VALUES(3, 4);
    INSERT INTO abc VALUES(5, 6);
  }







>







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  catchsql {SELECT substr('abcdefg',1,3)}
} {1 {bad function}}


#-----------------------------------------------------------------------
# Some basic tests to make sure short rows are handled.
#
sqlite3_db_config db DEFENSIVE 0
do_test alter2-1.1 {
  execsql {
    CREATE TABLE abc(a, b);
    INSERT INTO abc VALUES(1, 2);
    INSERT INTO abc VALUES(3, 4);
    INSERT INTO abc VALUES(5, 6);
  }
Changes to test/altercol.test.
549
550
551
552
553
554
555

556
557
558
559
560
561
562

do_execsql_test 13.1.3 {
  DROP TRIGGER tr1;
  CREATE INDEX x1i ON x1(i);
  SELECT sql FROM sqlite_master WHERE name='x1i';
} {{CREATE INDEX x1i ON x1(i)}}


do_execsql_test 13.1.4 {
  PRAGMA writable_schema = 1;
  UPDATE sqlite_master SET sql = 'CREATE INDEX x1i ON x1(j)' WHERE name='x1i';
} {}

do_catchsql_test 13.1.5 {
  ALTER TABLE x1 RENAME COLUMN t TO ttt;







>







549
550
551
552
553
554
555
556
557
558
559
560
561
562
563

do_execsql_test 13.1.3 {
  DROP TRIGGER tr1;
  CREATE INDEX x1i ON x1(i);
  SELECT sql FROM sqlite_master WHERE name='x1i';
} {{CREATE INDEX x1i ON x1(i)}}

sqlite3_db_config db DEFENSIVE 0
do_execsql_test 13.1.4 {
  PRAGMA writable_schema = 1;
  UPDATE sqlite_master SET sql = 'CREATE INDEX x1i ON x1(j)' WHERE name='x1i';
} {}

do_catchsql_test 13.1.5 {
  ALTER TABLE x1 RENAME COLUMN t TO ttt;
Changes to test/alterlegacy.test.
463
464
465
466
467
468
469
470
}
do_execsql_test 14.6 {
  ALTER TABLE t1 RENAME TO tt1;
}


finish_test








<
463
464
465
466
467
468
469

}
do_execsql_test 14.6 {
  ALTER TABLE t1 RENAME TO tt1;
}


finish_test

Changes to test/altertab.test.
501
502
503
504
505
506
507
508

do_execsql_test 15.5 {
  SELECT sql FROM sqlite_master WHERE name = 'y';
} {{CREATE VIEW y AS SELECT f2 AS f1 FROM x}}


finish_test








<
501
502
503
504
505
506
507


do_execsql_test 15.5 {
  SELECT sql FROM sqlite_master WHERE name = 'y';
} {{CREATE VIEW y AS SELECT f2 AS f1 FROM x}}


finish_test

Changes to test/altertab2.test.
39
40
41
42
43
44
45
46
    INSERT INTO rr VALUES('in', 'tcl');
    SELECT * FROM ffff;
  } {hello world in tcl}
}


finish_test








<
39
40
41
42
43
44
45

    INSERT INTO rr VALUES('in', 'tcl');
    SELECT * FROM ffff;
  } {hello world in tcl}
}


finish_test

Changes to test/analyze.test.
346
347
348
349
350
351
352

353
354
355
356
357
358
359
  } {t4i1 t4i2 t4}
}

# This test corrupts the database file so it must be the last test
# in the series.
#
do_test analyze-5.99 {

  execsql {
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1';
  }
  db close
  catch { sqlite3 db test.db }
  catchsql {







>







346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  } {t4i1 t4i2 t4}
}

# This test corrupts the database file so it must be the last test
# in the series.
#
do_test analyze-5.99 {
  sqlite3_db_config db DEFENSIVE 0
  execsql {
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1';
  }
  db close
  catch { sqlite3 db test.db }
  catchsql {
Changes to test/autoinc.test.
693
694
695
696
697
698
699

700
701
702
703
704
705
706
# Does not crash if the sqlite_sequence table schema is missing
# or corrupt.
#
do_test autoinc-12.1 {
  db close
  forcedelete test.db
  sqlite3 db test.db

  db eval {
    CREATE TABLE fake_sequence(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET
     sql=replace(sql,'fake_','sqlite_'),
     name='sqlite_sequence',
     tbl_name='sqlite_sequence'







>







693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# Does not crash if the sqlite_sequence table schema is missing
# or corrupt.
#
do_test autoinc-12.1 {
  db close
  forcedelete test.db
  sqlite3 db test.db
  sqlite3_db_config db DEFENSIVE 0
  db eval {
    CREATE TABLE fake_sequence(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET
     sql=replace(sql,'fake_','sqlite_'),
     name='sqlite_sequence',
     tbl_name='sqlite_sequence'
714
715
716
717
718
719
720

721
722
723
724
725
726
727
  }} msg]
  lappend res $msg
} {1 {database disk image is malformed}}
do_test autoinc-12.2 {
  db close
  forcedelete test.db
  sqlite3 db test.db

  db eval {
   CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   INSERT INTO t1(b) VALUES('one');
   PRAGMA writable_schema=on;
   UPDATE sqlite_master SET
     sql=replace(sql,'sqlite_','x_'),
     name='x_sequence',







>







715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
  }} msg]
  lappend res $msg
} {1 {database disk image is malformed}}
do_test autoinc-12.2 {
  db close
  forcedelete test.db
  sqlite3 db test.db
  sqlite3_db_config db DEFENSIVE 0
  db eval {
   CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   INSERT INTO t1(b) VALUES('one');
   PRAGMA writable_schema=on;
   UPDATE sqlite_master SET
     sql=replace(sql,'sqlite_','x_'),
     name='x_sequence',
740
741
742
743
744
745
746

747
748
749
750
751
752
753
} else {
  set err {malformed database schema (sqlite_sequence) - near "VIRTUAL": syntax error}
}
do_test autoinc-12.3 {
  db close
  forcedelete test.db
  sqlite3 db test.db

  db eval {
   CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   INSERT INTO t1(b) VALUES('one');
   PRAGMA writable_schema=on;
   UPDATE sqlite_master SET
     sql='CREATE VIRTUAL TABLE sqlite_sequence USING sqlite_dbpage'
    WHERE name='sqlite_sequence';







>







742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
} else {
  set err {malformed database schema (sqlite_sequence) - near "VIRTUAL": syntax error}
}
do_test autoinc-12.3 {
  db close
  forcedelete test.db
  sqlite3 db test.db
  sqlite3_db_config db DEFENSIVE 0
  db eval {
   CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
   INSERT INTO t1(b) VALUES('one');
   PRAGMA writable_schema=on;
   UPDATE sqlite_master SET
     sql='CREATE VIRTUAL TABLE sqlite_sequence USING sqlite_dbpage'
    WHERE name='sqlite_sequence';
768
769
770
771
772
773
774

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793

794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812

813
814
815
816
817
818
819
    INSERT INTO t1(b) VALUES('one');
    CREATE TABLE fake(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
  }
  set root1 [db one {SELECT rootpage FROM sqlite_master
                     WHERE name='sqlite_sequence'}]
  set root2 [db one {SELECT rootpage FROM sqlite_master
                     WHERE name='fake'}]

  db eval {
   PRAGMA writable_schema=on;
   UPDATE sqlite_master SET rootpage=$root2
    WHERE name='sqlite_sequence';
   UPDATE sqlite_master SET rootpage=$root1
    WHERE name='fake';
  }
  db close
  sqlite3 db test.db
  set res [catch {db eval {
    INSERT INTO t1(b) VALUES('two');
  }} msg]
  lappend res $msg
} {1 {database disk image is malformed}}
breakpoint
do_test autoinc-12.5 {
  db close
  forcedelete test.db
  sqlite3 db test.db

  db eval {
    CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
    INSERT INTO t1(b) VALUES('one');
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET
       sql='CREATE TABLE sqlite_sequence(x)'
      WHERE name='sqlite_sequence';
  }
  db close
  sqlite3 db test.db
  set res [catch {db eval {
    INSERT INTO t1(b) VALUES('two');
  }} msg]
  lappend res $msg
} {1 {database disk image is malformed}}
do_test autoinc-12.6 {
  db close
  forcedelete test.db
  sqlite3 db test.db

  db eval {
    CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
    INSERT INTO t1(b) VALUES('one');
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET
       sql='CREATE TABLE sqlite_sequence(x,y INTEGER PRIMARY KEY)'
      WHERE name='sqlite_sequence';







>



















>



















>







771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
    INSERT INTO t1(b) VALUES('one');
    CREATE TABLE fake(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
  }
  set root1 [db one {SELECT rootpage FROM sqlite_master
                     WHERE name='sqlite_sequence'}]
  set root2 [db one {SELECT rootpage FROM sqlite_master
                     WHERE name='fake'}]
  sqlite3_db_config db DEFENSIVE 0
  db eval {
   PRAGMA writable_schema=on;
   UPDATE sqlite_master SET rootpage=$root2
    WHERE name='sqlite_sequence';
   UPDATE sqlite_master SET rootpage=$root1
    WHERE name='fake';
  }
  db close
  sqlite3 db test.db
  set res [catch {db eval {
    INSERT INTO t1(b) VALUES('two');
  }} msg]
  lappend res $msg
} {1 {database disk image is malformed}}
breakpoint
do_test autoinc-12.5 {
  db close
  forcedelete test.db
  sqlite3 db test.db
  sqlite3_db_config db DEFENSIVE 0
  db eval {
    CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
    INSERT INTO t1(b) VALUES('one');
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET
       sql='CREATE TABLE sqlite_sequence(x)'
      WHERE name='sqlite_sequence';
  }
  db close
  sqlite3 db test.db
  set res [catch {db eval {
    INSERT INTO t1(b) VALUES('two');
  }} msg]
  lappend res $msg
} {1 {database disk image is malformed}}
do_test autoinc-12.6 {
  db close
  forcedelete test.db
  sqlite3 db test.db
  sqlite3_db_config db DEFENSIVE 0
  db eval {
    CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
    INSERT INTO t1(b) VALUES('one');
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET
       sql='CREATE TABLE sqlite_sequence(x,y INTEGER PRIMARY KEY)'
      WHERE name='sqlite_sequence';
827
828
829
830
831
832
833

834
835
836
837
838
839
840
  }} msg]
  lappend res $msg
} {0 ok}
do_test autoinc-12.7 {
  db close
  forcedelete test.db
  sqlite3 db test.db

  db eval {
    CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
    INSERT INTO t1(b) VALUES('one');
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET
       sql='CREATE TABLE sqlite_sequence(y INTEGER PRIMARY KEY,x)'
      WHERE name='sqlite_sequence';







>







833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
  }} msg]
  lappend res $msg
} {0 ok}
do_test autoinc-12.7 {
  db close
  forcedelete test.db
  sqlite3 db test.db
  sqlite3_db_config db DEFENSIVE 0
  db eval {
    CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
    INSERT INTO t1(b) VALUES('one');
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET
       sql='CREATE TABLE sqlite_sequence(y INTEGER PRIMARY KEY,x)'
      WHERE name='sqlite_sequence';
Changes to test/bestindex5.test.
243
244
245
246
247
248
249
250
do_execsql_test 3.3 { SELECT rowid, * FROM t4 WHERE x!=245; } {}
do_execsql_test 3.4 { SELECT rowid, * FROM t4 WHERE x!='245'; } {}

do_execsql_test 3.5 { SELECT rowid, * FROM t4 WHERE rowid!=1 OR x!='245'; } {}


finish_test








<
243
244
245
246
247
248
249

do_execsql_test 3.3 { SELECT rowid, * FROM t4 WHERE x!=245; } {}
do_execsql_test 3.4 { SELECT rowid, * FROM t4 WHERE x!='245'; } {}

do_execsql_test 3.5 { SELECT rowid, * FROM t4 WHERE rowid!=1 OR x!='245'; } {}


finish_test

Changes to test/capi3.test.
737
738
739
740
741
742
743

744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761

762
763
764
765
766
767
768
    execsql {
      CREATE TABLE t1(a);
    }
    db close
  } {}
  do_test capi3-8.2 {
    sqlite3 db test.db

    execsql {
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
    }
    db close
  } {}
  do_test capi3-8.3 {
    catch { sqlite3 db test.db }
    catchsql {
      SELECT * FROM sqlite_master;
    }
  } {1 {malformed database schema (?)}}
  do_test capi3-8.4 {
    # Build a 5-field row record. The first field is a string 'table', and
    # subsequent fields are all NULL.
    db close
    forcedelete test.db test.db-journal
    sqlite3 db test.db

    execsql {
      CREATE TABLE t1(a);
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
    }
    db close
  } {};







>


















>







737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
    execsql {
      CREATE TABLE t1(a);
    }
    db close
  } {}
  do_test capi3-8.2 {
    sqlite3 db test.db
    sqlite3_db_config db DEFENSIVE 0
    execsql {
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
    }
    db close
  } {}
  do_test capi3-8.3 {
    catch { sqlite3 db test.db }
    catchsql {
      SELECT * FROM sqlite_master;
    }
  } {1 {malformed database schema (?)}}
  do_test capi3-8.4 {
    # Build a 5-field row record. The first field is a string 'table', and
    # subsequent fields are all NULL.
    db close
    forcedelete test.db test.db-journal
    sqlite3 db test.db
    sqlite3_db_config db DEFENSIVE 0
    execsql {
      CREATE TABLE t1(a);
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
    }
    db close
  } {};
Changes to test/capi3c.test.
682
683
684
685
686
687
688

689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706

707
708
709
710
711
712
713
    execsql {
      CREATE TABLE t1(a);
    }
    db close
  } {}
  do_test capi3c-8.2 {
    sqlite3 db test.db

    execsql {
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
    }
    db close
  } {}
  do_test capi3c-8.3 {
    catch { sqlite3 db test.db }
    catchsql {
      SELECT * FROM sqlite_master;
    }
  } {1 {malformed database schema (?)}}
  do_test capi3c-8.4 {
    # Build a 5-field row record. The first field is a string 'table', and
    # subsequent fields are all NULL.
    db close
    forcedelete test.db test.db-journal
    sqlite3 db test.db

    execsql {
      CREATE TABLE t1(a);
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
    }
    db close
  } {};







>


















>







682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
    execsql {
      CREATE TABLE t1(a);
    }
    db close
  } {}
  do_test capi3c-8.2 {
    sqlite3 db test.db
    sqlite3_db_config db DEFENSIVE 0
    execsql {
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
    }
    db close
  } {}
  do_test capi3c-8.3 {
    catch { sqlite3 db test.db }
    catchsql {
      SELECT * FROM sqlite_master;
    }
  } {1 {malformed database schema (?)}}
  do_test capi3c-8.4 {
    # Build a 5-field row record. The first field is a string 'table', and
    # subsequent fields are all NULL.
    db close
    forcedelete test.db test.db-journal
    sqlite3 db test.db
    sqlite3_db_config db DEFENSIVE 0
    execsql {
      CREATE TABLE t1(a);
      PRAGMA writable_schema=ON;
      INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
    }
    db close
  } {};
Changes to test/corrupt5.test.
29
30
31
32
33
34
35

36
37
38
39
40
41
42
  finish_test
  return
}

# Create a database with a freelist containing at least two pages.
#
do_test corrupt5-1.1 {

  execsql {
    CREATE TABLE t1(a,b,c);
    CREATE INDEX i1 ON t1(a,b);
    PRAGMA writable_schema=ON;
    UPDATE sqlite_master SET name=NULL, sql=NULL WHERE name='i1';
  }
  db close







>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  finish_test
  return
}

# Create a database with a freelist containing at least two pages.
#
do_test corrupt5-1.1 {
  sqlite3_db_config db DEFENSIVE 0
  execsql {
    CREATE TABLE t1(a,b,c);
    CREATE INDEX i1 ON t1(a,b);
    PRAGMA writable_schema=ON;
    UPDATE sqlite_master SET name=NULL, sql=NULL WHERE name='i1';
  }
  db close
Changes to test/corruptI.test.
218
219
220
221
222
223
224

225
226
227
228
229
230
231
  PRAGMA auto_vacuum=0;
  CREATE TABLE t1(x PRIMARY KEY, y);
  INSERT INTO t1 VALUES('a', 'A');
  INSERT INTO t1 VALUES('b', 'A');
  INSERT INTO t1 VALUES('c', 'A');
  SELECT name FROM sqlite_master;
} {t1 sqlite_autoindex_t1_1}

do_execsql_test 7.1 {
  PRAGMA writable_schema = 1;
  DELETE FROM sqlite_master WHERE name = 'sqlite_autoindex_t1_1';
}
do_test 7.2 {
  db close
  sqlite3 db test.db







>







218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
  PRAGMA auto_vacuum=0;
  CREATE TABLE t1(x PRIMARY KEY, y);
  INSERT INTO t1 VALUES('a', 'A');
  INSERT INTO t1 VALUES('b', 'A');
  INSERT INTO t1 VALUES('c', 'A');
  SELECT name FROM sqlite_master;
} {t1 sqlite_autoindex_t1_1}
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 7.1 {
  PRAGMA writable_schema = 1;
  DELETE FROM sqlite_master WHERE name = 'sqlite_autoindex_t1_1';
}
do_test 7.2 {
  db close
  sqlite3 db test.db
Changes to test/corruptK.test.
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
    PRAGMA page_size=1024;
    CREATE TABLE t1(a, b, c);
    CREATE TABLE t2(a, b, c);
    CREATE TABLE t3(a, b, c);
    CREATE TABLE t4(a, b, c);
    CREATE TABLE t5(a, b, c);
  }
  
  do_execsql_test 3.2 {
    UPDATE sqlite_dbpage SET data = hex2blob('
   000: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
   010: 04 00 01 01 20 40 20 20 00 00 3e d9 00 00 00 06 .... @  ..>.....
   020: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................
   030: 0f 00 00 00 00 00 00 00 00 00 00 01 00 00 83 00 ................
   040: 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 00 .............8..







|







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
    PRAGMA page_size=1024;
    CREATE TABLE t1(a, b, c);
    CREATE TABLE t2(a, b, c);
    CREATE TABLE t3(a, b, c);
    CREATE TABLE t4(a, b, c);
    CREATE TABLE t5(a, b, c);
  }
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test 3.2 {
    UPDATE sqlite_dbpage SET data = hex2blob('
   000: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
   010: 04 00 01 01 20 40 20 20 00 00 3e d9 00 00 00 06 .... @  ..>.....
   020: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................
   030: 0f 00 00 00 00 00 00 00 00 00 00 01 00 00 83 00 ................
   040: 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 00 .............8..
Changes to test/countofview.test.
37
38
39
40
41
42
43
44
do_execsql_test 1.3 {
  select count(*) from (
    select c from t2 union all select f from t3
  )
} {3}

finish_test








<
37
38
39
40
41
42
43

do_execsql_test 1.3 {
  select count(*) from (
    select c from t2 union all select f from t3
  )
} {3}

finish_test

Changes to test/dbpage.test.
17
18
19
20
21
22
23

24
25
26
27
28
29
30
set testprefix dbpage

ifcapable !vtab||!compound {
  finish_test
  return
}


do_test 100 {
  execsql {
    PRAGMA auto_vacuum=0;
    PRAGMA page_size=4096;
    PRAGMA journal_mode=WAL;
  }
  execsql { 







>







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
set testprefix dbpage

ifcapable !vtab||!compound {
  finish_test
  return
}

sqlite3_db_config db DEFENSIVE 0
do_test 100 {
  execsql {
    PRAGMA auto_vacuum=0;
    PRAGMA page_size=4096;
    PRAGMA journal_mode=WAL;
  }
  execsql { 
Changes to test/e_reindex.test.
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

# EVIDENCE-OF: R-52173-44778 The REINDEX command is used to delete and
# recreate indices from scratch.
#
#    Test this by corrupting some database indexes, running REINDEX, and
#    observing that the corruption is gone.
#

do_execsql_test e_reindex-1.1 {
  INSERT INTO t1 VALUES(1, 2);
  INSERT INTO t1 VALUES(3, 4);
  INSERT INTO t1 VALUES(5, 6);

  CREATE TABLE saved(a,b,c,d,e);
  INSERT INTO saved SELECT * FROM sqlite_master WHERE type = 'index';
  PRAGMA writable_schema = 1;
  DELETE FROM sqlite_master WHERE type = 'index';
} {}

db close
sqlite3 db test.db

do_execsql_test e_reindex-1.2 {
  DELETE FROM t1 WHERE a = 3;
  INSERT INTO t1 VALUES(7, 8);
  INSERT INTO t1 VALUES(9, 10);
  PRAGMA writable_schema = 1;
  INSERT INTO sqlite_master SELECT * FROM saved;
  DROP TABLE saved;







>













>







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

# EVIDENCE-OF: R-52173-44778 The REINDEX command is used to delete and
# recreate indices from scratch.
#
#    Test this by corrupting some database indexes, running REINDEX, and
#    observing that the corruption is gone.
#
sqlite3_db_config db DEFENSIVE 0
do_execsql_test e_reindex-1.1 {
  INSERT INTO t1 VALUES(1, 2);
  INSERT INTO t1 VALUES(3, 4);
  INSERT INTO t1 VALUES(5, 6);

  CREATE TABLE saved(a,b,c,d,e);
  INSERT INTO saved SELECT * FROM sqlite_master WHERE type = 'index';
  PRAGMA writable_schema = 1;
  DELETE FROM sqlite_master WHERE type = 'index';
} {}

db close
sqlite3 db test.db
sqlite3_db_config db DEFENSIVE 0
do_execsql_test e_reindex-1.2 {
  DELETE FROM t1 WHERE a = 3;
  INSERT INTO t1 VALUES(7, 8);
  INSERT INTO t1 VALUES(9, 10);
  PRAGMA writable_schema = 1;
  INSERT INTO sqlite_master SELECT * FROM saved;
  DROP TABLE saved;
Changes to test/fts3auto.test.
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
proc fts3_zero_long_segments {tbl limit} {
  sqlite3_db_config db DEFENSIVE 0
  execsql " 
    UPDATE ${tbl}_segments 
    SET block = zeroblob(length(block)) 
    WHERE length(block)>$limit
  "
  sqlite3_db_config db DEFENSIVE 1
  return [db changes]
}


proc mit {blob} {
  set scan(littleEndian) i*
  set scan(bigEndian) I*







<







136
137
138
139
140
141
142

143
144
145
146
147
148
149
proc fts3_zero_long_segments {tbl limit} {
  sqlite3_db_config db DEFENSIVE 0
  execsql " 
    UPDATE ${tbl}_segments 
    SET block = zeroblob(length(block)) 
    WHERE length(block)>$limit
  "

  return [db changes]
}


proc mit {blob} {
  set scan(littleEndian) i*
  set scan(bigEndian) I*
Changes to test/fts3cov.test.
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  SELECT * FROM t1 WHERE t1 MATCH 'c*'
} {SQL logic error}

# Test the "replaced with NULL" case:
do_test fts3cov-2.4 {
  execsql { INSERT INTO t1_segments VALUES($left_child, NULL) }
} {}
sqlite3_db_config db DEFENSIVE 1
do_error_test fts3cov-2.5 {
  SELECT * FROM t1 WHERE t1 MATCH 'cloud'
} {SQL logic error}

#--------------------------------------------------------------------------
# The following tests are to test the effects of OOM errors while storing
# terms in the pending-hash table. Specifically, while creating doclist







<







99
100
101
102
103
104
105

106
107
108
109
110
111
112
  SELECT * FROM t1 WHERE t1 MATCH 'c*'
} {SQL logic error}

# Test the "replaced with NULL" case:
do_test fts3cov-2.4 {
  execsql { INSERT INTO t1_segments VALUES($left_child, NULL) }
} {}

do_error_test fts3cov-2.5 {
  SELECT * FROM t1 WHERE t1 MATCH 'cloud'
} {SQL logic error}

#--------------------------------------------------------------------------
# The following tests are to test the effects of OOM errors while storing
# terms in the pending-hash table. Specifically, while creating doclist
Changes to test/fts3d.test.
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
do_test fts3d-5.1 {
  execsql {
    UPDATE t1_segdir SET level = 2 WHERE level = 1 AND idx = 0;
    SELECT OPTIMIZE(t1) FROM t1 LIMIT 1;
    SELECT level, idx FROM t1_segdir ORDER BY level, idx;
  }
} {{Index already optimal} 2 0}
sqlite3_db_config db DEFENSIVE 1


# ALTER TABLE RENAME should work regardless of the database encoding.
#
do_test fts3d-6.0 {
  db close
  forcedelete test.db







<







300
301
302
303
304
305
306

307
308
309
310
311
312
313
do_test fts3d-5.1 {
  execsql {
    UPDATE t1_segdir SET level = 2 WHERE level = 1 AND idx = 0;
    SELECT OPTIMIZE(t1) FROM t1 LIMIT 1;
    SELECT level, idx FROM t1_segdir ORDER BY level, idx;
  }
} {{Index already optimal} 2 0}



# ALTER TABLE RENAME should work regardless of the database encoding.
#
do_test fts3d-6.0 {
  db close
  forcedelete test.db
Changes to test/fts3defer.test.
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 1.3 {
  SELECT count(*) FROM t1_segments WHERE length(block)>10000;
  UPDATE t1_segments 
    SET block = zeroblob(length(block)) 
    WHERE length(block)>10000;
} {1}
sqlite3_db_config db DEFENSIVE 1

do_select_tests 1.4 $tests

# Drop the table. It is corrupt now anyhow, so not useful for subsequent tests.
#
do_execsql_test 1.5 { DROP TABLE t1 }








<







62
63
64
65
66
67
68

69
70
71
72
73
74
75
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 1.3 {
  SELECT count(*) FROM t1_segments WHERE length(block)>10000;
  UPDATE t1_segments 
    SET block = zeroblob(length(block)) 
    WHERE length(block)>10000;
} {1}


do_select_tests 1.4 $tests

# Drop the table. It is corrupt now anyhow, so not useful for subsequent tests.
#
do_execsql_test 1.5 { DROP TABLE t1 }

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  3 {
    set dmt_modes {0 1 2}
    execsql { CREATE VIRTUAL TABLE t1 USING FTS4 }
    foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
    add_empty_records 1000
    sqlite3_db_config db DEFENSIVE 0
    execsql $zero_long_doclists
    sqlite3_db_config db DEFENSIVE 1
  }
  4 {
    set dmt_modes 0
    execsql { CREATE VIRTUAL TABLE t1 USING FTS4 }
    foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
    add_empty_records 1000
    execsql "INSERT INTO t1(t1) VALUES('optimize')"
    sqlite3_db_config db DEFENSIVE 0
    execsql $zero_long_doclists
    sqlite3_db_config db DEFENSIVE 1
  }
  5 {
    set dmt_modes 0
    execsql { CREATE VIRTUAL TABLE t1 USING FTS4(matchinfo=fts3) }
    foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
    add_empty_records 1000
    sqlite3_db_config db DEFENSIVE 0
    execsql $zero_long_doclists
    sqlite3_db_config db DEFENSIVE 1
  }
} {

  execsql { DROP TABLE IF EXISTS t1 }
  eval $setup
  set ::testprefix fts3defer-2.$tn
  set DO_MALLOC_TEST 0







<









<








<







224
225
226
227
228
229
230

231
232
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247

248
249
250
251
252
253
254
  3 {
    set dmt_modes {0 1 2}
    execsql { CREATE VIRTUAL TABLE t1 USING FTS4 }
    foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
    add_empty_records 1000
    sqlite3_db_config db DEFENSIVE 0
    execsql $zero_long_doclists

  }
  4 {
    set dmt_modes 0
    execsql { CREATE VIRTUAL TABLE t1 USING FTS4 }
    foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
    add_empty_records 1000
    execsql "INSERT INTO t1(t1) VALUES('optimize')"
    sqlite3_db_config db DEFENSIVE 0
    execsql $zero_long_doclists

  }
  5 {
    set dmt_modes 0
    execsql { CREATE VIRTUAL TABLE t1 USING FTS4(matchinfo=fts3) }
    foreach doc $data { execsql { INSERT INTO t1 VALUES($doc) } }
    add_empty_records 1000
    sqlite3_db_config db DEFENSIVE 0
    execsql $zero_long_doclists

  }
} {

  execsql { DROP TABLE IF EXISTS t1 }
  eval $setup
  set ::testprefix fts3defer-2.$tn
  set DO_MALLOC_TEST 0
Changes to test/fts3defer2.test.
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  INSERT INTO t1(t1) VALUES('optimize');
}
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 1.1.4 {
  SELECT count(*) FROM t1_segments WHERE length(block)>10000;
  UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000;
} {2}
sqlite3_db_config db DEFENSIVE 1

do_execsql_test 1.2.0 {
  SELECT content FROM t1 WHERE t1 MATCH 'f (e a)';
} {{a b c d e f a x y}}

do_execsql_test 1.2.1 {
  SELECT content FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)';







<







47
48
49
50
51
52
53

54
55
56
57
58
59
60
  INSERT INTO t1(t1) VALUES('optimize');
}
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 1.1.4 {
  SELECT count(*) FROM t1_segments WHERE length(block)>10000;
  UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000;
} {2}


do_execsql_test 1.2.0 {
  SELECT content FROM t1 WHERE t1 MATCH 'f (e a)';
} {{a b c d e f a x y}}

do_execsql_test 1.2.1 {
  SELECT content FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)';
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
  2 { INSERT INTO t2(t2) VALUES('optimize') }
  3 { UPDATE t2_segments SET block = zeroblob(length(block)) 
      WHERE length(block)>10000;
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  execsql $sql
  sqlite3_db_config db DEFENSIVE 1

  do_execsql_test 2.2.$tn.1 {
    SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b';
  } [list                                          \
    [list 2 1  1 54 54  1 3 3  54 372 8]        \
    [list 2 1  1 54 54  1 3 3  54 372 7]        \
  ]







<







97
98
99
100
101
102
103

104
105
106
107
108
109
110
  2 { INSERT INTO t2(t2) VALUES('optimize') }
  3 { UPDATE t2_segments SET block = zeroblob(length(block)) 
      WHERE length(block)>10000;
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  execsql $sql


  do_execsql_test 2.2.$tn.1 {
    SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b';
  } [list                                          \
    [list 2 1  1 54 54  1 3 3  54 372 8]        \
    [list 2 1  1 54 54  1 3 3  54 372 7]        \
  ]
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  2 { INSERT INTO t3(t3) VALUES('optimize') }
  3 { UPDATE t3_segments SET block = zeroblob(length(block)) 
      WHERE length(block)>10000;
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  execsql $sql
  sqlite3_db_config db DEFENSIVE 1
  do_execsql_test 2.4.$tn {
    SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"';
  } {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}}
}


finish_test







<







152
153
154
155
156
157
158

159
160
161
162
163
164
165
  2 { INSERT INTO t3(t3) VALUES('optimize') }
  3 { UPDATE t3_segments SET block = zeroblob(length(block)) 
      WHERE length(block)>10000;
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  execsql $sql

  do_execsql_test 2.4.$tn {
    SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"';
  } {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}}
}


finish_test
Changes to test/fts3matchinfo.test.
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
ifcapable fts4_deferred {
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test 4.4.0.2 {
    UPDATE t5_segments 
    SET block = zeroblob(length(block)) 
    WHERE length(block)>10000;
  }
  sqlite3_db_config db DEFENSIVE 1
}

do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'}         { s {2} }
do_matchinfo_test 4.4.1 t5 {t5 MATCH 'a a'}         { s {2 1} }
do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'}         { s {2} }
do_matchinfo_test 4.4.3 t5 {t5 MATCH 'a b a'}       { s {3} }
do_matchinfo_test 4.4.4 t5 {t5 MATCH 'a a a'}       { s {3 1} }







<







280
281
282
283
284
285
286

287
288
289
290
291
292
293
ifcapable fts4_deferred {
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test 4.4.0.2 {
    UPDATE t5_segments 
    SET block = zeroblob(length(block)) 
    WHERE length(block)>10000;
  }

}

do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'}         { s {2} }
do_matchinfo_test 4.4.1 t5 {t5 MATCH 'a a'}         { s {2 1} }
do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'}         { s {2} }
do_matchinfo_test 4.4.3 t5 {t5 MATCH 'a b a'}       { s {3} }
do_matchinfo_test 4.4.4 t5 {t5 MATCH 'a a a'}       { s {3 1} }
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
} {{0 0 20 2 0 0 27 2}}

sqlite3_db_config db DEFENSIVE 0
do_catchsql_test 6.2 {
  UPDATE t9_content SET c0content = 'this record is used to'; 
  SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to';
} {1 {database disk image is malformed}}
sqlite3_db_config db DEFENSIVE 1

#-------------------------------------------------------------------------
# Test the outcome of matchinfo() when used within a query that does not
# use the full-text index (i.e. lookup by rowid or full-table scan).
#
do_execsql_test 7.1 {
  CREATE VIRTUAL TABLE t10 USING fts4;







<







341
342
343
344
345
346
347

348
349
350
351
352
353
354
} {{0 0 20 2 0 0 27 2}}

sqlite3_db_config db DEFENSIVE 0
do_catchsql_test 6.2 {
  UPDATE t9_content SET c0content = 'this record is used to'; 
  SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to';
} {1 {database disk image is malformed}}


#-------------------------------------------------------------------------
# Test the outcome of matchinfo() when used within a query that does not
# use the full-text index (i.e. lookup by rowid or full-table scan).
#
do_execsql_test 7.1 {
  CREATE VIRTUAL TABLE t10 USING fts4;
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
  SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*'
} {1 {database disk image is malformed}}

do_execsql_test  8.4.3.1 { UPDATE t11_stat SET value = NULL; }
do_catchsql_test 8.5.3.2 {
  SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*'
} {1 {database disk image is malformed}}
sqlite3_db_config db DEFENSIVE 1

#-------------------------------------------------------------------------
do_execsql_test 8.1 {
  CREATE VIRTUAL TABLE t12 USING fts4;
  INSERT INTO t12 VALUES('a b c d');
  SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a';
} {{0 0 0 0 0 0 1 1 1}}







<







405
406
407
408
409
410
411

412
413
414
415
416
417
418
  SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*'
} {1 {database disk image is malformed}}

do_execsql_test  8.4.3.1 { UPDATE t11_stat SET value = NULL; }
do_catchsql_test 8.5.3.2 {
  SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*'
} {1 {database disk image is malformed}}


#-------------------------------------------------------------------------
do_execsql_test 8.1 {
  CREATE VIRTUAL TABLE t12 USING fts4;
  INSERT INTO t12 VALUES('a b c d');
  SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a';
} {{0 0 0 0 0 0 1 1 1}}
Changes to test/fts3query.test.
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
  1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo
  2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'"   offsets
  3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'"   snippet
  4 "SELECT optimize(content) FROM t2 WHERE t2 MATCH 'history'"  optimize
}
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 5.4.0 { UPDATE t2_content SET c0content = X'1234' }
sqlite3_db_config db DEFENSIVE 1
do_select_tests 5.4 -errorformat {
  illegal first argument to %s
} {
  1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo
  2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'"   offsets
  3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'"   snippet
  4 "SELECT optimize(content) FROM t2 WHERE t2 MATCH 'history'"  optimize







<







165
166
167
168
169
170
171

172
173
174
175
176
177
178
  1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo
  2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'"   offsets
  3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'"   snippet
  4 "SELECT optimize(content) FROM t2 WHERE t2 MATCH 'history'"  optimize
}
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 5.4.0 { UPDATE t2_content SET c0content = X'1234' }

do_select_tests 5.4 -errorformat {
  illegal first argument to %s
} {
  1 "SELECT matchinfo(content) FROM t2 WHERE t2 MATCH 'history'" matchinfo
  2 "SELECT offsets(content) FROM t2 WHERE t2 MATCH 'history'"   offsets
  3 "SELECT snippet(content) FROM t2 WHERE t2 MATCH 'history'"   snippet
  4 "SELECT optimize(content) FROM t2 WHERE t2 MATCH 'history'"  optimize
Changes to test/fts3snippet.test.
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
  set off [string first "onehundred " $numbers]
  do_offsets_test $T.2.2 {onehundred} \
    [list 0 0 $off 10 1 0 $off 10] [list 0 0 $off 10]

  # Test a corruption case:
  sqlite3_db_config db DEFENSIVE 0
  execsql { UPDATE ft_content SET c1b = 'hello world' WHERE c1b = $numbers }
  sqlite3_db_config db DEFENSIVE 1
  do_error_test $T.2.3 {
    SELECT offsets(ft) FROM ft WHERE ft MATCH 'onehundred'
  } {database disk image is malformed}
  
  ##########################################################################
  # Test the snippet function.
  #







<







182
183
184
185
186
187
188

189
190
191
192
193
194
195
  set off [string first "onehundred " $numbers]
  do_offsets_test $T.2.2 {onehundred} \
    [list 0 0 $off 10 1 0 $off 10] [list 0 0 $off 10]

  # Test a corruption case:
  sqlite3_db_config db DEFENSIVE 0
  execsql { UPDATE ft_content SET c1b = 'hello world' WHERE c1b = $numbers }

  do_error_test $T.2.3 {
    SELECT offsets(ft) FROM ft WHERE ft MATCH 'onehundred'
  } {database disk image is malformed}
  
  ##########################################################################
  # Test the snippet function.
  #
Changes to test/fts4check.test.
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
    DELETE FROM t1_segdir WHERE level=0 AND idx=(
      SELECT max(idx) FROM t1_segdir WHERE level=0
    );
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test  1.2.1.$tn "BEGIN; $disruption"
  sqlite3_db_config db DEFENSIVE 1
  do_catchsql_test 1.2.2.$tn {
    INSERT INTO t1 (t1) VALUES('integrity-check')
  } {1 {database disk image is malformed}}
  do_execsql_test  1.2.3.$tn "ROLLBACK"
}

do_test 1.3 { fts_integrity db t1 } {ok}







<







64
65
66
67
68
69
70

71
72
73
74
75
76
77
    DELETE FROM t1_segdir WHERE level=0 AND idx=(
      SELECT max(idx) FROM t1_segdir WHERE level=0
    );
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test  1.2.1.$tn "BEGIN; $disruption"

  do_catchsql_test 1.2.2.$tn {
    INSERT INTO t1 (t1) VALUES('integrity-check')
  } {1 {database disk image is malformed}}
  do_execsql_test  1.2.3.$tn "ROLLBACK"
}

do_test 1.3 { fts_integrity db t1 } {ok}
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
    DELETE FROM t2_segdir WHERE level=0 AND idx=(
      SELECT max(idx) FROM t2_segdir WHERE level=1024
    );
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test  2.2.1.$tn "BEGIN; $disruption"
  sqlite3_db_config db DEFENSIVE 1
  do_catchsql_test 2.2.2.$tn {
    INSERT INTO t2 (t2) VALUES('integrity-check')
  } {1 {database disk image is malformed}}
  do_execsql_test  2.2.3.$tn "ROLLBACK"
}









<







99
100
101
102
103
104
105

106
107
108
109
110
111
112
    DELETE FROM t2_segdir WHERE level=0 AND idx=(
      SELECT max(idx) FROM t2_segdir WHERE level=1024
    );
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test  2.2.1.$tn "BEGIN; $disruption"

  do_catchsql_test 2.2.2.$tn {
    INSERT INTO t2 (t2) VALUES('integrity-check')
  } {1 {database disk image is malformed}}
  do_execsql_test  2.2.3.$tn "ROLLBACK"
}


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    UPDATE t3_content SET langid=langid+1 WHERE rowid = (
      SELECT max(rowid) FROM t3_content
    )
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test  3.2.1.$tn "BEGIN; $disruption"
  sqlite3_db_config db DEFENSIVE 1
  do_catchsql_test 3.2.2.$tn {
    INSERT INTO t3 (t3) VALUES('integrity-check')
  } {1 {database disk image is malformed}}
  do_execsql_test  3.2.3.$tn "ROLLBACK"
}

#--------------------------------------------------------------------------







<







145
146
147
148
149
150
151

152
153
154
155
156
157
158
    UPDATE t3_content SET langid=langid+1 WHERE rowid = (
      SELECT max(rowid) FROM t3_content
    )
  }
} {
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test  3.2.1.$tn "BEGIN; $disruption"

  do_catchsql_test 3.2.2.$tn {
    INSERT INTO t3 (t3) VALUES('integrity-check')
  } {1 {database disk image is malformed}}
  do_execsql_test  3.2.3.$tn "ROLLBACK"
}

#--------------------------------------------------------------------------
Changes to test/fts4merge.test.
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
  
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test 4.4.2 {
    DELETE FROM t4_stat WHERE rowid=1;
    INSERT INTO t4(t4) VALUES('merge=1,12');
    SELECT level, group_concat(idx, ' ') FROM t4_segdir GROUP BY level;
  } "0 {0 1 2 3 4 5}                     1 0"
  sqlite3_db_config db DEFENSIVE 1
  
  
  #-------------------------------------------------------------------------
  # Test cases 5.*
  #
  # Test that if a crisis-merge occurs that disrupts an ongoing incremental
  # merge, the next call to "merge=A,B" identifies this and starts a new







<







158
159
160
161
162
163
164

165
166
167
168
169
170
171
  
  sqlite3_db_config db DEFENSIVE 0
  do_execsql_test 4.4.2 {
    DELETE FROM t4_stat WHERE rowid=1;
    INSERT INTO t4(t4) VALUES('merge=1,12');
    SELECT level, group_concat(idx, ' ') FROM t4_segdir GROUP BY level;
  } "0 {0 1 2 3 4 5}                     1 0"

  
  
  #-------------------------------------------------------------------------
  # Test cases 5.*
  #
  # Test that if a crisis-merge occurs that disrupts an ongoing incremental
  # merge, the next call to "merge=A,B" identifies this and starts a new
Changes to test/fts4opt.test.
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  
      DELETE FROM %_segdir;
      INSERT INTO %_segdir SELECT * FROM temp.tmp_segdir;
      DROP TABLE temp.tmp_segdir;
  
    COMMIT;
  }]
  sqlite3_db_config $db DEFENSIVE 1
}

do_test 1.1 {
  execsql { CREATE VIRTUAL TABLE t2 USING fts4(words, prefix="1,2,3") }
  foreach {docid words} [db eval { SELECT * FROM t1 }] {
    execsql { INSERT INTO t2(docid, words) VALUES($docid, $words) }
  }







<







55
56
57
58
59
60
61

62
63
64
65
66
67
68
  
      DELETE FROM %_segdir;
      INSERT INTO %_segdir SELECT * FROM temp.tmp_segdir;
      DROP TABLE temp.tmp_segdir;
  
    COMMIT;
  }]

}

do_test 1.1 {
  execsql { CREATE VIRTUAL TABLE t2 USING fts4(words, prefix="1,2,3") }
  foreach {docid words} [db eval { SELECT * FROM t1 }] {
    execsql { INSERT INTO t2(docid, words) VALUES($docid, $words) }
  }
Changes to test/index.test.
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# tested somewhere.
do_test index-18.1 {
  catchsql {
    CREATE TABLE sqlite_t1(a, b, c);
  }
} {1 {object name reserved for internal use: sqlite_t1}}
do_test index-18.1.2 {
  sqlite3_db_config db DEFENSIVE 1
  catchsql {
    CREATE TABLE sqlite_t1(a, b, c);
  }
} {1 {object name reserved for internal use: sqlite_t1}}
sqlite3_db_config db DEFENSIVE 0
do_test index-18.2 {
  catchsql {







<







622
623
624
625
626
627
628

629
630
631
632
633
634
635
# tested somewhere.
do_test index-18.1 {
  catchsql {
    CREATE TABLE sqlite_t1(a, b, c);
  }
} {1 {object name reserved for internal use: sqlite_t1}}
do_test index-18.1.2 {

  catchsql {
    CREATE TABLE sqlite_t1(a, b, c);
  }
} {1 {object name reserved for internal use: sqlite_t1}}
sqlite3_db_config db DEFENSIVE 0
do_test index-18.2 {
  catchsql {
Changes to test/index3.test.
79
80
81
82
83
84
85

86
87
88
89
90
91
92



# This test corrupts the database file so it must be the last test
# in the series.
#
do_test index3-99.1 {

  execsql {
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET sql='nonsense' WHERE name='t1d'
  }
  db close
  catch { sqlite3 db test.db }
  catchsql { DROP INDEX t1c }







>







79
80
81
82
83
84
85
86
87
88
89
90
91
92
93



# This test corrupts the database file so it must be the last test
# in the series.
#
do_test index3-99.1 {
  sqlite3_db_config db DEFENSIVE 0
  execsql {
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET sql='nonsense' WHERE name='t1d'
  }
  db close
  catch { sqlite3 db test.db }
  catchsql { DROP INDEX t1c }
Changes to test/misc1.test.
655
656
657
658
659
660
661

662
663
664
665
666
667
668
669
670
671
672
673
674
675
676

677
678
679
680
681
682
683
684
685
686
687

688
689
690
691
692
693
694
  SELECT ""+3 FROM (SELECT ""+5);
} {3}

# 2015-04-19: NULL pointer dereference on a corrupt schema
#
db close
sqlite3 db :memory:

do_execsql_test misc1-23.1 {
  CREATE TABLE t1(x);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE table t(d CHECK(T(#0)';
  BEGIN;
  CREATE TABLE t2(y);
  ROLLBACK;
  DROP TABLE IF EXISTS t3;
} {}

# 2015-04-19:  Faulty assert() statement
#
db close
database_may_be_corrupt
sqlite3 db :memory:

do_catchsql_test misc1-23.2 {
  CREATE TABLE t1(x UNIQUE);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE TABLE IF not EXISTS t(c)';
  BEGIN;
  CREATE TABLE t2(x);
  ROLLBACK;
  DROP TABLE F;
} {1 {no such table: F}}
db close
sqlite3 db :memory:

do_catchsql_test misc1-23.3 {
  CREATE TABLE t1(x UNIQUE);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE table y(a TEXT, a TEXT)';
  BEGIN;
  CREATE TABLE t2(y);
  ROLLBACK;







>















>











>







655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
  SELECT ""+3 FROM (SELECT ""+5);
} {3}

# 2015-04-19: NULL pointer dereference on a corrupt schema
#
db close
sqlite3 db :memory:
sqlite3_db_config db DEFENSIVE 0
do_execsql_test misc1-23.1 {
  CREATE TABLE t1(x);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE table t(d CHECK(T(#0)';
  BEGIN;
  CREATE TABLE t2(y);
  ROLLBACK;
  DROP TABLE IF EXISTS t3;
} {}

# 2015-04-19:  Faulty assert() statement
#
db close
database_may_be_corrupt
sqlite3 db :memory:
sqlite3_db_config db DEFENSIVE 0
do_catchsql_test misc1-23.2 {
  CREATE TABLE t1(x UNIQUE);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE TABLE IF not EXISTS t(c)';
  BEGIN;
  CREATE TABLE t2(x);
  ROLLBACK;
  DROP TABLE F;
} {1 {no such table: F}}
db close
sqlite3 db :memory:
sqlite3_db_config db DEFENSIVE 0
do_catchsql_test misc1-23.3 {
  CREATE TABLE t1(x UNIQUE);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE table y(a TEXT, a TEXT)';
  BEGIN;
  CREATE TABLE t2(y);
  ROLLBACK;
Changes to test/misc4.test.
208
209
210
211
212
213
214

215
216
217
218
219
220
221
  }
} {1}

# 2015-05-15.  Error message formatting problem.
#
db close
sqlite3 db :memory:

do_catchsql_test misc4-7.1 {
  CREATE TABLE t7(x);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE TABLE [M%s%s%s%s%s%s%s%s%s%s%s%s%s';
  VACUUM;
} {1 {unrecognized token: "[M%s%s%s%s%s%s%s%s%s%s%s%s%s"}}








>







208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  }
} {1}

# 2015-05-15.  Error message formatting problem.
#
db close
sqlite3 db :memory:
sqlite3_db_config db DEFENSIVE 0
do_catchsql_test misc4-7.1 {
  CREATE TABLE t7(x);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE TABLE [M%s%s%s%s%s%s%s%s%s%s%s%s%s';
  VACUUM;
} {1 {unrecognized token: "[M%s%s%s%s%s%s%s%s%s%s%s%s%s"}}

Changes to test/misc5.test.
586
587
588
589
590
591
592

593
594
595
596
597
598
599
} {1 {parser stack overflow}}

# Parser stack overflow is silently ignored when it occurs while parsing the
# schema and PRAGMA writable_schema is turned on.
#
do_test misc5-7.2 {
  sqlite3 db2 :memory:

  catchsql {
    CREATE TABLE t1(x UNIQUE);
    PRAGMA writable_schema=ON;
    UPDATE sqlite_master SET sql='CREATE table t(o CHECK(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((;VALUES(o)';
    BEGIN;
    CREATE TABLE t2(y);
    ROLLBACK;







>







586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
} {1 {parser stack overflow}}

# Parser stack overflow is silently ignored when it occurs while parsing the
# schema and PRAGMA writable_schema is turned on.
#
do_test misc5-7.2 {
  sqlite3 db2 :memory:
  sqlite3_db_config db2 DEFENSIVE 0
  catchsql {
    CREATE TABLE t1(x UNIQUE);
    PRAGMA writable_schema=ON;
    UPDATE sqlite_master SET sql='CREATE table t(o CHECK(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((;VALUES(o)';
    BEGIN;
    CREATE TABLE t2(y);
    ROLLBACK;
Changes to test/mjournal.test.
156
157
158
159
160
161
162
163
  BEGIN;
    INSERT INTO t1 VALUES(1);
    INSERT INTO t4 VALUES(1);
  COMMIT;
} {0}

finish_test








<
156
157
158
159
160
161
162

  BEGIN;
    INSERT INTO t1 VALUES(1);
    INSERT INTO t4 VALUES(1);
  COMMIT;
} {0}

finish_test

Changes to test/notnull.test.
602
603
604
605
606
607
608
609
do_uses_op_next_test notnull-6.7 "SELECT * FROM t7 WHERE a IS ?" 0
do_uses_op_next_test notnull-6.8 "SELECT * FROM t8 WHERE a IS ?" 0

do_uses_op_next_test notnull-6.9 "SELECT * FROM t8 WHERE a IS ?" 0
do_uses_op_next_test notnull-6.10 "SELECT * FROM t8 WHERE a IS ?" 0

finish_test








<
602
603
604
605
606
607
608

do_uses_op_next_test notnull-6.7 "SELECT * FROM t7 WHERE a IS ?" 0
do_uses_op_next_test notnull-6.8 "SELECT * FROM t8 WHERE a IS ?" 0

do_uses_op_next_test notnull-6.9 "SELECT * FROM t8 WHERE a IS ?" 0
do_uses_op_next_test notnull-6.10 "SELECT * FROM t8 WHERE a IS ?" 0

finish_test

Changes to test/pager1.test.
1875
1876
1877
1878
1879
1880
1881

1882
1883
1884
1885
1886
1887
1888
    INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1;
    INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1;
  }
} {}
do_test pager1-18.2 {
  set root [db one "SELECT rootpage FROM sqlite_master"]
  set lockingpage [expr (0x10000/1024) + 1]

  execsql {
    PRAGMA writable_schema = 1;
    UPDATE sqlite_master SET rootpage = $lockingpage;
  }
  sqlite3 db2 test.db
  catchsql { SELECT count(*) FROM t1 } db2
} {1 {database disk image is malformed}}







>







1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
    INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1;
    INSERT INTO t1 SELECT a_string(500), a_string(200) FROM t1;
  }
} {}
do_test pager1-18.2 {
  set root [db one "SELECT rootpage FROM sqlite_master"]
  set lockingpage [expr (0x10000/1024) + 1]
  sqlite3_db_config db DEFENSIVE 0
  execsql {
    PRAGMA writable_schema = 1;
    UPDATE sqlite_master SET rootpage = $lockingpage;
  }
  sqlite3 db2 test.db
  catchsql { SELECT count(*) FROM t1 } db2
} {1 {database disk image is malformed}}
1927
1928
1929
1930
1931
1932
1933

1934
1935
1936
1937
1938
1939
1940
  hexio_write test.db [expr ($pgno-1)*1024] 90000000
  sqlite3 db2 test.db
  catchsql { SELECT length(x||'') FROM t2 } db2
} {1 {database disk image is malformed}}
db2 close
do_test pager1-18.5 {
  sqlite3 db ""

  execsql {
    CREATE TABLE t1(a, b);
    CREATE TABLE t2(a, b);
    PRAGMA writable_schema = 1;
    UPDATE sqlite_master SET rootpage=5 WHERE tbl_name = 't1';
    PRAGMA writable_schema = 0;
    ALTER TABLE t1 RENAME TO x1;







>







1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
  hexio_write test.db [expr ($pgno-1)*1024] 90000000
  sqlite3 db2 test.db
  catchsql { SELECT length(x||'') FROM t2 } db2
} {1 {database disk image is malformed}}
db2 close
do_test pager1-18.5 {
  sqlite3 db ""
  sqlite3_db_config db DEFENSIVE 0
  execsql {
    CREATE TABLE t1(a, b);
    CREATE TABLE t2(a, b);
    PRAGMA writable_schema = 1;
    UPDATE sqlite_master SET rootpage=5 WHERE tbl_name = 't1';
    PRAGMA writable_schema = 0;
    ALTER TABLE t1 RENAME TO x1;
Changes to test/parser1.test.
24
25
26
27
28
29
30

31
32
33
34
35
36
37
} {1 {syntax error after column name "b"}}


# Verify that a legacy schema in the sqlite_master file is allowed to have
# COLLATE, ASC, and DESC keywords on the id list of a FK constraint, and that
# those keywords are silently ignored.
#

do_execsql_test parser1-1.2 {
  CREATE TABLE t1(
    a TEXT PRIMARY KEY,
    b TEXT,
    FOREIGN KEY(b) REFERENCES t1(a)
  );
  INSERT INTO t1 VALUES('abc',NULL),('xyz','abc');







>







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
} {1 {syntax error after column name "b"}}


# Verify that a legacy schema in the sqlite_master file is allowed to have
# COLLATE, ASC, and DESC keywords on the id list of a FK constraint, and that
# those keywords are silently ignored.
#
sqlite3_db_config db DEFENSIVE 0
do_execsql_test parser1-1.2 {
  CREATE TABLE t1(
    a TEXT PRIMARY KEY,
    b TEXT,
    FOREIGN KEY(b) REFERENCES t1(a)
  );
  INSERT INTO t1 VALUES('abc',NULL),('xyz','abc');
Changes to test/pragma.test.
493
494
495
496
497
498
499

500
501
502
503
504
505
506
    db eval {PRAGMA integrity_check}
  } {ok}
}

# Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL
# constraint violations.
#

do_execsql_test pragma-3.20 {
  CREATE TABLE t1(a,b);
  CREATE INDEX t1a ON t1(a);
  INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)'
   WHERE name='t1a';







>







493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
    db eval {PRAGMA integrity_check}
  } {ok}
}

# Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL
# constraint violations.
#
sqlite3_db_config db DEFENSIVE 0
do_execsql_test pragma-3.20 {
  CREATE TABLE t1(a,b);
  CREATE INDEX t1a ON t1(a);
  INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6);
  PRAGMA writable_schema=ON;
  UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)'
   WHERE name='t1a';
Changes to test/resetdb.test.
61
62
63
64
65
66
67

68
69
70
71
72
73
74
    PRAGMA page_count;
  } db2
} {210 6000 ok delete 8}

do_test 200 {
  # Thoroughly corrupt the database file by overwriting the first
  # page with randomness.

  catchsql {
    UPDATE sqlite_dbpage SET data=randomblob(4096) WHERE pgno=1;
    PRAGMA quick_check;
  }
} {1 {unsupported file format}}
do_test 201 {
  catchsql {







>







61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
    PRAGMA page_count;
  } db2
} {210 6000 ok delete 8}

do_test 200 {
  # Thoroughly corrupt the database file by overwriting the first
  # page with randomness.
  sqlite3_db_config db DEFENSIVE 0
  catchsql {
    UPDATE sqlite_dbpage SET data=randomblob(4096) WHERE pgno=1;
    PRAGMA quick_check;
  }
} {1 {unsupported file format}}
do_test 201 {
  catchsql {
121
122
123
124
125
126
127

128
129
130
131
132
133
134
    PRAGMA journal_mode;
    PRAGMA page_size;
    PRAGMA page_count;
  } db2
} {210 26000 ok wal 8192 12}

# Corrupt the database again

do_catchsql_test 320 {
  UPDATE sqlite_dbpage SET data=randomblob(8192) WHERE pgno=1;
  PRAGMA quick_check
} {1 {file is not a database}}

do_test 330 {
  catchsql {







>







122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    PRAGMA journal_mode;
    PRAGMA page_size;
    PRAGMA page_count;
  } db2
} {210 26000 ok wal 8192 12}

# Corrupt the database again
sqlite3_db_config db DEFENSIVE 0
do_catchsql_test 320 {
  UPDATE sqlite_dbpage SET data=randomblob(8192) WHERE pgno=1;
  PRAGMA quick_check
} {1 {file is not a database}}

do_test 330 {
  catchsql {
224
225
226
227
228
229
230

231
232
233
234
235
236
237
} {19 ok}

if {[nonzero_reserved_bytes]} {
  finish_test
  return
}


do_execsql_test 710 {
  UPDATE sqlite_dbpage SET data=
    X'53514C69746520666F726D61742033000200030100402020000000000000001300000000000000000000000300000004000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000D00000003017C0001D801AC017C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002E03061715110145696E6465787431626374310443524541544520494E4445582074316263204F4E20743128622C63292A0206171311013F696E64657874316174310343524541544520494E44455820743161204F4E20743128612926010617111101397461626C657431743102435245415445205441424C4520743128612C622C6329' WHERE pgno=1;
}

do_execsql_test 720 {
  PRAGMA integrity_check;







>







226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
} {19 ok}

if {[nonzero_reserved_bytes]} {
  finish_test
  return
}

sqlite3_db_config db DEFENSIVE 0
do_execsql_test 710 {
  UPDATE sqlite_dbpage SET data=
    X'53514C69746520666F726D61742033000200030100402020000000000000001300000000000000000000000300000004000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000D00000003017C0001D801AC017C00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002E03061715110145696E6465787431626374310443524541544520494E4445582074316263204F4E20743128622C63292A0206171311013F696E64657874316174310343524541544520494E44455820743161204F4E20743128612926010617111101397461626C657431743102435245415445205441424C4520743128612C622C6329' WHERE pgno=1;
}

do_execsql_test 720 {
  PRAGMA integrity_check;
Changes to test/shared8.test.
58
59
60
61
62
63
64

65
66
67
68
69
70
71
    INSERT INTO t1 VALUES(4, 4);
    CREATE VIEW v1 AS SELECT a, roman(b) FROM t1;
    SELECT * FROM v1;
  } db1
} {1 i 2 ii 3 iii 4 iv}

do_test 1.1 {

  execsql { 
    PRAGMA writable_schema = 1;
    DELETE FROM sqlite_master WHERE 1;
    PRAGMA writable_schema = 0;
    SELECT * FROM sqlite_master;
  } db1
} {}







>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
    INSERT INTO t1 VALUES(4, 4);
    CREATE VIEW v1 AS SELECT a, roman(b) FROM t1;
    SELECT * FROM v1;
  } db1
} {1 i 2 ii 3 iii 4 iv}

do_test 1.1 {
  sqlite3_db_config db1 DEFENSIVE 0
  execsql { 
    PRAGMA writable_schema = 1;
    DELETE FROM sqlite_master WHERE 1;
    PRAGMA writable_schema = 0;
    SELECT * FROM sqlite_master;
  } db1
} {}
Changes to test/snapshot2.test.
234
235
236
237
238
239
240
241
  execsql { INSERT INTO t2 VALUES('jkl') } 
  execsql BEGIN db2
  list [catch { sqlite3_snapshot_open_blob db2 main $snap } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}


finish_test








<
234
235
236
237
238
239
240

  execsql { INSERT INTO t2 VALUES('jkl') } 
  execsql BEGIN db2
  list [catch { sqlite3_snapshot_open_blob db2 main $snap } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}


finish_test

Changes to test/snapshot3.test.
93
94
95
96
97
98
99
100

do_test 1.8 {
  execsql BEGIN db3
  list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}

finish_test








<
93
94
95
96
97
98
99


do_test 1.8 {
  execsql BEGIN db3
  list [catch { sqlite3_snapshot_open_blob db3 main $snap } msg] $msg
} {1 SQLITE_ERROR_SNAPSHOT}

finish_test

Changes to test/snapshot4.test.
68
69
70
71
72
73
74
75
  execsql {
    SELECT count(*) FROM t1
  } 
} {100}


finish_test








<
68
69
70
71
72
73
74

  execsql {
    SELECT count(*) FROM t1
  } 
} {100}


finish_test

Changes to test/snapshot_up.test.
177
178
179
180
181
182
183
184
  set ::res
} {1 SQLITE_BUSY}

sqlite3_snapshot_free $::snap1
sqlite3_snapshot_free $::snap2

finish_test








<
177
178
179
180
181
182
183

  set ::res
} {1 SQLITE_BUSY}

sqlite3_snapshot_free $::snap1
sqlite3_snapshot_free $::snap2

finish_test

Changes to test/swarmvtab3.test.
227
228
229
230
231
232
233
234
}

db close
forcedelete {*}[glob test.db*]
forcedelete {*}[glob test_remote.db*]

finish_test








<
227
228
229
230
231
232
233

}

db close
forcedelete {*}[glob test.db*]
forcedelete {*}[glob test_remote.db*]

finish_test

Changes to test/swarmvtabfault.test.
59
60
61
62
63
64
65
66
} -body {
  execsql { SELECT a FROM xyz }
} -test {
  faultsim_test_result {0 {1 2 9}} {1 {sql error: out of memory}}
}

finish_test








<
59
60
61
62
63
64
65

} -body {
  execsql { SELECT a FROM xyz }
} -test {
  faultsim_test_result {0 {1 2 9}} {1 {sql error: out of memory}}
}

finish_test

Changes to test/table.test.
272
273
274
275
276
277
278

279
280
281
282
283
284
285
  }
} {}

do_test table-5.2.2 {
  db close
  forcedelete test.db
  sqlite3 db test.db

  db eval {
    CREATE TABLE t0(a,b);
    CREATE INDEX t ON t0(a);
    PRAGMA writable_schema=ON;
    UPDATE sqlite_master SET sql='CREATE TABLE a.b(a UNIQUE';
    BEGIN;
    CREATE TABLE t1(x);







>







272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
  }
} {}

do_test table-5.2.2 {
  db close
  forcedelete test.db
  sqlite3 db test.db
  sqlite3_db_config db DEFENSIVE 0
  db eval {
    CREATE TABLE t0(a,b);
    CREATE INDEX t ON t0(a);
    PRAGMA writable_schema=ON;
    UPDATE sqlite_master SET sql='CREATE TABLE a.b(a UNIQUE';
    BEGIN;
    CREATE TABLE t1(x);
Changes to test/tester.tcl.
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
      if {[info exists ::G(perm:presql)]} {
        [lindex $args 0] eval $::G(perm:presql)
      }
      if {[info exists ::G(perm:dbconfig)]} {
        set ::dbhandle [lindex $args 0]
        uplevel #0 $::G(perm:dbconfig)
      }
      sqlite3_db_config [lindex $args 0] DEFENSIVE 1
      set res
    } else {
      # This command is not opening a new database connection. Pass the
      # arguments through to the C implementation as the are.
      #
      uplevel 1 sqlite_orig $args
    }







<







125
126
127
128
129
130
131

132
133
134
135
136
137
138
      if {[info exists ::G(perm:presql)]} {
        [lindex $args 0] eval $::G(perm:presql)
      }
      if {[info exists ::G(perm:dbconfig)]} {
        set ::dbhandle [lindex $args 0]
        uplevel #0 $::G(perm:dbconfig)
      }

      set res
    } else {
      # This command is not opening a new database connection. Pass the
      # arguments through to the C implementation as the are.
      #
      uplevel 1 sqlite_orig $args
    }
Changes to test/trigger7.test.
102
103
104
105
106
107
108

109
110
111
112
113
114
115
  }
} {}

# This test corrupts the database file so it must be the last test
# in the series.
#
do_test trigger7-99.1 {

  execsql {
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET sql='nonsense';
  }
  db close
  catch { sqlite3 db test.db }
  catchsql { DROP TRIGGER t2r5 }







>







102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  }
} {}

# This test corrupts the database file so it must be the last test
# in the series.
#
do_test trigger7-99.1 {
  sqlite3_db_config db DEFENSIVE 0
  execsql {
    PRAGMA writable_schema=on;
    UPDATE sqlite_master SET sql='nonsense';
  }
  db close
  catch { sqlite3 db test.db }
  catchsql { DROP TRIGGER t2r5 }
Changes to test/triggerE.test.
64
65
66
67
68
69
70

71
72
73
74
75
76
77
  do_catchsql_test 1.2.$tn "CREATE TEMP TRIGGER tr1 $defn" [list 1 $errmsg]
}

#-------------------------------------------------------------------------
# Test that variable references within trigger definitions loaded from 
# the sqlite_master table are automatically converted to NULL.
#

do_execsql_test 2.1 {
  PRAGMA writable_schema = 1;
  INSERT INTO sqlite_master VALUES('trigger', 'tr1', 't1', 0,
    'CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN 
        INSERT INTO t2 VALUES(?1, ?2); 
     END'
  );







>







64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
  do_catchsql_test 1.2.$tn "CREATE TEMP TRIGGER tr1 $defn" [list 1 $errmsg]
}

#-------------------------------------------------------------------------
# Test that variable references within trigger definitions loaded from 
# the sqlite_master table are automatically converted to NULL.
#
sqlite3_db_config db DEFENSIVE 0
do_execsql_test 2.1 {
  PRAGMA writable_schema = 1;
  INSERT INTO sqlite_master VALUES('trigger', 'tr1', 't1', 0,
    'CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN 
        INSERT INTO t2 VALUES(?1, ?2); 
     END'
  );
Changes to test/unionvtab.test.
451
452
453
454
455
456
457
458
} {five six seven eight nine}

do_execsql_test 5.4 {
  SELECT * FROM cc WHERE two LIKE '6'
} {six 6}

finish_test








<
451
452
453
454
455
456
457

} {five six seven eight nine}

do_execsql_test 5.4 {
  SELECT * FROM cc WHERE two LIKE '6'
} {six 6}

finish_test

Changes to test/unionvtabfault.test.
77
78
79
80
81
82
83
84
} -test {
  faultsim_test_result {0 {}} {1 {initialization of unionvtab failed: }}
}



finish_test








<
77
78
79
80
81
82
83

} -test {
  faultsim_test_result {0 {}} {1 {initialization of unionvtab failed: }}
}



finish_test

Changes to test/vtab1.test.
1249
1250
1251
1252
1253
1254
1255

1256
1257
1258
1259
1260
1261
1262

# The following test case exposes an instance in sqlite3_declare_vtab()
# an error message was set using a call similar to sqlite3_mprintf(zErr),
# where zErr is an arbitrary string. This is no good if the string contains
# characters that can be mistaken for printf() formatting directives.
#
do_test vtab1-17.1 {

  execsql { 
    PRAGMA writable_schema = 1;
    INSERT INTO sqlite_master VALUES(
      'table', 't3', 't3', 0, 'INSERT INTO "%s%s" VALUES(1)'
    );
  }
  catchsql { CREATE VIRTUAL TABLE t4 USING echo(t3); }







>







1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263

# The following test case exposes an instance in sqlite3_declare_vtab()
# an error message was set using a call similar to sqlite3_mprintf(zErr),
# where zErr is an arbitrary string. This is no good if the string contains
# characters that can be mistaken for printf() formatting directives.
#
do_test vtab1-17.1 {
  sqlite3_db_config db DEFENSIVE 0
  execsql { 
    PRAGMA writable_schema = 1;
    INSERT INTO sqlite_master VALUES(
      'table', 't3', 't3', 0, 'INSERT INTO "%s%s" VALUES(1)'
    );
  }
  catchsql { CREATE VIRTUAL TABLE t4 USING echo(t3); }
Changes to test/wherelimit2.test.
293
294
295
296
297
298
299
300
  set ::log {}
  execsql { UPDATE "v w" SET "a b" = "a b" || 'x' ORDER BY "a b" LIMIT 5; }
  set ::log
} {ax a bx b cx c dx d ex a}


finish_test








<
293
294
295
296
297
298
299

  set ::log {}
  execsql { UPDATE "v w" SET "a b" = "a b" || 'x' ORDER BY "a b" LIMIT 5; }
  set ::log
} {ax a bx b cx c dx d ex a}


finish_test

Changes to test/window5.test.
90
91
92
93
94
95
96
97
} {1 {sum() may not be used as a window function}}
do_execsql_test 3.1 {
  SELECT sum(a) FROM t1;
} {21}


finish_test








<
90
91
92
93
94
95
96

} {1 {sum() may not be used as a window function}}
do_execsql_test 3.1 {
  SELECT sum(a) FROM t1;
} {21}


finish_test

Changes to test/windowfault.test.
159
160
161
162
163
164
165
166
    ORDER BY a;
  }
} -test {
  faultsim_test_result {0 {1 2 5 6 9 10}}
}

finish_test








<
159
160
161
162
163
164
165

    ORDER BY a;
  }
} -test {
  faultsim_test_result {0 {1 2 5 6 9 10}}
}

finish_test

Changes to test/zipfile2.test.
237
238
239
240
241
242
243
244
  INSERT INTO temp.zip (name,data) VALUES ('test1','test'); 
  INSERT INTO temp.zip (name,data) VALUES ('test2','test'); 
  UPDATE OR REPLACE zip SET name='test2' WHERE name='test1';
  SELECT name FROM zip;
} {test2}

finish_test








<
237
238
239
240
241
242
243

  INSERT INTO temp.zip (name,data) VALUES ('test1','test'); 
  INSERT INTO temp.zip (name,data) VALUES ('test2','test'); 
  UPDATE OR REPLACE zip SET name='test2' WHERE name='test1';
  SELECT name FROM zip;
} {test2}

finish_test

Changes to tool/genfkey.test.
347
348
349
350
351
352
353
354
} {1 {constraint failed}}
do_test genfkey-6.7 {
  execsql {
    SELECT * FROM parent;
    SELECT * FROM child;
  }
} {1 1}








<
347
348
349
350
351
352
353

} {1 {constraint failed}}
do_test genfkey-6.7 {
  execsql {
    SELECT * FROM parent;
    SELECT * FROM child;
  }
} {1 1}