/ Hex Artifact Content
Login

Artifact 20623ca337ca3bd7e008cc9fb49e44dbe97f1a80b238e10a12bb4afcd0da3776:


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 7d 0a 0a 70 72 6f 63 20 74  COMMIT.}..proc t
0440: 72 75 6e 63 61 74 65 5f 6e 6f 64 65 20 7b 6e 6f  runcate_node {no
0450: 64 65 6e 6f 20 6e 54 72 75 6e 63 7d 20 7b 0a 20  deno nTrunc} {. 
0460: 20 73 65 74 20 62 6c 6f 62 20 5b 64 62 20 6f 6e   set blob [db on
0470: 65 20 7b 53 45 4c 45 43 54 20 64 61 74 61 20 46  e {SELECT data F
0480: 52 4f 4d 20 74 31 5f 6e 6f 64 65 20 57 48 45 52  ROM t1_node WHER
0490: 45 20 6e 6f 64 65 6e 6f 3d 24 6e 6f 64 65 6e 6f  E nodeno=$nodeno
04a0: 7d 5d 0a 20 20 69 66 20 7b 24 6e 54 72 75 6e 63  }].  if {$nTrunc
04b0: 3c 30 7d 20 7b 73 65 74 20 6e 54 72 75 6e 63 20  <0} {set nTrunc 
04c0: 22 65 6e 64 2d 24 6e 54 72 75 6e 63 22 7d 0a 20  "end-$nTrunc"}. 
04d0: 20 73 65 74 20 62 6c 6f 62 20 5b 73 74 72 69 6e   set blob [strin
04e0: 67 20 72 61 6e 67 65 20 24 62 6c 6f 62 20 30 20  g range $blob 0 
04f0: 24 6e 54 72 75 6e 63 5d 0a 20 20 64 62 20 65 76  $nTrunc].  db ev
0500: 61 6c 20 7b 20 55 50 44 41 54 45 20 74 31 5f 6e  al { UPDATE t1_n
0510: 6f 64 65 20 53 45 54 20 64 61 74 61 20 3d 20 24  ode SET data = $
0520: 62 6c 6f 62 20 57 48 45 52 45 20 6e 6f 64 65 6e  blob WHERE noden
0530: 6f 3d 24 6e 6f 64 65 6e 6f 20 7d 0a 7d 0a 0a 70  o=$nodeno }.}..p
0540: 72 6f 63 20 73 65 74 5f 74 72 65 65 5f 64 65 70  roc set_tree_dep
0550: 74 68 20 7b 74 62 6c 20 7b 6e 65 77 76 61 6c 75  th {tbl {newvalu
0560: 65 20 22 22 7d 7d 20 7b 0a 20 20 73 65 74 20 62  e ""}} {.  set b
0570: 6c 6f 62 20 5b 64 62 20 6f 6e 65 20 22 53 45 4c  lob [db one "SEL
0580: 45 43 54 20 64 61 74 61 20 46 52 4f 4d 20 24 7b  ECT data FROM ${
0590: 74 62 6c 7d 5f 6e 6f 64 65 20 57 48 45 52 45 20  tbl}_node WHERE 
05a0: 6e 6f 64 65 6e 6f 3d 31 22 5d 0a 0a 20 20 69 66  nodeno=1"]..  if
05b0: 20 7b 24 6e 65 77 76 61 6c 75 65 20 3d 3d 20 22   {$newvalue == "
05c0: 22 7d 20 7b 0a 20 20 20 20 62 69 6e 61 72 79 20  "} {.    binary 
05d0: 73 63 61 6e 20 24 62 6c 6f 62 20 53 75 20 6f 6c  scan $blob Su ol
05e0: 64 76 61 6c 75 65 0a 20 20 20 20 72 65 74 75 72  dvalue.    retur
05f0: 6e 20 24 6f 6c 64 76 61 6c 75 65 0a 20 20 7d 0a  n $oldvalue.  }.
0600: 0a 20 20 73 65 74 20 62 6c 6f 62 20 5b 62 69 6e  .  set blob [bin
0610: 61 72 79 20 66 6f 72 6d 61 74 20 53 75 61 2a 20  ary format Sua* 
0620: 24 6e 65 77 76 61 6c 75 65 20 5b 73 74 72 69 6e  $newvalue [strin
0630: 67 20 72 61 6e 67 65 20 24 62 6c 6f 62 20 32 20  g range $blob 2 
0640: 65 6e 64 5d 5d 0a 20 20 64 62 20 65 76 61 6c 20  end]].  db eval 
0650: 22 55 50 44 41 54 45 20 24 7b 74 62 6c 7d 5f 6e  "UPDATE ${tbl}_n
0660: 6f 64 65 20 53 45 54 20 64 61 74 61 20 3d 20 5c  ode SET data = \
0670: 24 62 6c 6f 62 20 57 48 45 52 45 20 6e 6f 64 65  $blob WHERE node
0680: 6e 6f 3d 31 22 0a 20 20 72 65 74 75 72 6e 20 5b  no=1".  return [
0690: 73 65 74 5f 74 72 65 65 5f 64 65 70 74 68 20 24  set_tree_depth $
06a0: 74 62 6c 5d 0a 7d 0a 0a 70 72 6f 63 20 73 65 74  tbl].}..proc set
06b0: 5f 65 6e 74 72 79 5f 63 6f 75 6e 74 20 7b 74 62  _entry_count {tb
06c0: 6c 20 6e 6f 64 65 6e 6f 20 7b 6e 65 77 76 61 6c  l nodeno {newval
06d0: 75 65 20 22 22 7d 7d 20 7b 0a 20 20 73 65 74 20  ue ""}} {.  set 
06e0: 62 6c 6f 62 20 5b 64 62 20 6f 6e 65 20 22 53 45  blob [db one "SE
06f0: 4c 45 43 54 20 64 61 74 61 20 46 52 4f 4d 20 24  LECT data FROM $
0700: 7b 74 62 6c 7d 5f 6e 6f 64 65 20 57 48 45 52 45  {tbl}_node WHERE
0710: 20 6e 6f 64 65 6e 6f 3d 24 6e 6f 64 65 6e 6f 22   nodeno=$nodeno"
0720: 5d 0a 0a 20 20 69 66 20 7b 24 6e 65 77 76 61 6c  ]..  if {$newval
0730: 75 65 20 3d 3d 20 22 22 7d 20 7b 0a 20 20 20 20  ue == ""} {.    
0740: 62 69 6e 61 72 79 20 73 63 61 6e 20 5b 73 74 72  binary scan [str
0750: 69 6e 67 20 72 61 6e 67 65 20 24 62 6c 6f 62 20  ing range $blob 
0760: 32 20 65 6e 64 5d 20 53 75 20 6f 6c 64 76 61 6c  2 end] Su oldval
0770: 75 65 0a 20 20 20 20 72 65 74 75 72 6e 20 24 6f  ue.    return $o
0780: 6c 64 76 61 6c 75 65 0a 20 20 7d 0a 0a 20 20 73  ldvalue.  }..  s
0790: 65 74 20 62 6c 6f 62 20 5b 62 69 6e 61 72 79 20  et blob [binary 
07a0: 66 6f 72 6d 61 74 20 61 2a 53 75 61 2a 20 5c 0a  format a*Sua* \.
07b0: 20 20 20 20 5b 73 74 72 69 6e 67 20 72 61 6e 67      [string rang
07c0: 65 20 24 62 6c 6f 62 20 30 20 31 5d 20 24 6e 65  e $blob 0 1] $ne
07d0: 77 76 61 6c 75 65 20 5b 73 74 72 69 6e 67 20 72  wvalue [string r
07e0: 61 6e 67 65 20 24 62 6c 6f 62 20 34 20 65 6e 64  ange $blob 4 end
07f0: 5d 0a 20 20 5d 0a 20 20 64 62 20 65 76 61 6c 20  ].  ].  db eval 
0800: 22 55 50 44 41 54 45 20 24 7b 74 62 6c 7d 5f 6e  "UPDATE ${tbl}_n
0810: 6f 64 65 20 53 45 54 20 64 61 74 61 20 3d 20 5c  ode SET data = \
0820: 24 62 6c 6f 62 20 57 48 45 52 45 20 6e 6f 64 65  $blob WHERE node
0830: 6e 6f 3d 24 6e 6f 64 65 6e 6f 22 0a 20 20 72 65  no=$nodeno".  re
0840: 74 75 72 6e 20 5b 73 65 74 5f 65 6e 74 72 79 5f  turn [set_entry_
0850: 63 6f 75 6e 74 20 24 74 62 6c 20 24 6e 6f 64 65  count $tbl $node
0860: 6e 6f 5d 0a 7d 0a 0a 0a 70 72 6f 63 20 64 6f 5f  no].}...proc do_
0870: 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65 73 74 73  corruption_tests
0880: 20 7b 70 72 65 66 69 78 20 61 72 67 73 7d 20 7b   {prefix args} {
0890: 0a 20 20 73 65 74 20 74 65 73 74 61 72 72 61 79  .  set testarray
08a0: 20 5b 6c 69 6e 64 65 78 20 24 61 72 67 73 20 65   [lindex $args e
08b0: 6e 64 5d 0a 20 20 73 65 74 20 65 72 72 6f 72 6d  nd].  set errorm
08c0: 73 67 20 7b 64 61 74 61 62 61 73 65 20 64 69 73  sg {database dis
08d0: 6b 20 69 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f  k image is malfo
08e0: 72 6d 65 64 7d 0a 0a 20 20 66 6f 72 65 61 63 68  rmed}..  foreach
08f0: 20 7b 7a 20 76 61 6c 75 65 7d 20 5b 6c 72 61 6e   {z value} [lran
0900: 67 65 20 24 61 72 67 73 20 30 20 65 6e 64 2d 31  ge $args 0 end-1
0910: 5d 20 7b 0a 20 20 20 20 73 65 74 20 6e 20 5b 73  ] {.    set n [s
0920: 74 72 69 6e 67 20 6c 65 6e 67 74 68 20 24 7a 5d  tring length $z]
0930: 0a 20 20 20 20 69 66 20 7b 24 6e 3e 3d 32 20 26  .    if {$n>=2 &
0940: 26 20 5b 73 74 72 69 6e 67 20 65 71 75 61 6c 20  & [string equal 
0950: 2d 6c 65 6e 67 74 68 20 24 6e 20 24 7a 20 22 2d  -length $n $z "-
0960: 65 72 72 6f 72 22 5d 7d 20 7b 0a 20 20 20 20 20  error"]} {.     
0970: 20 73 65 74 20 65 72 72 6f 72 6d 73 67 20 24 76   set errormsg $v
0980: 61 6c 75 65 0a 20 20 20 20 7d 0a 20 20 7d 0a 0a  alue.    }.  }..
0990: 20 20 66 6f 72 65 61 63 68 20 7b 74 6e 20 73 71    foreach {tn sq
09a0: 6c 7d 20 24 74 65 73 74 61 72 72 61 79 20 7b 0a  l} $testarray {.
09b0: 20 20 20 20 64 6f 5f 63 61 74 63 68 73 71 6c 5f      do_catchsql_
09c0: 74 65 73 74 20 24 70 72 65 66 69 78 2e 24 74 6e  test $prefix.$tn
09d0: 20 24 73 71 6c 20 5b 6c 69 73 74 20 31 20 24 65   $sql [list 1 $e
09e0: 72 72 6f 72 6d 73 67 5d 0a 20 20 7d 0a 7d 0a 0a  rrormsg].  }.}..
09f0: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
0a00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a10: 2d 2d 2d 2d 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 0a 23 20 54 65 73  ----------.# Tes
0a40: 74 20 74 68 65 20 6c 69 62 72 61 72 69 65 73 20  t the libraries 
0a50: 72 65 73 70 6f 6e 73 65 20 69 66 20 74 68 65 20  response if the 
0a60: 25 5f 6e 6f 64 65 20 74 61 62 6c 65 20 69 73 20  %_node table is 
0a70: 63 6f 6d 70 6c 65 74 65 6c 79 20 65 6d 70 74 79  completely empty
0a80: 0a 23 20 28 69 2e 65 2e 20 74 68 65 20 72 6f 6f  .# (i.e. the roo
0a90: 74 20 6e 6f 64 65 20 69 73 20 6d 69 73 73 69 6e  t node is missin
0aa0: 67 29 2c 20 6f 72 20 68 61 73 20 62 65 65 6e 20  g), or has been 
0ab0: 72 65 6d 6f 76 65 64 20 66 72 6f 6d 20 74 68 65  removed from the
0ac0: 20 64 61 74 61 62 61 73 65 0a 23 20 65 6e 74 69   database.# enti
0ad0: 72 65 6c 79 2e 0a 23 0a 63 72 65 61 74 65 5f 74  rely..#.create_t
0ae0: 31 0a 70 6f 70 75 6c 61 74 65 5f 74 31 0a 64 6f  1.populate_t1.do
0af0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74  _execsql_test rt
0b00: 72 65 65 41 2d 31 2e 30 20 7b 0a 20 20 44 45 4c  reeA-1.0 {.  DEL
0b10: 45 54 45 20 46 52 4f 4d 20 74 31 5f 6e 6f 64 65  ETE FROM t1_node
0b20: 3b 0a 7d 20 7b 7d 0a 0a 64 6f 5f 63 6f 72 72 75  ;.} {}..do_corru
0b30: 70 74 69 6f 6e 5f 74 65 73 74 73 20 72 74 72 65  ption_tests rtre
0b40: 65 41 2d 31 2e 31 20 7b 0a 20 20 31 20 20 20 22  eA-1.1 {.  1   "
0b50: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
0b60: 22 0a 20 20 32 20 20 20 22 53 45 4c 45 43 54 20  ".  2   "SELECT 
0b70: 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20  * FROM t1 WHERE 
0b80: 72 6f 77 69 64 3d 35 22 0a 20 20 33 20 20 20 22  rowid=5".  3   "
0b90: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56  INSERT INTO t1 V
0ba0: 41 4c 55 45 53 28 31 30 30 30 2c 20 31 2c 20 32  ALUES(1000, 1, 2
0bb0: 2c 20 33 2c 20 34 29 22 0a 20 20 34 20 20 20 22  , 3, 4)".  4   "
0bc0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
0bd0: 20 57 48 45 52 45 20 78 31 3c 31 30 20 41 4e 44   WHERE x1<10 AND
0be0: 20 78 32 3e 31 32 22 0a 7d 0a 0a 64 6f 5f 65 78   x2>12".}..do_ex
0bf0: 65 63 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65  ecsql_test rtree
0c00: 41 2d 31 2e 31 2e 31 20 7b 0a 20 20 53 45 4c 45  A-1.1.1 {.  SELE
0c10: 43 54 20 72 74 72 65 65 63 68 65 63 6b 28 27 6d  CT rtreecheck('m
0c20: 61 69 6e 27 2c 20 27 74 31 27 29 0a 7d 20 7b 7b  ain', 't1').} {{
0c30: 4e 6f 64 65 20 31 20 6d 69 73 73 69 6e 67 20 66  Node 1 missing f
0c40: 72 6f 6d 20 64 61 74 61 62 61 73 65 0a 57 72 6f  rom database.Wro
0c50: 6e 67 20 6e 75 6d 62 65 72 20 6f 66 20 65 6e 74  ng number of ent
0c60: 72 69 65 73 20 69 6e 20 25 5f 72 6f 77 69 64 20  ries in %_rowid 
0c70: 74 61 62 6c 65 20 2d 20 65 78 70 65 63 74 65 64  table - expected
0c80: 20 30 2c 20 61 63 74 75 61 6c 20 35 30 30 0a 57   0, actual 500.W
0c90: 72 6f 6e 67 20 6e 75 6d 62 65 72 20 6f 66 20 65  rong number of e
0ca0: 6e 74 72 69 65 73 20 69 6e 20 25 5f 70 61 72 65  ntries in %_pare
0cb0: 6e 74 20 74 61 62 6c 65 20 2d 20 65 78 70 65 63  nt table - expec
0cc0: 74 65 64 20 30 2c 20 61 63 74 75 61 6c 20 32 33  ted 0, actual 23
0cd0: 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  }}..do_execsql_t
0ce0: 65 73 74 20 20 72 74 72 65 65 41 2d 31 2e 32 2e  est  rtreeA-1.2.
0cf0: 30 20 7b 20 44 52 4f 50 20 54 41 42 4c 45 20 74  0 { DROP TABLE t
0d00: 31 5f 6e 6f 64 65 20 7d 20 7b 7d 0a 64 6f 5f 63  1_node } {}.do_c
0d10: 6f 72 72 75 70 74 69 6f 6e 5f 74 65 73 74 73 20  orruption_tests 
0d20: 72 74 72 65 65 41 2d 31 2e 32 20 2d 65 72 72 6f  rtreeA-1.2 -erro
0d30: 72 20 22 64 61 74 61 62 61 73 65 20 64 69 73 6b  r "database disk
0d40: 20 69 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f 72   image is malfor
0d50: 6d 65 64 22 20 7b 0a 20 20 31 20 20 20 22 53 45  med" {.  1   "SE
0d60: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 22 0a  LECT * FROM t1".
0d70: 20 20 32 20 20 20 22 53 45 4c 45 43 54 20 2a 20    2   "SELECT * 
0d80: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 72 6f  FROM t1 WHERE ro
0d90: 77 69 64 3d 35 22 0a 20 20 33 20 20 20 22 49 4e  wid=5".  3   "IN
0da0: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
0db0: 55 45 53 28 31 30 30 30 2c 20 31 2c 20 32 2c 20  UES(1000, 1, 2, 
0dc0: 33 2c 20 34 29 22 0a 20 20 34 20 20 20 22 53 45  3, 4)".  4   "SE
0dd0: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57  LECT * FROM t1 W
0de0: 48 45 52 45 20 78 31 3c 31 30 20 41 4e 44 20 78  HERE x1<10 AND x
0df0: 32 3e 31 32 22 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  2>12".}..#------
0e00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 20 54 65 73 74 20 74 68 65 20 6c  ---.# Test the l
0e50: 69 62 72 61 72 69 65 73 20 72 65 73 70 6f 6e 73  ibraries respons
0e60: 65 20 69 66 20 73 6f 6d 65 20 6f 66 20 74 68 65  e if some of the
0e70: 20 65 6e 74 72 69 65 73 20 69 6e 20 74 68 65 20   entries in the 
0e80: 25 5f 6e 6f 64 65 20 74 61 62 6c 65 20 0a 23 20  %_node table .# 
0e90: 61 72 65 20 74 68 65 20 77 72 6f 6e 67 20 73 69  are the wrong si
0ea0: 7a 65 2e 0a 23 0a 63 72 65 61 74 65 5f 74 31 0a  ze..#.create_t1.
0eb0: 70 6f 70 75 6c 61 74 65 5f 74 31 0a 64 6f 5f 74  populate_t1.do_t
0ec0: 65 73 74 20 72 74 72 65 65 41 2d 32 2e 31 2e 30  est rtreeA-2.1.0
0ed0: 20 7b 0a 20 20 73 65 74 20 6e 6f 64 65 73 20 5b   {.  set nodes [
0ee0: 64 62 20 65 76 61 6c 20 7b 73 65 6c 65 63 74 20  db eval {select 
0ef0: 6e 6f 64 65 6e 6f 20 46 52 4f 4d 20 74 31 5f 6e  nodeno FROM t1_n
0f00: 6f 64 65 7d 5d 0a 20 20 66 6f 72 65 61 63 68 20  ode}].  foreach 
0f10: 7b 61 20 62 20 63 7d 20 24 6e 6f 64 65 73 20 7b  {a b c} $nodes {
0f20: 20 74 72 75 6e 63 61 74 65 5f 6e 6f 64 65 20 24   truncate_node $
0f30: 63 20 32 30 30 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f  c 200 }.} {}.do_
0f40: 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65 73 74 73  corruption_tests
0f50: 20 72 74 72 65 65 41 2d 32 2e 31 20 7b 0a 20 20   rtreeA-2.1 {.  
0f60: 31 20 20 20 22 53 45 4c 45 43 54 20 2a 20 46 52  1   "SELECT * FR
0f70: 4f 4d 20 74 31 22 0a 20 20 32 20 20 20 22 53 45  OM t1".  2   "SE
0f80: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57  LECT * FROM t1 W
0f90: 48 45 52 45 20 72 6f 77 69 64 3d 35 22 0a 20 20  HERE rowid=5".  
0fa0: 33 20 20 20 22 49 4e 53 45 52 54 20 49 4e 54 4f  3   "INSERT INTO
0fb0: 20 74 31 20 56 41 4c 55 45 53 28 31 30 30 30 2c   t1 VALUES(1000,
0fc0: 20 31 2c 20 32 2c 20 33 2c 20 34 29 22 0a 20 20   1, 2, 3, 4)".  
0fd0: 34 20 20 20 22 53 45 4c 45 43 54 20 2a 20 46 52  4   "SELECT * FR
0fe0: 4f 4d 20 74 31 20 57 48 45 52 45 20 78 31 3c 31  OM t1 WHERE x1<1
0ff0: 30 20 41 4e 44 20 78 32 3e 31 32 22 0a 7d 0a 0a  0 AND x2>12".}..
1000: 63 72 65 61 74 65 5f 74 31 0a 70 6f 70 75 6c 61  create_t1.popula
1010: 74 65 5f 74 31 0a 64 6f 5f 74 65 73 74 20 72 74  te_t1.do_test rt
1020: 72 65 65 41 2d 32 2e 32 2e 30 20 7b 20 74 72 75  reeA-2.2.0 { tru
1030: 6e 63 61 74 65 5f 6e 6f 64 65 20 31 20 32 30 30  ncate_node 1 200
1040: 20 7d 20 7b 7d 0a 64 6f 5f 63 6f 72 72 75 70 74   } {}.do_corrupt
1050: 69 6f 6e 5f 74 65 73 74 73 20 72 74 72 65 65 41  ion_tests rtreeA
1060: 2d 32 2e 32 20 7b 0a 20 20 31 20 20 20 22 53 45  -2.2 {.  1   "SE
1070: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 22 0a  LECT * FROM t1".
1080: 20 20 32 20 20 20 22 53 45 4c 45 43 54 20 2a 20    2   "SELECT * 
1090: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 72 6f  FROM t1 WHERE ro
10a0: 77 69 64 3d 35 22 0a 20 20 33 20 20 20 22 49 4e  wid=5".  3   "IN
10b0: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
10c0: 55 45 53 28 31 30 30 30 2c 20 31 2c 20 32 2c 20  UES(1000, 1, 2, 
10d0: 33 2c 20 34 29 22 0a 20 20 34 20 20 20 22 53 45  3, 4)".  4   "SE
10e0: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57  LECT * FROM t1 W
10f0: 48 45 52 45 20 78 31 3c 31 30 20 41 4e 44 20 78  HERE x1<10 AND x
1100: 32 3e 31 32 22 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  2>12".}..#------
1110: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 20 53 65 74 20 74 68 65 20 22 64  ---.# Set the "d
1160: 65 70 74 68 22 20 6f 66 20 74 68 65 20 74 72 65  epth" of the tre
1170: 65 20 73 74 6f 72 65 64 20 6f 6e 20 74 68 65 20  e stored on the 
1180: 72 6f 6f 74 20 6e 6f 64 65 20 69 6e 63 6f 72 72  root node incorr
1190: 65 63 74 6c 79 2e 20 54 65 73 74 0a 23 20 74 68  ectly. Test.# th
11a0: 61 74 20 74 68 69 73 20 64 6f 65 73 20 6e 6f 74  at this does not
11b0: 20 63 61 75 73 65 20 61 6e 79 20 70 72 6f 62 6c   cause any probl
11c0: 65 6d 73 2e 0a 23 0a 63 72 65 61 74 65 5f 74 31  ems..#.create_t1
11d0: 0a 70 6f 70 75 6c 61 74 65 5f 74 31 0a 64 6f 5f  .populate_t1.do_
11e0: 74 65 73 74 20 72 74 72 65 65 41 2d 33 2e 31 2e  test rtreeA-3.1.
11f0: 30 2e 31 20 7b 20 73 65 74 5f 74 72 65 65 5f 64  0.1 { set_tree_d
1200: 65 70 74 68 20 74 31 20 7d 20 7b 31 7d 0a 64 6f  epth t1 } {1}.do
1210: 5f 74 65 73 74 20 72 74 72 65 65 41 2d 33 2e 31  _test rtreeA-3.1
1220: 2e 30 2e 32 20 7b 20 73 65 74 5f 74 72 65 65 5f  .0.2 { set_tree_
1230: 64 65 70 74 68 20 74 31 20 33 20 7d 20 7b 33 7d  depth t1 3 } {3}
1240: 0a 64 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f 74  .do_corruption_t
1250: 65 73 74 73 20 72 74 72 65 65 41 2d 33 2e 31 20  ests rtreeA-3.1 
1260: 7b 0a 20 20 31 20 20 20 22 53 45 4c 45 43 54 20  {.  1   "SELECT 
1270: 2a 20 46 52 4f 4d 20 74 31 22 0a 20 20 32 20 20  * FROM t1".  2  
1280: 20 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20   "SELECT * FROM 
1290: 74 31 20 57 48 45 52 45 20 72 6f 77 69 64 3d 35  t1 WHERE rowid=5
12a0: 22 0a 20 20 33 20 20 20 22 49 4e 53 45 52 54 20  ".  3   "INSERT 
12b0: 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 31  INTO t1 VALUES(1
12c0: 30 30 30 2c 20 31 2c 20 32 2c 20 33 2c 20 34 29  000, 1, 2, 3, 4)
12d0: 22 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  ".}..do_execsql_
12e0: 74 65 73 74 20 72 74 72 65 65 41 2d 33 2e 31 2e  test rtreeA-3.1.
12f0: 30 2e 33 20 7b 0a 20 20 53 45 4c 45 43 54 20 72  0.3 {.  SELECT r
1300: 74 72 65 65 63 68 65 63 6b 28 27 6d 61 69 6e 27  treecheck('main'
1310: 2c 20 27 74 31 27 29 21 3d 22 6f 6b 22 0a 7d 20  , 't1')!="ok".} 
1320: 7b 31 7d 0a 0a 64 6f 5f 74 65 73 74 20 72 74 72  {1}..do_test rtr
1330: 65 65 41 2d 33 2e 32 2e 30 20 7b 20 73 65 74 5f  eeA-3.2.0 { set_
1340: 74 72 65 65 5f 64 65 70 74 68 20 74 31 20 31 30  tree_depth t1 10
1350: 30 30 20 7d 20 7b 31 30 30 30 7d 0a 64 6f 5f 63  00 } {1000}.do_c
1360: 6f 72 72 75 70 74 69 6f 6e 5f 74 65 73 74 73 20  orruption_tests 
1370: 72 74 72 65 65 41 2d 33 2e 32 20 7b 0a 20 20 31  rtreeA-3.2 {.  1
1380: 20 20 20 22 53 45 4c 45 43 54 20 2a 20 46 52 4f     "SELECT * FRO
1390: 4d 20 74 31 22 0a 20 20 32 20 20 20 22 53 45 4c  M t1".  2   "SEL
13a0: 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48  ECT * FROM t1 WH
13b0: 45 52 45 20 72 6f 77 69 64 3d 35 22 0a 20 20 33  ERE rowid=5".  3
13c0: 20 20 20 22 49 4e 53 45 52 54 20 49 4e 54 4f 20     "INSERT INTO 
13d0: 74 31 20 56 41 4c 55 45 53 28 31 30 30 30 2c 20  t1 VALUES(1000, 
13e0: 31 2c 20 32 2c 20 33 2c 20 34 29 22 0a 7d 0a 0a  1, 2, 3, 4)".}..
13f0: 63 72 65 61 74 65 5f 74 31 0a 70 6f 70 75 6c 61  create_t1.popula
1400: 74 65 5f 74 31 0a 64 6f 5f 74 65 73 74 20 72 74  te_t1.do_test rt
1410: 72 65 65 41 2d 33 2e 33 2e 30 20 7b 20 0a 20 20  reeA-3.3.0 { .  
1420: 65 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45  execsql { DELETE
1430: 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 72   FROM t1 WHERE r
1440: 6f 77 69 64 20 3d 20 30 20 7d 0a 20 20 73 65 74  owid = 0 }.  set
1450: 5f 74 72 65 65 5f 64 65 70 74 68 20 74 31 20 36  _tree_depth t1 6
1460: 35 35 33 35 0a 7d 20 7b 36 35 35 33 35 7d 0a 64  5535.} {65535}.d
1470: 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65 73  o_corruption_tes
1480: 74 73 20 72 74 72 65 65 41 2d 33 2e 33 20 7b 0a  ts rtreeA-3.3 {.
1490: 20 20 31 20 20 20 22 53 45 4c 45 43 54 20 2a 20    1   "SELECT * 
14a0: 46 52 4f 4d 20 74 31 22 0a 20 20 32 20 20 20 22  FROM t1".  2   "
14b0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
14c0: 20 57 48 45 52 45 20 72 6f 77 69 64 3d 35 22 0a   WHERE rowid=5".
14d0: 20 20 33 20 20 20 22 49 4e 53 45 52 54 20 49 4e    3   "INSERT IN
14e0: 54 4f 20 74 31 20 56 41 4c 55 45 53 28 31 30 30  TO t1 VALUES(100
14f0: 30 2c 20 31 2c 20 32 2c 20 33 2c 20 34 29 22 0a  0, 1, 2, 3, 4)".
1500: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
1510: 73 74 20 72 74 72 65 65 41 2d 33 2e 33 2e 33 2e  st rtreeA-3.3.3.
1520: 34 20 7b 0a 20 20 53 45 4c 45 43 54 20 72 74 72  4 {.  SELECT rtr
1530: 65 65 63 68 65 63 6b 28 27 6d 61 69 6e 27 2c 20  eecheck('main', 
1540: 27 74 31 27 29 0a 7d 20 7b 7b 52 74 72 65 65 20  't1').} {{Rtree 
1550: 64 65 70 74 68 20 6f 75 74 20 6f 66 20 72 61 6e  depth out of ran
1560: 67 65 20 28 36 35 35 33 35 29 0a 57 72 6f 6e 67  ge (65535).Wrong
1570: 20 6e 75 6d 62 65 72 20 6f 66 20 65 6e 74 72 69   number of entri
1580: 65 73 20 69 6e 20 25 5f 72 6f 77 69 64 20 74 61  es in %_rowid ta
1590: 62 6c 65 20 2d 20 65 78 70 65 63 74 65 64 20 30  ble - expected 0
15a0: 2c 20 61 63 74 75 61 6c 20 34 39 39 0a 57 72 6f  , actual 499.Wro
15b0: 6e 67 20 6e 75 6d 62 65 72 20 6f 66 20 65 6e 74  ng number of ent
15c0: 72 69 65 73 20 69 6e 20 25 5f 70 61 72 65 6e 74  ries in %_parent
15d0: 20 74 61 62 6c 65 20 2d 20 65 78 70 65 63 74 65   table - expecte
15e0: 64 20 30 2c 20 61 63 74 75 61 6c 20 32 33 7d 7d  d 0, actual 23}}
15f0: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
1600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1610: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 20 53  ------------.# S
1640: 65 74 20 74 68 65 20 22 6e 75 6d 62 65 72 20 6f  et the "number o
1650: 66 20 65 6e 74 72 69 65 73 22 20 66 69 65 6c 64  f entries" field
1660: 20 6f 6e 20 73 6f 6d 65 20 6e 6f 64 65 73 20 69   on some nodes i
1670: 6e 63 6f 72 72 65 63 74 6c 79 2e 0a 23 0a 63 72  ncorrectly..#.cr
1680: 65 61 74 65 5f 74 31 0a 70 6f 70 75 6c 61 74 65  eate_t1.populate
1690: 5f 74 31 0a 64 6f 5f 74 65 73 74 20 72 74 72 65  _t1.do_test rtre
16a0: 65 41 2d 34 2e 31 2e 30 20 7b 20 0a 20 20 73 65  eA-4.1.0 { .  se
16b0: 74 5f 65 6e 74 72 79 5f 63 6f 75 6e 74 20 74 31  t_entry_count t1
16c0: 20 31 20 34 30 30 30 0a 7d 20 7b 34 30 30 30 7d   1 4000.} {4000}
16d0: 0a 64 6f 5f 63 6f 72 72 75 70 74 69 6f 6e 5f 74  .do_corruption_t
16e0: 65 73 74 73 20 72 74 72 65 65 41 2d 34 2e 31 20  ests rtreeA-4.1 
16f0: 7b 0a 20 20 31 20 20 20 22 53 45 4c 45 43 54 20  {.  1   "SELECT 
1700: 2a 20 46 52 4f 4d 20 74 31 22 0a 20 20 32 20 20  * FROM t1".  2  
1710: 20 22 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20   "SELECT * FROM 
1720: 74 31 20 57 48 45 52 45 20 72 6f 77 69 64 3d 35  t1 WHERE rowid=5
1730: 22 0a 20 20 33 20 20 20 22 49 4e 53 45 52 54 20  ".  3   "INSERT 
1740: 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 31  INTO t1 VALUES(1
1750: 30 30 30 2c 20 31 2c 20 32 2c 20 33 2c 20 34 29  000, 1, 2, 3, 4)
1760: 22 0a 20 20 34 20 20 20 22 53 45 4c 45 43 54 20  ".  4   "SELECT 
1770: 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20  * FROM t1 WHERE 
1780: 78 31 3c 31 30 20 41 4e 44 20 78 32 3e 31 32 22  x1<10 AND x2>12"
1790: 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .}..#-----------
17a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23  --------------.#
17e0: 20 52 65 6d 6f 76 65 20 65 6e 74 72 69 65 73 20   Remove entries 
17f0: 66 72 6f 6d 20 74 68 65 20 25 5f 70 61 72 65 6e  from the %_paren
1800: 74 20 74 61 62 6c 65 20 61 6e 64 20 63 68 65 63  t table and chec
1810: 6b 20 74 68 61 74 20 74 68 69 73 20 64 6f 65 73  k that this does
1820: 20 6e 6f 74 0a 23 20 63 61 75 73 65 20 61 20 63   not.# cause a c
1830: 72 61 73 68 2e 0a 23 0a 63 72 65 61 74 65 5f 74  rash..#.create_t
1840: 31 0a 70 6f 70 75 6c 61 74 65 5f 74 31 0a 64 6f  1.populate_t1.do
1850: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74  _execsql_test rt
1860: 72 65 65 41 2d 35 2e 31 2e 30 20 7b 20 44 45 4c  reeA-5.1.0 { DEL
1870: 45 54 45 20 46 52 4f 4d 20 74 31 5f 70 61 72 65  ETE FROM t1_pare
1880: 6e 74 20 7d 20 7b 7d 0a 64 6f 5f 63 6f 72 72 75  nt } {}.do_corru
1890: 70 74 69 6f 6e 5f 74 65 73 74 73 20 72 74 72 65  ption_tests rtre
18a0: 65 41 2d 35 2e 31 20 7b 0a 20 20 31 20 20 20 22  eA-5.1 {.  1   "
18b0: 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31 20 57  DELETE FROM t1 W
18c0: 48 45 52 45 20 72 6f 77 69 64 20 3d 20 35 22 0a  HERE rowid = 5".
18d0: 20 20 32 20 20 20 22 44 45 4c 45 54 45 20 46 52    2   "DELETE FR
18e0: 4f 4d 20 74 31 22 0a 7d 0a 0a 64 6f 5f 65 78 65  OM t1".}..do_exe
18f0: 63 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65 41  csql_test rtreeA
1900: 2d 35 2e 32 20 7b 0a 20 20 53 45 4c 45 43 54 20  -5.2 {.  SELECT 
1910: 72 74 72 65 65 63 68 65 63 6b 28 27 6d 61 69 6e  rtreecheck('main
1920: 27 2c 20 27 74 31 27 29 21 3d 22 6f 6b 22 0a 7d  ', 't1')!="ok".}
1930: 20 7b 31 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d   {1}..#---------
1940: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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: 0a 23 20 41 64 64 20 73 6f 6d 65 20 62 61 64 20  .# Add some bad 
1990: 65 6e 74 72 69 65 73 20 74 6f 20 74 68 65 20 25  entries to the %
19a0: 5f 70 61 72 65 6e 74 20 74 61 62 6c 65 2e 0a 23  _parent table..#
19b0: 0a 63 72 65 61 74 65 5f 74 31 0a 70 6f 70 75 6c  .create_t1.popul
19c0: 61 74 65 5f 74 31 0a 64 6f 5f 65 78 65 63 73 71  ate_t1.do_execsq
19d0: 6c 5f 74 65 73 74 20 72 74 72 65 65 41 2d 36 2e  l_test rtreeA-6.
19e0: 31 2e 30 20 7b 20 0a 20 20 55 50 44 41 54 45 20  1.0 { .  UPDATE 
19f0: 74 31 5f 70 61 72 65 6e 74 20 73 65 74 20 70 61  t1_parent set pa
1a00: 72 65 6e 74 6e 6f 64 65 20 3d 20 70 61 72 65 6e  rentnode = paren
1a10: 74 6e 6f 64 65 2b 31 0a 7d 20 7b 7d 0a 64 6f 5f  tnode+1.} {}.do_
1a20: 63 6f 72 72 75 70 74 69 6f 6e 5f 74 65 73 74 73  corruption_tests
1a30: 20 72 74 72 65 65 41 2d 36 2e 31 20 7b 0a 20 20   rtreeA-6.1 {.  
1a40: 31 20 20 20 22 44 45 4c 45 54 45 20 46 52 4f 4d  1   "DELETE FROM
1a50: 20 74 31 20 57 48 45 52 45 20 72 6f 77 69 64 20   t1 WHERE rowid 
1a60: 3d 20 35 22 0a 20 20 32 20 20 20 22 55 50 44 41  = 5".  2   "UPDA
1a70: 54 45 20 74 31 20 53 45 54 20 78 31 3d 78 31 2b  TE t1 SET x1=x1+
1a80: 31 2c 20 78 32 3d 78 32 2b 31 22 0a 7d 0a 0a 64  1, x2=x2+1".}..d
1a90: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72  o_execsql_test r
1aa0: 74 72 65 65 41 2d 36 2e 32 20 7b 0a 20 20 53 45  treeA-6.2 {.  SE
1ab0: 4c 45 43 54 20 72 74 72 65 65 63 68 65 63 6b 28  LECT rtreecheck(
1ac0: 27 6d 61 69 6e 27 2c 20 27 74 31 27 29 21 3d 22  'main', 't1')!="
1ad0: 6f 6b 22 0a 7d 20 7b 31 7d 0a 0a 23 2d 2d 2d 2d  ok".} {1}..#----
1ae0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1af0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 20 54 72 75 6e 63 61 74 65  -----.# Truncate
1b30: 64 20 62 6c 6f 62 73 20 69 6e 20 74 68 65 20 5f  d blobs in the _
1b40: 6e 6f 64 65 20 74 61 62 6c 65 2e 0a 23 0a 63 72  node table..#.cr
1b50: 65 61 74 65 5f 74 31 0a 70 6f 70 75 6c 61 74 65  eate_t1.populate
1b60: 5f 74 31 0a 73 71 6c 69 74 65 33 20 64 62 20 74  _t1.sqlite3 db t
1b70: 65 73 74 2e 64 62 0a 64 6f 5f 65 78 65 63 73 71  est.db.do_execsq
1b80: 6c 5f 74 65 73 74 20 72 74 72 65 65 41 2d 37 2e  l_test rtreeA-7.
1b90: 31 30 30 20 7b 20 0a 20 20 55 50 44 41 54 45 20  100 { .  UPDATE 
1ba0: 74 31 5f 6e 6f 64 65 20 53 45 54 20 64 61 74 61  t1_node SET data
1bb0: 3d 78 27 27 20 57 48 45 52 45 20 72 6f 77 69 64  =x'' WHERE rowid
1bc0: 3d 31 3b 0a 7d 20 7b 7d 0a 64 6f 5f 63 61 74 63  =1;.} {}.do_catc
1bd0: 68 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65 41  hsql_test rtreeA
1be0: 2d 37 2e 31 31 30 20 7b 0a 20 20 53 45 4c 45 43  -7.110 {.  SELEC
1bf0: 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52  T * FROM t1 WHER
1c00: 45 20 78 31 3e 30 20 41 4e 44 20 78 31 3c 31 30  E x1>0 AND x1<10
1c10: 30 20 41 4e 44 20 78 32 3e 30 20 41 4e 44 20 78  0 AND x2>0 AND x
1c20: 32 3c 31 30 30 3b 0a 7d 20 7b 31 20 7b 75 6e 64  2<100;.} {1 {und
1c30: 65 72 73 69 7a 65 20 52 54 72 65 65 20 62 6c 6f  ersize RTree blo
1c40: 62 73 20 69 6e 20 22 74 31 5f 6e 6f 64 65 22 7d  bs in "t1_node"}
1c50: 7d 0a 64 6f 5f 74 65 73 74 20 72 74 72 65 65 41  }.do_test rtreeA
1c60: 2d 37 2e 31 32 30 20 7b 0a 20 20 73 71 6c 69 74  -7.120 {.  sqlit
1c70: 65 33 5f 65 78 74 65 6e 64 65 64 5f 65 72 72 63  e3_extended_errc
1c80: 6f 64 65 20 64 62 0a 7d 20 7b 53 51 4c 49 54 45  ode db.} {SQLITE
1c90: 5f 43 4f 52 52 55 50 54 5f 56 54 41 42 7d 0a 0a  _CORRUPT_VTAB}..
1ca0: 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a 0a        .finish_test..