/ Hex Artifact Content
Login

Artifact bd2d88182b9f7f30d300044048ad14683306b745:


0000: 23 20 32 30 31 34 20 4a 75 6e 65 20 31 37 0a 23  # 2014 June 17.#
0010: 0a 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69  .# The author di
0020: 73 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68  sclaims copyrigh
0030: 74 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65  t to this source
0040: 20 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65   code.  In place
0050: 20 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f   of.# a legal no
0060: 74 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20  tice, here is a 
0070: 62 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20  blessing:.#.#   
0080: 20 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64   May you do good
0090: 20 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23   and not evil..#
00a0: 20 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64      May you find
00b0: 20 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72   forgiveness for
00c0: 20 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f   yourself and fo
00d0: 72 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20  rgive others..# 
00e0: 20 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65     May you share
00f0: 20 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74   freely, never t
0100: 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20  aking more than 
0110: 79 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a  you 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 2a 0a 23 20 54 68 69 73 20 66 69  ******.# This fi
0170: 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 72 65  le implements re
0180: 67 72 65 73 73 69 6f 6e 20 74 65 73 74 73 20 66  gression tests f
0190: 6f 72 20 53 51 4c 69 74 65 20 6c 69 62 72 61 72  or SQLite librar
01a0: 79 2e 20 20 54 68 65 0a 23 20 66 6f 63 75 73 20  y.  The.# focus 
01b0: 6f 66 20 74 68 69 73 20 73 63 72 69 70 74 20 69  of this script i
01c0: 73 20 74 65 73 74 69 6e 67 20 74 68 65 20 46 54  s testing the FT
01d0: 53 35 20 6d 6f 64 75 6c 65 2e 0a 23 0a 0a 73 6f  S5 module..#..so
01e0: 75 72 63 65 20 5b 66 69 6c 65 20 6a 6f 69 6e 20  urce [file join 
01f0: 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20 5b 69  [file dirname [i
0200: 6e 66 6f 20 73 63 72 69 70 74 5d 5d 20 66 74 73  nfo script]] fts
0210: 35 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c 5d 0a 73 65  5_common.tcl].se
0220: 74 20 74 65 73 74 70 72 65 66 69 78 20 66 74 73  t testprefix fts
0230: 35 61 61 0a 0a 23 20 49 66 20 53 51 4c 49 54 45  5aa..# If SQLITE
0240: 5f 45 4e 41 42 4c 45 5f 46 54 53 35 20 69 73 20  _ENABLE_FTS5 is 
0250: 6e 6f 74 20 64 65 66 69 6e 65 64 2c 20 6f 6d 69  not defined, omi
0260: 74 20 74 68 69 73 20 66 69 6c 65 2e 0a 69 66 63  t this file..ifc
0270: 61 70 61 62 6c 65 20 21 66 74 73 35 20 7b 0a 20  apable !fts5 {. 
0280: 20 66 69 6e 69 73 68 5f 74 65 73 74 0a 20 20 72   finish_test.  r
0290: 65 74 75 72 6e 0a 7d 0a 0a 66 6f 72 65 61 63 68  eturn.}..foreach
02a0: 5f 64 65 74 61 69 6c 5f 6d 6f 64 65 20 24 3a 3a  _detail_mode $::
02b0: 74 65 73 74 70 72 65 66 69 78 20 7b 0a 0a 64 6f  testprefix {..do
02c0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 2e  _execsql_test 1.
02d0: 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52  0 {.  CREATE VIR
02e0: 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53  TUAL TABLE t1 US
02f0: 49 4e 47 20 66 74 73 35 28 61 2c 20 62 2c 20 63  ING fts5(a, b, c
0300: 29 3b 0a 20 20 53 45 4c 45 43 54 20 6e 61 6d 65  );.  SELECT name
0310: 2c 20 73 71 6c 20 46 52 4f 4d 20 73 71 6c 69 74  , sql FROM sqlit
0320: 65 5f 6d 61 73 74 65 72 3b 0a 7d 20 7b 0a 20 20  e_master;.} {.  
0330: 74 31 20 7b 43 52 45 41 54 45 20 56 49 52 54 55  t1 {CREATE VIRTU
0340: 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e  AL TABLE t1 USIN
0350: 47 20 66 74 73 35 28 61 2c 20 62 2c 20 63 29 7d  G fts5(a, b, c)}
0360: 0a 20 20 74 31 5f 64 61 74 61 20 7b 43 52 45 41  .  t1_data {CREA
0370: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74  TE TABLE 't1_dat
0380: 61 27 28 69 64 20 49 4e 54 45 47 45 52 20 50 52  a'(id INTEGER PR
0390: 49 4d 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b  IMARY KEY, block
03a0: 20 42 4c 4f 42 29 7d 0a 20 20 74 31 5f 69 64 78   BLOB)}.  t1_idx
03b0: 20 7b 43 52 45 41 54 45 20 54 41 42 4c 45 20 27   {CREATE TABLE '
03c0: 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20 74  t1_idx'(segid, t
03d0: 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d 41  erm, pgno, PRIMA
03e0: 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74 65  RY KEY(segid, te
03f0: 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f 57  rm)) WITHOUT ROW
0400: 49 44 7d 0a 20 20 74 31 5f 63 6f 6e 74 65 6e 74  ID}.  t1_content
0410: 20 7b 43 52 45 41 54 45 20 54 41 42 4c 45 20 27   {CREATE TABLE '
0420: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 69 64 20 49  t1_content'(id I
0430: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b  NTEGER PRIMARY K
0440: 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32 29 7d  EY, c0, c1, c2)}
0450: 0a 20 20 74 31 5f 64 6f 63 73 69 7a 65 20 7b 43  .  t1_docsize {C
0460: 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f  REATE TABLE 't1_
0470: 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45  docsize'(id INTE
0480: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c  GER PRIMARY KEY,
0490: 20 73 7a 20 42 4c 4f 42 29 7d 0a 20 20 74 31 5f   sz BLOB)}.  t1_
04a0: 63 6f 6e 66 69 67 20 7b 43 52 45 41 54 45 20 54  config {CREATE T
04b0: 41 42 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27  ABLE 't1_config'
04c0: 28 6b 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20  (k PRIMARY KEY, 
04d0: 76 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44  v) WITHOUT ROWID
04e0: 7d 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  }.}..do_execsql_
04f0: 74 65 73 74 20 31 2e 31 20 7b 0a 20 20 44 52 4f  test 1.1 {.  DRO
0500: 50 20 54 41 42 4c 45 20 74 31 3b 0a 20 20 53 45  P TABLE t1;.  SE
0510: 4c 45 43 54 20 6e 61 6d 65 2c 20 73 71 6c 20 46  LECT name, sql F
0520: 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65  ROM sqlite_maste
0530: 72 3b 0a 7d 20 7b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d  r;.} {.}..#-----
0540: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0560: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0570: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0580: 2d 2d 2d 2d 0a 23 0a 0a 64 6f 5f 65 78 65 63 73  ----.#..do_execs
0590: 71 6c 5f 74 65 73 74 20 32 2e 30 20 7b 0a 20 20  ql_test 2.0 {.  
05a0: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
05b0: 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74  ABLE t1 USING ft
05c0: 73 35 28 78 2c 20 79 2c 20 64 65 74 61 69 6c 3d  s5(x, y, detail=
05d0: 25 44 45 54 41 49 4c 25 29 3b 0a 7d 0a 64 6f 5f  %DETAIL%);.}.do_
05e0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e 31  execsql_test 2.1
05f0: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
0600: 20 74 31 20 56 41 4c 55 45 53 28 27 61 20 62 20   t1 VALUES('a b 
0610: 63 27 2c 20 27 64 20 65 20 66 27 29 3b 0a 7d 0a  c', 'd e f');.}.
0620: 0a 64 6f 5f 74 65 73 74 20 32 2e 32 20 7b 0a 20  .do_test 2.2 {. 
0630: 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43   execsql { SELEC
0640: 54 20 66 74 73 35 5f 64 65 63 6f 64 65 28 69 64  T fts5_decode(id
0650: 2c 20 62 6c 6f 63 6b 29 20 46 52 4f 4d 20 74 31  , block) FROM t1
0660: 5f 64 61 74 61 20 57 48 45 52 45 20 69 64 3d 3d  _data WHERE id==
0670: 31 30 20 7d 0a 7d 20 7b 2f 7b 7b 73 74 72 75 63  10 }.} {/{{struc
0680: 74 75 72 65 7d 20 7b 6c 76 6c 3d 30 20 6e 4d 65  ture} {lvl=0 nMe
0690: 72 67 65 3d 30 20 6e 53 65 67 3d 31 20 7b 69 64  rge=0 nSeg=1 {id
06a0: 3d 5b 30 31 32 33 34 35 36 37 38 39 5d 2a 20 6c  =[0123456789]* l
06b0: 65 61 76 65 73 3d 31 2e 2e 31 7d 7d 7d 2f 7d 0a  eaves=1..1}}}/}.
06c0: 0a 66 6f 72 65 61 63 68 20 77 20 7b 61 20 62 20  .foreach w {a b 
06d0: 63 20 64 20 65 20 66 7d 20 7b 0a 20 20 64 6f 5f  c d e f} {.  do_
06e0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e 33  execsql_test 2.3
06f0: 2e 24 77 2e 61 73 63 20 7b 0a 20 20 20 20 53 45  .$w.asc {.    SE
0700: 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20  LECT rowid FROM 
0710: 74 31 20 57 48 45 52 45 20 74 31 20 4d 41 54 43  t1 WHERE t1 MATC
0720: 48 20 24 77 3b 0a 20 20 7d 20 7b 31 7d 0a 20 20  H $w;.  } {1}.  
0730: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
0740: 32 2e 33 2e 24 77 2e 64 65 73 63 20 7b 0a 20 20  2.3.$w.desc {.  
0750: 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46    SELECT rowid F
0760: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 74 31 20  ROM t1 WHERE t1 
0770: 4d 41 54 43 48 20 24 77 20 4f 52 44 45 52 20 42  MATCH $w ORDER B
0780: 59 20 72 6f 77 69 64 20 44 45 53 43 3b 0a 20 20  Y rowid DESC;.  
0790: 7d 20 7b 31 7d 0a 7d 0a 0a 64 6f 5f 65 78 65 63  } {1}.}..do_exec
07a0: 73 71 6c 5f 74 65 73 74 20 32 2e 34 20 7b 0a 20  sql_test 2.4 {. 
07b0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28   INSERT INTO t1(
07c0: 74 31 29 20 56 41 4c 55 45 53 28 27 69 6e 74 65  t1) VALUES('inte
07d0: 67 72 69 74 79 2d 63 68 65 63 6b 27 29 3b 0a 7d  grity-check');.}
07e0: 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ...#------------
07f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0800: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0810: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0820: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a  -------------.#.
0830: 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63  reset_db.do_exec
0840: 73 71 6c 5f 74 65 73 74 20 33 2e 30 20 7b 0a 20  sql_test 3.0 {. 
0850: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
0860: 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66  TABLE t1 USING f
0870: 74 73 35 28 78 2c 79 2c 20 64 65 74 61 69 6c 3d  ts5(x,y, detail=
0880: 25 44 45 54 41 49 4c 25 29 3b 0a 7d 0a 66 6f 72  %DETAIL%);.}.for
0890: 65 61 63 68 20 7b 69 20 78 20 79 7d 20 7b 0a 20  each {i x y} {. 
08a0: 20 20 31 20 20 7b 67 20 66 20 64 20 62 20 66 7d    1  {g f d b f}
08b0: 20 7b 68 20 68 20 65 20 69 20 61 7d 0a 20 20 20   {h h e i a}.   
08c0: 32 20 20 7b 66 20 69 20 67 20 6a 20 65 7d 20 7b  2  {f i g j e} {
08d0: 69 20 6a 20 63 20 66 20 66 7d 0a 20 20 20 33 20  i j c f f}.   3 
08e0: 20 7b 65 20 65 20 69 20 66 20 61 7d 20 7b 65 20   {e e i f a} {e 
08f0: 68 20 66 20 64 20 66 7d 0a 20 20 20 34 20 20 7b  h f d f}.   4  {
0900: 68 20 6a 20 66 20 6a 20 69 7d 20 7b 68 20 61 20  h j f j i} {h a 
0910: 63 20 66 20 6a 7d 0a 20 20 20 35 20 20 7b 64 20  c f j}.   5  {d 
0920: 62 20 6a 20 63 20 67 7d 20 7b 66 20 65 20 69 20  b j c g} {f e i 
0930: 62 20 65 7d 0a 20 20 20 36 20 20 7b 61 20 6a 20  b e}.   6  {a j 
0940: 61 20 65 20 65 7d 20 7b 6a 20 64 20 66 20 64 20  a e e} {j d f d 
0950: 65 7d 0a 20 20 20 37 20 20 7b 67 20 69 20 6a 20  e}.   7  {g i j 
0960: 63 20 68 7d 20 7b 6a 20 64 20 68 20 63 20 61 7d  c h} {j d h c a}
0970: 0a 20 20 20 38 20 20 7b 6a 20 6a 20 69 20 64 20  .   8  {j j i d 
0980: 64 7d 20 7b 65 20 65 20 64 20 66 20 62 7d 0a 20  d} {e e d f b}. 
0990: 20 20 39 20 20 7b 63 20 6a 20 6a 20 64 20 63 7d    9  {c j j d c}
09a0: 20 7b 68 20 6a 20 69 20 66 20 67 7d 0a 20 20 20   {h j i f g}.   
09b0: 31 30 20 7b 62 20 66 20 68 20 69 20 61 7d 20 7b  10 {b f h i a} {
09c0: 63 20 66 20 62 20 62 20 6a 7d 0a 7d 20 7b 0a 20  c f b b j}.} {. 
09d0: 20 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74   do_execsql_test
09e0: 20 33 2e 24 69 2e 31 20 7b 20 49 4e 53 45 52 54   3.$i.1 { INSERT
09f0: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
0a00: 24 78 2c 20 24 79 29 20 7d 0a 20 20 64 6f 5f 65  $x, $y) }.  do_e
0a10: 78 65 63 73 71 6c 5f 74 65 73 74 20 33 2e 24 69  xecsql_test 3.$i
0a20: 2e 32 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f  .2 { INSERT INTO
0a30: 20 74 31 28 74 31 29 20 56 41 4c 55 45 53 28 27   t1(t1) VALUES('
0a40: 69 6e 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27  integrity-check'
0a50: 29 20 7d 0a 20 20 69 66 20 7b 5b 73 65 74 5f 74  ) }.  if {[set_t
0a60: 65 73 74 5f 63 6f 75 6e 74 65 72 20 65 72 72 6f  est_counter erro
0a70: 72 73 5d 7d 20 62 72 65 61 6b 0a 7d 0a 0a 23 2d  rs]} break.}..#-
0a80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0aa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ab0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ac0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65 73 65 74  --------.#.reset
0ad0: 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  _db.do_execsql_t
0ae0: 65 73 74 20 34 2e 30 20 7b 0a 20 20 43 52 45 41  est 4.0 {.  CREA
0af0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
0b00: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 78   t1 USING fts5(x
0b10: 2c 79 2c 20 64 65 74 61 69 6c 3d 25 44 45 54 41  ,y, detail=%DETA
0b20: 49 4c 25 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  IL%);.  INSERT I
0b30: 4e 54 4f 20 74 31 28 74 31 2c 20 72 61 6e 6b 29  NTO t1(t1, rank)
0b40: 20 56 41 4c 55 45 53 28 27 70 67 73 7a 27 2c 20   VALUES('pgsz', 
0b50: 33 32 29 3b 0a 7d 0a 66 6f 72 65 61 63 68 20 7b  32);.}.foreach {
0b60: 69 20 78 20 79 7d 20 7b 0a 20 20 20 31 20 20 7b  i x y} {.   1  {
0b70: 67 20 66 20 64 20 62 20 66 7d 20 7b 68 20 68 20  g f d b f} {h h 
0b80: 65 20 69 20 61 7d 0a 20 20 20 32 20 20 7b 66 20  e i a}.   2  {f 
0b90: 69 20 67 20 6a 20 65 7d 20 7b 69 20 6a 20 63 20  i g j e} {i j c 
0ba0: 66 20 66 7d 0a 20 20 20 33 20 20 7b 65 20 65 20  f f}.   3  {e e 
0bb0: 69 20 66 20 61 7d 20 7b 65 20 68 20 66 20 64 20  i f a} {e h f d 
0bc0: 66 7d 0a 20 20 20 34 20 20 7b 68 20 6a 20 66 20  f}.   4  {h j f 
0bd0: 6a 20 69 7d 20 7b 68 20 61 20 63 20 66 20 6a 7d  j i} {h a c f j}
0be0: 0a 20 20 20 35 20 20 7b 64 20 62 20 6a 20 63 20  .   5  {d b j c 
0bf0: 67 7d 20 7b 66 20 65 20 69 20 62 20 65 7d 0a 20  g} {f e i b e}. 
0c00: 20 20 36 20 20 7b 61 20 6a 20 61 20 65 20 65 7d    6  {a j a e e}
0c10: 20 7b 6a 20 64 20 66 20 64 20 65 7d 0a 20 20 20   {j d f d e}.   
0c20: 37 20 20 7b 67 20 69 20 6a 20 63 20 68 7d 20 7b  7  {g i j c h} {
0c30: 6a 20 64 20 68 20 63 20 61 7d 0a 20 20 20 38 20  j d h c a}.   8 
0c40: 20 7b 6a 20 6a 20 69 20 64 20 64 7d 20 7b 65 20   {j j i d d} {e 
0c50: 65 20 64 20 66 20 62 7d 0a 20 20 20 39 20 20 7b  e d f b}.   9  {
0c60: 63 20 6a 20 6a 20 64 20 63 7d 20 7b 68 20 6a 20  c j j d c} {h j 
0c70: 69 20 66 20 67 7d 0a 20 20 20 31 30 20 7b 62 20  i f g}.   10 {b 
0c80: 66 20 68 20 69 20 61 7d 20 7b 63 20 66 20 62 20  f h i a} {c f b 
0c90: 62 20 6a 7d 0a 7d 20 7b 0a 20 20 64 6f 5f 65 78  b j}.} {.  do_ex
0ca0: 65 63 73 71 6c 5f 74 65 73 74 20 34 2e 24 69 2e  ecsql_test 4.$i.
0cb0: 31 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  1 { INSERT INTO 
0cc0: 74 31 20 56 41 4c 55 45 53 28 24 78 2c 20 24 79  t1 VALUES($x, $y
0cd0: 29 20 7d 0a 20 20 64 6f 5f 65 78 65 63 73 71 6c  ) }.  do_execsql
0ce0: 5f 74 65 73 74 20 34 2e 24 69 2e 32 20 7b 20 49  _test 4.$i.2 { I
0cf0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31  NSERT INTO t1(t1
0d00: 29 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72  ) VALUES('integr
0d10: 69 74 79 2d 63 68 65 63 6b 27 29 20 7d 0a 20 20  ity-check') }.  
0d20: 69 66 20 7b 5b 73 65 74 5f 74 65 73 74 5f 63 6f  if {[set_test_co
0d30: 75 6e 74 65 72 20 65 72 72 6f 72 73 5d 7d 20 62  unter errors]} b
0d40: 72 65 61 6b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  reak.}..#-------
0d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d90: 2d 2d 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f  --.#.reset_db.do
0da0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e  _execsql_test 5.
0db0: 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52  0 {.  CREATE VIR
0dc0: 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53  TUAL TABLE t1 US
0dd0: 49 4e 47 20 66 74 73 35 28 78 2c 79 2c 20 64 65  ING fts5(x,y, de
0de0: 74 61 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a  tail=%DETAIL%);.
0df0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
0e00: 28 74 31 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45  (t1, rank) VALUE
0e10: 53 28 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a 7d  S('pgsz', 32);.}
0e20: 0a 66 6f 72 65 61 63 68 20 7b 69 20 78 20 79 7d  .foreach {i x y}
0e30: 20 7b 0a 20 20 20 31 20 20 7b 64 64 20 61 62 63   {.   1  {dd abc
0e40: 20 61 62 63 20 61 62 63 20 61 62 63 64 65 7d 20   abc abc abcde} 
0e50: 7b 61 61 61 20 64 64 20 64 64 64 20 64 64 64 20  {aaa dd ddd ddd 
0e60: 61 61 62 7d 0a 20 20 20 32 20 20 7b 64 64 20 61  aab}.   2  {dd a
0e70: 61 62 20 64 20 61 61 61 20 62 7d 20 7b 61 62 63  ab d aaa b} {abc
0e80: 64 65 20 63 20 61 61 61 20 61 61 61 20 61 61 61  de c aaa aaa aaa
0e90: 7d 0a 20 20 20 33 20 20 7b 61 62 63 64 65 20 64  }.   3  {abcde d
0ea0: 64 20 62 20 62 20 64 64 7d 20 7b 61 62 63 20 61  d b b dd} {abc a
0eb0: 62 63 20 64 20 61 62 63 20 64 64 64 64 64 7d 0a  bc d abc ddddd}.
0ec0: 20 20 20 34 20 20 7b 61 61 61 20 61 62 63 64 65     4  {aaa abcde
0ed0: 20 64 64 64 64 20 64 64 64 64 20 61 62 63 64 65   dddd dddd abcde
0ee0: 7d 20 7b 61 62 63 20 62 20 62 20 61 62 63 64 65  } {abc b b abcde
0ef0: 20 61 62 63 7d 0a 20 20 20 35 20 20 7b 61 61 62   abc}.   5  {aab
0f00: 20 64 64 64 64 20 64 20 64 64 64 64 20 63 7d 20   dddd d dddd c} 
0f10: 7b 64 64 64 20 61 62 63 64 65 20 64 64 64 64 20  {ddd abcde dddd 
0f20: 61 62 63 64 65 20 63 7d 0a 20 20 20 36 20 20 7b  abcde c}.   6  {
0f30: 64 64 64 20 64 64 20 62 20 61 61 62 20 61 62 63  ddd dd b aab abc
0f40: 64 65 7d 20 7b 64 20 64 64 64 64 64 20 64 64 64  de} {d ddddd ddd
0f50: 64 20 63 20 61 62 63 7d 0a 20 20 20 37 20 20 7b  d c abc}.   7  {
0f60: 64 20 64 64 64 64 64 20 64 64 64 20 63 20 61 62  d ddddd ddd c ab
0f70: 63 64 65 7d 20 7b 63 20 61 61 62 20 64 20 61 62  cde} {c aab d ab
0f80: 63 64 65 20 64 64 64 7d 0a 20 20 20 38 20 20 7b  cde ddd}.   8  {
0f90: 61 62 63 64 65 20 61 61 61 20 61 61 62 20 63 20  abcde aaa aab c 
0fa0: 63 7d 20 7b 64 64 64 20 63 20 64 64 64 64 20 62  c} {ddd c dddd b
0fb0: 20 61 61 61 7d 0a 20 20 20 39 20 20 7b 61 62 63   aaa}.   9  {abc
0fc0: 64 65 20 61 61 62 20 64 64 64 64 64 20 63 20 61  de aab ddddd c a
0fd0: 61 62 7d 20 7b 64 64 64 64 20 64 64 64 64 20 62  ab} {dddd dddd b
0fe0: 20 63 20 64 64 7d 0a 20 20 20 31 30 20 7b 64 64   c dd}.   10 {dd
0ff0: 64 20 61 62 63 64 65 20 64 64 64 64 20 64 64 20  d abcde dddd dd 
1000: 63 7d 20 7b 64 64 64 64 20 63 20 63 20 64 20 61  c} {dddd c c d a
1010: 62 63 64 65 7d 0a 7d 20 7b 0a 20 20 64 6f 5f 65  bcde}.} {.  do_e
1020: 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 24 69  xecsql_test 5.$i
1030: 2e 31 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f  .1 { INSERT INTO
1040: 20 74 31 20 56 41 4c 55 45 53 28 24 78 2c 20 24   t1 VALUES($x, $
1050: 79 29 20 7d 0a 20 20 64 6f 5f 65 78 65 63 73 71  y) }.  do_execsq
1060: 6c 5f 74 65 73 74 20 35 2e 24 69 2e 32 20 7b 20  l_test 5.$i.2 { 
1070: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74  INSERT INTO t1(t
1080: 31 29 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67  1) VALUES('integ
1090: 72 69 74 79 2d 63 68 65 63 6b 27 29 20 7d 0a 20  rity-check') }. 
10a0: 20 69 66 20 7b 5b 73 65 74 5f 74 65 73 74 5f 63   if {[set_test_c
10b0: 6f 75 6e 74 65 72 20 65 72 72 6f 72 73 5d 7d 20  ounter errors]} 
10c0: 62 72 65 61 6b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  break.}..#------
10d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10e0: 2d 2d 2d 2d 2d 2d 2d 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 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64  ---.#.reset_db.d
1120: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 36  o_execsql_test 6
1130: 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49  .0 {.  CREATE VI
1140: 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55  RTUAL TABLE t1 U
1150: 53 49 4e 47 20 66 74 73 35 28 78 2c 79 2c 20 64  SING fts5(x,y, d
1160: 65 74 61 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b  etail=%DETAIL%);
1170: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
1180: 31 28 74 31 2c 20 72 61 6e 6b 29 20 56 41 4c 55  1(t1, rank) VALU
1190: 45 53 28 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a  ES('pgsz', 32);.
11a0: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
11b0: 73 74 20 36 2e 31 20 7b 0a 20 20 49 4e 53 45 52  st 6.1 {.  INSER
11c0: 54 20 20 49 4e 54 4f 20 74 31 28 72 6f 77 69 64  T  INTO t1(rowid
11d0: 2c 20 78 2c 20 79 29 20 56 41 4c 55 45 53 28 32  , x, y) VALUES(2
11e0: 32 2c 20 27 61 20 62 20 63 27 2c 20 27 63 20 62  2, 'a b c', 'c b
11f0: 20 61 27 29 3b 0a 20 20 52 45 50 4c 41 43 45 20   a');.  REPLACE 
1200: 49 4e 54 4f 20 74 31 28 72 6f 77 69 64 2c 20 78  INTO t1(rowid, x
1210: 2c 20 79 29 20 56 41 4c 55 45 53 28 32 32 2c 20  , y) VALUES(22, 
1220: 27 64 20 65 20 66 27 2c 20 27 66 20 65 20 64 27  'd e f', 'f e d'
1230: 29 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  );.}..do_execsql
1240: 5f 74 65 73 74 20 36 2e 32 20 7b 0a 20 20 49 4e  _test 6.2 {.  IN
1250: 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29  SERT INTO t1(t1)
1260: 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69   VALUES('integri
1270: 74 79 2d 63 68 65 63 6b 27 29 20 0a 7d 0a 0a 64  ty-check') .}..d
1280: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 36  o_execsql_test 6
1290: 2e 33 20 7b 0a 20 20 52 45 50 4c 41 43 45 20 49  .3 {.  REPLACE I
12a0: 4e 54 4f 20 74 31 28 72 6f 77 69 64 2c 20 78 2c  NTO t1(rowid, x,
12b0: 20 79 29 20 56 41 4c 55 45 53 28 27 32 32 27 2c   y) VALUES('22',
12c0: 20 27 6c 20 6c 20 6c 27 2c 20 27 6c 20 6c 20 6c   'l l l', 'l l l
12d0: 27 29 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  ');.}..do_execsq
12e0: 6c 5f 74 65 73 74 20 36 2e 34 20 7b 0a 20 20 52  l_test 6.4 {.  R
12f0: 45 50 4c 41 43 45 20 49 4e 54 4f 20 74 31 28 78  EPLACE INTO t1(x
1300: 2c 20 79 29 20 56 41 4c 55 45 53 28 27 78 20 79  , y) VALUES('x y
1310: 20 7a 27 2c 20 27 78 20 79 20 7a 27 29 3b 0a 7d   z', 'x y z');.}
1320: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
1330: 74 20 36 2e 35 20 7b 0a 20 20 49 4e 53 45 52 54  t 6.5 {.  INSERT
1340: 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c   INTO t1(t1) VAL
1350: 55 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d 63  UES('integrity-c
1360: 68 65 63 6b 27 29 20 0a 7d 0a 0a 64 6f 5f 65 78  heck') .}..do_ex
1370: 65 63 73 71 6c 5f 74 65 73 74 20 36 2e 36 20 7b  ecsql_test 6.6 {
1380: 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 2c  .  SELECT rowid,
1390: 20 2a 20 46 52 4f 4d 20 74 31 3b 0a 7d 20 7b 0a   * FROM t1;.} {.
13a0: 20 20 32 32 20 7b 6c 20 6c 20 6c 7d 20 7b 6c 20    22 {l l l} {l 
13b0: 6c 20 6c 7d 0a 20 20 32 33 20 7b 78 20 79 20 7a  l l}.  23 {x y z
13c0: 7d 20 7b 78 20 79 20 7a 7d 0a 7d 0a 0a 23 2d 2d  } {x y z}.}..#--
13d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
13f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1410: 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65 73 65 74 5f  -------.#.reset_
1420: 64 62 0a 65 78 70 72 20 73 72 61 6e 64 28 30 29  db.expr srand(0)
1430: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
1440: 20 37 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20   7.0 {.  CREATE 
1450: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31  VIRTUAL TABLE t1
1460: 20 55 53 49 4e 47 20 66 74 73 35 28 78 2c 79 2c   USING fts5(x,y,
1470: 7a 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  z);.  INSERT INT
1480: 4f 20 74 31 28 74 31 2c 20 72 61 6e 6b 29 20 56  O t1(t1, rank) V
1490: 41 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32  ALUES('pgsz', 32
14a0: 29 3b 0a 7d 0a 0a 70 72 6f 63 20 64 6f 63 20 7b  );.}..proc doc {
14b0: 7d 20 7b 0a 20 20 73 65 74 20 76 20 5b 6c 69 73  } {.  set v [lis
14c0: 74 20 61 61 61 20 61 61 62 20 61 62 63 20 61 62  t aaa aab abc ab
14d0: 63 64 65 20 62 20 63 20 64 20 64 64 20 64 64 64  cde b c d dd ddd
14e0: 20 64 64 64 64 20 64 64 64 64 64 5d 0a 20 20 73   dddd ddddd].  s
14f0: 65 74 20 72 65 74 20 5b 6c 69 73 74 5d 0a 20 20  et ret [list].  
1500: 66 6f 72 20 7b 73 65 74 20 6a 20 30 7d 20 7b 24  for {set j 0} {$
1510: 6a 20 3c 20 32 30 7d 20 7b 69 6e 63 72 20 6a 7d  j < 20} {incr j}
1520: 20 7b 0a 20 20 20 20 6c 61 70 70 65 6e 64 20 72   {.    lappend r
1530: 65 74 20 5b 6c 69 6e 64 65 78 20 24 76 20 5b 65  et [lindex $v [e
1540: 78 70 72 20 69 6e 74 28 72 61 6e 64 28 29 2a 5b  xpr int(rand()*[
1550: 6c 6c 65 6e 67 74 68 20 24 76 5d 29 5d 5d 0a 20  llength $v])]]. 
1560: 20 7d 0a 20 20 72 65 74 75 72 6e 20 24 72 65 74   }.  return $ret
1570: 0a 7d 0a 0a 70 72 6f 63 20 64 75 6d 70 5f 73 74  .}..proc dump_st
1580: 72 75 63 74 75 72 65 20 7b 7d 20 7b 0a 20 20 64  ructure {} {.  d
1590: 62 20 65 76 61 6c 20 7b 53 45 4c 45 43 54 20 66  b eval {SELECT f
15a0: 74 73 35 5f 64 65 63 6f 64 65 28 69 64 2c 20 62  ts5_decode(id, b
15b0: 6c 6f 63 6b 29 20 41 53 20 74 20 46 52 4f 4d 20  lock) AS t FROM 
15c0: 74 31 5f 64 61 74 61 20 57 48 45 52 45 20 69 64  t1_data WHERE id
15d0: 3d 31 30 7d 20 7b 0a 20 20 20 20 66 6f 72 65 61  =10} {.    forea
15e0: 63 68 20 6c 76 6c 20 5b 6c 72 61 6e 67 65 20 24  ch lvl [lrange $
15f0: 74 20 31 20 65 6e 64 5d 20 7b 0a 20 20 20 20 20  t 1 end] {.     
1600: 20 73 65 74 20 73 65 67 20 5b 73 74 72 69 6e 67   set seg [string
1610: 20 72 65 70 65 61 74 20 2e 20 5b 65 78 70 72 20   repeat . [expr 
1620: 5b 6c 6c 65 6e 67 74 68 20 24 6c 76 6c 5d 2d 32  [llength $lvl]-2
1630: 5d 5d 0a 20 20 20 20 20 20 70 75 74 73 20 22 5b  ]].      puts "[
1640: 6c 72 61 6e 67 65 20 24 6c 76 6c 20 30 20 31 5d  lrange $lvl 0 1]
1650: 20 24 73 65 67 22 0a 20 20 20 20 7d 0a 20 20 7d   $seg".    }.  }
1660: 0a 7d 0a 0a 66 6f 72 20 7b 73 65 74 20 69 20 31  .}..for {set i 1
1670: 7d 20 7b 24 69 20 3c 3d 20 31 30 7d 20 7b 69 6e  } {$i <= 10} {in
1680: 63 72 20 69 7d 20 7b 0a 20 20 64 6f 5f 74 65 73  cr i} {.  do_tes
1690: 74 20 37 2e 24 69 20 7b 0a 20 20 20 20 66 6f 72  t 7.$i {.    for
16a0: 20 7b 73 65 74 20 6a 20 30 7d 20 7b 24 6a 20 3c   {set j 0} {$j <
16b0: 20 31 30 7d 20 7b 69 6e 63 72 20 6a 7d 20 7b 0a   10} {incr j} {.
16c0: 20 20 20 20 20 20 73 65 74 20 78 20 5b 64 6f 63        set x [doc
16d0: 5d 0a 20 20 20 20 20 20 73 65 74 20 79 20 5b 64  ].      set y [d
16e0: 6f 63 5d 0a 20 20 20 20 20 20 73 65 74 20 7a 20  oc].      set z 
16f0: 5b 64 6f 63 5d 0a 20 20 20 20 20 20 73 65 74 20  [doc].      set 
1700: 72 6f 77 69 64 20 5b 65 78 70 72 20 69 6e 74 28  rowid [expr int(
1710: 72 61 6e 64 28 29 20 2a 20 31 30 30 29 5d 0a 20  rand() * 100)]. 
1720: 20 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 52       execsql { R
1730: 45 50 4c 41 43 45 20 49 4e 54 4f 20 74 31 28 72  EPLACE INTO t1(r
1740: 6f 77 69 64 2c 78 2c 79 2c 7a 29 20 56 41 4c 55  owid,x,y,z) VALU
1750: 45 53 28 24 72 6f 77 69 64 2c 20 24 78 2c 20 24  ES($rowid, $x, $
1760: 79 2c 20 24 7a 29 20 7d 0a 20 20 20 20 7d 0a 20  y, $z) }.    }. 
1770: 20 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53     execsql { INS
1780: 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20  ERT INTO t1(t1) 
1790: 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74  VALUES('integrit
17a0: 79 2d 63 68 65 63 6b 27 29 3b 20 7d 0a 20 20 7d  y-check'); }.  }
17b0: 20 7b 7d 0a 20 20 69 66 20 7b 5b 73 65 74 5f 74   {}.  if {[set_t
17c0: 65 73 74 5f 63 6f 75 6e 74 65 72 20 65 72 72 6f  est_counter erro
17d0: 72 73 5d 7d 20 62 72 65 61 6b 0a 7d 0a 0a 23 2d  rs]} break.}..#-
17e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1800: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1810: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1820: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65 73 65 74  --------.#.reset
1830: 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  _db.do_execsql_t
1840: 65 73 74 20 38 2e 30 20 7b 0a 20 20 43 52 45 41  est 8.0 {.  CREA
1850: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
1860: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 78   t1 USING fts5(x
1870: 2c 20 70 72 65 66 69 78 3d 22 31 2c 32 2c 33 22  , prefix="1,2,3"
1880: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
1890: 20 74 31 28 74 31 2c 20 72 61 6e 6b 29 20 56 41   t1(t1, rank) VA
18a0: 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32 29  LUES('pgsz', 32)
18b0: 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  ;.}..do_execsql_
18c0: 74 65 73 74 20 38 2e 31 20 7b 0a 20 20 49 4e 53  test 8.1 {.  INS
18d0: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
18e0: 45 53 28 27 74 68 65 20 71 75 69 63 6b 20 62 72  ES('the quick br
18f0: 6f 77 6e 20 66 6f 78 27 29 3b 0a 20 20 49 4e 53  own fox');.  INS
1900: 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20  ERT INTO t1(t1) 
1910: 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74  VALUES('integrit
1920: 79 2d 63 68 65 63 6b 27 29 3b 0a 7d 0a 0a 0a 23  y-check');.}...#
1930: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 0a 72 65 73 65  ---------.#.rese
1980: 74 5f 64 62 0a 0a 65 78 70 72 20 73 72 61 6e 64  t_db..expr srand
1990: 28 30 29 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  (0)..do_execsql_
19a0: 74 65 73 74 20 39 2e 30 20 7b 0a 20 20 43 52 45  test 9.0 {.  CRE
19b0: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
19c0: 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28  E t1 USING fts5(
19d0: 78 2c 79 2c 7a 2c 20 70 72 65 66 69 78 3d 22 31  x,y,z, prefix="1
19e0: 2c 32 2c 33 22 29 3b 0a 20 20 49 4e 53 45 52 54  ,2,3");.  INSERT
19f0: 20 49 4e 54 4f 20 74 31 28 74 31 2c 20 72 61 6e   INTO t1(t1, ran
1a00: 6b 29 20 56 41 4c 55 45 53 28 27 70 67 73 7a 27  k) VALUES('pgsz'
1a10: 2c 20 33 32 29 3b 0a 7d 0a 0a 70 72 6f 63 20 64  , 32);.}..proc d
1a20: 6f 63 20 7b 7d 20 7b 0a 20 20 73 65 74 20 76 20  oc {} {.  set v 
1a30: 5b 6c 69 73 74 20 61 61 61 20 61 61 62 20 61 62  [list aaa aab ab
1a40: 63 20 61 62 63 64 65 20 62 20 63 20 64 20 64 64  c abcde b c d dd
1a50: 20 64 64 64 20 64 64 64 64 20 64 64 64 64 64 5d   ddd dddd ddddd]
1a60: 0a 20 20 73 65 74 20 72 65 74 20 5b 6c 69 73 74  .  set ret [list
1a70: 5d 0a 20 20 66 6f 72 20 7b 73 65 74 20 6a 20 30  ].  for {set j 0
1a80: 7d 20 7b 24 6a 20 3c 20 32 30 7d 20 7b 69 6e 63  } {$j < 20} {inc
1a90: 72 20 6a 7d 20 7b 0a 20 20 20 20 6c 61 70 70 65  r j} {.    lappe
1aa0: 6e 64 20 72 65 74 20 5b 6c 69 6e 64 65 78 20 24  nd ret [lindex $
1ab0: 76 20 5b 65 78 70 72 20 69 6e 74 28 72 61 6e 64  v [expr int(rand
1ac0: 28 29 2a 5b 6c 6c 65 6e 67 74 68 20 24 76 5d 29  ()*[llength $v])
1ad0: 5d 5d 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20  ]].  }.  return 
1ae0: 24 72 65 74 0a 7d 0a 0a 70 72 6f 63 20 64 75 6d  $ret.}..proc dum
1af0: 70 5f 73 74 72 75 63 74 75 72 65 20 7b 7d 20 7b  p_structure {} {
1b00: 0a 20 20 64 62 20 65 76 61 6c 20 7b 53 45 4c 45  .  db eval {SELE
1b10: 43 54 20 66 74 73 35 5f 64 65 63 6f 64 65 28 69  CT fts5_decode(i
1b20: 64 2c 20 62 6c 6f 63 6b 29 20 41 53 20 74 20 46  d, block) AS t F
1b30: 52 4f 4d 20 74 31 5f 64 61 74 61 20 57 48 45 52  ROM t1_data WHER
1b40: 45 20 69 64 3d 31 30 7d 20 7b 0a 20 20 20 20 66  E id=10} {.    f
1b50: 6f 72 65 61 63 68 20 6c 76 6c 20 5b 6c 72 61 6e  oreach lvl [lran
1b60: 67 65 20 24 74 20 31 20 65 6e 64 5d 20 7b 0a 20  ge $t 1 end] {. 
1b70: 20 20 20 20 20 73 65 74 20 73 65 67 20 5b 73 74       set seg [st
1b80: 72 69 6e 67 20 72 65 70 65 61 74 20 2e 20 5b 65  ring repeat . [e
1b90: 78 70 72 20 5b 6c 6c 65 6e 67 74 68 20 24 6c 76  xpr [llength $lv
1ba0: 6c 5d 2d 32 5d 5d 0a 20 20 20 20 20 20 70 75 74  l]-2]].      put
1bb0: 73 20 22 5b 6c 72 61 6e 67 65 20 24 6c 76 6c 20  s "[lrange $lvl 
1bc0: 30 20 31 5d 20 24 73 65 67 22 0a 20 20 20 20 7d  0 1] $seg".    }
1bd0: 0a 20 20 7d 0a 7d 0a 0a 66 6f 72 20 7b 73 65 74  .  }.}..for {set
1be0: 20 69 20 31 7d 20 7b 24 69 20 3c 3d 20 31 30 7d   i 1} {$i <= 10}
1bf0: 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 64 6f   {incr i} {.  do
1c00: 5f 74 65 73 74 20 39 2e 24 69 20 7b 0a 20 20 20  _test 9.$i {.   
1c10: 20 66 6f 72 20 7b 73 65 74 20 6a 20 30 7d 20 7b   for {set j 0} {
1c20: 24 6a 20 3c 20 31 30 30 7d 20 7b 69 6e 63 72 20  $j < 100} {incr 
1c30: 6a 7d 20 7b 0a 20 20 20 20 20 20 73 65 74 20 78  j} {.      set x
1c40: 20 5b 64 6f 63 5d 0a 20 20 20 20 20 20 73 65 74   [doc].      set
1c50: 20 79 20 5b 64 6f 63 5d 0a 20 20 20 20 20 20 73   y [doc].      s
1c60: 65 74 20 7a 20 5b 64 6f 63 5d 0a 20 20 20 20 20  et z [doc].     
1c70: 20 73 65 74 20 72 6f 77 69 64 20 5b 65 78 70 72   set rowid [expr
1c80: 20 69 6e 74 28 72 61 6e 64 28 29 20 2a 20 31 30   int(rand() * 10
1c90: 30 29 5d 0a 20 20 20 20 20 20 65 78 65 63 73 71  0)].      execsq
1ca0: 6c 20 7b 20 52 45 50 4c 41 43 45 20 49 4e 54 4f  l { REPLACE INTO
1cb0: 20 74 31 28 72 6f 77 69 64 2c 78 2c 79 2c 7a 29   t1(rowid,x,y,z)
1cc0: 20 56 41 4c 55 45 53 28 24 72 6f 77 69 64 2c 20   VALUES($rowid, 
1cd0: 24 78 2c 20 24 79 2c 20 24 7a 29 20 7d 0a 20 20  $x, $y, $z) }.  
1ce0: 20 20 7d 0a 20 20 20 20 65 78 65 63 73 71 6c 20    }.    execsql 
1cf0: 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31  { INSERT INTO t1
1d00: 28 74 31 29 20 56 41 4c 55 45 53 28 27 69 6e 74  (t1) VALUES('int
1d10: 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29 3b 20  egrity-check'); 
1d20: 7d 0a 20 20 7d 20 7b 7d 0a 20 20 69 66 20 7b 5b  }.  } {}.  if {[
1d30: 73 65 74 5f 74 65 73 74 5f 63 6f 75 6e 74 65 72  set_test_counter
1d40: 20 65 72 72 6f 72 73 5d 7d 20 62 72 65 61 6b 0a   errors]} break.
1d50: 7d 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }...#-----------
1d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
1da0: 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65  .reset_db.do_exe
1db0: 63 73 71 6c 5f 74 65 73 74 20 31 30 2e 30 20 7b  csql_test 10.0 {
1dc0: 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41  .  CREATE VIRTUA
1dd0: 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47  L TABLE t1 USING
1de0: 20 66 74 73 35 28 78 2c 79 2c 20 64 65 74 61 69   fts5(x,y, detai
1df0: 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 7d 0a 73  l=%DETAIL%);.}.s
1e00: 65 74 20 64 31 30 20 7b 0a 20 20 20 31 20 20 7b  et d10 {.   1  {
1e10: 67 20 66 20 64 20 62 20 66 7d 20 7b 68 20 68 20  g f d b f} {h h 
1e20: 65 20 69 20 61 7d 0a 20 20 20 32 20 20 7b 66 20  e i a}.   2  {f 
1e30: 69 20 67 20 6a 20 65 7d 20 7b 69 20 6a 20 63 20  i g j e} {i j c 
1e40: 66 20 66 7d 0a 20 20 20 33 20 20 7b 65 20 65 20  f f}.   3  {e e 
1e50: 69 20 66 20 61 7d 20 7b 65 20 68 20 66 20 64 20  i f a} {e h f d 
1e60: 66 7d 0a 20 20 20 34 20 20 7b 68 20 6a 20 66 20  f}.   4  {h j f 
1e70: 6a 20 69 7d 20 7b 68 20 61 20 63 20 66 20 6a 7d  j i} {h a c f j}
1e80: 0a 20 20 20 35 20 20 7b 64 20 62 20 6a 20 63 20  .   5  {d b j c 
1e90: 67 7d 20 7b 66 20 65 20 69 20 62 20 65 7d 0a 20  g} {f e i b e}. 
1ea0: 20 20 36 20 20 7b 61 20 6a 20 61 20 65 20 65 7d    6  {a j a e e}
1eb0: 20 7b 6a 20 64 20 66 20 64 20 65 7d 0a 20 20 20   {j d f d e}.   
1ec0: 37 20 20 7b 67 20 69 20 6a 20 63 20 68 7d 20 7b  7  {g i j c h} {
1ed0: 6a 20 64 20 68 20 63 20 61 7d 0a 20 20 20 38 20  j d h c a}.   8 
1ee0: 20 7b 6a 20 6a 20 69 20 64 20 64 7d 20 7b 65 20   {j j i d d} {e 
1ef0: 65 20 64 20 66 20 62 7d 0a 20 20 20 39 20 20 7b  e d f b}.   9  {
1f00: 63 20 6a 20 6a 20 64 20 63 7d 20 7b 68 20 6a 20  c j j d c} {h j 
1f10: 69 20 66 20 67 7d 0a 20 20 31 30 20 20 7b 62 20  i f g}.  10  {b 
1f20: 66 20 68 20 69 20 61 7d 20 7b 63 20 66 20 62 20  f h i a} {c f b 
1f30: 62 20 6a 7d 0a 7d 0a 66 6f 72 65 61 63 68 20 7b  b j}.}.foreach {
1f40: 72 6f 77 69 64 20 78 20 79 7d 20 24 64 31 30 20  rowid x y} $d10 
1f50: 7b 0a 20 20 64 6f 5f 65 78 65 63 73 71 6c 5f 74  {.  do_execsql_t
1f60: 65 73 74 20 31 30 2e 31 2e 24 72 6f 77 69 64 2e  est 10.1.$rowid.
1f70: 31 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  1 { INSERT INTO 
1f80: 74 31 20 56 41 4c 55 45 53 28 24 78 2c 20 24 79  t1 VALUES($x, $y
1f90: 29 20 7d 0a 20 20 64 6f 5f 65 78 65 63 73 71 6c  ) }.  do_execsql
1fa0: 5f 74 65 73 74 20 31 30 2e 31 2e 24 72 6f 77 69  _test 10.1.$rowi
1fb0: 64 2e 32 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  d.2 { INSERT INT
1fc0: 4f 20 74 31 28 74 31 29 20 56 41 4c 55 45 53 28  O t1(t1) VALUES(
1fd0: 27 69 6e 74 65 67 72 69 74 79 2d 63 68 65 63 6b  'integrity-check
1fe0: 27 29 20 7d 0a 7d 0a 66 6f 72 65 61 63 68 20 72  ') }.}.foreach r
1ff0: 6f 77 69 64 20 7b 35 20 39 20 38 20 31 20 32 20  owid {5 9 8 1 2 
2000: 34 20 31 30 20 37 20 33 20 35 20 36 7d 20 7b 0a  4 10 7 3 5 6} {.
2010: 20 20 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73    do_execsql_tes
2020: 74 20 31 30 2e 32 2e 24 72 6f 77 69 64 2e 31 20  t 10.2.$rowid.1 
2030: 7b 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31  { DELETE FROM t1
2040: 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20 24   WHERE rowid = $
2050: 72 6f 77 69 64 20 7d 0a 20 20 64 6f 5f 65 78 65  rowid }.  do_exe
2060: 63 73 71 6c 5f 74 65 73 74 20 31 30 2e 32 2e 24  csql_test 10.2.$
2070: 72 6f 77 69 64 2e 32 20 7b 20 49 4e 53 45 52 54  rowid.2 { INSERT
2080: 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c   INTO t1(t1) VAL
2090: 55 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d 63  UES('integrity-c
20a0: 68 65 63 6b 27 29 20 7d 0a 7d 0a 66 6f 72 65 61  heck') }.}.forea
20b0: 63 68 20 7b 72 6f 77 69 64 20 78 20 79 7d 20 24  ch {rowid x y} $
20c0: 64 31 30 20 7b 0a 20 20 64 6f 5f 65 78 65 63 73  d10 {.  do_execs
20d0: 71 6c 5f 74 65 73 74 20 31 30 2e 33 2e 24 72 6f  ql_test 10.3.$ro
20e0: 77 69 64 2e 31 20 7b 20 49 4e 53 45 52 54 20 49  wid.1 { INSERT I
20f0: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 24 78  NTO t1 VALUES($x
2100: 2c 20 24 79 29 20 7d 0a 20 20 64 6f 5f 65 78 65  , $y) }.  do_exe
2110: 63 73 71 6c 5f 74 65 73 74 20 31 30 2e 33 2e 24  csql_test 10.3.$
2120: 72 6f 77 69 64 2e 32 20 7b 20 49 4e 53 45 52 54  rowid.2 { INSERT
2130: 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c   INTO t1(t1) VAL
2140: 55 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d 63  UES('integrity-c
2150: 68 65 63 6b 27 29 20 7d 0a 7d 0a 0a 64 6f 5f 65  heck') }.}..do_e
2160: 78 65 63 73 71 6c 5f 74 65 73 74 20 31 30 2e 34  xecsql_test 10.4
2170: 2e 31 20 7b 20 44 45 4c 45 54 45 20 46 52 4f 4d  .1 { DELETE FROM
2180: 20 74 31 20 7d 0a 64 6f 5f 65 78 65 63 73 71 6c   t1 }.do_execsql
2190: 5f 74 65 73 74 20 31 30 2e 34 2e 32 20 7b 20 49  _test 10.4.2 { I
21a0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31  NSERT INTO t1(t1
21b0: 29 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72  ) VALUES('integr
21c0: 69 74 79 2d 63 68 65 63 6b 27 29 20 7d 0a 0a 23  ity-check') }..#
21d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
21e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
21f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 64 6f 5f 63  ---------.#.do_c
2220: 61 74 63 68 73 71 6c 5f 74 65 73 74 20 31 31 2e  atchsql_test 11.
2230: 31 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52  1 {.  CREATE VIR
2240: 54 55 41 4c 20 54 41 42 4c 45 20 74 32 20 55 53  TUAL TABLE t2 US
2250: 49 4e 47 20 66 74 73 35 28 61 2c 20 62 2c 20 63  ING fts5(a, b, c
2260: 2c 20 72 61 6e 6b 2c 20 64 65 74 61 69 6c 3d 25  , rank, detail=%
2270: 44 45 54 41 49 4c 25 29 3b 0a 7d 20 7b 31 20 7b  DETAIL%);.} {1 {
2280: 72 65 73 65 72 76 65 64 20 66 74 73 35 20 63 6f  reserved fts5 co
2290: 6c 75 6d 6e 20 6e 61 6d 65 3a 20 72 61 6e 6b 7d  lumn name: rank}
22a0: 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65  }.do_catchsql_te
22b0: 73 74 20 31 31 2e 32 20 7b 0a 20 20 43 52 45 41  st 11.2 {.  CREA
22c0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
22d0: 20 72 61 6e 6b 20 55 53 49 4e 47 20 66 74 73 35   rank USING fts5
22e0: 28 61 2c 20 62 2c 20 63 2c 20 64 65 74 61 69 6c  (a, b, c, detail
22f0: 3d 25 44 45 54 41 49 4c 25 29 3b 0a 7d 20 7b 31  =%DETAIL%);.} {1
2300: 20 7b 72 65 73 65 72 76 65 64 20 66 74 73 35 20   {reserved fts5 
2310: 74 61 62 6c 65 20 6e 61 6d 65 3a 20 72 61 6e 6b  table name: rank
2320: 7d 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74  }}.do_catchsql_t
2330: 65 73 74 20 31 31 2e 33 20 7b 0a 20 20 43 52 45  est 11.3 {.  CRE
2340: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
2350: 45 20 74 32 20 55 53 49 4e 47 20 66 74 73 35 28  E t2 USING fts5(
2360: 61 2c 20 62 2c 20 63 2c 20 72 6f 77 69 64 2c 20  a, b, c, rowid, 
2370: 64 65 74 61 69 6c 3d 25 44 45 54 41 49 4c 25 29  detail=%DETAIL%)
2380: 3b 0a 7d 20 7b 31 20 7b 72 65 73 65 72 76 65 64  ;.} {1 {reserved
2390: 20 66 74 73 35 20 63 6f 6c 75 6d 6e 20 6e 61 6d   fts5 column nam
23a0: 65 3a 20 72 6f 77 69 64 7d 7d 0a 0a 23 2d 2d 2d  e: rowid}}..#---
23b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
23c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
23d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
23e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
23f0: 2d 2d 2d 2d 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63  ------.#.do_exec
2400: 73 71 6c 5f 74 65 73 74 20 31 32 2e 31 20 7b 0a  sql_test 12.1 {.
2410: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
2420: 20 54 41 42 4c 45 20 74 32 20 55 53 49 4e 47 20   TABLE t2 USING 
2430: 66 74 73 35 28 78 2c 79 2c 20 64 65 74 61 69 6c  fts5(x,y, detail
2440: 3d 25 44 45 54 41 49 4c 25 29 3b 0a 7d 20 7b 7d  =%DETAIL%);.} {}
2450: 0a 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65  ..do_catchsql_te
2460: 73 74 20 31 32 2e 32 20 7b 0a 20 20 53 45 4c 45  st 12.2 {.  SELE
2470: 43 54 20 74 32 20 46 52 4f 4d 20 74 32 20 57 48  CT t2 FROM t2 WH
2480: 45 52 45 20 74 32 20 4d 41 54 43 48 20 27 2a 73  ERE t2 MATCH '*s
2490: 74 75 66 66 27 0a 7d 20 7b 31 20 7b 75 6e 6b 6e  tuff'.} {1 {unkn
24a0: 6f 77 6e 20 73 70 65 63 69 61 6c 20 71 75 65 72  own special quer
24b0: 79 3a 20 73 74 75 66 66 7d 7d 0a 0a 64 6f 5f 74  y: stuff}}..do_t
24c0: 65 73 74 20 31 32 2e 33 20 7b 0a 20 20 73 65 74  est 12.3 {.  set
24d0: 20 72 65 73 20 5b 64 62 20 65 76 61 6c 20 7b 20   res [db eval { 
24e0: 53 45 4c 45 43 54 20 74 32 20 46 52 4f 4d 20 74  SELECT t2 FROM t
24f0: 32 20 57 48 45 52 45 20 74 32 20 4d 41 54 43 48  2 WHERE t2 MATCH
2500: 20 27 2a 20 72 65 61 64 73 20 27 20 7d 5d 0a 20   '* reads ' }]. 
2510: 20 73 74 72 69 6e 67 20 69 73 20 69 6e 74 65 67   string is integ
2520: 65 72 20 24 72 65 73 0a 7d 20 7b 31 7d 0a 0a 23  er $res.} {1}..#
2530: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2540: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2560: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2570: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65 73 65  ---------.#.rese
2580: 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  t_db.do_execsql_
2590: 74 65 73 74 20 31 33 2e 31 20 7b 0a 20 20 43 52  test 13.1 {.  CR
25a0: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42  EATE VIRTUAL TAB
25b0: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35  LE t1 USING fts5
25c0: 28 78 2c 20 64 65 74 61 69 6c 3d 25 44 45 54 41  (x, detail=%DETA
25d0: 49 4c 25 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  IL%);.  INSERT I
25e0: 4e 54 4f 20 74 31 28 72 6f 77 69 64 2c 20 78 29  NTO t1(rowid, x)
25f0: 20 56 41 4c 55 45 53 28 31 2c 20 27 6f 20 6e 20   VALUES(1, 'o n 
2600: 65 27 29 2c 20 28 32 2c 20 27 74 20 77 20 6f 27  e'), (2, 't w o'
2610: 29 3b 0a 7d 20 7b 7d 0a 0a 64 6f 5f 65 78 65 63  );.} {}..do_exec
2620: 73 71 6c 5f 74 65 73 74 20 31 33 2e 32 20 7b 0a  sql_test 13.2 {.
2630: 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46    SELECT rowid F
2640: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 74 31 20  ROM t1 WHERE t1 
2650: 4d 41 54 43 48 20 27 6f 27 3b 0a 7d 20 7b 31 20  MATCH 'o';.} {1 
2660: 32 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  2}..do_execsql_t
2670: 65 73 74 20 31 33 2e 34 20 7b 0a 20 20 44 45 4c  est 13.4 {.  DEL
2680: 45 54 45 20 46 52 4f 4d 20 74 31 20 57 48 45 52  ETE FROM t1 WHER
2690: 45 20 72 6f 77 69 64 3d 32 3b 0a 7d 20 7b 7d 0a  E rowid=2;.} {}.
26a0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
26b0: 20 31 33 2e 35 20 7b 0a 20 20 53 45 4c 45 43 54   13.5 {.  SELECT
26c0: 20 72 6f 77 69 64 20 46 52 4f 4d 20 74 31 20 57   rowid FROM t1 W
26d0: 48 45 52 45 20 74 31 20 4d 41 54 43 48 20 27 6f  HERE t1 MATCH 'o
26e0: 27 3b 0a 7d 20 7b 31 7d 0a 0a 64 6f 5f 65 78 65  ';.} {1}..do_exe
26f0: 63 73 71 6c 5f 74 65 73 74 20 31 33 2e 36 20 7b  csql_test 13.6 {
2700: 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20  .  SELECT rowid 
2710: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 74 31  FROM t1 WHERE t1
2720: 20 4d 41 54 43 48 20 27 22 22 27 3b 0a 7d 20 7b   MATCH '""';.} {
2730: 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }..#------------
2740: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2750: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2760: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2770: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a  -------------.#.
2780: 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63  reset_db.do_exec
2790: 73 71 6c 5f 74 65 73 74 20 31 34 2e 31 20 7b 0a  sql_test 14.1 {.
27a0: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
27b0: 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20   TABLE t1 USING 
27c0: 66 74 73 35 28 78 2c 20 79 2c 20 64 65 74 61 69  fts5(x, y, detai
27d0: 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20 20 49  l=%DETAIL%);.  I
27e0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31  NSERT INTO t1(t1
27f0: 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45 53 28 27  , rank) VALUES('
2800: 70 67 73 7a 27 2c 20 33 32 29 3b 0a 20 20 57 49  pgsz', 32);.  WI
2810: 54 48 20 64 28 78 2c 79 29 20 41 53 20 28 0a 20  TH d(x,y) AS (. 
2820: 20 20 20 53 45 4c 45 43 54 20 4e 55 4c 4c 2c 20     SELECT NULL, 
2830: 27 78 79 7a 20 78 79 7a 20 78 79 7a 20 78 79 7a  'xyz xyz xyz xyz
2840: 20 78 79 7a 20 78 79 7a 27 0a 20 20 20 20 55 4e   xyz xyz'.    UN
2850: 49 4f 4e 20 41 4c 4c 20 0a 20 20 20 20 53 45 4c  ION ALL .    SEL
2860: 45 43 54 20 4e 55 4c 4c 2c 20 27 78 79 7a 20 78  ECT NULL, 'xyz x
2870: 79 7a 20 78 79 7a 20 78 79 7a 20 78 79 7a 20 78  yz xyz xyz xyz x
2880: 79 7a 27 20 46 52 4f 4d 20 64 0a 20 20 29 0a 20  yz' FROM d.  ). 
2890: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
28a0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 64 20  SELECT * FROM d 
28b0: 4c 49 4d 49 54 20 32 30 30 3b 0a 7d 0a 0a 64 6f  LIMIT 200;.}..do
28c0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 35  _execsql_test 15
28d0: 2e 78 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e  .x {.  INSERT IN
28e0: 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55 45 53  TO t1(t1) VALUES
28f0: 28 27 69 6e 74 65 67 72 69 74 79 2d 63 68 65 63  ('integrity-chec
2900: 6b 27 29 3b 0a 7d 0a 0a 64 6f 5f 74 65 73 74 20  k');.}..do_test 
2910: 31 34 2e 32 20 7b 0a 20 20 73 65 74 20 6e 52 6f  14.2 {.  set nRo
2920: 77 20 30 0a 20 20 64 62 20 65 76 61 6c 20 7b 20  w 0.  db eval { 
2930: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
2940: 20 57 48 45 52 45 20 74 31 20 4d 41 54 43 48 20   WHERE t1 MATCH 
2950: 27 78 79 7a 27 20 7d 20 7b 0a 20 20 20 20 64 62  'xyz' } {.    db
2960: 20 65 76 61 6c 20 7b 0a 20 20 20 20 20 20 42 45   eval {.      BE
2970: 47 49 4e 3b 0a 20 20 20 20 20 20 20 20 43 52 45  GIN;.        CRE
2980: 41 54 45 20 54 41 42 4c 45 20 74 32 28 61 2c 20  ATE TABLE t2(a, 
2990: 62 29 3b 0a 20 20 20 20 20 20 52 4f 4c 4c 42 41  b);.      ROLLBA
29a0: 43 4b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 6e  CK;.    }.    in
29b0: 63 72 20 6e 52 6f 77 0a 20 20 7d 0a 20 20 73 65  cr nRow.  }.  se
29c0: 74 20 6e 52 6f 77 0a 7d 20 7b 32 30 30 7d 0a 0a  t nRow.} {200}..
29d0: 64 6f 5f 74 65 73 74 20 31 34 2e 33 20 7b 0a 20  do_test 14.3 {. 
29e0: 20 73 65 74 20 6e 52 6f 77 20 30 0a 20 20 64 62   set nRow 0.  db
29f0: 20 65 76 61 6c 20 7b 20 42 45 47 49 4e 3b 20 7d   eval { BEGIN; }
2a00: 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 53 45 4c  .  db eval { SEL
2a10: 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48  ECT * FROM t1 WH
2a20: 45 52 45 20 74 31 20 4d 41 54 43 48 20 27 78 79  ERE t1 MATCH 'xy
2a30: 7a 27 20 7d 20 7b 0a 20 20 20 20 64 62 20 65 76  z' } {.    db ev
2a40: 61 6c 20 7b 0a 20 20 20 20 20 20 53 41 56 45 50  al {.      SAVEP
2a50: 4f 49 4e 54 20 61 61 61 3b 0a 20 20 20 20 20 20  OINT aaa;.      
2a60: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74    CREATE TABLE t
2a70: 32 28 61 2c 20 62 29 3b 0a 20 20 20 20 20 20 52  2(a, b);.      R
2a80: 4f 4c 4c 42 41 43 4b 20 54 4f 20 61 61 61 3b 0a  OLLBACK TO aaa;.
2a90: 20 20 20 20 20 20 52 45 4c 45 41 53 45 20 61 61        RELEASE aa
2aa0: 61 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 6e 63  a;.    }.    inc
2ab0: 72 20 6e 52 6f 77 0a 20 20 7d 0a 20 20 73 65 74  r nRow.  }.  set
2ac0: 20 6e 52 6f 77 0a 7d 20 7b 32 30 30 7d 0a 0a 64   nRow.} {200}..d
2ad0: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31  o_execsql_test 1
2ae0: 35 2e 30 20 7b 0a 20 20 49 4e 53 45 52 54 20 49  5.0 {.  INSERT I
2af0: 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55 45  NTO t1(t1) VALUE
2b00: 53 28 27 69 6e 74 65 67 72 69 74 79 2d 63 68 65  S('integrity-che
2b10: 63 6b 27 29 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73  ck');.}.do_execs
2b20: 71 6c 5f 74 65 73 74 20 31 35 2e 31 20 7b 0a 20  ql_test 15.1 {. 
2b30: 20 55 50 44 41 54 45 20 74 31 5f 63 6f 6e 74 65   UPDATE t1_conte
2b40: 6e 74 20 53 45 54 20 63 31 20 3d 20 27 78 79 7a  nt SET c1 = 'xyz
2b50: 20 78 79 7a 20 78 79 7a 20 78 79 7a 20 78 79 7a   xyz xyz xyz xyz
2b60: 20 61 62 63 27 20 57 48 45 52 45 20 72 6f 77 69   abc' WHERE rowi
2b70: 64 20 3d 20 31 3b 0a 7d 0a 64 6f 5f 63 61 74 63  d = 1;.}.do_catc
2b80: 68 73 71 6c 5f 74 65 73 74 20 31 35 2e 32 20 7b  hsql_test 15.2 {
2b90: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
2ba0: 31 28 74 31 29 20 56 41 4c 55 45 53 28 27 69 6e  1(t1) VALUES('in
2bb0: 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29 3b  tegrity-check');
2bc0: 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20  .} {1 {database 
2bd0: 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61  disk image is ma
2be0: 6c 66 6f 72 6d 65 64 7d 7d 0a 0a 23 2d 2d 2d 2d  lformed}}..#----
2bf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c30: 2d 2d 2d 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63 73  -----.#.do_execs
2c40: 71 6c 5f 74 65 73 74 20 31 36 2e 31 20 7b 0a 20  ql_test 16.1 {. 
2c50: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
2c60: 54 41 42 4c 45 20 6e 31 20 55 53 49 4e 47 20 66  TABLE n1 USING f
2c70: 74 73 35 28 61 29 3b 0a 20 20 49 4e 53 45 52 54  ts5(a);.  INSERT
2c80: 20 49 4e 54 4f 20 6e 31 20 56 41 4c 55 45 53 28   INTO n1 VALUES(
2c90: 27 61 20 62 20 63 20 64 27 29 3b 0a 7d 0a 0a 70  'a b c d');.}..p
2ca0: 72 6f 63 20 66 75 6e 6b 20 7b 7d 20 7b 0a 20 20  roc funk {} {.  
2cb0: 64 62 20 65 76 61 6c 20 7b 20 55 50 44 41 54 45  db eval { UPDATE
2cc0: 20 6e 31 5f 63 6f 6e 66 69 67 20 53 45 54 20 76   n1_config SET v
2cd0: 3d 35 30 20 57 48 45 52 45 20 6b 3d 27 76 65 72  =50 WHERE k='ver
2ce0: 73 69 6f 6e 27 20 7d 0a 20 20 73 65 74 20 66 64  sion' }.  set fd
2cf0: 20 5b 64 62 20 69 6e 63 72 62 6c 6f 62 20 6d 61   [db incrblob ma
2d00: 69 6e 20 6e 31 5f 64 61 74 61 20 62 6c 6f 63 6b  in n1_data block
2d10: 20 31 30 5d 0a 20 20 66 63 6f 6e 66 69 67 75 72   10].  fconfigur
2d20: 65 20 24 66 64 20 2d 65 6e 63 6f 64 69 6e 67 20  e $fd -encoding 
2d30: 62 69 6e 61 72 79 20 2d 74 72 61 6e 73 6c 61 74  binary -translat
2d40: 69 6f 6e 20 62 69 6e 61 72 79 0a 20 20 70 75 74  ion binary.  put
2d50: 73 20 2d 6e 6f 6e 65 77 6c 69 6e 65 20 24 66 64  s -nonewline $fd
2d60: 20 22 5c 78 34 34 5c 78 34 35 22 0a 20 20 63 6c   "\x44\x45".  cl
2d70: 6f 73 65 20 24 66 64 0a 7d 0a 64 62 20 66 75 6e  ose $fd.}.db fun
2d80: 63 20 66 75 6e 6b 20 66 75 6e 6b 0a 0a 23 20 54  c funk funk..# T
2d90: 68 69 73 20 74 65 73 74 20 63 61 73 65 20 63 6f  his test case co
2da0: 72 72 75 70 74 73 20 74 68 65 20 73 74 72 75 63  rrupts the struc
2db0: 74 75 72 65 20 72 65 63 6f 72 64 20 77 69 74 68  ture record with
2dc0: 69 6e 20 74 68 65 20 66 69 72 73 74 20 69 6e 76  in the first inv
2dd0: 6f 63 61 74 69 6f 6e 0a 23 20 6f 66 20 66 75 6e  ocation.# of fun
2de0: 63 74 69 6f 6e 20 66 75 6e 6b 28 29 2e 20 57 68  ction funk(). Wh
2df0: 69 63 68 20 75 73 65 64 20 74 6f 20 63 61 75 73  ich used to caus
2e00: 65 20 74 68 65 20 62 6d 32 35 28 29 20 66 75 6e  e the bm25() fun
2e10: 63 74 69 6f 6e 20 74 6f 20 74 68 72 6f 77 20 61  ction to throw a
2e20: 6e 0a 23 20 65 78 63 65 70 74 69 6f 6e 2e 20 42  n.# exception. B
2e30: 75 74 20 73 69 6e 63 65 20 62 6d 32 35 28 29 20  ut since bm25() 
2e40: 63 61 6e 20 6e 6f 77 20 75 73 65 64 20 74 68 65  can now used the
2e50: 20 63 61 63 68 65 64 20 73 74 72 75 63 74 75 72   cached structur
2e60: 65 20 72 65 63 6f 72 64 2c 0a 23 20 69 74 20 6e  e record,.# it n
2e70: 65 76 65 72 20 73 65 65 73 20 74 68 65 20 63 6f  ever sees the co
2e80: 72 72 75 70 74 69 6f 6e 20 69 6e 74 72 6f 64 75  rruption introdu
2e90: 63 65 64 20 62 79 20 66 75 6e 6b 28 29 20 61 6e  ced by funk() an
2ea0: 64 20 73 6f 20 74 68 65 20 66 6f 6c 6c 6f 77 69  d so the followi
2eb0: 6e 67 20 0a 23 20 73 74 61 74 65 6d 65 6e 74 20  ng .# statement 
2ec0: 6e 6f 20 6c 6f 6e 67 65 72 20 66 61 69 6c 73 2e  no longer fails.
2ed0: 0a 23 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74  .#.do_catchsql_t
2ee0: 65 73 74 20 31 36 2e 32 20 7b 0a 20 20 53 45 4c  est 16.2 {.  SEL
2ef0: 45 43 54 20 66 75 6e 6b 28 29 2c 20 62 6d 32 35  ECT funk(), bm25
2f00: 28 6e 31 29 2c 20 66 75 6e 6b 28 29 20 46 52 4f  (n1), funk() FRO
2f10: 4d 20 6e 31 20 57 48 45 52 45 20 6e 31 20 4d 41  M n1 WHERE n1 MA
2f20: 54 43 48 20 27 61 2b 62 2b 63 2b 64 27 0a 7d 20  TCH 'a+b+c+d'.} 
2f30: 7b 30 20 7b 7b 7d 20 2d 31 65 2d 30 36 20 7b 7d  {0 {{} -1e-06 {}
2f40: 7d 7d 0a 23 20 7b 31 20 7b 53 51 4c 20 6c 6f 67  }}.# {1 {SQL log
2f50: 69 63 20 65 72 72 6f 72 20 6f 72 20 6d 69 73 73  ic error or miss
2f60: 69 6e 67 20 64 61 74 61 62 61 73 65 7d 7d 0a 0a  ing database}}..
2f70: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
2f80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2fa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2fb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65 73  ----------.#.res
2fc0: 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c  et_db.do_execsql
2fd0: 5f 74 65 73 74 20 31 37 2e 31 20 7b 0a 20 20 43  _test 17.1 {.  C
2fe0: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
2ff0: 42 4c 45 20 62 32 20 55 53 49 4e 47 20 66 74 73  BLE b2 USING fts
3000: 35 28 78 2c 20 64 65 74 61 69 6c 3d 25 44 45 54  5(x, detail=%DET
3010: 41 49 4c 25 29 3b 0a 20 20 49 4e 53 45 52 54 20  AIL%);.  INSERT 
3020: 49 4e 54 4f 20 62 32 20 56 41 4c 55 45 53 28 27  INTO b2 VALUES('
3030: 61 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  a');.  INSERT IN
3040: 54 4f 20 62 32 20 56 41 4c 55 45 53 28 27 62 27  TO b2 VALUES('b'
3050: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
3060: 20 62 32 20 56 41 4c 55 45 53 28 27 63 27 29 3b   b2 VALUES('c');
3070: 0a 7d 0a 0a 64 6f 5f 74 65 73 74 20 31 37 2e 32  .}..do_test 17.2
3080: 20 7b 0a 20 20 73 65 74 20 72 65 73 20 5b 6c 69   {.  set res [li
3090: 73 74 5d 0a 20 20 64 62 20 65 76 61 6c 20 7b 20  st].  db eval { 
30a0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 62 32  SELECT * FROM b2
30b0: 20 4f 52 44 45 52 20 42 59 20 72 6f 77 69 64 20   ORDER BY rowid 
30c0: 41 53 43 20 7d 20 7b 0a 20 20 20 20 6c 61 70 70  ASC } {.    lapp
30d0: 65 6e 64 20 72 65 73 20 5b 65 78 65 63 73 71 6c  end res [execsql
30e0: 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d   { SELECT * FROM
30f0: 20 62 32 20 4f 52 44 45 52 20 42 59 20 72 6f 77   b2 ORDER BY row
3100: 69 64 20 41 53 43 20 7d 5d 0a 20 20 7d 0a 20 20  id ASC }].  }.  
3110: 73 65 74 20 72 65 73 0a 7d 20 7b 7b 61 20 62 20  set res.} {{a b 
3120: 63 7d 20 7b 61 20 62 20 63 7d 20 7b 61 20 62 20  c} {a b c} {a b 
3130: 63 7d 7d 0a 0a 69 66 20 7b 5b 73 74 72 69 6e 67  c}}..if {[string
3140: 20 6d 61 74 63 68 20 6e 2a 20 25 44 45 54 41 49   match n* %DETAI
3150: 4c 25 5d 3d 3d 30 7d 20 7b 0a 20 20 72 65 73 65  L%]==0} {.  rese
3160: 74 5f 64 62 0a 20 20 64 6f 5f 65 78 65 63 73 71  t_db.  do_execsq
3170: 6c 5f 74 65 73 74 20 31 37 2e 33 20 7b 0a 20 20  l_test 17.3 {.  
3180: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
3190: 20 54 41 42 4c 45 20 63 32 20 55 53 49 4e 47 20   TABLE c2 USING 
31a0: 66 74 73 35 28 78 2c 20 79 2c 20 64 65 74 61 69  fts5(x, y, detai
31b0: 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20 20 20  l=%DETAIL%);.   
31c0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 63 32 20   INSERT INTO c2 
31d0: 56 41 4c 55 45 53 28 27 78 20 78 20 78 27 2c 20  VALUES('x x x', 
31e0: 27 78 20 78 20 78 27 29 3b 0a 20 20 20 20 53 45  'x x x');.    SE
31f0: 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20  LECT rowid FROM 
3200: 63 32 20 57 48 45 52 45 20 63 32 20 4d 41 54 43  c2 WHERE c2 MATC
3210: 48 20 27 79 3a 78 27 3b 0a 20 20 7d 20 7b 31 7d  H 'y:x';.  } {1}
3220: 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .}..#-----------
3230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3260: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
3270: 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65  .reset_db.do_exe
3280: 63 73 71 6c 5f 74 65 73 74 20 31 37 2e 31 20 7b  csql_test 17.1 {
3290: 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41  .  CREATE VIRTUA
32a0: 4c 20 54 41 42 4c 45 20 75 69 6f 20 55 53 49 4e  L TABLE uio USIN
32b0: 47 20 66 74 73 35 28 74 74 74 2c 20 64 65 74 61  G fts5(ttt, deta
32c0: 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20 20  il=%DETAIL%);.  
32d0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 75 69 6f 20  INSERT INTO uio 
32e0: 56 41 4c 55 45 53 28 4e 55 4c 4c 29 3b 0a 20 20  VALUES(NULL);.  
32f0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 75 69 6f 20  INSERT INTO uio 
3300: 53 45 4c 45 43 54 20 4e 55 4c 4c 20 46 52 4f 4d  SELECT NULL FROM
3310: 20 75 69 6f 3b 0a 20 20 49 4e 53 45 52 54 20 49   uio;.  INSERT I
3320: 4e 54 4f 20 75 69 6f 20 53 45 4c 45 43 54 20 4e  NTO uio SELECT N
3330: 55 4c 4c 20 46 52 4f 4d 20 75 69 6f 3b 0a 20 20  ULL FROM uio;.  
3340: 49 4e 53 45 52 54 20 49 4e 54 4f 20 75 69 6f 20  INSERT INTO uio 
3350: 53 45 4c 45 43 54 20 4e 55 4c 4c 20 46 52 4f 4d  SELECT NULL FROM
3360: 20 75 69 6f 3b 0a 20 20 49 4e 53 45 52 54 20 49   uio;.  INSERT I
3370: 4e 54 4f 20 75 69 6f 20 53 45 4c 45 43 54 20 4e  NTO uio SELECT N
3380: 55 4c 4c 20 46 52 4f 4d 20 75 69 6f 3b 0a 20 20  ULL FROM uio;.  
3390: 49 4e 53 45 52 54 20 49 4e 54 4f 20 75 69 6f 20  INSERT INTO uio 
33a0: 53 45 4c 45 43 54 20 4e 55 4c 4c 20 46 52 4f 4d  SELECT NULL FROM
33b0: 20 75 69 6f 3b 0a 20 20 49 4e 53 45 52 54 20 49   uio;.  INSERT I
33c0: 4e 54 4f 20 75 69 6f 20 53 45 4c 45 43 54 20 4e  NTO uio SELECT N
33d0: 55 4c 4c 20 46 52 4f 4d 20 75 69 6f 3b 0a 20 20  ULL FROM uio;.  
33e0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 75 69 6f 20  INSERT INTO uio 
33f0: 53 45 4c 45 43 54 20 4e 55 4c 4c 20 46 52 4f 4d  SELECT NULL FROM
3400: 20 75 69 6f 3b 0a 20 20 49 4e 53 45 52 54 20 49   uio;.  INSERT I
3410: 4e 54 4f 20 75 69 6f 20 53 45 4c 45 43 54 20 4e  NTO uio SELECT N
3420: 55 4c 4c 20 46 52 4f 4d 20 75 69 6f 3b 0a 20 20  ULL FROM uio;.  
3430: 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20  SELECT count(*) 
3440: 46 52 4f 4d 20 75 69 6f 3b 0a 7d 20 7b 32 35 36  FROM uio;.} {256
3450: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
3460: 73 74 20 31 37 2e 32 20 7b 0a 20 20 53 45 4c 45  st 17.2 {.  SELE
3470: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d  CT count(*) FROM
3480: 20 75 69 6f 20 57 48 45 52 45 20 72 6f 77 69 64   uio WHERE rowid
3490: 20 42 45 54 57 45 45 4e 20 38 20 41 4e 44 20 31   BETWEEN 8 AND 1
34a0: 37 0a 7d 20 7b 31 30 7d 0a 64 6f 5f 65 78 65 63  7.} {10}.do_exec
34b0: 73 71 6c 5f 74 65 73 74 20 31 37 2e 33 20 7b 0a  sql_test 17.3 {.
34c0: 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46    SELECT rowid F
34d0: 52 4f 4d 20 75 69 6f 20 57 48 45 52 45 20 72 6f  ROM uio WHERE ro
34e0: 77 69 64 20 42 45 54 57 45 45 4e 20 38 20 41 4e  wid BETWEEN 8 AN
34f0: 44 20 31 37 0a 7d 20 7b 38 20 39 20 31 30 20 31  D 17.} {8 9 10 1
3500: 31 20 31 32 20 31 33 20 31 34 20 31 35 20 31 36  1 12 13 14 15 16
3510: 20 31 37 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f   17}.do_execsql_
3520: 74 65 73 74 20 31 37 2e 34 20 7b 0a 20 20 53 45  test 17.4 {.  SE
3530: 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20  LECT rowid FROM 
3540: 75 69 6f 20 57 48 45 52 45 20 72 6f 77 69 64 20  uio WHERE rowid 
3550: 42 45 54 57 45 45 4e 20 38 20 41 4e 44 20 31 37  BETWEEN 8 AND 17
3560: 20 4f 52 44 45 52 20 42 59 20 72 6f 77 69 64 20   ORDER BY rowid 
3570: 44 45 53 43 0a 7d 20 7b 31 37 20 31 36 20 31 35  DESC.} {17 16 15
3580: 20 31 34 20 31 33 20 31 32 20 31 31 20 31 30 20   14 13 12 11 10 
3590: 39 20 38 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  9 8}.do_execsql_
35a0: 74 65 73 74 20 31 37 2e 35 20 7b 0a 20 20 53 45  test 17.5 {.  SE
35b0: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
35c0: 4f 4d 20 75 69 6f 0a 7d 20 7b 32 35 36 7d 0a 0a  OM uio.} {256}..
35d0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
35e0: 31 37 2e 36 20 7b 0a 20 20 49 4e 53 45 52 54 20  17.6 {.  INSERT 
35f0: 49 4e 54 4f 20 75 69 6f 28 72 6f 77 69 64 29 20  INTO uio(rowid) 
3600: 56 41 4c 55 45 53 28 39 32 32 33 33 37 32 30 33  VALUES(922337203
3610: 36 38 35 34 37 37 35 38 30 37 29 3b 0a 20 20 49  6854775807);.  I
3620: 4e 53 45 52 54 20 49 4e 54 4f 20 75 69 6f 28 72  NSERT INTO uio(r
3630: 6f 77 69 64 29 20 56 41 4c 55 45 53 28 2d 39 32  owid) VALUES(-92
3640: 32 33 33 37 32 30 33 36 38 35 34 37 37 35 38 30  2337203685477580
3650: 38 29 3b 0a 20 20 53 45 4c 45 43 54 20 63 6f 75  8);.  SELECT cou
3660: 6e 74 28 2a 29 20 46 52 4f 4d 20 75 69 6f 3b 0a  nt(*) FROM uio;.
3670: 7d 20 7b 32 35 38 7d 0a 64 6f 5f 65 78 65 63 73  } {258}.do_execs
3680: 71 6c 5f 74 65 73 74 20 31 37 2e 37 20 7b 0a 20  ql_test 17.7 {. 
3690: 20 53 45 4c 45 43 54 20 6d 69 6e 28 72 6f 77 69   SELECT min(rowi
36a0: 64 29 2c 20 6d 61 78 28 72 6f 77 69 64 29 20 46  d), max(rowid) F
36b0: 52 4f 4d 20 75 69 6f 3b 0a 7d 20 7b 2d 39 32 32  ROM uio;.} {-922
36c0: 33 33 37 32 30 33 36 38 35 34 37 37 35 38 30 38  3372036854775808
36d0: 20 39 32 32 33 33 37 32 30 33 36 38 35 34 37 37   922337203685477
36e0: 35 38 30 37 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  5807}..do_execsq
36f0: 6c 5f 74 65 73 74 20 31 37 2e 38 20 7b 0a 20 20  l_test 17.8 {.  
3700: 49 4e 53 45 52 54 20 49 4e 54 4f 20 75 69 6f 20  INSERT INTO uio 
3710: 44 45 46 41 55 4c 54 20 56 41 4c 55 45 53 3b 0a  DEFAULT VALUES;.
3720: 20 20 53 45 4c 45 43 54 20 6d 69 6e 28 72 6f 77    SELECT min(row
3730: 69 64 29 2c 20 6d 61 78 28 72 6f 77 69 64 29 2c  id), max(rowid),
3740: 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 75   count(*) FROM u
3750: 69 6f 3b 0a 7d 20 7b 2d 39 32 32 33 33 37 32 30  io;.} {-92233720
3760: 33 36 38 35 34 37 37 35 38 30 38 20 39 32 32 33  36854775808 9223
3770: 33 37 32 30 33 36 38 35 34 37 37 35 38 30 37 20  372036854775807 
3780: 32 35 39 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  259}..do_execsql
3790: 5f 74 65 73 74 20 31 37 2e 39 20 7b 0a 20 20 53  _test 17.9 {.  S
37a0: 45 4c 45 43 54 20 6d 69 6e 28 72 6f 77 69 64 29  ELECT min(rowid)
37b0: 2c 20 6d 61 78 28 72 6f 77 69 64 29 2c 20 63 6f  , max(rowid), co
37c0: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 75 69 6f 20  unt(*) FROM uio 
37d0: 57 48 45 52 45 20 72 6f 77 69 64 20 3c 20 31 30  WHERE rowid < 10
37e0: 3b 0a 7d 20 7b 2d 39 32 32 33 33 37 32 30 33 36  ;.} {-9223372036
37f0: 38 35 34 37 37 35 38 30 38 20 39 20 31 30 7d 0a  854775808 9 10}.
3800: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
3810: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3820: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3830: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3840: 2d 2d 2d 2d 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63  ------.#.do_exec
3850: 73 71 6c 5f 74 65 73 74 20 31 38 2e 31 20 7b 0a  sql_test 18.1 {.
3860: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
3870: 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20   TABLE t1 USING 
3880: 66 74 73 35 28 61 2c 20 62 2c 20 64 65 74 61 69  fts5(a, b, detai
3890: 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20 20 43  l=%DETAIL%);.  C
38a0: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
38b0: 42 4c 45 20 74 32 20 55 53 49 4e 47 20 66 74 73  BLE t2 USING fts
38c0: 35 28 63 2c 20 64 2c 20 64 65 74 61 69 6c 3d 25  5(c, d, detail=%
38d0: 44 45 54 41 49 4c 25 29 3b 0a 20 20 49 4e 53 45  DETAIL%);.  INSE
38e0: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
38f0: 53 28 27 61 62 63 2a 27 2c 20 4e 55 4c 4c 29 3b  S('abc*', NULL);
3900: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
3910: 32 20 56 41 4c 55 45 53 28 31 2c 20 27 61 62 63  2 VALUES(1, 'abc
3920: 64 65 66 67 27 29 3b 0a 7d 0a 64 6f 5f 65 78 65  defg');.}.do_exe
3930: 63 73 71 6c 5f 74 65 73 74 20 31 38 2e 32 20 7b  csql_test 18.2 {
3940: 0a 20 20 53 45 4c 45 43 54 20 74 31 2e 72 6f 77  .  SELECT t1.row
3950: 69 64 2c 20 74 32 2e 72 6f 77 69 64 20 46 52 4f  id, t2.rowid FRO
3960: 4d 20 74 31 2c 20 74 32 20 57 48 45 52 45 20 74  M t1, t2 WHERE t
3970: 32 20 4d 41 54 43 48 20 74 31 2e 61 20 41 4e 44  2 MATCH t1.a AND
3980: 20 74 31 2e 72 6f 77 69 64 20 3d 20 74 32 2e 63   t1.rowid = t2.c
3990: 0a 7d 20 7b 31 20 31 7d 0a 64 6f 5f 65 78 65 63  .} {1 1}.do_exec
39a0: 73 71 6c 5f 74 65 73 74 20 31 38 2e 33 20 7b 0a  sql_test 18.3 {.
39b0: 20 20 53 45 4c 45 43 54 20 74 31 2e 72 6f 77 69    SELECT t1.rowi
39c0: 64 2c 20 74 32 2e 72 6f 77 69 64 20 46 52 4f 4d  d, t2.rowid FROM
39d0: 20 74 32 2c 20 74 31 20 57 48 45 52 45 20 74 32   t2, t1 WHERE t2
39e0: 20 4d 41 54 43 48 20 74 31 2e 61 20 41 4e 44 20   MATCH t1.a AND 
39f0: 74 31 2e 72 6f 77 69 64 20 3d 20 74 32 2e 63 0a  t1.rowid = t2.c.
3a00: 7d 20 7b 31 20 31 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  } {1 1}..#------
3a10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3a20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3a30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3a40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
3a50: 20 66 74 73 35 20 74 61 62 6c 65 20 69 6e 20 74   fts5 table in t
3a60: 68 65 20 74 65 6d 70 20 73 63 68 65 6d 61 2e 0a  he temp schema..
3a70: 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78  #.reset_db.do_ex
3a80: 65 63 73 71 6c 5f 74 65 73 74 20 31 39 2e 30 20  ecsql_test 19.0 
3a90: 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55  {.  CREATE VIRTU
3aa0: 41 4c 20 54 41 42 4c 45 20 74 65 6d 70 2e 74 31  AL TABLE temp.t1
3ab0: 20 55 53 49 4e 47 20 66 74 73 35 28 78 2c 20 64   USING fts5(x, d
3ac0: 65 74 61 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b  etail=%DETAIL%);
3ad0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
3ae0: 31 20 56 41 4c 55 45 53 28 27 78 20 79 20 7a 27  1 VALUES('x y z'
3af0: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
3b00: 20 74 31 20 56 41 4c 55 45 53 28 27 77 20 78 20   t1 VALUES('w x 
3b10: 31 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 72 6f  1');.  SELECT ro
3b20: 77 69 64 20 46 52 4f 4d 20 74 31 20 57 48 45 52  wid FROM t1 WHER
3b30: 45 20 74 31 20 4d 41 54 43 48 20 27 78 27 3b 0a  E t1 MATCH 'x';.
3b40: 7d 20 7b 31 20 32 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  } {1 2}..#------
3b50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3b60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3b70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3b80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
3b90: 20 54 65 73 74 20 74 68 61 74 20 36 20 61 6e 64   Test that 6 and
3ba0: 20 37 20 62 79 74 65 20 76 61 72 69 6e 74 73 20   7 byte varints 
3bb0: 63 61 6e 20 62 65 20 72 65 61 64 2e 0a 23 0a 72  can be read..#.r
3bc0: 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73  eset_db.do_execs
3bd0: 71 6c 5f 74 65 73 74 20 32 30 2e 30 20 7b 0a 20  ql_test 20.0 {. 
3be0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
3bf0: 54 41 42 4c 45 20 74 65 6d 70 2e 74 6d 70 20 55  TABLE temp.tmp U
3c00: 53 49 4e 47 20 66 74 73 35 28 78 2c 20 64 65 74  SING fts5(x, det
3c10: 61 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 7d  ail=%DETAIL%);.}
3c20: 0a 73 65 74 20 3a 3a 69 64 73 20 5b 6c 69 73 74  .set ::ids [list
3c30: 20 5c 0a 20 20 30 20 5b 65 78 70 72 20 31 3c 3c   \.  0 [expr 1<<
3c40: 33 36 5d 20 5b 65 78 70 72 20 32 3c 3c 33 36 5d  36] [expr 2<<36]
3c50: 20 5b 65 78 70 72 20 31 3c 3c 34 33 5d 20 5b 65   [expr 1<<43] [e
3c60: 78 70 72 20 32 3c 3c 34 33 5d 0a 5d 0a 64 6f 5f  xpr 2<<43].].do_
3c70: 74 65 73 74 20 32 30 2e 31 20 7b 0a 20 20 66 6f  test 20.1 {.  fo
3c80: 72 65 61 63 68 20 69 64 20 24 3a 3a 69 64 73 20  reach id $::ids 
3c90: 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20  {.    execsql { 
3ca0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 6d 70 28  INSERT INTO tmp(
3cb0: 72 6f 77 69 64 2c 20 78 29 20 56 41 4c 55 45 53  rowid, x) VALUES
3cc0: 28 24 69 64 2c 20 27 78 20 79 20 7a 27 29 20 7d  ($id, 'x y z') }
3cd0: 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b  .  }.  execsql {
3ce0: 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52   SELECT rowid FR
3cf0: 4f 4d 20 74 6d 70 20 57 48 45 52 45 20 74 6d 70  OM tmp WHERE tmp
3d00: 20 4d 41 54 43 48 20 27 79 27 20 7d 0a 7d 20 24   MATCH 'y' }.} $
3d10: 3a 3a 69 64 73 0a 0a 7d 0a 0a 0a 66 69 6e 69 73  ::ids..}...finis
3d20: 68 5f 74 65 73 74 0a 0a 0a                       h_test...