/ Hex Artifact Content
Login

Artifact 649f5a37ec656028a4a32674b9b1183104285a7625a09d2a8f52a1cef72c93f2:


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 5b 66 69 6c 65 20 6a   .source [file j
01e0: 6f 69 6e 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d  oin [file dirnam
01f0: 65 20 5b 69 6e 66 6f 20 73 63 72 69 70 74 5d 5d  e [info script]]
0200: 20 72 74 72 65 65 5f 75 74 69 6c 2e 74 63 6c 5d   rtree_util.tcl]
0210: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72  .source $testdir
0220: 2f 74 65 73 74 65 72 2e 74 63 6c 0a 69 66 63 61  /tester.tcl.ifca
0230: 70 61 62 6c 65 20 21 72 74 72 65 65 20 7b 20 66  pable !rtree { f
0240: 69 6e 69 73 68 5f 74 65 73 74 20 3b 20 72 65 74  inish_test ; ret
0250: 75 72 6e 20 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  urn }..#--------
0260: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0270: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0280: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0290: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02a0: 2d 0a 23 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e  -.# The followin
02b0: 67 20 62 6c 6f 63 6b 20 6f 66 20 74 65 73 74 73  g block of tests
02c0: 20 2d 20 72 74 72 65 65 38 2d 31 2e 2a 20 2d 20   - rtree8-1.* - 
02d0: 66 65 61 74 75 72 65 20 72 65 61 64 69 6e 67 20  feature reading 
02e0: 61 6e 64 20 77 72 69 74 69 6e 67 0a 23 20 61 6e  and writing.# an
02f0: 20 72 2d 74 72 65 65 20 74 61 62 6c 65 20 77 68   r-tree table wh
0300: 69 6c 65 20 74 68 65 72 65 20 65 78 69 73 74 20  ile there exist 
0310: 6f 70 65 6e 20 63 75 72 73 6f 72 73 20 6f 6e 20  open cursors on 
0320: 69 74 2e 0a 23 0a 70 72 6f 63 20 70 6f 70 75 6c  it..#.proc popul
0330: 61 74 65 5f 74 31 20 7b 6e 7d 20 7b 0a 20 20 65  ate_t1 {n} {.  e
0340: 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45 20  xecsql { DELETE 
0350: 46 52 4f 4d 20 74 31 20 7d 0a 20 20 66 6f 72 20  FROM t1 }.  for 
0360: 7b 73 65 74 20 69 20 31 7d 20 7b 24 69 20 3c 3d  {set i 1} {$i <=
0370: 20 24 6e 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a   $n} {incr i} {.
0380: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e      execsql { IN
0390: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
03a0: 55 45 53 28 24 69 2c 20 24 69 2c 20 24 69 2b 32  UES($i, $i, $i+2
03b0: 29 20 7d 0a 20 20 7d 0a 7d 0a 0a 23 20 41 20 44  ) }.  }.}..# A D
03c0: 45 4c 45 54 45 20 77 68 69 6c 65 20 61 20 63 75  ELETE while a cu
03d0: 72 73 6f 72 20 69 73 20 72 65 61 64 69 6e 67 20  rsor is reading 
03e0: 74 68 65 20 74 61 62 6c 65 2e 0a 23 0a 64 6f 5f  the table..#.do_
03f0: 74 65 73 74 20 72 74 72 65 65 38 2d 31 2e 31 2e  test rtree8-1.1.
0400: 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  1 {.  execsql { 
0410: 50 52 41 47 4d 41 20 70 61 67 65 5f 73 69 7a 65  PRAGMA page_size
0420: 20 3d 20 35 31 32 20 7d 0a 20 20 65 78 65 63 73   = 512 }.  execs
0430: 71 6c 20 7b 20 43 52 45 41 54 45 20 56 49 52 54  ql { CREATE VIRT
0440: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49  UAL TABLE t1 USI
0450: 4e 47 20 72 74 72 65 65 5f 69 33 32 28 69 64 2c  NG rtree_i32(id,
0460: 20 78 31 2c 20 78 32 29 20 7d 0a 20 20 70 6f 70   x1, x2) }.  pop
0470: 75 6c 61 74 65 5f 74 31 20 35 0a 7d 20 7b 7d 0a  ulate_t1 5.} {}.
0480: 64 6f 5f 74 65 73 74 20 72 74 72 65 65 38 2d 31  do_test rtree8-1
0490: 2e 31 2e 32 20 7b 0a 20 20 73 65 74 20 72 65 73  .1.2 {.  set res
04a0: 20 5b 6c 69 73 74 5d 0a 20 20 64 62 20 65 76 61   [list].  db eva
04b0: 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f  l { SELECT * FRO
04c0: 4d 20 74 31 20 7d 20 7b 20 0a 20 20 20 20 6c 61  M t1 } { .    la
04d0: 70 70 65 6e 64 20 72 65 73 20 24 78 31 20 24 78  ppend res $x1 $x
04e0: 32 0a 20 20 20 20 69 66 20 7b 24 69 64 3d 3d 33  2.    if {$id==3
04f0: 7d 20 7b 20 64 62 20 65 76 61 6c 20 7b 20 44 45  } { db eval { DE
0500: 4c 45 54 45 20 46 52 4f 4d 20 74 31 20 57 48 45  LETE FROM t1 WHE
0510: 52 45 20 69 64 3e 33 20 7d 20 7d 0a 20 20 7d 0a  RE id>3 } }.  }.
0520: 20 20 73 65 74 20 72 65 73 0a 7d 20 7b 31 20 33    set res.} {1 3
0530: 20 32 20 34 20 33 20 35 7d 0a 64 6f 5f 74 65 73   2 4 3 5}.do_tes
0540: 74 20 72 74 72 65 65 38 2d 31 2e 31 2e 33 20 7b  t rtree8-1.1.3 {
0550: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c  .  execsql { SEL
0560: 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 7d 0a  ECT * FROM t1 }.
0570: 7d 20 7b 31 20 31 20 33 20 32 20 32 20 34 20 33  } {1 1 3 2 2 4 3
0580: 20 33 20 35 7d 0a 0a 23 20 4d 61 6e 79 20 53 45   3 5}..# Many SE
0590: 4c 45 43 54 73 20 6f 6e 20 74 68 65 20 73 61 6d  LECTs on the sam
05a0: 65 20 73 6d 61 6c 6c 20 74 61 62 6c 65 2e 0a 23  e small table..#
05b0: 0a 70 72 6f 63 20 6e 65 73 74 65 64 5f 73 65 6c  .proc nested_sel
05c0: 65 63 74 20 7b 6e 7d 20 7b 0a 20 20 73 65 74 20  ect {n} {.  set 
05d0: 3a 3a 6d 61 78 20 24 6e 0a 20 20 64 62 20 65 76  ::max $n.  db ev
05e0: 61 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52  al { SELECT * FR
05f0: 4f 4d 20 74 31 20 7d 20 7b 0a 20 20 20 20 69 66  OM t1 } {.    if
0600: 20 7b 24 69 64 20 3d 3d 20 24 6e 7d 20 7b 20 6e   {$id == $n} { n
0610: 65 73 74 65 64 5f 73 65 6c 65 63 74 20 5b 65 78  ested_select [ex
0620: 70 72 20 24 6e 2b 31 5d 20 7d 0a 20 20 7d 0a 20  pr $n+1] }.  }. 
0630: 20 72 65 74 75 72 6e 20 24 3a 3a 6d 61 78 0a 7d   return $::max.}
0640: 0a 64 6f 5f 74 65 73 74 20 72 74 72 65 65 38 2d  .do_test rtree8-
0650: 31 2e 32 2e 31 20 7b 20 70 6f 70 75 6c 61 74 65  1.2.1 { populate
0660: 5f 74 31 20 35 30 20 20 7d 20 7b 7d 0a 64 6f 5f  _t1 50  } {}.do_
0670: 74 65 73 74 20 72 74 72 65 65 38 2d 31 2e 32 2e  test rtree8-1.2.
0680: 32 20 7b 20 6e 65 73 74 65 64 5f 73 65 6c 65 63  2 { nested_selec
0690: 74 20 31 20 7d 20 7b 35 31 7d 0a 0a 23 20 54 68  t 1 } {51}..# Th
06a0: 69 73 20 74 65 73 74 20 72 75 6e 73 20 6d 61 6e  is test runs man
06b0: 79 20 53 45 4c 45 43 54 20 71 75 65 72 69 65 73  y SELECT queries
06c0: 20 73 69 6d 75 6c 74 61 6e 65 6f 75 73 6c 79 20   simultaneously 
06d0: 61 67 61 69 6e 73 74 20 61 20 6c 61 72 67 65 20  against a large 
06e0: 0a 23 20 74 61 62 6c 65 2c 20 63 61 75 73 69 6e  .# table, causin
06f0: 67 20 61 20 63 6f 6c 6c 69 73 69 6f 6e 20 69 6e  g a collision in
0700: 20 74 68 65 20 68 61 73 68 2d 74 61 62 6c 65 20   the hash-table 
0710: 75 73 65 64 20 74 6f 20 73 74 6f 72 65 20 72 2d  used to store r-
0720: 74 72 65 65 20 0a 23 20 6e 6f 64 65 73 20 69 6e  tree .# nodes in
0730: 74 65 72 6e 61 6c 6c 79 2e 0a 23 0a 70 6f 70 75  ternally..#.popu
0740: 6c 61 74 65 5f 74 31 20 31 35 30 30 0a 64 6f 5f  late_t1 1500.do_
0750: 72 74 72 65 65 5f 69 6e 74 65 67 72 69 74 79 5f  rtree_integrity_
0760: 74 65 73 74 20 72 74 72 65 65 38 2d 31 2e 33 2e  test rtree8-1.3.
0770: 30 20 74 31 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  0 t1.do_execsql_
0780: 74 65 73 74 20 72 74 72 65 65 38 2d 31 2e 33 2e  test rtree8-1.3.
0790: 31 20 7b 20 53 45 4c 45 43 54 20 6d 61 78 28 6e  1 { SELECT max(n
07a0: 6f 64 65 6e 6f 29 20 46 52 4f 4d 20 74 31 5f 6e  odeno) FROM t1_n
07b0: 6f 64 65 20 7d 20 7b 31 36 34 7d 0a 64 6f 5f 74  ode } {164}.do_t
07c0: 65 73 74 20 72 74 72 65 65 38 2d 31 2e 33 2e 32  est rtree8-1.3.2
07d0: 20 7b 0a 20 20 73 65 74 20 72 6f 77 69 64 73 20   {.  set rowids 
07e0: 5b 65 78 65 63 73 71 6c 20 7b 53 45 4c 45 43 54  [execsql {SELECT
07f0: 20 6d 69 6e 28 72 6f 77 69 64 29 20 46 52 4f 4d   min(rowid) FROM
0800: 20 74 31 5f 72 6f 77 69 64 20 47 52 4f 55 50 20   t1_rowid GROUP 
0810: 42 59 20 6e 6f 64 65 6e 6f 7d 5d 0a 20 20 73 65  BY nodeno}].  se
0820: 74 20 73 74 6d 74 5f 6c 69 73 74 20 5b 6c 69 73  t stmt_list [lis
0830: 74 5d 0a 20 20 66 6f 72 65 61 63 68 20 72 6f 77  t].  foreach row
0840: 20 24 72 6f 77 69 64 73 20 7b 0a 20 20 20 20 73   $rowids {.    s
0850: 65 74 20 73 74 6d 74 20 5b 73 71 6c 69 74 65 33  et stmt [sqlite3
0860: 5f 70 72 65 70 61 72 65 20 64 62 20 22 53 45 4c  _prepare db "SEL
0870: 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48  ECT * FROM t1 WH
0880: 45 52 45 20 69 64 20 3d 20 24 72 6f 77 22 20 2d  ERE id = $row" -
0890: 31 20 74 61 69 6c 5d 0a 20 20 20 20 73 71 6c 69  1 tail].    sqli
08a0: 74 65 33 5f 73 74 65 70 20 24 73 74 6d 74 0a 20  te3_step $stmt. 
08b0: 20 20 20 6c 61 70 70 65 6e 64 20 72 65 73 5f 6c     lappend res_l
08c0: 69 73 74 20 5b 73 71 6c 69 74 65 33 5f 63 6f 6c  ist [sqlite3_col
08d0: 75 6d 6e 5f 69 6e 74 20 24 73 74 6d 74 20 30 5d  umn_int $stmt 0]
08e0: 0a 20 20 20 20 6c 61 70 70 65 6e 64 20 73 74 6d  .    lappend stm
08f0: 74 5f 6c 69 73 74 20 24 73 74 6d 74 20 0a 20 20  t_list $stmt .  
0900: 7d 0a 7d 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 72  }.} {}.do_test r
0910: 74 72 65 65 38 2d 31 2e 33 2e 33 20 7b 20 73 65  tree8-1.3.3 { se
0920: 74 20 72 65 73 5f 6c 69 73 74 20 7d 20 24 72 6f  t res_list } $ro
0930: 77 69 64 73 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  wids.do_execsql_
0940: 74 65 73 74 20 72 74 72 65 65 38 2d 31 2e 33 2e  test rtree8-1.3.
0950: 34 20 7b 20 53 45 4c 45 43 54 20 63 6f 75 6e 74  4 { SELECT count
0960: 28 2a 29 20 46 52 4f 4d 20 74 31 20 7d 20 7b 31  (*) FROM t1 } {1
0970: 35 30 30 7d 0a 64 6f 5f 74 65 73 74 20 72 74 72  500}.do_test rtr
0980: 65 65 38 2d 31 2e 33 2e 35 20 7b 20 0a 20 20 66  ee8-1.3.5 { .  f
0990: 6f 72 65 61 63 68 20 73 74 6d 74 20 24 73 74 6d  oreach stmt $stm
09a0: 74 5f 6c 69 73 74 20 7b 20 73 71 6c 69 74 65 33  t_list { sqlite3
09b0: 5f 66 69 6e 61 6c 69 7a 65 20 24 73 74 6d 74 20  _finalize $stmt 
09c0: 7d 0a 7d 20 7b 7d 0a 0a 0a 23 2d 2d 2d 2d 2d 2d  }.} {}...#------
09d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09f0: 2d 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 0a 23 20 54 68 65 20 66 6f 6c 6c 6f 77  ---.# The follow
0a20: 69 6e 67 20 62 6c 6f 63 6b 20 6f 66 20 74 65 73  ing block of tes
0a30: 74 73 20 2d 20 72 74 72 65 65 38 2d 32 2e 2a 20  ts - rtree8-2.* 
0a40: 2d 20 74 65 73 74 20 61 20 63 6f 75 70 6c 65 20  - test a couple 
0a50: 6f 66 20 64 61 74 61 62 61 73 65 0a 23 20 63 6f  of database.# co
0a60: 72 72 75 70 74 69 6f 6e 20 63 61 73 65 73 2e 20  rruption cases. 
0a70: 49 6e 20 74 68 69 73 20 63 61 73 65 20 74 68 69  In this case thi
0a80: 6e 67 73 20 61 72 65 20 6e 6f 74 20 63 6f 72 72  ngs are not corr
0a90: 75 70 74 65 64 20 61 74 20 74 68 65 20 62 2d 74  upted at the b-t
0aa0: 72 65 65 0a 23 20 6c 65 76 65 6c 2c 20 62 75 74  ree.# level, but
0ab0: 20 74 68 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66   the contents of
0ac0: 20 74 68 65 20 76 61 72 69 6f 75 73 20 74 61 62   the various tab
0ad0: 6c 65 73 20 75 73 65 64 20 69 6e 74 65 72 6e 61  les used interna
0ae0: 6c 6c 79 20 62 79 20 61 6e 0a 23 20 72 2d 74 72  lly by an.# r-tr
0af0: 65 65 20 74 61 62 6c 65 20 61 72 65 20 69 6e 63  ee table are inc
0b00: 6f 6e 73 69 73 74 65 6e 74 2e 0a 23 0a 70 6f 70  onsistent..#.pop
0b10: 75 6c 61 74 65 5f 74 31 20 35 30 0a 64 6f 5f 65  ulate_t1 50.do_e
0b20: 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74 72 65  xecsql_test rtre
0b30: 65 38 2d 32 2e 31 2e 31 20 7b 20 53 45 4c 45 43  e8-2.1.1 { SELEC
0b40: 54 20 6d 61 78 28 6e 6f 64 65 6e 6f 29 20 46 52  T max(nodeno) FR
0b50: 4f 4d 20 74 31 5f 6e 6f 64 65 20 7d 20 7b 35 7d  OM t1_node } {5}
0b60: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
0b70: 20 72 74 72 65 65 38 2d 32 2e 31 2e 32 20 7b 20   rtree8-2.1.2 { 
0b80: 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31 5f 6e  DELETE FROM t1_n
0b90: 6f 64 65 20 7d 20 7b 7d 0a 66 6f 72 20 7b 73 65  ode } {}.for {se
0ba0: 74 20 69 20 31 7d 20 7b 24 69 20 3c 3d 20 35 30  t i 1} {$i <= 50
0bb0: 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 64  } {incr i} {.  d
0bc0: 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20  o_catchsql_test 
0bd0: 72 74 72 65 65 38 2d 32 2e 31 2e 33 2e 24 69 20  rtree8-2.1.3.$i 
0be0: 7b 20 0a 20 20 20 20 53 45 4c 45 43 54 20 2a 20  { .    SELECT * 
0bf0: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 69 64  FROM t1 WHERE id
0c00: 20 3d 20 24 69 20 0a 20 20 7d 20 7b 31 20 7b 64   = $i .  } {1 {d
0c10: 61 74 61 62 61 73 65 20 64 69 73 6b 20 69 6d 61  atabase disk ima
0c20: 67 65 20 69 73 20 6d 61 6c 66 6f 72 6d 65 64 7d  ge is malformed}
0c30: 7d 0a 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f  }.}.do_catchsql_
0c40: 74 65 73 74 20 72 74 72 65 65 38 2d 32 2e 31 2e  test rtree8-2.1.
0c50: 34 20 7b 20 0a 20 20 53 45 4c 45 43 54 20 2a 20  4 { .  SELECT * 
0c60: 46 52 4f 4d 20 74 31 0a 7d 20 7b 31 20 7b 64 61  FROM t1.} {1 {da
0c70: 74 61 62 61 73 65 20 64 69 73 6b 20 69 6d 61 67  tabase disk imag
0c80: 65 20 69 73 20 6d 61 6c 66 6f 72 6d 65 64 7d 7d  e is malformed}}
0c90: 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73  .do_catchsql_tes
0ca0: 74 20 72 74 72 65 65 38 2d 32 2e 31 2e 35 20 7b  t rtree8-2.1.5 {
0cb0: 20 0a 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20   .  DELETE FROM 
0cc0: 74 31 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73  t1.} {1 {databas
0cd0: 65 20 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20  e disk image is 
0ce0: 6d 61 6c 66 6f 72 6d 65 64 7d 7d 0a 0a 64 6f 5f  malformed}}..do_
0cf0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74 72  execsql_test rtr
0d00: 65 65 38 2d 32 2e 31 2e 36 20 7b 20 0a 20 20 44  ee8-2.1.6 { .  D
0d10: 52 4f 50 20 54 41 42 4c 45 20 74 31 3b 0a 20 20  ROP TABLE t1;.  
0d20: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
0d30: 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74  ABLE t1 USING rt
0d40: 72 65 65 5f 69 33 32 28 69 64 2c 20 78 31 2c 20  ree_i32(id, x1, 
0d50: 78 32 29 3b 0a 7d 20 7b 7d 0a 0a 0a 70 6f 70 75  x2);.} {}...popu
0d60: 6c 61 74 65 5f 74 31 20 35 30 0a 64 6f 5f 65 78  late_t1 50.do_ex
0d70: 65 63 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65  ecsql_test rtree
0d80: 38 2d 32 2e 32 2e 31 20 7b 0a 20 20 44 45 4c 45  8-2.2.1 {.  DELE
0d90: 54 45 20 46 52 4f 4d 20 74 31 5f 70 61 72 65 6e  TE FROM t1_paren
0da0: 74 0a 7d 20 7b 7d 0a 64 6f 5f 63 61 74 63 68 73  t.} {}.do_catchs
0db0: 71 6c 5f 74 65 73 74 20 72 74 72 65 65 38 2d 32  ql_test rtree8-2
0dc0: 2e 32 2e 32 20 7b 0a 20 20 44 45 4c 45 54 45 20  .2.2 {.  DELETE 
0dd0: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 69 64  FROM t1 WHERE id
0de0: 3d 32 35 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61  =25.} {1 {databa
0df0: 73 65 20 64 69 73 6b 20 69 6d 61 67 65 20 69 73  se disk image is
0e00: 20 6d 61 6c 66 6f 72 6d 65 64 7d 7d 0a 64 6f 5f   malformed}}.do_
0e10: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 72 74 72  execsql_test rtr
0e20: 65 65 38 2d 32 2e 32 2e 33 20 7b 20 0a 20 20 44  ee8-2.2.3 { .  D
0e30: 52 4f 50 20 54 41 42 4c 45 20 74 31 3b 0a 20 20  ROP TABLE t1;.  
0e40: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
0e50: 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74  ABLE t1 USING rt
0e60: 72 65 65 5f 69 33 32 28 69 64 2c 20 78 31 2c 20  ree_i32(id, x1, 
0e70: 78 32 29 3b 0a 7d 20 7b 7d 0a 0a 0a 23 2d 2d 2d  x2);.} {}...#---
0e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0e90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ea0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0eb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ec0: 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 74 68  ------.# Test th
0ed0: 61 74 20 74 72 79 69 6e 67 20 74 6f 20 75 73 65  at trying to use
0ee0: 20 74 68 65 20 4d 41 54 43 48 20 6f 70 65 72 61   the MATCH opera
0ef0: 74 6f 72 20 77 69 74 68 20 74 68 65 20 72 2d 74  tor with the r-t
0f00: 72 65 65 20 6d 6f 64 75 6c 65 20 64 6f 65 73 0a  ree module does.
0f10: 23 20 6e 6f 74 20 63 6f 6e 66 75 73 65 20 69 74  # not confuse it
0f20: 2e 20 0a 23 0a 70 6f 70 75 6c 61 74 65 5f 74 31  . .#.populate_t1
0f30: 20 31 30 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f   10.do_catchsql_
0f40: 74 65 73 74 20 72 74 72 65 65 38 2d 33 2e 31 20  test rtree8-3.1 
0f50: 7b 20 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52  { .  SELECT * FR
0f60: 4f 4d 20 74 31 20 57 48 45 52 45 20 78 31 20 4d  OM t1 WHERE x1 M
0f70: 41 54 43 48 20 27 31 32 33 34 27 0a 7d 20 7b 31  ATCH '1234'.} {1
0f80: 20 7b 53 51 4c 20 6c 6f 67 69 63 20 65 72 72 6f   {SQL logic erro
0f90: 72 7d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  r}}..#----------
0fa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0fb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0fc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0fd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
0fe0: 23 20 54 65 73 74 20 61 20 63 6f 75 70 6c 65 20  # Test a couple 
0ff0: 6f 66 20 69 6e 76 61 6c 69 64 20 61 72 67 75 6d  of invalid argum
1000: 65 6e 74 73 20 74 6f 20 72 74 72 65 65 64 65 70  ents to rtreedep
1010: 74 68 28 29 2e 0a 23 0a 64 6f 5f 63 61 74 63 68  th()..#.do_catch
1020: 73 71 6c 5f 74 65 73 74 20 72 74 72 65 65 38 2d  sql_test rtree8-
1030: 34 2e 31 20 7b 0a 20 20 53 45 4c 45 43 54 20 72  4.1 {.  SELECT r
1040: 74 72 65 65 64 65 70 74 68 28 27 68 65 6c 6c 6f  treedepth('hello
1050: 20 77 6f 72 6c 64 27 29 0a 7d 20 7b 31 20 7b 49   world').} {1 {I
1060: 6e 76 61 6c 69 64 20 61 72 67 75 6d 65 6e 74 20  nvalid argument 
1070: 74 6f 20 72 74 72 65 65 64 65 70 74 68 28 29 7d  to rtreedepth()}
1080: 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65  }.do_catchsql_te
1090: 73 74 20 72 74 72 65 65 38 2d 34 2e 32 20 7b 0a  st rtree8-4.2 {.
10a0: 20 20 53 45 4c 45 43 54 20 72 74 72 65 65 64 65    SELECT rtreede
10b0: 70 74 68 28 58 27 30 30 27 29 0a 7d 20 7b 31 20  pth(X'00').} {1 
10c0: 7b 49 6e 76 61 6c 69 64 20 61 72 67 75 6d 65 6e  {Invalid argumen
10d0: 74 20 74 6f 20 72 74 72 65 65 64 65 70 74 68 28  t to rtreedepth(
10e0: 29 7d 7d 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  )}}...#---------
10f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1100: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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: 0a 23 20 44 65 6c 65 74 65 20 68 61 6c 66 20 6f  .# Delete half o
1140: 66 20 61 20 6c 6f 70 73 69 64 65 64 20 74 72 65  f a lopsided tre
1150: 65 2e 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  e..#.do_execsql_
1160: 74 65 73 74 20 72 74 72 65 65 38 2d 35 2e 31 20  test rtree8-5.1 
1170: 7b 20 0a 20 20 43 52 45 41 54 45 20 56 49 52 54  { .  CREATE VIRT
1180: 55 41 4c 20 54 41 42 4c 45 20 74 32 20 55 53 49  UAL TABLE t2 USI
1190: 4e 47 20 72 74 72 65 65 5f 69 33 32 28 69 64 2c  NG rtree_i32(id,
11a0: 20 78 31 2c 20 78 32 29 20 0a 7d 20 7b 7d 0a 64   x1, x2) .} {}.d
11b0: 6f 5f 74 65 73 74 20 72 74 72 65 65 38 2d 35 2e  o_test rtree8-5.
11c0: 32 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 42 45  2 {.  execsql BE
11d0: 47 49 4e 0a 20 20 66 6f 72 20 7b 73 65 74 20 69  GIN.  for {set i
11e0: 20 30 7d 20 7b 24 69 20 3c 20 31 30 30 7d 20 7b   0} {$i < 100} {
11f0: 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20 65 78  incr i} {.    ex
1200: 65 63 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49  ecsql { INSERT I
1210: 4e 54 4f 20 74 32 20 56 41 4c 55 45 53 28 24 69  NTO t2 VALUES($i
1220: 2c 20 31 30 30 2c 20 31 30 31 29 20 7d 0a 20 20  , 100, 101) }.  
1230: 7d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20 31  }.  for {set i 1
1240: 30 30 7d 20 7b 24 69 20 3c 20 32 30 30 7d 20 7b  00} {$i < 200} {
1250: 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20 65 78  incr i} {.    ex
1260: 65 63 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49  ecsql { INSERT I
1270: 4e 54 4f 20 74 32 20 56 41 4c 55 45 53 28 24 69  NTO t2 VALUES($i
1280: 2c 20 31 30 30 30 2c 20 31 30 30 31 29 20 7d 0a  , 1000, 1001) }.
1290: 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 43 4f    }.  execsql CO
12a0: 4d 4d 49 54 0a 7d 20 7b 7d 0a 64 6f 5f 72 74 72  MMIT.} {}.do_rtr
12b0: 65 65 5f 69 6e 74 65 67 72 69 74 79 5f 74 65 73  ee_integrity_tes
12c0: 74 20 72 74 72 65 65 38 2d 35 2e 33 20 74 32 0a  t rtree8-5.3 t2.
12d0: 64 6f 5f 74 65 73 74 20 72 74 72 65 65 38 2d 35  do_test rtree8-5
12e0: 2e 34 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 42  .4 {.  execsql B
12f0: 45 47 49 4e 0a 20 20 66 6f 72 20 7b 73 65 74 20  EGIN.  for {set 
1300: 69 20 30 7d 20 7b 24 69 20 3c 20 32 30 30 7d 20  i 0} {$i < 200} 
1310: 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20 65  {incr i} {.    e
1320: 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45 20  xecsql { DELETE 
1330: 46 52 4f 4d 20 74 32 20 57 48 45 52 45 20 69 64  FROM t2 WHERE id
1340: 20 3d 20 24 69 20 7d 0a 20 20 7d 0a 20 20 65 78   = $i }.  }.  ex
1350: 65 63 73 71 6c 20 43 4f 4d 4d 49 54 0a 7d 20 7b  ecsql COMMIT.} {
1360: 7d 0a 64 6f 5f 72 74 72 65 65 5f 69 6e 74 65 67  }.do_rtree_integ
1370: 72 69 74 79 5f 74 65 73 74 20 72 74 72 65 65 38  rity_test rtree8
1380: 2d 35 2e 35 20 74 32 0a 0a 0a 66 69 6e 69 73 68  -5.5 t2...finish
1390: 5f 74 65 73 74 0a                                _test.