/ Hex Artifact Content
Login

Artifact f7eac9fadfe67765c4a0d6202c85f7272766fb9e:


0000: 23 20 32 30 31 34 20 4d 61 79 20 31 32 0a 23 0a  # 2014 May 12.#.
0010: 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73  # The author dis
0020: 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74  claims copyright
0030: 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20   to this source 
0040: 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20  code.  In place 
0050: 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74  of.# a legal not
0060: 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62  ice, here is a b
0070: 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20  lessing:.#.#    
0080: 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20  May you do good 
0090: 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20  and not evil..# 
00a0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20     May you find 
00b0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20  forgiveness for 
00c0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72  yourself and for
00d0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20  give others..#  
00e0: 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20    May you share 
00f0: 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61  freely, never ta
0100: 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79  king more than y
0110: 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a  ou give..#.#****
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 2a 2a 0a 23 20 54 68 69 73 20 66 69 6c  *****.# This fil
0170: 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 72 65 67  e implements reg
0180: 72 65 73 73 69 6f 6e 20 74 65 73 74 73 20 66 6f  ression tests fo
0190: 72 20 53 51 4c 69 74 65 20 6c 69 62 72 61 72 79  r SQLite library
01a0: 2e 20 20 54 68 65 0a 23 20 66 6f 63 75 73 20 6f  .  The.# focus o
01b0: 66 20 74 68 69 73 20 73 63 72 69 70 74 20 69 73  f this script is
01c0: 20 74 65 73 74 69 6e 67 20 74 68 65 20 46 54 53   testing the FTS
01d0: 34 20 6d 6f 64 75 6c 65 2e 0a 23 0a 23 0a 0a 73  4 module..#.#..s
01e0: 65 74 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65  et testdir [file
01f0: 20 64 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d   dirname $argv0]
0200: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72  .source $testdir
0210: 2f 74 65 73 74 65 72 2e 74 63 6c 0a 73 65 74 20  /tester.tcl.set 
0220: 74 65 73 74 70 72 65 66 69 78 20 66 74 73 34 67  testprefix fts4g
0230: 72 6f 77 74 68 0a 0a 23 20 49 66 20 53 51 4c 49  rowth..# If SQLI
0240: 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53 33 20 69  TE_ENABLE_FTS3 i
0250: 73 20 64 65 66 69 6e 65 64 2c 20 6f 6d 69 74 20  s defined, omit 
0260: 74 68 69 73 20 66 69 6c 65 2e 0a 69 66 63 61 70  this file..ifcap
0270: 61 62 6c 65 20 21 66 74 73 33 20 7b 0a 20 20 66  able !fts3 {.  f
0280: 69 6e 69 73 68 5f 74 65 73 74 0a 20 20 72 65 74  inish_test.  ret
0290: 75 72 6e 0a 7d 0a 0a 73 6f 75 72 63 65 20 24 74  urn.}..source $t
02a0: 65 73 74 64 69 72 2f 67 65 6e 65 73 69 73 2e 74  estdir/genesis.t
02b0: 63 6c 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  cl..do_execsql_t
02c0: 65 73 74 20 31 2e 31 20 7b 20 43 52 45 41 54 45  est 1.1 { CREATE
02d0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78   VIRTUAL TABLE x
02e0: 31 20 55 53 49 4e 47 20 66 74 73 33 3b 20 7d 0a  1 USING fts3; }.
02f0: 0a 64 6f 5f 74 65 73 74 20 31 2e 32 20 7b 0a 20  .do_test 1.2 {. 
0300: 20 66 6f 72 65 61 63 68 20 4c 20 7b 0a 20 20 20   foreach L {.   
0310: 20 7b 22 53 65 65 20 68 65 72 65 2c 20 79 6f 75   {"See here, you
0320: 6e 67 20 6d 61 6e 2c 22 20 73 61 69 64 20 4d 75  ng man," said Mu
0330: 6c 67 61 20 42 69 6c 6c 2c 20 22 66 72 6f 6d 20  lga Bill, "from 
0340: 57 61 6c 67 65 74 74 20 74 6f 20 74 68 65 20 73  Walgett to the s
0350: 65 61 2c 7d 0a 20 20 20 20 7b 46 72 6f 6d 20 43  ea,}.    {From C
0360: 6f 6e 72 6f 79 27 73 20 47 61 70 20 74 6f 20 43  onroy's Gap to C
0370: 61 73 74 6c 65 72 65 61 67 68 2c 20 74 68 65 72  astlereagh, ther
0380: 65 27 73 20 6e 6f 6e 65 20 63 61 6e 20 72 69 64  e's none can rid
0390: 65 20 6c 69 6b 65 20 6d 65 2e 7d 0a 20 20 20 20  e like me.}.    
03a0: 7b 49 27 6d 20 67 6f 6f 64 20 61 6c 6c 20 72 6f  {I'm good all ro
03b0: 75 6e 64 20 61 74 20 65 76 65 72 79 74 68 69 6e  und at everythin
03c0: 67 20 61 73 20 65 76 65 72 79 62 6f 64 79 20 6b  g as everybody k
03d0: 6e 6f 77 73 2c 7d 0a 20 20 20 20 7b 41 6c 74 68  nows,}.    {Alth
03e0: 6f 75 67 68 20 49 27 6d 20 6e 6f 74 20 74 68 65  ough I'm not the
03f0: 20 6f 6e 65 20 74 6f 20 74 61 6c 6b 20 2d 2d 20   one to talk -- 
0400: 49 20 68 61 74 65 20 61 20 6d 61 6e 20 74 68 61  I hate a man tha
0410: 74 20 62 6c 6f 77 73 2e 7d 0a 20 20 7d 20 7b 0a  t blows.}.  } {.
0420: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e      execsql { IN
0430: 53 45 52 54 20 49 4e 54 4f 20 78 31 20 56 41 4c  SERT INTO x1 VAL
0440: 55 45 53 28 24 4c 29 20 7d 0a 20 20 7d 0a 20 20  UES($L) }.  }.  
0450: 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54  execsql { SELECT
0460: 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c 65 6e 67   end_block, leng
0470: 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d 20 78 31  th(root) FROM x1
0480: 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b 7b 30 20  _segdir }.} {{0 
0490: 31 31 34 7d 20 31 31 34 20 7b 30 20 31 31 38 7d  114} 114 {0 118}
04a0: 20 31 31 38 20 7b 30 20 39 35 7d 20 39 35 20 7b   118 {0 95} 95 {
04b0: 30 20 31 31 35 7d 20 31 31 35 7d 0a 0a 64 6f 5f  0 115} 115}..do_
04c0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 2e 33  execsql_test 1.3
04d0: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
04e0: 20 78 31 28 78 31 29 20 56 41 4c 55 45 53 28 27   x1(x1) VALUES('
04f0: 6f 70 74 69 6d 69 7a 65 27 29 3b 0a 20 20 53 45  optimize');.  SE
0500: 4c 45 43 54 20 6c 65 76 65 6c 2c 20 65 6e 64 5f  LECT level, end_
0510: 62 6c 6f 63 6b 2c 20 6c 65 6e 67 74 68 28 72 6f  block, length(ro
0520: 6f 74 29 20 46 52 4f 4d 20 78 31 5f 73 65 67 64  ot) FROM x1_segd
0530: 69 72 3b 0a 7d 20 7b 30 20 7b 30 20 33 39 34 7d  ir;.} {0 {0 394}
0540: 20 33 39 34 7d 0a 0a 64 6f 5f 74 65 73 74 20 31   394}..do_test 1
0550: 2e 34 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 4c  .4 {.  foreach L
0560: 20 7b 0a 20 20 20 20 7b 42 75 74 20 72 69 64 69   {.    {But ridi
0570: 6e 67 20 69 73 20 6d 79 20 73 70 65 63 69 61 6c  ng is my special
0580: 20 67 69 66 74 2c 20 6d 79 20 63 68 69 65 66 65   gift, my chiefe
0590: 73 74 2c 20 73 6f 6c 65 20 64 65 6c 69 67 68 74  st, sole delight
05a0: 3b 7d 0a 20 20 20 20 7b 4a 75 73 74 20 61 73 6b  ;}.    {Just ask
05b0: 20 61 20 77 69 6c 64 20 64 75 63 6b 20 63 61 6e   a wild duck can
05c0: 20 69 74 20 73 77 69 6d 2c 20 61 20 77 69 6c 64   it swim, a wild
05d0: 63 61 74 20 63 61 6e 20 69 74 20 66 69 67 68 74  cat can it fight
05e0: 2e 7d 0a 20 20 20 20 7b 54 68 65 72 65 27 73 20  .}.    {There's 
05f0: 6e 6f 74 68 69 6e 67 20 63 6c 6f 74 68 65 64 20  nothing clothed 
0600: 69 6e 20 68 61 69 72 20 6f 72 20 68 69 64 65 2c  in hair or hide,
0610: 20 6f 72 20 62 75 69 6c 74 20 6f 66 20 66 6c 65   or built of fle
0620: 73 68 20 6f 72 20 73 74 65 65 6c 2c 7d 0a 20 20  sh or steel,}.  
0630: 20 20 7b 54 68 65 72 65 27 73 20 6e 6f 74 68 69    {There's nothi
0640: 6e 67 20 77 61 6c 6b 73 20 6f 72 20 6a 75 6d 70  ng walks or jump
0650: 73 2c 20 6f 72 20 72 75 6e 73 2c 20 6f 6e 20 61  s, or runs, on a
0660: 78 6c 65 2c 20 68 6f 6f 66 2c 20 6f 72 20 77 68  xle, hoof, or wh
0670: 65 65 6c 2c 7d 0a 20 20 20 20 7b 42 75 74 20 77  eel,}.    {But w
0680: 68 61 74 20 49 27 6c 6c 20 73 69 74 2c 20 77 68  hat I'll sit, wh
0690: 69 6c 65 20 68 69 64 65 20 77 69 6c 6c 20 68 6f  ile hide will ho
06a0: 6c 64 20 61 6e 64 20 67 69 72 74 68 73 20 61 6e  ld and girths an
06b0: 64 20 73 74 72 61 70 73 20 61 72 65 20 74 69 67  d straps are tig
06c0: 68 74 3a 7d 0a 20 20 20 20 7b 49 27 6c 6c 20 72  ht:}.    {I'll r
06d0: 69 64 65 20 74 68 69 73 20 68 65 72 65 20 74 77  ide this here tw
06e0: 6f 2d 77 68 65 65 6c 65 64 20 63 6f 6e 63 65 72  o-wheeled concer
06f0: 6e 20 72 69 67 68 74 20 73 74 72 61 69 67 68 74  n right straight
0700: 20 61 77 61 79 20 61 74 20 73 69 67 68 74 2e 22   away at sight."
0710: 7d 0a 20 20 7d 20 7b 0a 20 20 20 20 65 78 65 63  }.  } {.    exec
0720: 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  sql { INSERT INT
0730: 4f 20 78 31 20 56 41 4c 55 45 53 28 24 4c 29 20  O x1 VALUES($L) 
0740: 7d 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20  }.  }.  execsql 
0750: 7b 20 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  { .    INSERT IN
0760: 54 4f 20 78 31 28 78 31 29 20 56 41 4c 55 45 53  TO x1(x1) VALUES
0770: 28 27 6d 65 72 67 65 3d 34 2c 34 27 29 3b 0a 20  ('merge=4,4');. 
0780: 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c     SELECT level,
0790: 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c 65 6e 67   end_block, leng
07a0: 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d 20 78 31  th(root) FROM x1
07b0: 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a 7d 20 7b  _segdir;.  }.} {
07c0: 30 20 7b 30 20 31 31 30 7d 20 31 31 30 20 30 20  0 {0 110} 110 0 
07d0: 7b 30 20 31 33 32 7d 20 31 33 32 20 30 20 7b 30  {0 132} 132 0 {0
07e0: 20 31 32 39 7d 20 31 32 39 20 31 20 7b 31 32 38   129} 129 1 {128
07f0: 20 36 35 38 7d 20 32 7d 0a 0a 64 6f 5f 65 78 65   658} 2}..do_exe
0800: 63 73 71 6c 5f 74 65 73 74 20 31 2e 35 20 7b 0a  csql_test 1.5 {.
0810: 20 20 53 45 4c 45 43 54 20 6c 65 6e 67 74 68 28    SELECT length(
0820: 62 6c 6f 63 6b 29 20 46 52 4f 4d 20 78 31 5f 73  block) FROM x1_s
0830: 65 67 6d 65 6e 74 73 3b 0a 7d 20 7b 36 35 38 20  egments;.} {658 
0840: 7b 7d 7d 0a 0a 64 6f 5f 74 65 73 74 20 31 2e 36  {}}..do_test 1.6
0850: 20 7b 0a 20 20 66 6f 72 65 61 63 68 20 4c 20 7b   {.  foreach L {
0860: 0a 20 20 20 20 7b 27 54 77 61 73 20 4d 75 6c 67  .    {'Twas Mulg
0870: 61 20 42 69 6c 6c 2c 20 66 72 6f 6d 20 45 61 67  a Bill, from Eag
0880: 6c 65 68 61 77 6b 2c 20 74 68 61 74 20 73 6f 75  lehawk, that sou
0890: 67 68 74 20 68 69 73 20 6f 77 6e 20 61 62 6f 64  ght his own abod
08a0: 65 2c 7d 0a 20 20 20 20 7b 54 68 61 74 20 70 65  e,}.    {That pe
08b0: 72 63 68 65 64 20 61 62 6f 76 65 20 44 65 61 64  rched above Dead
08c0: 20 4d 61 6e 27 73 20 43 72 65 65 6b 2c 20 62 65   Man's Creek, be
08d0: 73 69 64 65 20 74 68 65 20 6d 6f 75 6e 74 61 69  side the mountai
08e0: 6e 20 72 6f 61 64 2e 7d 0a 20 20 20 20 7b 48 65  n road.}.    {He
08f0: 20 74 75 72 6e 65 64 20 74 68 65 20 63 79 63 6c   turned the cycl
0900: 65 20 64 6f 77 6e 20 74 68 65 20 68 69 6c 6c 20  e down the hill 
0910: 61 6e 64 20 6d 6f 75 6e 74 65 64 20 66 6f 72 20  and mounted for 
0920: 74 68 65 20 66 72 61 79 2c 7d 0a 20 20 20 20 7b  the fray,}.    {
0930: 42 75 74 20 27 65 72 65 20 68 65 27 64 20 67 6f  But 'ere he'd go
0940: 6e 65 20 61 20 64 6f 7a 65 6e 20 79 61 72 64 73  ne a dozen yards
0950: 20 69 74 20 62 6f 6c 74 65 64 20 63 6c 65 61 6e   it bolted clean
0960: 20 61 77 61 79 2e 7d 0a 20 20 20 20 7b 49 74 20   away.}.    {It 
0970: 6c 65 66 74 20 74 68 65 20 74 72 61 63 6b 2c 20  left the track, 
0980: 61 6e 64 20 74 68 72 6f 75 67 68 20 74 68 65 20  and through the 
0990: 74 72 65 65 73 2c 20 6a 75 73 74 20 6c 69 6b 65  trees, just like
09a0: 20 61 20 73 69 6c 76 65 72 20 73 74 65 61 6b 2c   a silver steak,
09b0: 7d 0a 20 20 20 20 7b 49 74 20 77 68 69 73 74 6c  }.    {It whistl
09c0: 65 64 20 64 6f 77 6e 20 74 68 65 20 61 77 66 75  ed down the awfu
09d0: 6c 20 73 6c 6f 70 65 20 74 6f 77 61 72 64 73 20  l slope towards 
09e0: 74 68 65 20 44 65 61 64 20 4d 61 6e 27 73 20 43  the Dead Man's C
09f0: 72 65 65 6b 2e 7d 0a 20 20 20 20 7b 49 74 20 73  reek.}.    {It s
0a00: 68 61 76 65 64 20 61 20 73 74 75 6d 70 20 62 79  haved a stump by
0a10: 20 68 61 6c 66 20 61 6e 20 69 6e 63 68 2c 20 69   half an inch, i
0a20: 74 20 64 6f 64 67 65 64 20 61 20 62 69 67 20 77  t dodged a big w
0a30: 68 69 74 65 2d 62 6f 78 3a 7d 0a 20 20 20 20 7b  hite-box:}.    {
0a40: 54 68 65 20 76 65 72 79 20 77 61 6c 6c 61 72 6f  The very wallaro
0a50: 6f 73 20 69 6e 20 66 72 69 67 68 74 20 77 65 6e  os in fright wen
0a60: 74 20 73 63 72 61 6d 62 6c 69 6e 67 20 75 70 20  t scrambling up 
0a70: 74 68 65 20 72 6f 63 6b 73 2c 7d 0a 20 20 20 20  the rocks,}.    
0a80: 7b 54 68 65 20 77 6f 6d 62 61 74 73 20 68 69 64  {The wombats hid
0a90: 69 6e 67 20 69 6e 20 74 68 65 69 72 20 63 61 76  ing in their cav
0aa0: 65 73 20 64 75 67 20 64 65 65 70 65 72 20 75 6e  es dug deeper un
0ab0: 64 65 72 67 72 6f 75 6e 64 2c 7d 0a 20 20 20 20  derground,}.    
0ac0: 7b 41 73 20 4d 75 6c 67 61 20 42 69 6c 6c 2c 20  {As Mulga Bill, 
0ad0: 61 73 20 77 68 69 74 65 20 61 73 20 63 68 61 6c  as white as chal
0ae0: 6b 2c 20 73 61 74 20 74 69 67 68 74 20 74 6f 20  k, sat tight to 
0af0: 65 76 65 72 79 20 62 6f 75 6e 64 2e 7d 0a 20 20  every bound.}.  
0b00: 20 20 7b 49 74 20 73 74 72 75 63 6b 20 61 20 73    {It struck a s
0b10: 74 6f 6e 65 20 61 6e 64 20 67 61 76 65 20 61 20  tone and gave a 
0b20: 73 70 72 69 6e 67 20 74 68 61 74 20 63 6c 65 61  spring that clea
0b30: 72 65 64 20 61 20 66 61 6c 6c 65 6e 20 74 72 65  red a fallen tre
0b40: 65 2c 7d 0a 20 20 20 20 7b 49 74 20 72 61 63 65  e,}.    {It race
0b50: 64 20 62 65 73 69 64 65 20 61 20 70 72 65 63 69  d beside a preci
0b60: 70 69 63 65 20 61 73 20 63 6c 6f 73 65 20 61 73  pice as close as
0b70: 20 63 6c 6f 73 65 20 63 6f 75 6c 64 20 62 65 3b   close could be;
0b80: 7d 0a 20 20 20 20 7b 41 6e 64 20 74 68 65 6e 20  }.    {And then 
0b90: 61 73 20 4d 75 6c 67 61 20 42 69 6c 6c 20 6c 65  as Mulga Bill le
0ba0: 74 20 6f 75 74 20 6f 6e 65 20 6c 61 73 74 20 64  t out one last d
0bb0: 65 73 70 61 69 72 69 6e 67 20 73 68 72 69 65 6b  espairing shriek
0bc0: 7d 0a 20 20 20 20 7b 49 74 20 6d 61 64 65 20 61  }.    {It made a
0bd0: 20 6c 65 61 70 20 6f 66 20 74 77 65 6e 74 79 20   leap of twenty 
0be0: 66 65 65 74 20 69 6e 74 6f 20 74 68 65 20 44 65  feet into the De
0bf0: 61 64 20 4d 61 6e 27 73 20 43 72 65 65 6b 2e 7d  ad Man's Creek.}
0c00: 0a 20 20 7d 20 7b 0a 20 20 20 20 65 78 65 63 73  .  } {.    execs
0c10: 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f  ql { INSERT INTO
0c20: 20 78 31 20 56 41 4c 55 45 53 28 24 4c 29 20 7d   x1 VALUES($L) }
0c30: 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b  .  }.  execsql {
0c40: 20 0a 20 20 20 20 53 45 4c 45 43 54 20 6c 65 76   .    SELECT lev
0c50: 65 6c 2c 20 65 6e 64 5f 62 6c 6f 63 6b 2c 20 6c  el, end_block, l
0c60: 65 6e 67 74 68 28 72 6f 6f 74 29 20 46 52 4f 4d  ength(root) FROM
0c70: 20 78 31 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a   x1_segdir;.  }.
0c80: 7d 20 7b 31 20 7b 31 32 38 20 36 35 38 7d 20 32  } {1 {128 658} 2
0c90: 20 31 20 7b 31 33 30 20 31 33 37 37 7d 20 36 20   1 {130 1377} 6 
0ca0: 30 20 7b 30 20 31 31 37 7d 20 31 31 37 7d 0a 0a  0 {0 117} 117}..
0cb0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
0cc0: 31 2e 37 20 7b 0a 20 20 53 45 4c 45 43 54 20 73  1.7 {.  SELECT s
0cd0: 75 6d 28 6c 65 6e 67 74 68 28 62 6c 6f 63 6b 29  um(length(block)
0ce0: 29 20 46 52 4f 4d 20 78 31 5f 73 65 67 6d 65 6e  ) FROM x1_segmen
0cf0: 74 73 20 57 48 45 52 45 20 62 6c 6f 63 6b 69 64  ts WHERE blockid
0d00: 20 49 4e 20 28 31 32 39 2c 20 31 33 30 29 3b 0a   IN (129, 130);.
0d10: 7d 20 7b 31 33 37 37 7d 0a 0a 23 2d 2d 2d 2d 2d  } {1377}..#-----
0d20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d60: 2d 2d 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63 73 71  ----.#.do_execsq
0d70: 6c 5f 74 65 73 74 20 32 2e 31 20 7b 20 0a 20 20  l_test 2.1 { .  
0d80: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28  CREATE TABLE t1(
0d90: 64 6f 63 69 64 2c 20 77 6f 72 64 73 29 3b 0a 20  docid, words);. 
0da0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
0db0: 54 41 42 4c 45 20 78 32 20 55 53 49 4e 47 20 66  TABLE x2 USING f
0dc0: 74 73 34 3b 0a 7d 0a 66 74 73 5f 6b 6a 76 5f 67  ts4;.}.fts_kjv_g
0dd0: 65 6e 65 73 69 73 20 0a 64 6f 5f 74 65 73 74 20  enesis .do_test 
0de0: 32 2e 32 20 7b 0a 20 20 66 6f 72 65 61 63 68 20  2.2 {.  foreach 
0df0: 69 64 20 5b 64 62 20 65 76 61 6c 20 7b 53 45 4c  id [db eval {SEL
0e00: 45 43 54 20 64 6f 63 69 64 20 46 52 4f 4d 20 74  ECT docid FROM t
0e10: 31 7d 5d 20 7b 0a 20 20 20 20 65 78 65 63 73 71  1}] {.    execsq
0e20: 6c 20 7b 0a 20 20 20 20 20 20 49 4e 53 45 52 54  l {.      INSERT
0e30: 20 49 4e 54 4f 20 78 32 28 64 6f 63 69 64 2c 20   INTO x2(docid, 
0e40: 63 6f 6e 74 65 6e 74 29 20 53 45 4c 45 43 54 20  content) SELECT 
0e50: 24 69 64 2c 20 77 6f 72 64 73 20 46 52 4f 4d 20  $id, words FROM 
0e60: 74 31 20 57 48 45 52 45 20 64 6f 63 69 64 3d 24  t1 WHERE docid=$
0e70: 69 64 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 66  id.    }.  }.  f
0e80: 6f 72 65 61 63 68 20 69 64 20 5b 64 62 20 65 76  oreach id [db ev
0e90: 61 6c 20 7b 53 45 4c 45 43 54 20 64 6f 63 69 64  al {SELECT docid
0ea0: 20 46 52 4f 4d 20 74 31 7d 5d 20 7b 0a 20 20 20   FROM t1}] {.   
0eb0: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20   execsql {.     
0ec0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 28   INSERT INTO x2(
0ed0: 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20  docid, content) 
0ee0: 53 45 4c 45 43 54 20 4e 55 4c 4c 2c 20 77 6f 72  SELECT NULL, wor
0ef0: 64 73 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45  ds FROM t1 WHERE
0f00: 20 64 6f 63 69 64 3d 24 69 64 0a 20 20 20 20 7d   docid=$id.    }
0f10: 0a 20 20 20 20 69 66 20 7b 5b 64 62 20 6f 6e 65  .    if {[db one
0f20: 20 7b 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a   {SELECT count(*
0f30: 29 20 46 52 4f 4d 20 78 32 5f 73 65 67 64 69 72  ) FROM x2_segdir
0f40: 20 57 48 45 52 45 20 6c 65 76 65 6c 3c 32 7d 5d   WHERE level<2}]
0f50: 3d 3d 32 7d 20 62 72 65 61 6b 0a 20 20 7d 0a 7d  ==2} break.  }.}
0f60: 20 7b 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f   {}..do_execsql_
0f70: 74 65 73 74 20 32 2e 33 20 7b 20 0a 20 20 53 45  test 2.3 { .  SE
0f80: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
0f90: 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48 45  OM x2_segdir WHE
0fa0: 52 45 20 6c 65 76 65 6c 3d 32 3b 0a 20 20 53 45  RE level=2;.  SE
0fb0: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
0fc0: 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48 45  OM x2_segdir WHE
0fd0: 52 45 20 6c 65 76 65 6c 3d 33 3b 0a 7d 20 7b 36  RE level=3;.} {6
0fe0: 20 30 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f   0}..do_execsql_
0ff0: 74 65 73 74 20 32 2e 34 20 7b 20 0a 20 20 49 4e  test 2.4 { .  IN
1000: 53 45 52 54 20 49 4e 54 4f 20 78 32 28 78 32 29  SERT INTO x2(x2)
1010: 20 56 41 4c 55 45 53 28 27 6d 65 72 67 65 3d 34   VALUES('merge=4
1020: 2c 34 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 63  ,4');.  SELECT c
1030: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f  ount(*) FROM x2_
1040: 73 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76  segdir WHERE lev
1050: 65 6c 3d 32 3b 0a 20 20 53 45 4c 45 43 54 20 63  el=2;.  SELECT c
1060: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f  ount(*) FROM x2_
1070: 73 65 67 64 69 72 20 57 48 45 52 45 20 6c 65 76  segdir WHERE lev
1080: 65 6c 3d 33 3b 0a 7d 20 7b 36 20 31 7d 0a 0a 64  el=3;.} {6 1}..d
1090: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32  o_execsql_test 2
10a0: 2e 35 20 7b 20 0a 20 20 53 45 4c 45 43 54 20 65  .5 { .  SELECT e
10b0: 6e 64 5f 62 6c 6f 63 6b 20 46 52 4f 4d 20 78 32  nd_block FROM x2
10c0: 5f 73 65 67 64 69 72 20 57 48 45 52 45 20 6c 65  _segdir WHERE le
10d0: 76 65 6c 3d 33 3b 0a 20 20 49 4e 53 45 52 54 20  vel=3;.  INSERT 
10e0: 49 4e 54 4f 20 78 32 28 78 32 29 20 56 41 4c 55  INTO x2(x2) VALU
10f0: 45 53 28 27 6d 65 72 67 65 3d 34 2c 34 27 29 3b  ES('merge=4,4');
1100: 0a 20 20 53 45 4c 45 43 54 20 65 6e 64 5f 62 6c  .  SELECT end_bl
1110: 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65 67 64  ock FROM x2_segd
1120: 69 72 20 57 48 45 52 45 20 6c 65 76 65 6c 3d 33  ir WHERE level=3
1130: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
1140: 78 32 28 78 32 29 20 56 41 4c 55 45 53 28 27 6d  x2(x2) VALUES('m
1150: 65 72 67 65 3d 34 2c 34 27 29 3b 0a 20 20 53 45  erge=4,4');.  SE
1160: 4c 45 43 54 20 65 6e 64 5f 62 6c 6f 63 6b 20 46  LECT end_block F
1170: 52 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 57 48  ROM x2_segdir WH
1180: 45 52 45 20 6c 65 76 65 6c 3d 33 3b 0a 7d 20 7b  ERE level=3;.} {
1190: 7b 33 38 32 38 20 33 34 33 30 7d 20 7b 33 38 32  {3828 3430} {382
11a0: 38 20 31 30 31 39 31 7d 20 7b 33 38 32 38 20 31  8 10191} {3828 1
11b0: 34 31 30 39 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73  4109}}..do_execs
11c0: 71 6c 5f 74 65 73 74 20 32 2e 36 20 7b 0a 20 20  ql_test 2.6 {.  
11d0: 53 45 4c 45 43 54 20 73 75 6d 28 6c 65 6e 67 74  SELECT sum(lengt
11e0: 68 28 62 6c 6f 63 6b 29 29 20 46 52 4f 4d 20 78  h(block)) FROM x
11f0: 32 5f 73 65 67 64 69 72 2c 20 78 32 5f 73 65 67  2_segdir, x2_seg
1200: 6d 65 6e 74 73 20 57 48 45 52 45 20 0a 20 20 20  ments WHERE .   
1210: 20 62 6c 6f 63 6b 69 64 20 42 45 54 57 45 45 4e   blockid BETWEEN
1220: 20 73 74 61 72 74 5f 62 6c 6f 63 6b 20 41 4e 44   start_block AND
1230: 20 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   leaves_end_bloc
1240: 6b 0a 20 20 20 20 41 4e 44 20 6c 65 76 65 6c 3d  k.    AND level=
1250: 33 0a 7d 20 7b 31 34 31 30 39 7d 0a 0a 64 6f 5f  3.} {14109}..do_
1260: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e 37  execsql_test 2.7
1270: 20 7b 20 0a 20 20 49 4e 53 45 52 54 20 49 4e 54   { .  INSERT INT
1280: 4f 20 78 32 28 78 32 29 20 56 41 4c 55 45 53 28  O x2(x2) VALUES(
1290: 27 6d 65 72 67 65 3d 31 30 30 30 2c 34 27 29 3b  'merge=1000,4');
12a0: 0a 20 20 53 45 4c 45 43 54 20 65 6e 64 5f 62 6c  .  SELECT end_bl
12b0: 6f 63 6b 20 46 52 4f 4d 20 78 32 5f 73 65 67 64  ock FROM x2_segd
12c0: 69 72 20 57 48 45 52 45 20 6c 65 76 65 6c 3d 33  ir WHERE level=3
12d0: 3b 0a 7d 20 7b 7b 33 38 32 38 20 38 36 31 32 30  ;.} {{3828 86120
12e0: 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  }}..do_execsql_t
12f0: 65 73 74 20 32 2e 38 20 7b 0a 20 20 53 45 4c 45  est 2.8 {.  SELE
1300: 43 54 20 73 75 6d 28 6c 65 6e 67 74 68 28 62 6c  CT sum(length(bl
1310: 6f 63 6b 29 29 20 46 52 4f 4d 20 78 32 5f 73 65  ock)) FROM x2_se
1320: 67 64 69 72 2c 20 78 32 5f 73 65 67 6d 65 6e 74  gdir, x2_segment
1330: 73 20 57 48 45 52 45 20 0a 20 20 20 20 62 6c 6f  s WHERE .    blo
1340: 63 6b 69 64 20 42 45 54 57 45 45 4e 20 73 74 61  ckid BETWEEN sta
1350: 72 74 5f 62 6c 6f 63 6b 20 41 4e 44 20 6c 65 61  rt_block AND lea
1360: 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 0a 20 20  ves_end_block.  
1370: 20 20 41 4e 44 20 6c 65 76 65 6c 3d 33 0a 7d 20    AND level=3.} 
1380: 7b 38 36 31 32 30 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  {86120}..#------
1390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13d0: 2d 2d 2d 2d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  ----..do_execsql
13e0: 5f 74 65 73 74 20 33 2e 31 20 7b 0a 20 20 44 52  _test 3.1 {.  DR
13f0: 4f 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53  OP TABLE IF EXIS
1400: 54 53 20 78 32 3b 0a 20 20 44 52 4f 50 20 54 41  TS x2;.  DROP TA
1410: 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 74 31  BLE IF EXISTS t1
1420: 3b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45  ;.  CREATE TABLE
1430: 20 74 31 28 64 6f 63 69 64 2c 20 77 6f 72 64 73   t1(docid, words
1440: 29 3b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54  );.  CREATE VIRT
1450: 55 41 4c 20 54 41 42 4c 45 20 78 32 20 55 53 49  UAL TABLE x2 USI
1460: 4e 47 20 66 74 73 34 3b 0a 7d 0a 66 74 73 5f 6b  NG fts4;.}.fts_k
1470: 6a 76 5f 67 65 6e 65 73 69 73 20 0a 0a 70 72 6f  jv_genesis ..pro
1480: 63 20 74 31 5f 74 6f 5f 78 32 20 7b 7d 20 7b 0a  c t1_to_x2 {} {.
1490: 20 20 66 6f 72 65 61 63 68 20 69 64 20 5b 64 62    foreach id [db
14a0: 20 65 76 61 6c 20 7b 53 45 4c 45 43 54 20 64 6f   eval {SELECT do
14b0: 63 69 64 20 46 52 4f 4d 20 74 31 20 4c 49 4d 49  cid FROM t1 LIMI
14c0: 54 20 32 7d 5d 20 7b 0a 20 20 20 20 65 78 65 63  T 2}] {.    exec
14d0: 73 71 6c 20 7b 0a 20 20 20 20 20 20 44 45 4c 45  sql {.      DELE
14e0: 54 45 20 46 52 4f 4d 20 78 32 20 57 48 45 52 45  TE FROM x2 WHERE
14f0: 20 64 6f 63 69 64 3d 24 69 64 3b 0a 20 20 20 20   docid=$id;.    
1500: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 32    INSERT INTO x2
1510: 28 64 6f 63 69 64 2c 20 63 6f 6e 74 65 6e 74 29  (docid, content)
1520: 20 53 45 4c 45 43 54 20 24 69 64 2c 20 77 6f 72   SELECT $id, wor
1530: 64 73 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45  ds FROM t1 WHERE
1540: 20 64 6f 63 69 64 3d 24 69 64 3b 0a 20 20 20 20   docid=$id;.    
1550: 7d 0a 20 20 7d 0a 7d 0a 0a 23 64 6f 5f 74 65 73  }.  }.}..#do_tes
1560: 74 20 33 2e 32 20 7b 0a 20 20 23 74 31 5f 74 6f  t 3.2 {.  #t1_to
1570: 5f 78 32 0a 20 20 23 65 78 65 63 73 71 6c 20 7b  _x2.  #execsql {
1580: 53 45 4c 45 43 54 20 6c 65 76 65 6c 2c 20 63 6f  SELECT level, co
1590: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 78 32 5f 73  unt(*) FROM x2_s
15a0: 65 67 64 69 72 20 47 52 4f 55 50 20 42 59 20 6c  egdir GROUP BY l
15b0: 65 76 65 6c 7d 0a 23 7d 20 7b 30 20 31 33 20 31  evel}.#} {0 13 1
15c0: 20 31 35 20 32 20 35 7d 0a 0a 23 70 72 6f 63 20   15 2 5}..#proc 
15d0: 73 65 63 6f 6e 64 20 7b 78 7d 20 7b 20 6c 69 6e  second {x} { lin
15e0: 64 65 78 20 24 78 20 31 20 7d 0a 23 64 62 20 66  dex $x 1 }.#db f
15f0: 75 6e 63 20 73 65 63 6f 6e 64 20 73 65 63 6f 6e  unc second secon
1600: 64 0a 23 66 6f 72 20 7b 73 65 74 20 69 20 30 7d  d.#for {set i 0}
1610: 20 7b 24 69 20 3c 31 30 30 30 7d 20 7b 69 6e 63   {$i <1000} {inc
1620: 72 20 69 7d 20 7b 0a 23 20 20 74 31 5f 74 6f 5f  r i} {.#  t1_to_
1630: 78 32 0a 23 20 20 64 62 20 65 76 61 6c 20 7b 0a  x2.#  db eval {.
1640: 23 20 20 20 20 53 45 4c 45 43 54 20 6c 65 76 65  #    SELECT leve
1650: 6c 2c 20 67 72 6f 75 70 5f 63 6f 6e 63 61 74 28  l, group_concat(
1660: 20 73 65 63 6f 6e 64 28 65 6e 64 5f 62 6c 6f 63   second(end_bloc
1670: 6b 29 2c 20 27 20 27 20 29 20 41 53 20 63 20 46  k), ' ' ) AS c F
1680: 52 4f 4d 20 78 32 5f 73 65 67 64 69 72 20 47 52  ROM x2_segdir GR
1690: 4f 55 50 20 42 59 20 6c 65 76 65 6c 3b 0a 23 20  OUP BY level;.# 
16a0: 20 7d 20 7b 0a 23 20 20 20 20 70 75 74 73 20 22   } {.#    puts "
16b0: 24 69 2e 24 6c 65 76 65 6c 3a 20 24 63 22 0a 23  $i.$level: $c".#
16c0: 20 20 7d 0a 23 7d 0a 0a 0a 66 69 6e 69 73 68 5f    }.#}...finish_
16d0: 74 65 73 74 0a 0a 0a                             test...