/ Hex Artifact Content
Login

Artifact ed2f1be9c06dde0b1ab93a95dd9e87eeaa02db2d30bcb4b9179b69ee3dc3319b:


0000: 23 20 32 30 31 30 20 53 65 70 74 65 6d 62 65 72  # 2010 September
0010: 20 32 32 0a 23 0a 23 20 54 68 65 20 61 75 74 68   22.#.# The auth
0020: 6f 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70  or disclaims cop
0030: 79 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73  yright to this s
0040: 6f 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20  ource code.  In 
0050: 70 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67  place of.# a leg
0060: 61 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20  al notice, here 
0070: 69 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23  is a blessing:.#
0080: 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f  .#    May you do
0090: 20 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76   good and not ev
00a0: 69 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75  il..#    May you
00b0: 20 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73   find forgivenes
00c0: 73 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61  s for yourself a
00d0: 6e 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72  nd forgive other
00e0: 73 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20  s..#    May you 
00f0: 73 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65  share freely, ne
0100: 76 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20  ver taking more 
0110: 74 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23  than you give..#
0120: 0a 23 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 2a 2a 2a 2a 2a 2a 2a 0a 23 20 54 68 69 73  *********.# This
0170: 20 66 69 6c 65 20 63 6f 6e 74 61 69 6e 73 20 74   file contains t
0180: 65 73 74 73 20 66 6f 72 20 74 68 65 20 72 2d 74  ests for the r-t
0190: 72 65 65 20 6d 6f 64 75 6c 65 2e 20 53 70 65 63  ree module. Spec
01a0: 69 66 69 63 61 6c 6c 79 2c 20 69 74 20 74 65 73  ifically, it tes
01b0: 74 73 0a 23 20 74 68 61 74 20 63 6f 72 72 75 70  ts.# that corrup
01c0: 74 20 6f 72 20 69 6e 63 6f 6e 73 69 73 74 65 6e  t or inconsisten
01d0: 74 20 64 61 74 61 62 61 73 65 73 20 64 6f 20 6e  t databases do n
01e0: 6f 74 20 63 61 75 73 65 20 63 72 61 73 68 65 73  ot cause crashes
01f0: 20 69 6e 20 74 68 65 20 72 2d 74 72 65 65 0a 23   in the r-tree.#
0200: 20 6d 6f 64 75 6c 65 2e 0a 23 20 0a 0a 69 66 20   module..# ..if 
0210: 7b 21 5b 69 6e 66 6f 20 65 78 69 73 74 73 20 74  {![info exists t
0220: 65 73 74 64 69 72 5d 7d 20 7b 0a 20 20 73 65 74  estdir]} {.  set
0230: 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65 20 6a   testdir [file j
0240: 6f 69 6e 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d  oin [file dirnam
0250: 65 20 5b 69 6e 66 6f 20 73 63 72 69 70 74 5d 5d  e [info script]]
0260: 20 2e 2e 20 2e 2e 20 74 65 73 74 5d 0a 7d 20 0a   .. .. test].} .
0270: 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72 2f  source $testdir/
0280: 74 65 73 74 65 72 2e 74 63 6c 0a 69 66 63 61 70  tester.tcl.ifcap
0290: 61 62 6c 65 20 21 72 74 72 65 65 20 7b 20 66 69  able !rtree { fi
02a0: 6e 69 73 68 5f 74 65 73 74 20 3b 20 72 65 74 75  nish_test ; retu
02b0: 72 6e 20 7d 0a 0a 70 72 6f 63 20 63 72 65 61 74  rn }..proc creat
02c0: 65 5f 74 31 20 7b 7d 20 7b 0a 20 20 64 62 20 63  e_t1 {} {.  db c
02d0: 6c 6f 73 65 0a 20 20 66 6f 72 63 65 64 65 6c 65  lose.  forcedele
02e0: 74 65 20 74 65 73 74 2e 64 62 0a 20 20 73 71 6c  te test.db.  sql
02f0: 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62 0a  ite3 db test.db.
0300: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
0310: 50 52 41 47 4d 41 20 70 61 67 65 5f 73 69 7a 65  PRAGMA page_size
0320: 20 3d 20 31 30 32 34 3b 0a 20 20 20 20 43 52 45   = 1024;.    CRE
0330: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
0340: 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 65 65  E t1 USING rtree
0350: 28 69 64 2c 20 78 31 2c 20 78 32 2c 20 79 31 2c  (id, x1, x2, y1,
0360: 20 79 32 29 3b 0a 20 20 7d 0a 7d 0a 70 72 6f 63   y2);.  }.}.proc
0370: 20 70 6f 70 75 6c 61 74 65 5f 74 31 20 7b 7d 20   populate_t1 {} 
0380: 7b 0a 20 20 65 78 65 63 73 71 6c 20 42 45 47 49  {.  execsql BEGI
0390: 4e 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20 30  N.  for {set i 0
03a0: 7d 20 7b 24 69 20 3c 20 35 30 30 7d 20 7b 69 6e  } {$i < 500} {in
03b0: 63 72 20 69 7d 20 7b 0a 20 20 20 20 73 65 74 20  cr i} {.    set 
03c0: 78 32 20 5b 65 78 70 72 20 24 69 2b 35 5d 0a 20  x2 [expr $i+5]. 
03d0: 20 20 20 73 65 74 20 79 32 20 5b 65 78 70 72 20     set y2 [expr 
03e0: 24 69 2b 35 5d 0a 20 20 20 20 65 78 65 63 73 71  $i+5].    execsq
03f0: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
0400: 74 31 20 56 41 4c 55 45 53 28 24 69 2c 20 24 69  t1 VALUES($i, $i
0410: 2c 20 24 78 32 2c 20 24 69 2c 20 24 79 32 29 20  , $x2, $i, $y2) 
0420: 7d 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20  }.  }.  execsql 
0430: 43 4f 4d 4d 49 54 0a 20 20 73 71 6c 69 74 65 33  COMMIT.  sqlite3
0440: 5f 64 62 5f 63 6f 6e 66 69 67 20 64 62 20 44 45  _db_config db DE
0450: 46 45 4e 53 49 56 45 20 30 0a 7d 0a 0a 70 72 6f  FENSIVE 0.}..pro
0460: 63 20 74 72 75 6e 63 61 74 65 5f 6e 6f 64 65 20  c truncate_node 
0470: 7b 6e 6f 64 65 6e 6f 20 6e 54 72 75 6e 63 7d 20  {nodeno nTrunc} 
0480: 7b 0a 20 20 73 65 74 20 62 6c 6f 62 20 5b 64 62  {.  set blob [db
0490: 20 6f 6e 65 20 7b 53 45 4c 45 43 54 20 64 61 74   one {SELECT dat
04a0: 61 20 46 52 4f 4d 20 74 31 5f 6e 6f 64 65 20 57  a FROM t1_node W
04b0: 48 45 52 45 20 6e 6f 64 65 6e 6f 3d 24 6e 6f 64  HERE nodeno=$nod
04c0: 65 6e 6f 7d 5d 0a 20 20 69 66 20 7b 24 6e 54 72  eno}].  if {$nTr
04d0: 75 6e 63 3c 30 7d 20 7b 73 65 74 20 6e 54 72 75  unc<0} {set nTru
04e0: 6e 63 20 22 65 6e 64 2d 24 6e 54 72 75 6e 63 22  nc "end-$nTrunc"
04f0: 7d 0a 20 20 73 65 74 20 62 6c 6f 62 20 5b 73 74  }.  set blob [st
0500: 72 69 6e 67 20 72 61 6e 67 65 20 24 62 6c 6f 62  ring range $blob
0510: 20 30 20 24 6e 54 72 75 6e 63 5d 0a 20 20 64 62   0 $nTrunc].  db
0520: 20 65 76 61 6c 20 7b 20 55 50 44 41 54 45 20 74   eval { UPDATE t
0530: 31 5f 6e 6f 64 65 20 53 45 54 20 64 61 74 61 20  1_node SET data 
0540: 3d 20 24 62 6c 6f 62 20 57 48 45 52 45 20 6e 6f  = $blob WHERE no
0550: 64 65 6e 6f 3d 24 6e 6f 64 65 6e 6f 20 7d 0a 7d  deno=$nodeno }.}
0560: 0a 0a 70 72 6f 63 20 73 65 74 5f 74 72 65 65 5f  ..proc set_tree_
0570: 64 65 70 74 68 20 7b 74 62 6c 20 7b 6e 65 77 76  depth {tbl {newv
0580: 61 6c 75 65 20 22 22 7d 7d 20 7b 0a 20 20 73 65  alue ""}} {.  se
0590: 74 20 62 6c 6f 62 20 5b 64 62 20 6f 6e 65 20 22  t blob [db one "
05a0: 53 45 4c 45 43 54 20 64 61 74 61 20 46 52 4f 4d  SELECT data FROM
05b0: 20 24 7b 74 62 6c 7d 5f 6e 6f 64 65 20 57 48 45   ${tbl}_node WHE
05c0: 52 45 20 6e 6f 64 65 6e 6f 3d 31 22 5d 0a 0a 20  RE nodeno=1"].. 
05d0: 20 69 66 20 7b 24 6e 65 77 76 61 6c 75 65 20 3d   if {$newvalue =
05e0: 3d 20 22 22 7d 20 7b 0a 20 20 20 20 62 69 6e 61  = ""} {.    bina
05f0: 72 79 20 73 63 61 6e 20 24 62 6c 6f 62 20 53 75  ry scan $blob Su
0600: 20 6f 6c 64 76 61 6c 75 65 0a 20 20 20 20 72 65   oldvalue.    re
0610: 74 75 72 6e 20 24 6f 6c 64 76 61 6c 75 65 0a 20  turn $oldvalue. 
0620: 20 7d 0a 0a 20 20 73 65 74 20 62 6c 6f 62 20 5b   }..  set blob [
0630: 62 69 6e 61 72 79 20 66 6f 72 6d 61 74 20 53 75  binary format Su
0640: 61 2a 20 24 6e 65 77 76 61 6c 75 65 20 5b 73 74  a* $newvalue [st
0650: 72 69 6e 67 20 72 61 6e 67 65 20 24 62 6c 6f 62  ring range $blob
0660: 20 32 20 65 6e 64 5d 5d 0a 20 20 64 62 20 65 76   2 end]].  db ev
0670: 61 6c 20 22 55 50 44 41 54 45 20 24 7b 74 62 6c  al "UPDATE ${tbl
0680: 7d 5f 6e 6f 64 65 20 53 45 54 20 64 61 74 61 20  }_node SET data 
0690: 3d 20 5c 24 62 6c 6f 62 20 57 48 45 52 45 20 6e  = \$blob WHERE n
06a0: 6f 64 65 6e 6f 3d 31 22 0a 20 20 72 65 74 75 72  odeno=1".  retur
06b0: 6e 20 5b 73 65 74 5f 74 72 65 65 5f 64 65 70 74  n [set_tree_dept
06c0: 68 20 24 74 62 6c 5d 0a 7d 0a 0a 70 72 6f 63 20  h $tbl].}..proc 
06d0: 73 65 74 5f 65 6e 74 72 79 5f 63 6f 75 6e 74 20  set_entry_count 
06e0: 7b 74 62 6c 20 6e 6f 64 65 6e 6f 20 7b 6e 65 77  {tbl nodeno {new
06f0: 76 61 6c 75 65 20 22 22 7d 7d 20 7b 0a 20 20 73  value ""}} {.  s
0700: 65 74 20 62 6c 6f 62 20 5b 64 62 20 6f 6e 65 20  et blob [db one 
0710: 22 53 45 4c 45 43 54 20 64 61 74 61 20 46 52 4f  "SELECT data FRO
0720: 4d 20 24 7b 74 62 6c 7d 5f 6e 6f 64 65 20 57 48  M ${tbl}_node WH
0730: 45 52 45 20 6e 6f 64 65 6e 6f 3d 24 6e 6f 64 65  ERE nodeno=$node
0740: 6e 6f 22 5d 0a 0a 20 20 69 66 20 7b 24 6e 65 77  no"]..  if {$new
0750: 76 61 6c 75 65 20 3d 3d 20 22 22 7d 20 7b 0a 20  value == ""} {. 
0760: 20 20 20 62 69 6e 61 72 79 20 73 63 61 6e 20 5b     binary scan [
0770: 73 74 72 69 6e 67 20 72 61 6e 67 65 20 24 62 6c  string range $bl
0780: 6f 62 20 32 20 65 6e 64 5d 20 53 75 20 6f 6c 64  ob 2 end] Su old
0790: 76 61 6c 75 65 0a 20 20 20 20 72 65 74 75 72 6e  value.    return
07a0: 20 24 6f 6c 64 76 61 6c 75 65 0a 20 20 7d 0a 0a   $oldvalue.  }..
07b0: 20 20 73 65 74 20 62 6c 6f 62 20 5b 62 69 6e 61    set blob [bina
07c0: 72 79 20 66 6f 72 6d 61 74 20 61 2a 53 75 61 2a  ry format a*Sua*
07d0: 20 5c 0a 20 20 20 20 5b 73 74 72 69 6e 67 20 72   \.    [string r
07e0: 61 6e 67 65 20 24 62 6c 6f 62 20 30 20 31 5d 20  ange $blob 0 1] 
07f0: 24 6e 65 77 76 61 6c 75 65 20 5b 73 74 72 69 6e  $newvalue [strin
0800: 67 20 72 61 6e 67 65 20 24 62 6c 6f 62 20 34 20  g range $blob 4 
0810: 65 6e 64 5d 0a 20 20 5d 0a 20 20 64 62 20 65 76  end].  ].  db ev
0820: 61 6c 20 22 55 50 44 41 54 45 20 24 7b 74 62 6c  al "UPDATE ${tbl
0830: 7d 5f 6e 6f 64 65 20 53 45 54 20 64 61 74 61 20  }_node SET data 
0840: 3d 20 5c 24 62 6c 6f 62 20 57 48 45 52 45 20 6e  = \$blob WHERE n
0850: 6f 64 65 6e 6f 3d 24 6e 6f 64 65 6e 6f 22 0a 20  odeno=$nodeno". 
0860: 20 72 65 74 75 72 6e 20 5b 73 65 74 5f 65 6e 74   return [set_ent
0870: 72 79 5f 63 6f 75 6e 74 20 24 74 62 6c 20 24 6e  ry_count $tbl $n
0880: 6f 64 65 6e 6f 5d 0a 7d 0a 0a 0a 70 72 6f 63 20  odeno].}...proc 
0890: 64 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65  do_corruption_te
08a0: 73 74 73 20 7b 70 72 65 66 69 78 20 61 72 67 73  sts {prefix args
08b0: 7d 20 7b 0a 20 20 73 65 74 20 74 65 73 74 61 72  } {.  set testar
08c0: 72 61 79 20 5b 6c 69 6e 64 65 78 20 24 61 72 67  ray [lindex $arg
08d0: 73 20 65 6e 64 5d 0a 20 20 73 65 74 20 65 72 72  s end].  set err
08e0: 6f 72 6d 73 67 20 7b 64 61 74 61 62 61 73 65 20  ormsg {database 
08f0: 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61  disk image is ma
0900: 6c 66 6f 72 6d 65 64 7d 0a 0a 20 20 66 6f 72 65  lformed}..  fore
0910: 61 63 68 20 7b 7a 20 76 61 6c 75 65 7d 20 5b 6c  ach {z value} [l
0920: 72 61 6e 67 65 20 24 61 72 67 73 20 30 20 65 6e  range $args 0 en
0930: 64 2d 31 5d 20 7b 0a 20 20 20 20 73 65 74 20 6e  d-1] {.    set n
0940: 20 5b 73 74 72 69 6e 67 20 6c 65 6e 67 74 68 20   [string length 
0950: 24 7a 5d 0a 20 20 20 20 69 66 20 7b 24 6e 3e 3d  $z].    if {$n>=
0960: 32 20 26 26 20 5b 73 74 72 69 6e 67 20 65 71 75  2 && [string equ
0970: 61 6c 20 2d 6c 65 6e 67 74 68 20 24 6e 20 24 7a  al -length $n $z
0980: 20 22 2d 65 72 72 6f 72 22 5d 7d 20 7b 0a 20 20   "-error"]} {.  
0990: 20 20 20 20 73 65 74 20 65 72 72 6f 72 6d 73 67      set errormsg
09a0: 20 24 76 61 6c 75 65 0a 20 20 20 20 7d 0a 20 20   $value.    }.  
09b0: 7d 0a 0a 20 20 66 6f 72 65 61 63 68 20 7b 74 6e  }..  foreach {tn
09c0: 20 73 71 6c 7d 20 24 74 65 73 74 61 72 72 61 79   sql} $testarray
09d0: 20 7b 0a 20 20 20 20 64 6f 5f 63 61 74 63 68 73   {.    do_catchs
09e0: 71 6c 5f 74 65 73 74 20 24 70 72 65 66 69 78 2e  ql_test $prefix.
09f0: 24 74 6e 20 24 73 71 6c 20 5b 6c 69 73 74 20 31  $tn $sql [list 1
0a00: 20 24 65 72 72 6f 72 6d 73 67 5d 0a 20 20 7d 0a   $errormsg].  }.
0a10: 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }..#------------
0a20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
0a60: 54 65 73 74 20 74 68 65 20 6c 69 62 72 61 72 69  Test the librari
0a70: 65 73 20 72 65 73 70 6f 6e 73 65 20 69 66 20 74  es response if t
0a80: 68 65 20 25 5f 6e 6f 64 65 20 74 61 62 6c 65 20  he %_node table 
0a90: 69 73 20 63 6f 6d 70 6c 65 74 65 6c 79 20 65 6d  is completely em
0aa0: 70 74 79 0a 23 20 28 69 2e 65 2e 20 74 68 65 20  pty.# (i.e. the 
0ab0: 72 6f 6f 74 20 6e 6f 64 65 20 69 73 20 6d 69 73  root node is mis
0ac0: 73 69 6e 67 29 2c 20 6f 72 20 68 61 73 20 62 65  sing), or has be
0ad0: 65 6e 20 72 65 6d 6f 76 65 64 20 66 72 6f 6d 20  en removed from 
0ae0: 74 68 65 20 64 61 74 61 62 61 73 65 0a 23 20 65  the database.# e
0af0: 6e 74 69 72 65 6c 79 2e 0a 23 0a 63 72 65 61 74  ntirely..#.creat
0b00: 65 5f 74 31 0a 70 6f 70 75 6c 61 74 65 5f 74 31  e_t1.populate_t1
0b10: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
0b20: 20 72 74 72 65 65 41 2d 31 2e 30 20 7b 0a 20 20   rtreeA-1.0 {.  
0b30: 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31 5f 6e  DELETE FROM t1_n
0b40: 6f 64 65 3b 0a 7d 20 7b 7d 0a 0a 64 6f 5f 63 6f  ode;.} {}..do_co
0b50: 72 72 75 70 74 69 6f 6e 5f 74 65 73 74 73 20 72  rruption_tests r
0b60: 74 72 65 65 41 2d 31 2e 31 20 7b 0a 20 20 31 20  treeA-1.1 {.  1 
0b70: 20 20 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d    "SELECT * FROM
0b80: 20 74 31 22 0a 20 20 32 20 20 20 22 53 45 4c 45   t1".  2   "SELE
0b90: 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45  CT * FROM t1 WHE
0ba0: 52 45 20 72 6f 77 69 64 3d 35 22 0a 20 20 33 20  RE rowid=5".  3 
0bb0: 20 20 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 74    "INSERT INTO t
0bc0: 31 20 56 41 4c 55 45 53 28 31 30 30 30 2c 20 31  1 VALUES(1000, 1
0bd0: 2c 20 32 2c 20 33 2c 20 34 29 22 0a 20 20 34 20  , 2, 3, 4)".  4 
0be0: 20 20 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d    "SELECT * FROM
0bf0: 20 74 31 20 57 48 45 52 45 20 78 31 3c 31 30 20   t1 WHERE x1<10 
0c00: 41 4e 44 20 78 32 3e 31 32 22 0a 7d 0a 0a 64 6f  AND x2>12".}..do
0c10: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74  _execsql_test rt
0c20: 72 65 65 41 2d 31 2e 31 2e 31 20 7b 0a 20 20 53  reeA-1.1.1 {.  S
0c30: 45 4c 45 43 54 20 72 74 72 65 65 63 68 65 63 6b  ELECT rtreecheck
0c40: 28 27 6d 61 69 6e 27 2c 20 27 74 31 27 29 0a 7d  ('main', 't1').}
0c50: 20 7b 7b 4e 6f 64 65 20 31 20 6d 69 73 73 69 6e   {{Node 1 missin
0c60: 67 20 66 72 6f 6d 20 64 61 74 61 62 61 73 65 0a  g from database.
0c70: 57 72 6f 6e 67 20 6e 75 6d 62 65 72 20 6f 66 20  Wrong number of 
0c80: 65 6e 74 72 69 65 73 20 69 6e 20 25 5f 72 6f 77  entries in %_row
0c90: 69 64 20 74 61 62 6c 65 20 2d 20 65 78 70 65 63  id table - expec
0ca0: 74 65 64 20 30 2c 20 61 63 74 75 61 6c 20 35 30  ted 0, actual 50
0cb0: 30 0a 57 72 6f 6e 67 20 6e 75 6d 62 65 72 20 6f  0.Wrong number o
0cc0: 66 20 65 6e 74 72 69 65 73 20 69 6e 20 25 5f 70  f entries in %_p
0cd0: 61 72 65 6e 74 20 74 61 62 6c 65 20 2d 20 65 78  arent table - ex
0ce0: 70 65 63 74 65 64 20 30 2c 20 61 63 74 75 61 6c  pected 0, actual
0cf0: 20 32 33 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71   23}}..do_execsq
0d00: 6c 5f 74 65 73 74 20 20 72 74 72 65 65 41 2d 31  l_test  rtreeA-1
0d10: 2e 32 2e 30 20 7b 20 44 52 4f 50 20 54 41 42 4c  .2.0 { DROP TABL
0d20: 45 20 74 31 5f 6e 6f 64 65 20 7d 20 7b 7d 0a 64  E t1_node } {}.d
0d30: 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65 73  o_corruption_tes
0d40: 74 73 20 72 74 72 65 65 41 2d 31 2e 32 20 2d 65  ts rtreeA-1.2 -e
0d50: 72 72 6f 72 20 22 64 61 74 61 62 61 73 65 20 64  rror "database d
0d60: 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61 6c  isk image is mal
0d70: 66 6f 72 6d 65 64 22 20 7b 0a 20 20 31 20 20 20  formed" {.  1   
0d80: 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74  "SELECT * FROM t
0d90: 31 22 0a 20 20 32 20 20 20 22 53 45 4c 45 43 54  1".  2   "SELECT
0da0: 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45   * FROM t1 WHERE
0db0: 20 72 6f 77 69 64 3d 35 22 0a 20 20 33 20 20 20   rowid=5".  3   
0dc0: 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20  "INSERT INTO t1 
0dd0: 56 41 4c 55 45 53 28 31 30 30 30 2c 20 31 2c 20  VALUES(1000, 1, 
0de0: 32 2c 20 33 2c 20 34 29 22 0a 20 20 34 20 20 20  2, 3, 4)".  4   
0df0: 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74  "SELECT * FROM t
0e00: 31 20 57 48 45 52 45 20 78 31 3c 31 30 20 41 4e  1 WHERE x1<10 AN
0e10: 44 20 78 32 3e 31 32 22 0a 7d 0a 0a 23 2d 2d 2d  D x2>12".}..#---
0e20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e60: 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 74 68  ------.# Test th
0e70: 65 20 6c 69 62 72 61 72 69 65 73 20 72 65 73 70  e libraries resp
0e80: 6f 6e 73 65 20 69 66 20 73 6f 6d 65 20 6f 66 20  onse if some of 
0e90: 74 68 65 20 65 6e 74 72 69 65 73 20 69 6e 20 74  the entries in t
0ea0: 68 65 20 25 5f 6e 6f 64 65 20 74 61 62 6c 65 20  he %_node table 
0eb0: 0a 23 20 61 72 65 20 74 68 65 20 77 72 6f 6e 67  .# are the wrong
0ec0: 20 73 69 7a 65 2e 0a 23 0a 63 72 65 61 74 65 5f   size..#.create_
0ed0: 74 31 0a 70 6f 70 75 6c 61 74 65 5f 74 31 0a 64  t1.populate_t1.d
0ee0: 6f 5f 74 65 73 74 20 72 74 72 65 65 41 2d 32 2e  o_test rtreeA-2.
0ef0: 31 2e 30 20 7b 0a 20 20 73 65 74 20 6e 6f 64 65  1.0 {.  set node
0f00: 73 20 5b 64 62 20 65 76 61 6c 20 7b 73 65 6c 65  s [db eval {sele
0f10: 63 74 20 6e 6f 64 65 6e 6f 20 46 52 4f 4d 20 74  ct nodeno FROM t
0f20: 31 5f 6e 6f 64 65 7d 5d 0a 20 20 66 6f 72 65 61  1_node}].  forea
0f30: 63 68 20 7b 61 20 62 20 63 7d 20 24 6e 6f 64 65  ch {a b c} $node
0f40: 73 20 7b 20 74 72 75 6e 63 61 74 65 5f 6e 6f 64  s { truncate_nod
0f50: 65 20 24 63 20 32 30 30 20 7d 0a 7d 20 7b 7d 0a  e $c 200 }.} {}.
0f60: 64 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65  do_corruption_te
0f70: 73 74 73 20 72 74 72 65 65 41 2d 32 2e 31 20 7b  sts rtreeA-2.1 {
0f80: 0a 20 20 31 20 20 20 22 53 45 4c 45 43 54 20 2a  .  1   "SELECT *
0f90: 20 46 52 4f 4d 20 74 31 22 0a 20 20 32 20 20 20   FROM t1".  2   
0fa0: 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74  "SELECT * FROM t
0fb0: 31 20 57 48 45 52 45 20 72 6f 77 69 64 3d 35 22  1 WHERE rowid=5"
0fc0: 0a 20 20 33 20 20 20 22 49 4e 53 45 52 54 20 49  .  3   "INSERT I
0fd0: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 31 30  NTO t1 VALUES(10
0fe0: 30 30 2c 20 31 2c 20 32 2c 20 33 2c 20 34 29 22  00, 1, 2, 3, 4)"
0ff0: 0a 20 20 34 20 20 20 22 53 45 4c 45 43 54 20 2a  .  4   "SELECT *
1000: 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 78   FROM t1 WHERE x
1010: 31 3c 31 30 20 41 4e 44 20 78 32 3e 31 32 22 0a  1<10 AND x2>12".
1020: 7d 0a 0a 63 72 65 61 74 65 5f 74 31 0a 70 6f 70  }..create_t1.pop
1030: 75 6c 61 74 65 5f 74 31 0a 64 6f 5f 74 65 73 74  ulate_t1.do_test
1040: 20 72 74 72 65 65 41 2d 32 2e 32 2e 30 20 7b 20   rtreeA-2.2.0 { 
1050: 74 72 75 6e 63 61 74 65 5f 6e 6f 64 65 20 31 20  truncate_node 1 
1060: 32 30 30 20 7d 20 7b 7d 0a 64 6f 5f 63 6f 72 72  200 } {}.do_corr
1070: 75 70 74 69 6f 6e 5f 74 65 73 74 73 20 72 74 72  uption_tests rtr
1080: 65 65 41 2d 32 2e 32 20 7b 0a 20 20 31 20 20 20  eeA-2.2 {.  1   
1090: 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74  "SELECT * FROM t
10a0: 31 22 0a 20 20 32 20 20 20 22 53 45 4c 45 43 54  1".  2   "SELECT
10b0: 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45   * FROM t1 WHERE
10c0: 20 72 6f 77 69 64 3d 35 22 0a 20 20 33 20 20 20   rowid=5".  3   
10d0: 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20  "INSERT INTO t1 
10e0: 56 41 4c 55 45 53 28 31 30 30 30 2c 20 31 2c 20  VALUES(1000, 1, 
10f0: 32 2c 20 33 2c 20 34 29 22 0a 20 20 34 20 20 20  2, 3, 4)".  4   
1100: 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74  "SELECT * FROM t
1110: 31 20 57 48 45 52 45 20 78 31 3c 31 30 20 41 4e  1 WHERE x1<10 AN
1120: 44 20 78 32 3e 31 32 22 0a 7d 0a 0a 23 2d 2d 2d  D x2>12".}..#---
1130: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1160: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1170: 2d 2d 2d 2d 2d 2d 0a 23 20 53 65 74 20 74 68 65  ------.# Set the
1180: 20 22 64 65 70 74 68 22 20 6f 66 20 74 68 65 20   "depth" of the 
1190: 74 72 65 65 20 73 74 6f 72 65 64 20 6f 6e 20 74  tree stored on t
11a0: 68 65 20 72 6f 6f 74 20 6e 6f 64 65 20 69 6e 63  he root node inc
11b0: 6f 72 72 65 63 74 6c 79 2e 20 54 65 73 74 0a 23  orrectly. Test.#
11c0: 20 74 68 61 74 20 74 68 69 73 20 64 6f 65 73 20   that this does 
11d0: 6e 6f 74 20 63 61 75 73 65 20 61 6e 79 20 70 72  not cause any pr
11e0: 6f 62 6c 65 6d 73 2e 0a 23 0a 63 72 65 61 74 65  oblems..#.create
11f0: 5f 74 31 0a 70 6f 70 75 6c 61 74 65 5f 74 31 0a  _t1.populate_t1.
1200: 64 6f 5f 74 65 73 74 20 72 74 72 65 65 41 2d 33  do_test rtreeA-3
1210: 2e 31 2e 30 2e 31 20 7b 20 73 65 74 5f 74 72 65  .1.0.1 { set_tre
1220: 65 5f 64 65 70 74 68 20 74 31 20 7d 20 7b 31 7d  e_depth t1 } {1}
1230: 0a 64 6f 5f 74 65 73 74 20 72 74 72 65 65 41 2d  .do_test rtreeA-
1240: 33 2e 31 2e 30 2e 32 20 7b 20 73 65 74 5f 74 72  3.1.0.2 { set_tr
1250: 65 65 5f 64 65 70 74 68 20 74 31 20 33 20 7d 20  ee_depth t1 3 } 
1260: 7b 33 7d 0a 64 6f 5f 63 6f 72 72 75 70 74 69 6f  {3}.do_corruptio
1270: 6e 5f 74 65 73 74 73 20 72 74 72 65 65 41 2d 33  n_tests rtreeA-3
1280: 2e 31 20 7b 0a 20 20 31 20 20 20 22 53 45 4c 45  .1 {.  1   "SELE
1290: 43 54 20 2a 20 46 52 4f 4d 20 74 31 22 0a 20 20  CT * FROM t1".  
12a0: 32 20 20 20 22 53 45 4c 45 43 54 20 2a 20 46 52  2   "SELECT * FR
12b0: 4f 4d 20 74 31 20 57 48 45 52 45 20 72 6f 77 69  OM t1 WHERE rowi
12c0: 64 3d 35 22 0a 20 20 33 20 20 20 22 49 4e 53 45  d=5".  3   "INSE
12d0: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
12e0: 53 28 31 30 30 30 2c 20 31 2c 20 32 2c 20 33 2c  S(1000, 1, 2, 3,
12f0: 20 34 29 22 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73   4)".}..do_execs
1300: 71 6c 5f 74 65 73 74 20 72 74 72 65 65 41 2d 33  ql_test rtreeA-3
1310: 2e 31 2e 30 2e 33 20 7b 0a 20 20 53 45 4c 45 43  .1.0.3 {.  SELEC
1320: 54 20 72 74 72 65 65 63 68 65 63 6b 28 27 6d 61  T rtreecheck('ma
1330: 69 6e 27 2c 20 27 74 31 27 29 21 3d 22 6f 6b 22  in', 't1')!="ok"
1340: 0a 7d 20 7b 31 7d 0a 0a 64 6f 5f 74 65 73 74 20  .} {1}..do_test 
1350: 72 74 72 65 65 41 2d 33 2e 32 2e 30 20 7b 20 73  rtreeA-3.2.0 { s
1360: 65 74 5f 74 72 65 65 5f 64 65 70 74 68 20 74 31  et_tree_depth t1
1370: 20 31 30 30 30 20 7d 20 7b 31 30 30 30 7d 0a 64   1000 } {1000}.d
1380: 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65 73  o_corruption_tes
1390: 74 73 20 72 74 72 65 65 41 2d 33 2e 32 20 7b 0a  ts rtreeA-3.2 {.
13a0: 20 20 31 20 20 20 22 53 45 4c 45 43 54 20 2a 20    1   "SELECT * 
13b0: 46 52 4f 4d 20 74 31 22 0a 20 20 32 20 20 20 22  FROM t1".  2   "
13c0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
13d0: 20 57 48 45 52 45 20 72 6f 77 69 64 3d 35 22 0a   WHERE rowid=5".
13e0: 20 20 33 20 20 20 22 49 4e 53 45 52 54 20 49 4e    3   "INSERT IN
13f0: 54 4f 20 74 31 20 56 41 4c 55 45 53 28 31 30 30  TO t1 VALUES(100
1400: 30 2c 20 31 2c 20 32 2c 20 33 2c 20 34 29 22 0a  0, 1, 2, 3, 4)".
1410: 7d 0a 0a 63 72 65 61 74 65 5f 74 31 0a 70 6f 70  }..create_t1.pop
1420: 75 6c 61 74 65 5f 74 31 0a 64 6f 5f 74 65 73 74  ulate_t1.do_test
1430: 20 72 74 72 65 65 41 2d 33 2e 33 2e 30 20 7b 20   rtreeA-3.3.0 { 
1440: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 44 45 4c  .  execsql { DEL
1450: 45 54 45 20 46 52 4f 4d 20 74 31 20 57 48 45 52  ETE FROM t1 WHER
1460: 45 20 72 6f 77 69 64 20 3d 20 30 20 7d 0a 20 20  E rowid = 0 }.  
1470: 73 65 74 5f 74 72 65 65 5f 64 65 70 74 68 20 74  set_tree_depth t
1480: 31 20 36 35 35 33 35 0a 7d 20 7b 36 35 35 33 35  1 65535.} {65535
1490: 7d 0a 64 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f  }.do_corruption_
14a0: 74 65 73 74 73 20 72 74 72 65 65 41 2d 33 2e 33  tests rtreeA-3.3
14b0: 20 7b 0a 20 20 31 20 20 20 22 53 45 4c 45 43 54   {.  1   "SELECT
14c0: 20 2a 20 46 52 4f 4d 20 74 31 22 0a 20 20 32 20   * FROM t1".  2 
14d0: 20 20 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d    "SELECT * FROM
14e0: 20 74 31 20 57 48 45 52 45 20 72 6f 77 69 64 3d   t1 WHERE rowid=
14f0: 35 22 0a 20 20 33 20 20 20 22 49 4e 53 45 52 54  5".  3   "INSERT
1500: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
1510: 31 30 30 30 2c 20 31 2c 20 32 2c 20 33 2c 20 34  1000, 1, 2, 3, 4
1520: 29 22 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  )".}..do_execsql
1530: 5f 74 65 73 74 20 72 74 72 65 65 41 2d 33 2e 33  _test rtreeA-3.3
1540: 2e 33 2e 34 20 7b 0a 20 20 53 45 4c 45 43 54 20  .3.4 {.  SELECT 
1550: 72 74 72 65 65 63 68 65 63 6b 28 27 6d 61 69 6e  rtreecheck('main
1560: 27 2c 20 27 74 31 27 29 0a 7d 20 7b 7b 52 74 72  ', 't1').} {{Rtr
1570: 65 65 20 64 65 70 74 68 20 6f 75 74 20 6f 66 20  ee depth out of 
1580: 72 61 6e 67 65 20 28 36 35 35 33 35 29 0a 57 72  range (65535).Wr
1590: 6f 6e 67 20 6e 75 6d 62 65 72 20 6f 66 20 65 6e  ong number of en
15a0: 74 72 69 65 73 20 69 6e 20 25 5f 72 6f 77 69 64  tries in %_rowid
15b0: 20 74 61 62 6c 65 20 2d 20 65 78 70 65 63 74 65   table - expecte
15c0: 64 20 30 2c 20 61 63 74 75 61 6c 20 34 39 39 0a  d 0, actual 499.
15d0: 57 72 6f 6e 67 20 6e 75 6d 62 65 72 20 6f 66 20  Wrong number of 
15e0: 65 6e 74 72 69 65 73 20 69 6e 20 25 5f 70 61 72  entries in %_par
15f0: 65 6e 74 20 74 61 62 6c 65 20 2d 20 65 78 70 65  ent table - expe
1600: 63 74 65 64 20 30 2c 20 61 63 74 75 61 6c 20 32  cted 0, actual 2
1610: 33 7d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  3}}..#----------
1620: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1630: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1640: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1650: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
1660: 23 20 53 65 74 20 74 68 65 20 22 6e 75 6d 62 65  # Set the "numbe
1670: 72 20 6f 66 20 65 6e 74 72 69 65 73 22 20 66 69  r of entries" fi
1680: 65 6c 64 20 6f 6e 20 73 6f 6d 65 20 6e 6f 64 65  eld on some node
1690: 73 20 69 6e 63 6f 72 72 65 63 74 6c 79 2e 0a 23  s incorrectly..#
16a0: 0a 63 72 65 61 74 65 5f 74 31 0a 70 6f 70 75 6c  .create_t1.popul
16b0: 61 74 65 5f 74 31 0a 64 6f 5f 74 65 73 74 20 72  ate_t1.do_test r
16c0: 74 72 65 65 41 2d 34 2e 31 2e 30 20 7b 20 0a 20  treeA-4.1.0 { . 
16d0: 20 73 65 74 5f 65 6e 74 72 79 5f 63 6f 75 6e 74   set_entry_count
16e0: 20 74 31 20 31 20 34 30 30 30 0a 7d 20 7b 34 30   t1 1 4000.} {40
16f0: 30 30 7d 0a 64 6f 5f 63 6f 72 72 75 70 74 69 6f  00}.do_corruptio
1700: 6e 5f 74 65 73 74 73 20 72 74 72 65 65 41 2d 34  n_tests rtreeA-4
1710: 2e 31 20 7b 0a 20 20 31 20 20 20 22 53 45 4c 45  .1 {.  1   "SELE
1720: 43 54 20 2a 20 46 52 4f 4d 20 74 31 22 0a 20 20  CT * FROM t1".  
1730: 32 20 20 20 22 53 45 4c 45 43 54 20 2a 20 46 52  2   "SELECT * FR
1740: 4f 4d 20 74 31 20 57 48 45 52 45 20 72 6f 77 69  OM t1 WHERE rowi
1750: 64 3d 35 22 0a 20 20 33 20 20 20 22 49 4e 53 45  d=5".  3   "INSE
1760: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
1770: 53 28 31 30 30 30 2c 20 31 2c 20 32 2c 20 33 2c  S(1000, 1, 2, 3,
1780: 20 34 29 22 0a 20 20 34 20 20 20 22 53 45 4c 45   4)".  4   "SELE
1790: 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45  CT * FROM t1 WHE
17a0: 52 45 20 78 31 3c 31 30 20 41 4e 44 20 78 32 3e  RE x1<10 AND x2>
17b0: 31 32 22 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  12".}..#--------
17c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1800: 2d 0a 23 20 52 65 6d 6f 76 65 20 65 6e 74 72 69  -.# Remove entri
1810: 65 73 20 66 72 6f 6d 20 74 68 65 20 25 5f 70 61  es from the %_pa
1820: 72 65 6e 74 20 74 61 62 6c 65 20 61 6e 64 20 63  rent table and c
1830: 68 65 63 6b 20 74 68 61 74 20 74 68 69 73 20 64  heck that this d
1840: 6f 65 73 20 6e 6f 74 0a 23 20 63 61 75 73 65 20  oes not.# cause 
1850: 61 20 63 72 61 73 68 2e 0a 23 0a 63 72 65 61 74  a crash..#.creat
1860: 65 5f 74 31 0a 70 6f 70 75 6c 61 74 65 5f 74 31  e_t1.populate_t1
1870: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
1880: 20 72 74 72 65 65 41 2d 35 2e 31 2e 30 20 7b 20   rtreeA-5.1.0 { 
1890: 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31 5f 70  DELETE FROM t1_p
18a0: 61 72 65 6e 74 20 7d 20 7b 7d 0a 64 6f 5f 63 6f  arent } {}.do_co
18b0: 72 72 75 70 74 69 6f 6e 5f 74 65 73 74 73 20 72  rruption_tests r
18c0: 74 72 65 65 41 2d 35 2e 31 20 7b 0a 20 20 31 20  treeA-5.1 {.  1 
18d0: 20 20 22 44 45 4c 45 54 45 20 46 52 4f 4d 20 74    "DELETE FROM t
18e0: 31 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20  1 WHERE rowid = 
18f0: 35 22 0a 20 20 32 20 20 20 22 44 45 4c 45 54 45  5".  2   "DELETE
1900: 20 46 52 4f 4d 20 74 31 22 0a 7d 0a 0a 64 6f 5f   FROM t1".}..do_
1910: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74 72  execsql_test rtr
1920: 65 65 41 2d 35 2e 32 20 7b 0a 20 20 53 45 4c 45  eeA-5.2 {.  SELE
1930: 43 54 20 72 74 72 65 65 63 68 65 63 6b 28 27 6d  CT rtreecheck('m
1940: 61 69 6e 27 2c 20 27 74 31 27 29 21 3d 22 6f 6b  ain', 't1')!="ok
1950: 22 0a 7d 20 7b 31 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  ".} {1}..#------
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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
19a0: 2d 2d 2d 0a 23 20 41 64 64 20 73 6f 6d 65 20 62  ---.# Add some b
19b0: 61 64 20 65 6e 74 72 69 65 73 20 74 6f 20 74 68  ad entries to th
19c0: 65 20 25 5f 70 61 72 65 6e 74 20 74 61 62 6c 65  e %_parent table
19d0: 2e 0a 23 0a 63 72 65 61 74 65 5f 74 31 0a 70 6f  ..#.create_t1.po
19e0: 70 75 6c 61 74 65 5f 74 31 0a 64 6f 5f 65 78 65  pulate_t1.do_exe
19f0: 63 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65 41  csql_test rtreeA
1a00: 2d 36 2e 31 2e 30 20 7b 20 0a 20 20 55 50 44 41  -6.1.0 { .  UPDA
1a10: 54 45 20 74 31 5f 70 61 72 65 6e 74 20 73 65 74  TE t1_parent set
1a20: 20 70 61 72 65 6e 74 6e 6f 64 65 20 3d 20 70 61   parentnode = pa
1a30: 72 65 6e 74 6e 6f 64 65 2b 31 0a 7d 20 7b 7d 0a  rentnode+1.} {}.
1a40: 64 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65  do_corruption_te
1a50: 73 74 73 20 72 74 72 65 65 41 2d 36 2e 31 20 7b  sts rtreeA-6.1 {
1a60: 0a 20 20 31 20 20 20 22 44 45 4c 45 54 45 20 46  .  1   "DELETE F
1a70: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 72 6f 77  ROM t1 WHERE row
1a80: 69 64 20 3d 20 35 22 0a 20 20 32 20 20 20 22 55  id = 5".  2   "U
1a90: 50 44 41 54 45 20 74 31 20 53 45 54 20 78 31 3d  PDATE t1 SET x1=
1aa0: 78 31 2b 31 2c 20 78 32 3d 78 32 2b 31 22 0a 7d  x1+1, x2=x2+1".}
1ab0: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
1ac0: 74 20 72 74 72 65 65 41 2d 36 2e 32 20 7b 0a 20  t rtreeA-6.2 {. 
1ad0: 20 53 45 4c 45 43 54 20 72 74 72 65 65 63 68 65   SELECT rtreeche
1ae0: 63 6b 28 27 6d 61 69 6e 27 2c 20 27 74 31 27 29  ck('main', 't1')
1af0: 21 3d 22 6f 6b 22 0a 7d 20 7b 31 7d 0a 0a 23 2d  !="ok".} {1}..#-
1b00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1b10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1b20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1b30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1b40: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 72 75 6e 63  --------.# Trunc
1b50: 61 74 65 64 20 62 6c 6f 62 73 20 69 6e 20 74 68  ated blobs in th
1b60: 65 20 5f 6e 6f 64 65 20 74 61 62 6c 65 2e 0a 23  e _node table..#
1b70: 0a 63 72 65 61 74 65 5f 74 31 0a 70 6f 70 75 6c  .create_t1.popul
1b80: 61 74 65 5f 74 31 0a 73 71 6c 69 74 65 33 20 64  ate_t1.sqlite3 d
1b90: 62 20 74 65 73 74 2e 64 62 0a 73 71 6c 69 74 65  b test.db.sqlite
1ba0: 33 5f 64 62 5f 63 6f 6e 66 69 67 20 64 62 20 44  3_db_config db D
1bb0: 45 46 45 4e 53 49 56 45 20 30 0a 64 6f 5f 65 78  EFENSIVE 0.do_ex
1bc0: 65 63 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65  ecsql_test rtree
1bd0: 41 2d 37 2e 31 30 30 20 7b 20 0a 20 20 55 50 44  A-7.100 { .  UPD
1be0: 41 54 45 20 74 31 5f 6e 6f 64 65 20 53 45 54 20  ATE t1_node SET 
1bf0: 64 61 74 61 3d 78 27 27 20 57 48 45 52 45 20 72  data=x'' WHERE r
1c00: 6f 77 69 64 3d 31 3b 0a 7d 20 7b 7d 0a 64 6f 5f  owid=1;.} {}.do_
1c10: 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20 72 74  catchsql_test rt
1c20: 72 65 65 41 2d 37 2e 31 31 30 20 7b 0a 20 20 53  reeA-7.110 {.  S
1c30: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20  ELECT * FROM t1 
1c40: 57 48 45 52 45 20 78 31 3e 30 20 41 4e 44 20 78  WHERE x1>0 AND x
1c50: 31 3c 31 30 30 20 41 4e 44 20 78 32 3e 30 20 41  1<100 AND x2>0 A
1c60: 4e 44 20 78 32 3c 31 30 30 3b 0a 7d 20 7b 31 20  ND x2<100;.} {1 
1c70: 7b 75 6e 64 65 72 73 69 7a 65 20 52 54 72 65 65  {undersize RTree
1c80: 20 62 6c 6f 62 73 20 69 6e 20 22 74 31 5f 6e 6f   blobs in "t1_no
1c90: 64 65 22 7d 7d 0a 64 6f 5f 74 65 73 74 20 72 74  de"}}.do_test rt
1ca0: 72 65 65 41 2d 37 2e 31 32 30 20 7b 0a 20 20 73  reeA-7.120 {.  s
1cb0: 71 6c 69 74 65 33 5f 65 78 74 65 6e 64 65 64 5f  qlite3_extended_
1cc0: 65 72 72 63 6f 64 65 20 64 62 0a 7d 20 7b 53 51  errcode db.} {SQ
1cd0: 4c 49 54 45 5f 43 4f 52 52 55 50 54 5f 56 54 41  LITE_CORRUPT_VTA
1ce0: 42 7d 0a 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74  B}...finish_test
1cf0: 0a                                               .