/ Hex Artifact Content
Login

Artifact 9772e16da71e17e02bdebf0a5188590f289ab37d:


0000: 23 20 32 30 31 30 20 46 65 62 72 75 61 72 79 20  # 2010 February 
0010: 31 36 0a 23 0a 23 20 54 68 65 20 61 75 74 68 6f  16.#.# The autho
0020: 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 79  r disclaims copy
0030: 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 6f  right to this so
0040: 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 70  urce code.  In p
0050: 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67 61  lace of.# a lega
0060: 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20 69  l notice, here i
0070: 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23 0a  s a blessing:.#.
0080: 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f 20  #    May you do 
0090: 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76 69  good and not evi
00a0: 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20  l..#    May you 
00b0: 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73 73  find forgiveness
00c0: 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61 6e   for yourself an
00d0: 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72 73  d forgive others
00e0: 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 73  ..#    May you s
00f0: 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65 76  hare freely, nev
0100: 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20 74  er taking more t
0110: 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23 0a  han you give..#.
0120: 23 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 2a 2a 2a 2a 2a 2a 0a 23 20 0a 23 0a 0a 69  ********.# .#..i
0170: 66 20 7b 21 5b 69 6e 66 6f 20 65 78 69 73 74 73  f {![info exists
0180: 20 74 65 73 74 64 69 72 5d 7d 20 7b 0a 20 20 73   testdir]} {.  s
0190: 65 74 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65  et testdir [file
01a0: 20 6a 6f 69 6e 20 5b 66 69 6c 65 20 64 69 72 6e   join [file dirn
01b0: 61 6d 65 20 5b 69 6e 66 6f 20 73 63 72 69 70 74  ame [info script
01c0: 5d 5d 20 2e 2e 20 2e 2e 20 74 65 73 74 5d 0a 7d  ]] .. .. test].}
01d0: 20 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69   .source $testdi
01e0: 72 2f 74 65 73 74 65 72 2e 74 63 6c 0a 69 66 63  r/tester.tcl.ifc
01f0: 61 70 61 62 6c 65 20 21 72 74 72 65 65 20 7b 20  apable !rtree { 
0200: 66 69 6e 69 73 68 5f 74 65 73 74 20 3b 20 72 65  finish_test ; re
0210: 74 75 72 6e 20 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  turn }..#-------
0220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0260: 2d 2d 0a 23 20 54 68 65 20 66 6f 6c 6c 6f 77 69  --.# The followi
0270: 6e 67 20 62 6c 6f 63 6b 20 6f 66 20 74 65 73 74  ng block of test
0280: 73 20 2d 20 72 74 72 65 65 38 2d 31 2e 2a 20 2d  s - rtree8-1.* -
0290: 20 66 65 61 74 75 72 65 20 72 65 61 64 69 6e 67   feature reading
02a0: 20 61 6e 64 20 77 72 69 74 69 6e 67 0a 23 20 61   and writing.# a
02b0: 6e 20 72 2d 74 72 65 65 20 74 61 62 6c 65 20 77  n r-tree table w
02c0: 68 69 6c 65 20 74 68 65 72 65 20 65 78 69 73 74  hile there exist
02d0: 20 6f 70 65 6e 20 63 75 72 73 6f 72 73 20 6f 6e   open cursors on
02e0: 20 69 74 2e 0a 23 0a 70 72 6f 63 20 70 6f 70 75   it..#.proc popu
02f0: 6c 61 74 65 5f 74 31 20 7b 6e 7d 20 7b 0a 20 20  late_t1 {n} {.  
0300: 65 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45  execsql { DELETE
0310: 20 46 52 4f 4d 20 74 31 20 7d 0a 20 20 66 6f 72   FROM t1 }.  for
0320: 20 7b 73 65 74 20 69 20 31 7d 20 7b 24 69 20 3c   {set i 1} {$i <
0330: 3d 20 24 6e 7d 20 7b 69 6e 63 72 20 69 7d 20 7b  = $n} {incr i} {
0340: 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 49  .    execsql { I
0350: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41  NSERT INTO t1 VA
0360: 4c 55 45 53 28 24 69 2c 20 24 69 2c 20 24 69 2b  LUES($i, $i, $i+
0370: 32 29 20 7d 0a 20 20 7d 0a 7d 0a 0a 23 20 41 20  2) }.  }.}..# A 
0380: 44 45 4c 45 54 45 20 77 68 69 6c 65 20 61 20 63  DELETE while a c
0390: 75 72 73 6f 72 20 69 73 20 72 65 61 64 69 6e 67  ursor is reading
03a0: 20 74 68 65 20 74 61 62 6c 65 2e 0a 23 0a 64 6f   the table..#.do
03b0: 5f 74 65 73 74 20 72 74 72 65 65 38 2d 31 2e 31  _test rtree8-1.1
03c0: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
03d0: 20 50 52 41 47 4d 41 20 70 61 67 65 5f 73 69 7a   PRAGMA page_siz
03e0: 65 20 3d 20 35 31 32 20 7d 0a 20 20 65 78 65 63  e = 512 }.  exec
03f0: 73 71 6c 20 7b 20 43 52 45 41 54 45 20 56 49 52  sql { CREATE VIR
0400: 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53  TUAL TABLE t1 US
0410: 49 4e 47 20 72 74 72 65 65 5f 69 33 32 28 69 64  ING rtree_i32(id
0420: 2c 20 78 31 2c 20 78 32 29 20 7d 0a 20 20 70 6f  , x1, x2) }.  po
0430: 70 75 6c 61 74 65 5f 74 31 20 35 0a 7d 20 7b 7d  pulate_t1 5.} {}
0440: 0a 64 6f 5f 74 65 73 74 20 72 74 72 65 65 38 2d  .do_test rtree8-
0450: 31 2e 31 2e 32 20 7b 0a 20 20 73 65 74 20 72 65  1.1.2 {.  set re
0460: 73 20 5b 6c 69 73 74 5d 0a 20 20 64 62 20 65 76  s [list].  db ev
0470: 61 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52  al { SELECT * FR
0480: 4f 4d 20 74 31 20 7d 20 7b 20 0a 20 20 20 20 6c  OM t1 } { .    l
0490: 61 70 70 65 6e 64 20 72 65 73 20 24 78 31 20 24  append res $x1 $
04a0: 78 32 0a 20 20 20 20 69 66 20 7b 24 69 64 3d 3d  x2.    if {$id==
04b0: 33 7d 20 7b 20 64 62 20 65 76 61 6c 20 7b 20 44  3} { db eval { D
04c0: 45 4c 45 54 45 20 46 52 4f 4d 20 74 31 20 57 48  ELETE FROM t1 WH
04d0: 45 52 45 20 69 64 3e 33 20 7d 20 7d 0a 20 20 7d  ERE id>3 } }.  }
04e0: 0a 20 20 73 65 74 20 72 65 73 0a 7d 20 7b 31 20  .  set res.} {1 
04f0: 33 20 32 20 34 20 33 20 35 7d 0a 64 6f 5f 74 65  3 2 4 3 5}.do_te
0500: 73 74 20 72 74 72 65 65 38 2d 31 2e 31 2e 33 20  st rtree8-1.1.3 
0510: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45  {.  execsql { SE
0520: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 7d  LECT * FROM t1 }
0530: 0a 7d 20 7b 31 20 31 20 33 20 32 20 32 20 34 20  .} {1 1 3 2 2 4 
0540: 33 20 33 20 35 7d 0a 0a 23 20 4d 61 6e 79 20 53  3 3 5}..# Many S
0550: 45 4c 45 43 54 73 20 6f 6e 20 74 68 65 20 73 61  ELECTs on the sa
0560: 6d 65 20 73 6d 61 6c 6c 20 74 61 62 6c 65 2e 0a  me small table..
0570: 23 0a 70 72 6f 63 20 6e 65 73 74 65 64 5f 73 65  #.proc nested_se
0580: 6c 65 63 74 20 7b 6e 7d 20 7b 0a 20 20 73 65 74  lect {n} {.  set
0590: 20 3a 3a 6d 61 78 20 24 6e 0a 20 20 64 62 20 65   ::max $n.  db e
05a0: 76 61 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46  val { SELECT * F
05b0: 52 4f 4d 20 74 31 20 7d 20 7b 0a 20 20 20 20 69  ROM t1 } {.    i
05c0: 66 20 7b 24 69 64 20 3d 3d 20 24 6e 7d 20 7b 20  f {$id == $n} { 
05d0: 6e 65 73 74 65 64 5f 73 65 6c 65 63 74 20 5b 65  nested_select [e
05e0: 78 70 72 20 24 6e 2b 31 5d 20 7d 0a 20 20 7d 0a  xpr $n+1] }.  }.
05f0: 20 20 72 65 74 75 72 6e 20 24 3a 3a 6d 61 78 0a    return $::max.
0600: 7d 0a 64 6f 5f 74 65 73 74 20 72 74 72 65 65 38  }.do_test rtree8
0610: 2d 31 2e 32 2e 31 20 7b 20 70 6f 70 75 6c 61 74  -1.2.1 { populat
0620: 65 5f 74 31 20 35 30 20 20 7d 20 7b 7d 0a 64 6f  e_t1 50  } {}.do
0630: 5f 74 65 73 74 20 72 74 72 65 65 38 2d 31 2e 32  _test rtree8-1.2
0640: 2e 32 20 7b 20 6e 65 73 74 65 64 5f 73 65 6c 65  .2 { nested_sele
0650: 63 74 20 31 20 7d 20 7b 35 31 7d 0a 0a 23 20 54  ct 1 } {51}..# T
0660: 68 69 73 20 74 65 73 74 20 72 75 6e 73 20 6d 61  his test runs ma
0670: 6e 79 20 53 45 4c 45 43 54 20 71 75 65 72 69 65  ny SELECT querie
0680: 73 20 73 69 6d 75 6c 74 61 6e 65 6f 75 73 6c 79  s simultaneously
0690: 20 61 67 61 69 6e 73 74 20 61 20 6c 61 72 67 65   against a large
06a0: 20 0a 23 20 74 61 62 6c 65 2c 20 63 61 75 73 69   .# table, causi
06b0: 6e 67 20 61 20 63 6f 6c 6c 69 73 69 6f 6e 20 69  ng a collision i
06c0: 6e 20 74 68 65 20 68 61 73 68 2d 74 61 62 6c 65  n the hash-table
06d0: 20 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 72   used to store r
06e0: 2d 74 72 65 65 20 0a 23 20 6e 6f 64 65 73 20 69  -tree .# nodes i
06f0: 6e 74 65 72 6e 61 6c 6c 79 2e 0a 23 0a 70 6f 70  nternally..#.pop
0700: 75 6c 61 74 65 5f 74 31 20 31 35 30 30 0a 64 6f  ulate_t1 1500.do
0710: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74  _execsql_test rt
0720: 72 65 65 38 2d 31 2e 33 2e 31 20 7b 20 53 45 4c  ree8-1.3.1 { SEL
0730: 45 43 54 20 6d 61 78 28 6e 6f 64 65 6e 6f 29 20  ECT max(nodeno) 
0740: 46 52 4f 4d 20 74 31 5f 6e 6f 64 65 20 7d 20 7b  FROM t1_node } {
0750: 31 36 34 7d 0a 64 6f 5f 74 65 73 74 20 72 74 72  164}.do_test rtr
0760: 65 65 38 2d 31 2e 33 2e 32 20 7b 0a 20 20 73 65  ee8-1.3.2 {.  se
0770: 74 20 72 6f 77 69 64 73 20 5b 65 78 65 63 73 71  t rowids [execsq
0780: 6c 20 7b 53 45 4c 45 43 54 20 6d 69 6e 28 72 6f  l {SELECT min(ro
0790: 77 69 64 29 20 46 52 4f 4d 20 74 31 5f 72 6f 77  wid) FROM t1_row
07a0: 69 64 20 47 52 4f 55 50 20 42 59 20 6e 6f 64 65  id GROUP BY node
07b0: 6e 6f 7d 5d 0a 20 20 73 65 74 20 73 74 6d 74 5f  no}].  set stmt_
07c0: 6c 69 73 74 20 5b 6c 69 73 74 5d 0a 20 20 66 6f  list [list].  fo
07d0: 72 65 61 63 68 20 72 6f 77 20 24 72 6f 77 69 64  reach row $rowid
07e0: 73 20 7b 0a 20 20 20 20 73 65 74 20 73 74 6d 74  s {.    set stmt
07f0: 20 5b 73 71 6c 69 74 65 33 5f 70 72 65 70 61 72   [sqlite3_prepar
0800: 65 20 64 62 20 22 53 45 4c 45 43 54 20 2a 20 46  e db "SELECT * F
0810: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 69 64 20  ROM t1 WHERE id 
0820: 3d 20 24 72 6f 77 22 20 2d 31 20 74 61 69 6c 5d  = $row" -1 tail]
0830: 0a 20 20 20 20 73 71 6c 69 74 65 33 5f 73 74 65  .    sqlite3_ste
0840: 70 20 24 73 74 6d 74 0a 20 20 20 20 6c 61 70 70  p $stmt.    lapp
0850: 65 6e 64 20 72 65 73 5f 6c 69 73 74 20 5b 73 71  end res_list [sq
0860: 6c 69 74 65 33 5f 63 6f 6c 75 6d 6e 5f 69 6e 74  lite3_column_int
0870: 20 24 73 74 6d 74 20 30 5d 0a 20 20 20 20 6c 61   $stmt 0].    la
0880: 70 70 65 6e 64 20 73 74 6d 74 5f 6c 69 73 74 20  ppend stmt_list 
0890: 24 73 74 6d 74 20 0a 20 20 7d 0a 7d 20 7b 7d 0a  $stmt .  }.} {}.
08a0: 64 6f 5f 74 65 73 74 20 72 74 72 65 65 38 2d 31  do_test rtree8-1
08b0: 2e 33 2e 33 20 7b 20 73 65 74 20 72 65 73 5f 6c  .3.3 { set res_l
08c0: 69 73 74 20 7d 20 24 72 6f 77 69 64 73 0a 64 6f  ist } $rowids.do
08d0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74  _execsql_test rt
08e0: 72 65 65 38 2d 31 2e 33 2e 34 20 7b 20 53 45 4c  ree8-1.3.4 { SEL
08f0: 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f  ECT count(*) FRO
0900: 4d 20 74 31 20 7d 20 7b 31 35 30 30 7d 0a 64 6f  M t1 } {1500}.do
0910: 5f 74 65 73 74 20 72 74 72 65 65 38 2d 31 2e 33  _test rtree8-1.3
0920: 2e 35 20 7b 20 0a 20 20 66 6f 72 65 61 63 68 20  .5 { .  foreach 
0930: 73 74 6d 74 20 24 73 74 6d 74 5f 6c 69 73 74 20  stmt $stmt_list 
0940: 7b 20 73 71 6c 69 74 65 33 5f 66 69 6e 61 6c 69  { sqlite3_finali
0950: 7a 65 20 24 73 74 6d 74 20 7d 0a 7d 20 7b 7d 0a  ze $stmt }.} {}.
0960: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
0970: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0980: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0990: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54  ------------.# T
09b0: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 62 6c 6f  he following blo
09c0: 63 6b 20 6f 66 20 74 65 73 74 73 20 2d 20 72 74  ck of tests - rt
09d0: 72 65 65 38 2d 32 2e 2a 20 2d 20 74 65 73 74 20  ree8-2.* - test 
09e0: 61 20 63 6f 75 70 6c 65 20 6f 66 20 64 61 74 61  a couple of data
09f0: 62 61 73 65 0a 23 20 63 6f 72 72 75 70 74 69 6f  base.# corruptio
0a00: 6e 20 63 61 73 65 73 2e 20 49 6e 20 74 68 69 73  n cases. In this
0a10: 20 63 61 73 65 20 74 68 69 6e 67 73 20 61 72 65   case things are
0a20: 20 6e 6f 74 20 63 6f 72 72 75 70 74 65 64 20 61   not corrupted a
0a30: 74 20 74 68 65 20 62 2d 74 72 65 65 0a 23 20 6c  t the b-tree.# l
0a40: 65 76 65 6c 2c 20 62 75 74 20 74 68 65 20 63 6f  evel, but the co
0a50: 6e 74 65 6e 74 73 20 6f 66 20 74 68 65 20 76 61  ntents of the va
0a60: 72 69 6f 75 73 20 74 61 62 6c 65 73 20 75 73 65  rious tables use
0a70: 64 20 69 6e 74 65 72 6e 61 6c 6c 79 20 62 79 20  d internally by 
0a80: 61 6e 0a 23 20 72 2d 74 72 65 65 20 74 61 62 6c  an.# r-tree tabl
0a90: 65 20 61 72 65 20 69 6e 63 6f 6e 73 69 73 74 65  e are inconsiste
0aa0: 6e 74 2e 0a 23 0a 70 6f 70 75 6c 61 74 65 5f 74  nt..#.populate_t
0ab0: 31 20 35 30 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  1 50.do_execsql_
0ac0: 74 65 73 74 20 72 74 72 65 65 38 2d 32 2e 31 2e  test rtree8-2.1.
0ad0: 31 20 7b 20 53 45 4c 45 43 54 20 6d 61 78 28 6e  1 { SELECT max(n
0ae0: 6f 64 65 6e 6f 29 20 46 52 4f 4d 20 74 31 5f 6e  odeno) FROM t1_n
0af0: 6f 64 65 20 7d 20 7b 35 7d 0a 64 6f 5f 65 78 65  ode } {5}.do_exe
0b00: 63 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65 38  csql_test rtree8
0b10: 2d 32 2e 31 2e 32 20 7b 20 44 45 4c 45 54 45 20  -2.1.2 { DELETE 
0b20: 46 52 4f 4d 20 74 31 5f 6e 6f 64 65 20 7d 20 7b  FROM t1_node } {
0b30: 7d 0a 66 6f 72 20 7b 73 65 74 20 69 20 31 7d 20  }.for {set i 1} 
0b40: 7b 24 69 20 3c 3d 20 35 30 7d 20 7b 69 6e 63 72  {$i <= 50} {incr
0b50: 20 69 7d 20 7b 0a 20 20 64 6f 5f 63 61 74 63 68   i} {.  do_catch
0b60: 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65 38 2d  sql_test rtree8-
0b70: 32 2e 31 2e 33 2e 24 69 20 7b 20 0a 20 20 20 20  2.1.3.$i { .    
0b80: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
0b90: 20 57 48 45 52 45 20 69 64 20 3d 20 24 69 20 0a   WHERE id = $i .
0ba0: 20 20 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65    } {1 {database
0bb0: 20 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d   disk image is m
0bc0: 61 6c 66 6f 72 6d 65 64 7d 7d 0a 7d 0a 64 6f 5f  alformed}}.}.do_
0bd0: 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20 72 74  catchsql_test rt
0be0: 72 65 65 38 2d 32 2e 31 2e 34 20 7b 20 0a 20 20  ree8-2.1.4 { .  
0bf0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
0c00: 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20  .} {1 {database 
0c10: 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61  disk image is ma
0c20: 6c 66 6f 72 6d 65 64 7d 7d 0a 64 6f 5f 63 61 74  lformed}}.do_cat
0c30: 63 68 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65  chsql_test rtree
0c40: 38 2d 32 2e 31 2e 35 20 7b 20 0a 20 20 44 45 4c  8-2.1.5 { .  DEL
0c50: 45 54 45 20 46 52 4f 4d 20 74 31 0a 7d 20 7b 31  ETE FROM t1.} {1
0c60: 20 7b 64 61 74 61 62 61 73 65 20 64 69 73 6b 20   {database disk 
0c70: 69 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f 72 6d  image is malform
0c80: 65 64 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  ed}}..do_execsql
0c90: 5f 74 65 73 74 20 72 74 72 65 65 38 2d 32 2e 31  _test rtree8-2.1
0ca0: 2e 36 20 7b 20 0a 20 20 44 52 4f 50 20 54 41 42  .6 { .  DROP TAB
0cb0: 4c 45 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20  LE t1;.  CREATE 
0cc0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31  VIRTUAL TABLE t1
0cd0: 20 55 53 49 4e 47 20 72 74 72 65 65 5f 69 33 32   USING rtree_i32
0ce0: 28 69 64 2c 20 78 31 2c 20 78 32 29 3b 0a 7d 20  (id, x1, x2);.} 
0cf0: 7b 7d 0a 0a 0a 70 6f 70 75 6c 61 74 65 5f 74 31  {}...populate_t1
0d00: 20 35 30 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74   50.do_execsql_t
0d10: 65 73 74 20 72 74 72 65 65 38 2d 32 2e 32 2e 31  est rtree8-2.2.1
0d20: 20 7b 0a 20 20 44 45 4c 45 54 45 20 46 52 4f 4d   {.  DELETE FROM
0d30: 20 74 31 5f 70 61 72 65 6e 74 0a 7d 20 7b 7d 0a   t1_parent.} {}.
0d40: 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74  do_catchsql_test
0d50: 20 72 74 72 65 65 38 2d 32 2e 32 2e 32 20 7b 0a   rtree8-2.2.2 {.
0d60: 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31    DELETE FROM t1
0d70: 20 57 48 45 52 45 20 69 64 3d 32 35 0a 7d 20 7b   WHERE id=25.} {
0d80: 31 20 7b 64 61 74 61 62 61 73 65 20 64 69 73 6b  1 {database disk
0d90: 20 69 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f 72   image is malfor
0da0: 6d 65 64 7d 7d 0a 64 6f 5f 65 78 65 63 73 71 6c  med}}.do_execsql
0db0: 5f 74 65 73 74 20 72 74 72 65 65 38 2d 32 2e 32  _test rtree8-2.2
0dc0: 2e 33 20 7b 20 0a 20 20 44 52 4f 50 20 54 41 42  .3 { .  DROP TAB
0dd0: 4c 45 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20  LE t1;.  CREATE 
0de0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31  VIRTUAL TABLE t1
0df0: 20 55 53 49 4e 47 20 72 74 72 65 65 5f 69 33 32   USING rtree_i32
0e00: 28 69 64 2c 20 78 31 2c 20 78 32 29 3b 0a 7d 20  (id, x1, x2);.} 
0e10: 7b 7d 0a 0a 0a 23 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 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 0a  ---------------.
0e60: 23 20 54 65 73 74 20 74 68 61 74 20 74 72 79 69  # Test that tryi
0e70: 6e 67 20 74 6f 20 75 73 65 20 74 68 65 20 4d 41  ng to use the MA
0e80: 54 43 48 20 6f 70 65 72 61 74 6f 72 20 77 69 74  TCH operator wit
0e90: 68 20 74 68 65 20 72 2d 74 72 65 65 20 6d 6f 64  h the r-tree mod
0ea0: 75 6c 65 20 64 6f 65 73 0a 23 20 6e 6f 74 20 63  ule does.# not c
0eb0: 6f 6e 66 75 73 65 20 69 74 2e 20 0a 23 0a 70 6f  onfuse it. .#.po
0ec0: 70 75 6c 61 74 65 5f 74 31 20 31 30 0a 64 6f 5f  pulate_t1 10.do_
0ed0: 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20 72 74  catchsql_test rt
0ee0: 72 65 65 38 2d 33 2e 31 20 7b 20 0a 20 20 53 45  ree8-3.1 { .  SE
0ef0: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57  LECT * FROM t1 W
0f00: 48 45 52 45 20 78 31 20 4d 41 54 43 48 20 27 31  HERE x1 MATCH '1
0f10: 32 33 34 27 0a 7d 20 7b 31 20 7b 53 51 4c 20 6c  234'.} {1 {SQL l
0f20: 6f 67 69 63 20 65 72 72 6f 72 20 6f 72 20 6d 69  ogic error or mi
0f30: 73 73 69 6e 67 20 64 61 74 61 62 61 73 65 7d 7d  ssing database}}
0f40: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
0f50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0f60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0f70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0f80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54  ------------.# T
0f90: 65 73 74 20 61 20 63 6f 75 70 6c 65 20 6f 66 20  est a couple of 
0fa0: 69 6e 76 61 6c 69 64 20 61 72 67 75 6d 65 6e 74  invalid argument
0fb0: 73 20 74 6f 20 72 74 72 65 65 64 65 70 74 68 28  s to rtreedepth(
0fc0: 29 2e 0a 23 0a 64 6f 5f 63 61 74 63 68 73 71 6c  )..#.do_catchsql
0fd0: 5f 74 65 73 74 20 72 74 72 65 65 38 2d 34 2e 31  _test rtree8-4.1
0fe0: 20 7b 0a 20 20 53 45 4c 45 43 54 20 72 74 72 65   {.  SELECT rtre
0ff0: 65 64 65 70 74 68 28 27 68 65 6c 6c 6f 20 77 6f  edepth('hello wo
1000: 72 6c 64 27 29 0a 7d 20 7b 31 20 7b 49 6e 76 61  rld').} {1 {Inva
1010: 6c 69 64 20 61 72 67 75 6d 65 6e 74 20 74 6f 20  lid argument to 
1020: 72 74 72 65 65 64 65 70 74 68 28 29 7d 7d 0a 64  rtreedepth()}}.d
1030: 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20  o_catchsql_test 
1040: 72 74 72 65 65 38 2d 34 2e 32 20 7b 0a 20 20 53  rtree8-4.2 {.  S
1050: 45 4c 45 43 54 20 72 74 72 65 65 64 65 70 74 68  ELECT rtreedepth
1060: 28 58 27 30 30 27 29 0a 7d 20 7b 31 20 7b 49 6e  (X'00').} {1 {In
1070: 76 61 6c 69 64 20 61 72 67 75 6d 65 6e 74 20 74  valid argument t
1080: 6f 20 72 74 72 65 65 64 65 70 74 68 28 29 7d 7d  o rtreedepth()}}
1090: 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ...#------------
10a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
10e0: 44 65 6c 65 74 65 20 68 61 6c 66 20 6f 66 20 61  Delete half of a
10f0: 20 6c 6f 70 73 69 64 65 64 20 74 72 65 65 2e 0a   lopsided tree..
1100: 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  #.do_execsql_tes
1110: 74 20 72 74 72 65 65 38 2d 35 2e 31 20 7b 20 0a  t rtree8-5.1 { .
1120: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
1130: 20 54 41 42 4c 45 20 74 32 20 55 53 49 4e 47 20   TABLE t2 USING 
1140: 72 74 72 65 65 5f 69 33 32 28 69 64 2c 20 78 31  rtree_i32(id, x1
1150: 2c 20 78 32 29 20 0a 7d 20 7b 7d 0a 64 6f 5f 74  , x2) .} {}.do_t
1160: 65 73 74 20 72 74 72 65 65 38 2d 35 2e 32 20 7b  est rtree8-5.2 {
1170: 0a 20 20 65 78 65 63 73 71 6c 20 42 45 47 49 4e  .  execsql BEGIN
1180: 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20 30 7d  .  for {set i 0}
1190: 20 7b 24 69 20 3c 20 31 30 30 7d 20 7b 69 6e 63   {$i < 100} {inc
11a0: 72 20 69 7d 20 7b 0a 20 20 20 20 65 78 65 63 73  r i} {.    execs
11b0: 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f  ql { INSERT INTO
11c0: 20 74 32 20 56 41 4c 55 45 53 28 24 69 2c 20 31   t2 VALUES($i, 1
11d0: 30 30 2c 20 31 30 31 29 20 7d 0a 20 20 7d 0a 20  00, 101) }.  }. 
11e0: 20 66 6f 72 20 7b 73 65 74 20 69 20 31 30 30 7d   for {set i 100}
11f0: 20 7b 24 69 20 3c 20 32 30 30 7d 20 7b 69 6e 63   {$i < 200} {inc
1200: 72 20 69 7d 20 7b 0a 20 20 20 20 65 78 65 63 73  r i} {.    execs
1210: 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f  ql { INSERT INTO
1220: 20 74 32 20 56 41 4c 55 45 53 28 24 69 2c 20 31   t2 VALUES($i, 1
1230: 30 30 30 2c 20 31 30 30 31 29 20 7d 0a 20 20 7d  000, 1001) }.  }
1240: 0a 20 20 65 78 65 63 73 71 6c 20 43 4f 4d 4d 49  .  execsql COMMI
1250: 54 0a 7d 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 72  T.} {}.do_test r
1260: 74 72 65 65 38 2d 35 2e 33 20 7b 0a 20 20 65 78  tree8-5.3 {.  ex
1270: 65 63 73 71 6c 20 42 45 47 49 4e 0a 20 20 66 6f  ecsql BEGIN.  fo
1280: 72 20 7b 73 65 74 20 69 20 30 7d 20 7b 24 69 20  r {set i 0} {$i 
1290: 3c 20 32 30 30 7d 20 7b 69 6e 63 72 20 69 7d 20  < 200} {incr i} 
12a0: 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20  {.    execsql { 
12b0: 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 32 20 57  DELETE FROM t2 W
12c0: 48 45 52 45 20 69 64 20 3d 20 24 69 20 7d 0a 20  HERE id = $i }. 
12d0: 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 43 4f 4d   }.  execsql COM
12e0: 4d 49 54 0a 7d 20 7b 7d 0a 0a 0a 66 69 6e 69 73  MIT.} {}...finis
12f0: 68 5f 74 65 73 74 0a 0a                          h_test..