/ Hex Artifact Content
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Artifact a17bbf54fdde78d43cf3cc34b0057719fd4a173a3d824285b67dc5257c064c7b:


0000: 23 20 32 30 31 34 2d 30 31 2d 32 30 0a 23 0a 23  # 2014-01-20.#.#
0010: 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73 63   The author disc
0020: 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74 20  laims copyright 
0030: 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20 63  to this source c
0040: 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20 6f  ode.  In place o
0050: 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74 69  f.# a legal noti
0060: 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62 6c  ce, here is a bl
0070: 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20 4d  essing:.#.#    M
0080: 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20 61  ay you do good a
0090: 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20 20  nd not evil..#  
00a0: 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20 66    May you find f
00b0: 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20 79  orgiveness for y
00c0: 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72 67  ourself and forg
00d0: 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20 20  ive others..#   
00e0: 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20 66   May you share f
00f0: 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61 6b  reely, never tak
0100: 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79 6f  ing more than yo
0110: 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a 2a  u give..#.#*****
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 0a 23 0a 0a 73 65 74 20 74 65 73 74 64 69  **.#..set testdi
0170: 72 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20  r [file dirname 
0180: 24 61 72 67 76 30 5d 0a 73 6f 75 72 63 65 20 24  $argv0].source $
0190: 74 65 73 74 64 69 72 2f 74 65 73 74 65 72 2e 74  testdir/tester.t
01a0: 63 6c 0a 73 65 74 20 74 65 73 74 70 72 65 66 69  cl.set testprefi
01b0: 78 20 63 6f 72 72 75 70 74 49 0a 0a 69 66 20 7b  x corruptI..if {
01c0: 5b 70 65 72 6d 75 74 61 74 69 6f 6e 5d 3d 3d 22  [permutation]=="
01d0: 6d 6d 61 70 22 7d 20 7b 0a 20 20 66 69 6e 69 73  mmap"} {.  finis
01e0: 68 5f 74 65 73 74 0a 20 20 72 65 74 75 72 6e 0a  h_test.  return.
01f0: 7d 0a 0a 23 20 54 68 69 73 20 6d 6f 64 75 6c 65  }..# This module
0200: 20 75 73 65 73 20 68 61 72 64 2d 63 6f 64 65 64   uses hard-coded
0210: 20 6f 66 66 73 65 74 73 20 77 68 69 63 68 20 64   offsets which d
0220: 6f 20 6e 6f 74 20 77 6f 72 6b 20 69 66 20 74 68  o not work if th
0230: 65 20 72 65 73 65 72 76 65 64 5f 62 79 74 65 73  e reserved_bytes
0240: 0a 23 20 76 61 6c 75 65 20 69 73 20 6e 6f 6e 7a  .# value is nonz
0250: 65 72 6f 2e 0a 69 66 20 7b 5b 6e 6f 6e 7a 65 72  ero..if {[nonzer
0260: 6f 5f 72 65 73 65 72 76 65 64 5f 62 79 74 65 73  o_reserved_bytes
0270: 5d 7d 20 7b 66 69 6e 69 73 68 5f 74 65 73 74 3b  ]} {finish_test;
0280: 20 72 65 74 75 72 6e 3b 7d 0a 0a 64 61 74 61 62   return;}..datab
0290: 61 73 65 5f 6d 61 79 5f 62 65 5f 63 6f 72 72 75  ase_may_be_corru
02a0: 70 74 0a 0a 23 20 49 6e 69 74 69 61 6c 69 7a 65  pt..# Initialize
02b0: 20 74 68 65 20 64 61 74 61 62 61 73 65 2e 0a 23   the database..#
02c0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
02d0: 20 31 2e 31 20 7b 0a 20 20 50 52 41 47 4d 41 20   1.1 {.  PRAGMA 
02e0: 70 61 67 65 5f 73 69 7a 65 3d 31 30 32 34 3b 0a  page_size=1024;.
02f0: 20 20 50 52 41 47 4d 41 20 61 75 74 6f 5f 76 61    PRAGMA auto_va
0300: 63 75 75 6d 3d 30 3b 0a 20 20 43 52 45 41 54 45  cuum=0;.  CREATE
0310: 20 54 41 42 4c 45 20 74 31 28 61 29 3b 0a 20 20   TABLE t1(a);.  
0320: 43 52 45 41 54 45 20 49 4e 44 45 58 20 69 31 20  CREATE INDEX i1 
0330: 4f 4e 20 74 31 28 61 29 3b 0a 20 20 49 4e 53 45  ON t1(a);.  INSE
0340: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
0350: 53 28 27 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d  S('abcdefghijklm
0360: 6e 6f 70 27 29 3b 0a 7d 20 7b 7d 0a 64 62 20 63  nop');.} {}.db c
0370: 6c 6f 73 65 0a 0a 64 6f 5f 74 65 73 74 20 31 2e  lose..do_test 1.
0380: 32 20 7b 0a 20 20 73 65 74 20 6f 66 66 73 65 74  2 {.  set offset
0390: 20 5b 68 65 78 69 6f 5f 67 65 74 5f 69 6e 74 20   [hexio_get_int 
03a0: 5b 68 65 78 69 6f 5f 72 65 61 64 20 74 65 73 74  [hexio_read test
03b0: 2e 64 62 20 5b 65 78 70 72 20 32 2a 31 30 32 34  .db [expr 2*1024
03c0: 20 2b 20 38 5d 20 32 5d 5d 0a 20 20 73 65 74 20   + 8] 2]].  set 
03d0: 6f 66 66 20 5b 65 78 70 72 20 32 2a 31 30 32 34  off [expr 2*1024
03e0: 20 2b 20 24 6f 66 66 73 65 74 20 2b 20 31 5d 0a   + $offset + 1].
03f0: 20 20 68 65 78 69 6f 5f 77 72 69 74 65 20 74 65    hexio_write te
0400: 73 74 2e 64 62 20 24 6f 66 66 20 37 66 30 36 0a  st.db $off 7f06.
0410: 20 20 73 71 6c 69 74 65 33 20 64 62 20 74 65 73    sqlite3 db tes
0420: 74 2e 64 62 0a 20 20 63 61 74 63 68 73 71 6c 20  t.db.  catchsql 
0430: 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20  { SELECT * FROM 
0440: 74 31 20 57 48 45 52 45 20 61 20 3d 20 31 30 20  t1 WHERE a = 10 
0450: 7d 0a 7d 20 7b 30 20 7b 7d 7d 0a 0a 64 6f 5f 74  }.} {0 {}}..do_t
0460: 65 73 74 20 31 2e 33 20 7b 0a 20 20 64 62 20 63  est 1.3 {.  db c
0470: 6c 6f 73 65 0a 20 20 73 65 74 20 6f 66 66 73 65  lose.  set offse
0480: 74 20 5b 68 65 78 69 6f 5f 67 65 74 5f 69 6e 74  t [hexio_get_int
0490: 20 5b 68 65 78 69 6f 5f 72 65 61 64 20 74 65 73   [hexio_read tes
04a0: 74 2e 64 62 20 5b 65 78 70 72 20 32 2a 31 30 32  t.db [expr 2*102
04b0: 34 20 2b 20 38 5d 20 32 5d 5d 0a 20 20 73 65 74  4 + 8] 2]].  set
04c0: 20 6f 66 66 20 5b 65 78 70 72 20 32 2a 31 30 32   off [expr 2*102
04d0: 34 20 2b 20 24 6f 66 66 73 65 74 20 2b 20 31 5d  4 + $offset + 1]
04e0: 0a 20 20 68 65 78 69 6f 5f 77 72 69 74 65 20 74  .  hexio_write t
04f0: 65 73 74 2e 64 62 20 24 6f 66 66 20 46 46 46 46  est.db $off FFFF
0500: 37 66 30 32 0a 20 20 73 71 6c 69 74 65 33 20 64  7f02.  sqlite3 d
0510: 62 20 74 65 73 74 2e 64 62 0a 20 20 63 61 74 63  b test.db.  catc
0520: 68 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20  hsql { SELECT * 
0530: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 61 20  FROM t1 WHERE a 
0540: 3d 20 31 30 20 7d 0a 7d 20 7b 31 20 7b 64 61 74  = 10 }.} {1 {dat
0550: 61 62 61 73 65 20 64 69 73 6b 20 69 6d 61 67 65  abase disk image
0560: 20 69 73 20 6d 61 6c 66 6f 72 6d 65 64 7d 7d 0a   is malformed}}.
0570: 0a 64 6f 5f 74 65 73 74 20 32 2e 30 20 7b 0a 20  .do_test 2.0 {. 
0580: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43   execsql {.    C
0590: 52 45 41 54 45 20 54 41 42 4c 45 20 72 28 78 29  REATE TABLE r(x)
05a0: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
05b0: 4f 20 72 20 56 41 4c 55 45 53 28 27 41 42 43 44  O r VALUES('ABCD
05c0: 45 46 47 48 49 4a 4b 27 29 3b 0a 20 20 20 20 43  EFGHIJK');.    C
05d0: 52 45 41 54 45 20 49 4e 44 45 58 20 72 31 20 4f  REATE INDEX r1 O
05e0: 4e 20 72 28 78 29 3b 0a 20 20 7d 0a 20 20 73 65  N r(x);.  }.  se
05f0: 74 20 70 67 20 5b 64 62 20 6f 6e 65 20 7b 53 45  t pg [db one {SE
0600: 4c 45 43 54 20 72 6f 6f 74 70 61 67 65 20 46 52  LECT rootpage FR
0610: 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72  OM sqlite_master
0620: 20 57 48 45 52 45 20 6e 61 6d 65 20 3d 20 27 72   WHERE name = 'r
0630: 31 27 7d 5d 0a 7d 20 7b 35 7d 0a 0a 64 6f 5f 74  1'}].} {5}..do_t
0640: 65 73 74 20 32 2e 31 20 7b 0a 20 20 64 62 20 63  est 2.1 {.  db c
0650: 6c 6f 73 65 0a 20 20 73 65 74 20 6f 66 66 73 65  lose.  set offse
0660: 74 20 5b 68 65 78 69 6f 5f 67 65 74 5f 69 6e 74  t [hexio_get_int
0670: 20 5b 68 65 78 69 6f 5f 72 65 61 64 20 74 65 73   [hexio_read tes
0680: 74 2e 64 62 20 5b 65 78 70 72 20 28 35 2d 31 29  t.db [expr (5-1)
0690: 2a 31 30 32 34 20 2b 20 38 5d 20 32 5d 5d 0a 20  *1024 + 8] 2]]. 
06a0: 20 73 65 74 20 6f 66 66 20 5b 65 78 70 72 20 28   set off [expr (
06b0: 35 2d 31 29 2a 31 30 32 34 20 2b 20 24 6f 66 66  5-1)*1024 + $off
06c0: 73 65 74 20 2b 20 31 5d 0a 20 20 68 65 78 69 6f  set + 1].  hexio
06d0: 5f 77 72 69 74 65 20 74 65 73 74 2e 64 62 20 24  _write test.db $
06e0: 6f 66 66 20 46 46 46 46 30 30 30 34 0a 20 20 73  off FFFF0004.  s
06f0: 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64  qlite3 db test.d
0700: 62 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 20 53  b.  catchsql { S
0710: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 72 20 57  ELECT * FROM r W
0720: 48 45 52 45 20 78 20 3e 3d 20 31 30 2e 30 20 7d  HERE x >= 10.0 }
0730: 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20  .} {1 {database 
0740: 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61  disk image is ma
0750: 6c 66 6f 72 6d 65 64 7d 7d 0a 0a 64 6f 5f 74 65  lformed}}..do_te
0760: 73 74 20 32 2e 32 20 7b 0a 20 20 63 61 74 63 68  st 2.2 {.  catch
0770: 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46  sql { SELECT * F
0780: 52 4f 4d 20 72 20 57 48 45 52 45 20 78 20 3e 3d  ROM r WHERE x >=
0790: 20 31 30 20 7d 0a 7d 20 7b 31 20 7b 64 61 74 61   10 }.} {1 {data
07a0: 62 61 73 65 20 64 69 73 6b 20 69 6d 61 67 65 20  base disk image 
07b0: 69 73 20 6d 61 6c 66 6f 72 6d 65 64 7d 7d 0a 0a  is malformed}}..
07c0: 69 66 20 7b 5b 64 62 20 6f 6e 65 20 7b 53 45 4c  if {[db one {SEL
07d0: 45 43 54 20 73 71 6c 69 74 65 5f 63 6f 6d 70 69  ECT sqlite_compi
07e0: 6c 65 6f 70 74 69 6f 6e 5f 75 73 65 64 28 27 45  leoption_used('E
07f0: 4e 41 42 4c 45 5f 4f 56 45 52 53 49 5a 45 5f 43  NABLE_OVERSIZE_C
0800: 45 4c 4c 5f 43 48 45 43 4b 27 29 7d 5d 7d 20 7b  ELL_CHECK')}]} {
0810: 0a 20 20 23 20 54 68 65 20 66 6f 6c 6c 6f 77 69  .  # The followi
0820: 6e 67 20 74 65 73 74 73 20 6f 6e 6c 79 20 77 6f  ng tests only wo
0830: 72 6b 20 69 66 20 4f 56 45 52 53 49 5a 45 5f 43  rk if OVERSIZE_C
0840: 45 4c 4c 5f 43 48 45 43 4b 20 69 73 20 64 69 73  ELL_CHECK is dis
0850: 61 62 6c 65 64 0a 7d 20 65 6c 73 65 20 7b 0a 20  abled.} else {. 
0860: 20 72 65 73 65 74 5f 64 62 0a 20 20 64 6f 5f 65   reset_db.  do_e
0870: 78 65 63 73 71 6c 5f 74 65 73 74 20 33 2e 31 20  xecsql_test 3.1 
0880: 7b 0a 20 20 20 20 20 50 52 41 47 4d 41 20 61 75  {.     PRAGMA au
0890: 74 6f 5f 76 61 63 75 75 6d 3d 30 3b 0a 20 20 20  to_vacuum=0;.   
08a0: 20 20 50 52 41 47 4d 41 20 70 61 67 65 5f 73 69    PRAGMA page_si
08b0: 7a 65 20 3d 20 35 31 32 3b 0a 20 20 20 20 20 43  ze = 512;.     C
08c0: 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 61  REATE TABLE t1(a
08d0: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59   INTEGER PRIMARY
08e0: 20 4b 45 59 2c 20 62 29 3b 0a 20 20 20 20 20 57   KEY, b);.     W
08f0: 49 54 48 20 73 28 61 2c 20 62 29 20 41 53 20 28  ITH s(a, b) AS (
0900: 0a 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 32  .       SELECT 2
0910: 2c 20 27 61 62 63 64 65 66 67 68 69 6a 27 0a 20  , 'abcdefghij'. 
0920: 20 20 20 20 20 20 55 4e 49 4f 4e 20 41 4c 4c 0a        UNION ALL.
0930: 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 61 2b         SELECT a+
0940: 32 2c 20 62 20 46 52 4f 4d 20 73 20 57 48 45 52  2, b FROM s WHER
0950: 65 20 61 20 3c 20 34 30 0a 20 20 20 20 20 29 0a  e a < 40.     ).
0960: 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f       INSERT INTO
0970: 20 74 31 20 53 45 4c 45 43 54 20 2a 20 46 52 4f   t1 SELECT * FRO
0980: 4d 20 73 3b 0a 20 20 20 7d 20 7b 7d 0a 20 20 20  M s;.   } {}.   
0990: 0a 20 20 20 64 6f 5f 74 65 73 74 20 33 2e 32 20  .   do_test 3.2 
09a0: 7b 0a 20 20 20 20 20 68 65 78 69 6f 5f 77 72 69  {.     hexio_wri
09b0: 74 65 20 74 65 73 74 2e 64 62 20 5b 65 78 70 72  te test.db [expr
09c0: 20 35 31 32 2b 33 5d 20 30 30 35 34 0a 20 20 20   512+3] 0054.   
09d0: 20 20 64 62 20 63 6c 6f 73 65 0a 20 20 20 20 20    db close.     
09e0: 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e  sqlite3 db test.
09f0: 64 62 0a 20 20 20 20 20 65 78 65 63 73 71 6c 20  db.     execsql 
0a00: 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31  { INSERT INTO t1
0a10: 20 56 41 4c 55 45 53 28 35 2c 20 27 6b 6c 6d 6e   VALUES(5, 'klmn
0a20: 6f 70 71 72 73 74 27 29 20 7d 0a 20 20 20 20 20  opqrst') }.     
0a30: 65 78 65 63 73 71 6c 20 7b 20 49 4e 53 45 52 54  execsql { INSERT
0a40: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
0a50: 37 2c 20 27 6b 6c 6d 6e 6f 70 71 72 73 74 27 29  7, 'klmnopqrst')
0a60: 20 7d 0a 20 20 20 7d 20 7b 7d 0a 20 20 20 0a 20   }.   } {}.   . 
0a70: 20 20 64 62 20 63 6c 6f 73 65 0a 20 20 20 73 71    db close.   sq
0a80: 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62  lite3 db test.db
0a90: 0a 20 20 20 64 6f 5f 63 61 74 63 68 73 71 6c 5f  .   do_catchsql_
0aa0: 74 65 73 74 20 33 2e 33 20 7b 0a 20 20 20 20 20  test 3.3 {.     
0ab0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56  INSERT INTO t1 V
0ac0: 41 4c 55 45 53 28 39 2c 20 27 6b 6c 6d 6e 6f 70  ALUES(9, 'klmnop
0ad0: 71 72 73 74 27 29 3b 0a 20 20 20 7d 20 7b 31 20  qrst');.   } {1 
0ae0: 7b 64 61 74 61 62 61 73 65 20 64 69 73 6b 20 69  {database disk i
0af0: 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f 72 6d 65  mage is malforme
0b00: 64 7d 7d 0a 7d 20 3b 23 20 65 6e 64 2d 69 66 20  d}}.} ;# end-if 
0b10: 21 64 65 66 69 6e 65 64 28 45 4e 41 42 4c 45 5f  !defined(ENABLE_
0b20: 4f 56 45 52 53 49 5a 45 5f 43 45 4c 4c 5f 43 48  OVERSIZE_CELL_CH
0b30: 45 43 4b 29 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  ECK)...#--------
0b40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b80: 2d 0a 23 20 54 65 73 74 20 74 68 61 74 20 61 6e  -.# Test that an
0b90: 20 61 73 73 65 72 74 28 29 20 66 61 69 6c 75 72   assert() failur
0ba0: 65 20 64 69 73 63 6f 76 65 72 65 64 20 62 79 20  e discovered by 
0bb0: 41 46 4c 20 63 6f 72 72 75 70 74 20 64 61 74 61  AFL corrupt data
0bc0: 62 61 73 65 20 66 69 6c 65 0a 23 20 74 65 73 74  base file.# test
0bd0: 69 6e 67 20 68 61 73 20 62 65 65 6e 20 66 69 78  ing has been fix
0be0: 65 64 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64  ed..#.reset_db.d
0bf0: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 34  o_execsql_test 4
0c00: 2e 30 20 7b 0a 20 20 50 52 41 47 4d 41 20 70 61  .0 {.  PRAGMA pa
0c10: 67 65 5f 73 69 7a 65 20 3d 20 36 35 35 33 36 3b  ge_size = 65536;
0c20: 0a 20 20 50 52 41 47 4d 41 20 61 75 74 6f 76 61  .  PRAGMA autova
0c30: 63 75 75 6d 20 3d 20 30 3b 0a 20 20 43 52 45 41  cuum = 0;.  CREA
0c40: 54 45 20 54 41 42 4c 45 20 74 31 28 61 20 49 4e  TE TABLE t1(a IN
0c50: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45  TEGER PRIMARY KE
0c60: 59 2c 20 62 29 3b 0a 20 20 49 4e 53 45 52 54 20  Y, b);.  INSERT 
0c70: 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 2d  INTO t1 VALUES(-
0c80: 31 2c 20 27 61 62 63 64 65 66 67 68 69 6a 27 29  1, 'abcdefghij')
0c90: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
0ca0: 74 31 20 56 41 4c 55 45 53 28 30 2c 20 27 61 62  t1 VALUES(0, 'ab
0cb0: 63 64 65 66 67 68 69 6a 27 29 3b 0a 7d 0a 0a 73  cdefghij');.}..s
0cc0: 65 74 20 72 6f 6f 74 20 5b 64 62 20 6f 6e 65 20  et root [db one 
0cd0: 7b 53 45 4c 45 43 54 20 72 6f 6f 74 70 61 67 65  {SELECT rootpage
0ce0: 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73   FROM sqlite_mas
0cf0: 74 65 72 7d 5d 0a 73 65 74 20 6f 66 66 73 65 74  ter}].set offset
0d00: 20 5b 65 78 70 72 20 28 24 72 6f 6f 74 2d 31 29   [expr ($root-1)
0d10: 20 2a 20 36 35 35 33 36 5d 0a 0a 69 66 63 61 70   * 65536]..ifcap
0d20: 61 62 6c 65 20 6f 76 65 72 73 69 7a 65 5f 63 65  able oversize_ce
0d30: 6c 6c 5f 63 68 65 63 6b 20 7b 0a 20 20 73 65 74  ll_check {.  set
0d40: 20 72 65 73 20 7b 31 20 7b 64 61 74 61 62 61 73   res {1 {databas
0d50: 65 20 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20  e disk image is 
0d60: 6d 61 6c 66 6f 72 6d 65 64 7d 7d 0a 7d 20 65 6c  malformed}}.} el
0d70: 73 65 20 7b 0a 20 20 73 65 74 20 72 65 73 20 7b  se {.  set res {
0d80: 30 20 7b 7d 7d 0a 7d 0a 64 6f 5f 74 65 73 74 20  0 {}}.}.do_test 
0d90: 34 2e 31 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65  4.1 {.  db close
0da0: 0a 20 20 68 65 78 69 6f 5f 77 72 69 74 65 20 74  .  hexio_write t
0db0: 65 73 74 2e 64 62 20 5b 65 78 70 72 20 24 6f 66  est.db [expr $of
0dc0: 66 73 65 74 20 2b 20 38 20 2b 20 32 5d 20 30 30  fset + 8 + 2] 00
0dd0: 30 30 0a 20 20 68 65 78 69 6f 5f 77 72 69 74 65  00.  hexio_write
0de0: 20 74 65 73 74 2e 64 62 20 5b 65 78 70 72 20 24   test.db [expr $
0df0: 6f 66 66 73 65 74 20 2b 20 35 5d 20 30 30 30 30  offset + 5] 0000
0e00: 0a 20 20 73 71 6c 69 74 65 33 20 64 62 20 74 65  .  sqlite3 db te
0e10: 73 74 2e 64 62 0a 20 20 63 61 74 63 68 73 71 6c  st.db.  catchsql
0e20: 20 7b 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74   { DELETE FROM t
0e30: 31 20 57 48 45 52 45 20 61 3d 30 20 7d 0a 7d 20  1 WHERE a=0 }.} 
0e40: 24 72 65 73 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  $res...#--------
0e50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e90: 2d 0a 23 20 44 61 74 61 62 61 73 65 20 70 72 6f  -.# Database pro
0ea0: 70 65 72 74 69 65 73 3a 0a 23 0a 23 20 20 20 2a  perties:.#.#   *
0eb0: 20 49 6e 63 72 65 6d 65 6e 74 61 6c 20 76 61 63   Incremental vac
0ec0: 75 75 6d 20 6d 6f 64 65 2e 0a 23 20 20 20 2a 20  uum mode..#   * 
0ed0: 44 61 74 61 62 61 73 65 20 72 6f 6f 74 20 74 61  Database root ta
0ee0: 62 6c 65 20 68 61 73 20 61 20 73 69 6e 67 6c 65  ble has a single
0ef0: 20 6c 65 61 66 20 70 61 67 65 2e 0a 23 20 20 20   leaf page..#   
0f00: 2a 20 46 72 65 65 20 6c 69 73 74 20 63 6f 6e 73  * Free list cons
0f10: 69 73 74 73 20 6f 66 20 61 20 73 69 6e 67 6c 65  ists of a single
0f20: 20 74 72 75 6e 6b 20 70 61 67 65 2e 0a 23 0a 23   trunk page..#.#
0f30: 20 54 68 65 20 64 62 20 69 73 20 74 68 65 6e 20   The db is then 
0f40: 63 6f 72 72 75 70 74 65 64 20 62 79 20 61 64 64  corrupted by add
0f50: 69 6e 67 20 74 68 65 20 72 6f 6f 74 20 74 61 62  ing the root tab
0f60: 6c 65 20 6c 65 61 66 20 70 61 67 65 20 61 73 20  le leaf page as 
0f70: 61 20 66 72 65 65 2d 6c 69 73 74 0a 23 20 6c 65  a free-list.# le
0f80: 61 66 20 70 61 67 65 20 28 73 6f 20 74 68 61 74  af page (so that
0f90: 20 69 74 20 69 73 20 72 65 66 65 72 65 6e 63 65   it is reference
0fa0: 64 20 74 77 69 63 65 29 2e 0a 23 0a 23 20 54 68  d twice)..#.# Th
0fb0: 65 6e 2c 20 61 20 6e 65 77 20 74 61 62 6c 65 20  en, a new table 
0fc0: 69 73 20 63 72 65 61 74 65 64 2e 20 54 68 65 20  is created. The 
0fd0: 6e 65 77 20 72 6f 6f 74 20 70 61 67 65 20 69 73  new root page is
0fe0: 20 74 68 65 20 63 75 72 72 65 6e 74 20 66 72 65   the current fre
0ff0: 65 2d 6c 69 73 74 0a 23 20 74 72 75 6e 6b 2e 20  e-list.# trunk. 
1000: 54 68 69 73 20 6d 65 61 6e 73 20 74 68 61 74 20  This means that 
1010: 74 68 65 20 72 6f 6f 74 20 74 61 62 6c 65 20 6c  the root table l
1020: 65 61 66 20 70 61 67 65 20 69 73 20 6d 61 64 65  eaf page is made
1030: 20 69 6e 74 6f 20 74 68 65 20 6e 65 77 0a 23 20   into the new.# 
1040: 66 72 65 65 20 6c 69 73 74 20 74 72 75 6e 6b 2c  free list trunk,
1050: 20 77 68 69 63 68 20 63 6f 72 72 75 70 74 73 20   which corrupts 
1060: 69 74 73 20 68 65 61 64 65 72 2e 20 54 68 65 6e  its header. Then
1070: 2c 20 77 68 65 6e 20 74 68 65 20 6e 65 77 20 65  , when the new e
1080: 6e 74 72 79 20 69 73 0a 23 20 69 6e 73 65 72 74  ntry is.# insert
1090: 65 64 20 69 6e 74 6f 20 74 68 65 20 72 6f 6f 74  ed into the root
10a0: 20 74 61 62 6c 65 2c 20 74 68 69 6e 67 73 20 77   table, things w
10b0: 6f 75 6c 64 20 67 65 74 20 63 68 61 6f 74 69 63  ould get chaotic
10c0: 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f  ..#.reset_db.do_
10d0: 74 65 73 74 20 35 2e 30 20 7b 0a 20 20 65 78 65  test 5.0 {.  exe
10e0: 63 73 71 6c 20 7b 0a 20 20 20 20 50 52 41 47 4d  csql {.    PRAGM
10f0: 41 20 70 61 67 65 5f 73 69 7a 65 20 3d 20 35 31  A page_size = 51
1100: 32 3b 0a 20 20 20 20 50 52 41 47 4d 41 20 61 75  2;.    PRAGMA au
1110: 74 6f 5f 76 61 63 75 75 6d 20 3d 20 32 3b 0a 20  to_vacuum = 2;. 
1120: 20 7d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20   }.  for {set i 
1130: 33 7d 20 7b 31 7d 20 7b 69 6e 63 72 20 69 7d 20  3} {1} {incr i} 
1140: 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 22 43  {.    execsql "C
1150: 52 45 41 54 45 20 54 41 42 4c 45 20 74 24 7b 69  REATE TABLE t${i
1160: 7d 28 78 29 22 0a 20 20 20 20 69 66 20 7b 5b 64  }(x)".    if {[d
1170: 62 20 6f 6e 65 20 7b 50 52 41 47 4d 41 20 70 61  b one {PRAGMA pa
1180: 67 65 5f 63 6f 75 6e 74 7d 5d 3e 24 69 7d 20 62  ge_count}]>$i} b
1190: 72 65 61 6b 0a 20 20 7d 0a 20 20 73 65 74 20 6e  reak.  }.  set n
11a0: 50 61 67 65 20 5b 64 62 20 6f 6e 65 20 7b 50 52  Page [db one {PR
11b0: 41 47 4d 41 20 70 61 67 65 5f 63 6f 75 6e 74 7d  AGMA page_count}
11c0: 5d 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20  ].  execsql {.  
11d0: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74    CREATE TABLE t
11e0: 31 30 30 28 78 29 3b 0a 20 20 20 20 44 52 4f 50  100(x);.    DROP
11f0: 20 54 41 42 4c 45 20 74 31 30 30 3b 0a 20 20 7d   TABLE t100;.  }
1200: 0a 7d 20 7b 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  .} {}..do_execsq
1210: 6c 5f 74 65 73 74 20 35 2e 31 20 7b 20 0a 20 20  l_test 5.1 { .  
1220: 50 52 41 47 4d 41 20 70 61 67 65 5f 63 6f 75 6e  PRAGMA page_coun
1230: 74 20 0a 7d 20 5b 65 78 70 72 20 24 6e 50 61 67  t .} [expr $nPag
1240: 65 2b 31 5d 0a 0a 64 6f 5f 74 65 73 74 20 35 2e  e+1]..do_test 5.
1250: 32 20 7b 20 0a 20 20 23 20 54 68 65 20 6c 61 73  2 { .  # The las
1260: 74 20 70 61 67 65 20 6f 66 20 74 68 65 20 64 62  t page of the db
1270: 20 69 73 20 6e 6f 77 20 74 68 65 20 6f 6e 6c 79   is now the only
1280: 20 6c 65 61 66 20 6f 66 20 74 68 65 20 73 71 6c   leaf of the sql
1290: 69 74 65 5f 6d 61 73 74 65 72 20 74 61 62 6c 65  ite_master table
12a0: 2e 0a 20 20 23 20 43 6f 72 72 75 70 74 20 74 68  ..  # Corrupt th
12b0: 65 20 64 62 20 62 79 20 61 64 64 69 6e 67 20 69  e db by adding i
12c0: 74 20 74 6f 20 74 68 65 20 66 72 65 65 2d 6c 69  t to the free-li
12d0: 73 74 20 61 73 20 77 65 6c 6c 20 28 74 68 65 20  st as well (the 
12e0: 73 65 63 6f 6e 64 20 6c 61 73 74 0a 20 20 23 20  second last.  # 
12f0: 70 61 67 65 20 6f 66 20 74 68 65 20 64 62 20 69  page of the db i
1300: 73 20 74 68 65 20 66 72 65 65 2d 6c 69 73 74 20  s the free-list 
1310: 74 72 75 6e 6b 29 2e 0a 20 20 64 62 20 63 6c 6f  trunk)..  db clo
1320: 73 65 0a 20 20 68 65 78 69 6f 5f 77 72 69 74 65  se.  hexio_write
1330: 20 74 65 73 74 2e 64 62 20 5b 65 78 70 72 20 35   test.db [expr 5
1340: 31 32 2a 28 24 6e 50 61 67 65 2d 31 29 5d 20 5b  12*($nPage-1)] [
1350: 0a 20 20 20 20 66 6f 72 6d 61 74 20 22 25 2e 38  .    format "%.8
1360: 58 25 2e 38 58 25 2e 38 58 22 20 30 20 31 20 5b  X%.8X%.8X" 0 1 [
1370: 65 78 70 72 20 24 6e 50 61 67 65 2b 31 5d 0a 20  expr $nPage+1]. 
1380: 20 5d 0a 7d 20 7b 31 32 7d 0a 0a 64 6f 5f 74 65   ].} {12}..do_te
1390: 73 74 20 35 2e 33 20 7b 0a 20 20 73 71 6c 69 74  st 5.3 {.  sqlit
13a0: 65 33 20 64 62 20 74 65 73 74 2e 64 62 0a 20 20  e3 db test.db.  
13b0: 63 61 74 63 68 73 71 6c 20 7b 20 43 52 45 41 54  catchsql { CREAT
13c0: 45 20 54 41 42 4c 45 20 74 78 28 78 29 3b 20 7d  E TABLE tx(x); }
13d0: 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20  .} {1 {database 
13e0: 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61  disk image is ma
13f0: 6c 66 6f 72 6d 65 64 7d 7d 0a 0a 0a 23 2d 2d 2d  lformed}}...#---
1400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1410: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1420: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1440: 2d 2d 2d 2d 2d 2d 0a 23 20 53 65 74 20 74 68 65  ------.# Set the
1450: 20 70 61 79 6c 6f 61 64 20 73 69 7a 65 20 6f 66   payload size of
1460: 20 61 20 63 65 6c 6c 20 74 6f 20 6a 75 73 74 20   a cell to just 
1470: 6c 65 73 73 20 74 68 61 6e 20 32 5e 33 32 20 62  less than 2^32 b
1480: 79 74 65 73 20 28 6e 6f 74 0a 23 20 70 6f 73 73  ytes (not.# poss
1490: 69 62 6c 65 20 69 6e 20 61 6e 20 75 6e 63 6f 72  ible in an uncor
14a0: 72 75 70 74 65 64 20 64 62 29 2e 20 54 68 65 6e  rupted db). Then
14b0: 20 74 72 79 20 74 6f 20 64 65 6c 65 74 65 20 74   try to delete t
14c0: 68 65 20 63 65 6c 6c 2e 20 41 74 20 6f 6e 65 0a  he cell. At one.
14d0: 23 20 70 6f 69 6e 74 20 74 68 69 73 20 6c 65 64  # point this led
14e0: 20 74 6f 20 61 6e 20 69 6e 74 65 67 65 72 20 6f   to an integer o
14f0: 76 65 72 66 6c 6f 77 20 74 68 61 74 20 63 61 75  verflow that cau
1500: 73 65 64 20 61 6e 20 61 73 73 65 72 74 28 29 20  sed an assert() 
1510: 74 6f 20 66 61 69 6c 2e 0a 23 0a 72 65 73 65 74  to fail..#.reset
1520: 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  _db.do_execsql_t
1530: 65 73 74 20 36 2e 30 20 7b 0a 20 20 50 52 41 47  est 6.0 {.  PRAG
1540: 4d 41 20 70 61 67 65 5f 73 69 7a 65 20 3d 20 35  MA page_size = 5
1550: 31 32 3b 0a 20 20 50 52 41 47 4d 41 20 61 75 74  12;.  PRAGMA aut
1560: 6f 5f 76 61 63 75 75 6d 3d 30 3b 0a 20 20 43 52  o_vacuum=0;.  CR
1570: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 29  EATE TABLE t1(x)
1580: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
1590: 74 31 20 56 41 4c 55 45 53 28 7a 65 72 6f 62 6c  t1 VALUES(zerobl
15a0: 6f 62 28 33 30 30 29 29 3b 0a 20 20 49 4e 53 45  ob(300));.  INSE
15b0: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
15c0: 53 28 7a 65 72 6f 62 6c 6f 62 28 36 30 30 29 29  S(zeroblob(600))
15d0: 3b 0a 7d 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 36  ;.} {}.do_test 6
15e0: 2e 31 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a  .1 {.  db close.
15f0: 20 20 68 65 78 69 6f 5f 77 72 69 74 65 20 74 65    hexio_write te
1600: 73 74 2e 64 62 20 36 31 36 20 38 46 46 46 46 46  st.db 616 8FFFFF
1610: 46 46 37 46 30 32 0a 20 20 73 71 6c 69 74 65 33  FF7F02.  sqlite3
1620: 20 64 62 20 74 65 73 74 2e 64 62 0a 20 20 65 78   db test.db.  ex
1630: 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45 20 46  ecsql { DELETE F
1640: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 72 6f 77  ROM t1 WHERE row
1650: 69 64 3d 32 20 7d 0a 7d 20 7b 7d 0a 0a 23 2d 2d  id=2 }.} {}..#--
1660: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1670: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1680: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1690: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
16a0: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 53 65 65 20 77 68  -------.# See wh
16b0: 61 74 20 68 61 70 70 65 6e 73 20 69 66 20 74 68  at happens if th
16c0: 65 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20  e sqlite_master 
16d0: 65 6e 74 72 79 20 61 73 73 6f 63 69 61 74 65 64  entry associated
16e0: 20 77 69 74 68 20 61 20 50 52 49 4d 41 52 59 0a   with a PRIMARY.
16f0: 23 20 4b 45 59 20 6f 72 20 55 4e 49 51 55 45 20  # KEY or UNIQUE 
1700: 69 6e 64 65 78 20 69 73 20 72 65 6d 6f 76 65 64  index is removed
1710: 2e 20 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f  . .#.reset_db.do
1720: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 37 2e  _execsql_test 7.
1730: 30 20 7b 0a 20 20 50 52 41 47 4d 41 20 61 75 74  0 {.  PRAGMA aut
1740: 6f 5f 76 61 63 75 75 6d 3d 30 3b 0a 20 20 43 52  o_vacuum=0;.  CR
1750: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 20  EATE TABLE t1(x 
1760: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 79 29 3b  PRIMARY KEY, y);
1770: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
1780: 31 20 56 41 4c 55 45 53 28 27 61 27 2c 20 27 41  1 VALUES('a', 'A
1790: 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  ');.  INSERT INT
17a0: 4f 20 74 31 20 56 41 4c 55 45 53 28 27 62 27 2c  O t1 VALUES('b',
17b0: 20 27 41 27 29 3b 0a 20 20 49 4e 53 45 52 54 20   'A');.  INSERT 
17c0: 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27  INTO t1 VALUES('
17d0: 63 27 2c 20 27 41 27 29 3b 0a 20 20 53 45 4c 45  c', 'A');.  SELE
17e0: 43 54 20 6e 61 6d 65 20 46 52 4f 4d 20 73 71 6c  CT name FROM sql
17f0: 69 74 65 5f 6d 61 73 74 65 72 3b 0a 7d 20 7b 74  ite_master;.} {t
1800: 31 20 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64  1 sqlite_autoind
1810: 65 78 5f 74 31 5f 31 7d 0a 73 71 6c 69 74 65 33  ex_t1_1}.sqlite3
1820: 5f 64 62 5f 63 6f 6e 66 69 67 20 64 62 20 44 45  _db_config db DE
1830: 46 45 4e 53 49 56 45 20 30 0a 64 6f 5f 65 78 65  FENSIVE 0.do_exe
1840: 63 73 71 6c 5f 74 65 73 74 20 37 2e 31 20 7b 0a  csql_test 7.1 {.
1850: 20 20 50 52 41 47 4d 41 20 77 72 69 74 61 62 6c    PRAGMA writabl
1860: 65 5f 73 63 68 65 6d 61 20 3d 20 31 3b 0a 20 20  e_schema = 1;.  
1870: 44 45 4c 45 54 45 20 46 52 4f 4d 20 73 71 6c 69  DELETE FROM sqli
1880: 74 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45 20  te_master WHERE 
1890: 6e 61 6d 65 20 3d 20 27 73 71 6c 69 74 65 5f 61  name = 'sqlite_a
18a0: 75 74 6f 69 6e 64 65 78 5f 74 31 5f 31 27 3b 0a  utoindex_t1_1';.
18b0: 7d 0a 64 6f 5f 74 65 73 74 20 37 2e 32 20 7b 0a  }.do_test 7.2 {.
18c0: 20 20 64 62 20 63 6c 6f 73 65 0a 20 20 73 71 6c    db close.  sql
18d0: 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62 0a  ite3 db test.db.
18e0: 20 20 63 61 74 63 68 73 71 6c 20 7b 20 55 50 44    catchsql { UPD
18f0: 41 54 45 20 74 31 20 53 45 54 20 78 3d 27 64 27  ATE t1 SET x='d'
1900: 20 41 4e 44 20 79 3d 27 44 27 20 57 48 45 52 45   AND y='D' WHERE
1910: 20 72 6f 77 69 64 20 3d 20 32 20 7d 0a 7d 20 7b   rowid = 2 }.} {
1920: 31 20 7b 64 61 74 61 62 61 73 65 20 64 69 73 6b  1 {database disk
1930: 20 69 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f 72   image is malfor
1940: 6d 65 64 7d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  med}}..#--------
1950: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1960: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1970: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1980: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1990: 2d 0a 23 20 41 74 20 6f 6e 65 20 70 6f 69 6e 74  -.# At one point
19a0: 20 61 6e 20 61 73 73 65 72 74 28 29 20 77 6f 75   an assert() wou
19b0: 6c 64 20 66 61 69 6c 20 69 66 20 61 74 74 65 6d  ld fail if attem
19c0: 70 74 20 77 61 73 20 6d 61 64 65 20 74 6f 20 66  pt was made to f
19d0: 72 65 65 20 70 61 67 65 20 31 2e 0a 23 0a 72 65  ree page 1..#.re
19e0: 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71  set_db.do_execsq
19f0: 6c 5f 74 65 73 74 20 38 2e 30 20 7b 0a 20 20 50  l_test 8.0 {.  P
1a00: 52 41 47 4d 41 20 61 75 74 6f 5f 76 61 63 75 75  RAGMA auto_vacuu
1a10: 6d 3d 30 3b 0a 20 20 43 52 45 41 54 45 20 54 41  m=0;.  CREATE TA
1a20: 42 4c 45 20 74 31 28 78 29 3b 0a 20 20 49 4e 53  BLE t1(x);.  INS
1a30: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
1a40: 45 53 28 7a 65 72 6f 62 6c 6f 62 28 33 30 30 29  ES(zeroblob(300)
1a50: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
1a60: 20 74 31 20 56 41 4c 55 45 53 28 7a 65 72 6f 62   t1 VALUES(zerob
1a70: 6c 6f 62 28 33 30 30 29 29 3b 0a 20 20 49 4e 53  lob(300));.  INS
1a80: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
1a90: 45 53 28 7a 65 72 6f 62 6c 6f 62 28 33 30 30 29  ES(zeroblob(300)
1aa0: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
1ab0: 20 74 31 20 56 41 4c 55 45 53 28 7a 65 72 6f 62   t1 VALUES(zerob
1ac0: 6c 6f 62 28 33 30 30 29 29 3b 0a 7d 20 7b 7d 0a  lob(300));.} {}.
1ad0: 0a 64 6f 5f 74 65 73 74 20 38 2e 31 20 7b 0a 20  .do_test 8.1 {. 
1ae0: 20 64 62 20 63 6c 6f 73 65 0a 20 20 68 65 78 69   db close.  hexi
1af0: 6f 5f 77 72 69 74 65 20 74 65 73 74 2e 64 62 20  o_write test.db 
1b00: 5b 65 78 70 72 20 31 30 32 34 20 2b 20 38 5d 20  [expr 1024 + 8] 
1b10: 30 30 30 30 30 30 30 31 0a 20 20 73 71 6c 69 74  00000001.  sqlit
1b20: 65 33 20 64 62 20 74 65 73 74 2e 64 62 0a 20 20  e3 db test.db.  
1b30: 63 61 74 63 68 73 71 6c 20 7b 20 44 45 4c 45 54  catchsql { DELET
1b40: 45 20 46 52 4f 4d 20 74 31 20 7d 0a 7d 20 7b 31  E FROM t1 }.} {1
1b50: 20 7b 64 61 74 61 62 61 73 65 20 64 69 73 6b 20   {database disk 
1b60: 69 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f 72 6d  image is malform
1b70: 65 64 7d 7d 0a 0a 64 6f 5f 74 65 73 74 20 38 2e  ed}}..do_test 8.
1b80: 32 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a 20  2 {.  db close. 
1b90: 20 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74   sqlite3 db test
1ba0: 2e 64 62 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  .db.  execsql { 
1bb0: 50 52 41 47 4d 41 20 69 6e 74 65 67 72 69 74 79  PRAGMA integrity
1bc0: 5f 63 68 65 63 6b 20 7d 0a 7d 20 7b 2f 2e 2a 69  _check }.} {/.*i
1bd0: 6e 20 64 61 74 61 62 61 73 65 20 6d 61 69 6e 2e  n database main.
1be0: 2a 2f 7d 0a 0a 0a 66 69 6e 69 73 68 5f 74 65 73  */}...finish_tes
1bf0: 74 0a                                            t.