/ Hex Artifact Content
Login

Artifact 5bd43427b7d08ce2e19c488a26534be450538b9232d4d5305049e8de236e9aa9:


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 7d 0a 0a 23 2d 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 0a 23 0a 0a 64 6f 5f 65 78 65 63 73 71  ---.#..do_execsq
0590: 6c 5f 74 65 73 74 20 32 2e 30 20 7b 0a 20 20 43  l_test 2.0 {.  C
05a0: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
05b0: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73  BLE t1 USING fts
05c0: 35 28 78 2c 20 79 2c 20 64 65 74 61 69 6c 3d 25  5(x, y, detail=%
05d0: 44 45 54 41 49 4c 25 29 3b 0a 7d 0a 64 6f 5f 65  DETAIL%);.}.do_e
05e0: 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e 31 20  xecsql_test 2.1 
05f0: 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  {.  INSERT INTO 
0600: 74 31 20 56 41 4c 55 45 53 28 27 61 20 62 20 63  t1 VALUES('a b c
0610: 27 2c 20 27 64 20 65 20 66 27 29 3b 0a 7d 0a 0a  ', 'd e f');.}..
0620: 64 6f 5f 74 65 73 74 20 32 2e 32 20 7b 0a 20 20  do_test 2.2 {.  
0630: 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54  execsql { SELECT
0640: 20 66 74 73 35 5f 64 65 63 6f 64 65 28 69 64 2c   fts5_decode(id,
0650: 20 62 6c 6f 63 6b 29 20 46 52 4f 4d 20 74 31 5f   block) FROM t1_
0660: 64 61 74 61 20 57 48 45 52 45 20 69 64 3d 3d 31  data WHERE id==1
0670: 30 20 7d 0a 7d 20 7b 2f 7b 7b 73 74 72 75 63 74  0 }.} {/{{struct
0680: 75 72 65 7d 20 7b 6c 76 6c 3d 30 20 6e 4d 65 72  ure} {lvl=0 nMer
0690: 67 65 3d 30 20 6e 53 65 67 3d 31 20 7b 69 64 3d  ge=0 nSeg=1 {id=
06a0: 5b 30 31 32 33 34 35 36 37 38 39 5d 2a 20 6c 65  [0123456789]* le
06b0: 61 76 65 73 3d 31 2e 2e 31 7d 7d 7d 2f 7d 0a 0a  aves=1..1}}}/}..
06c0: 66 6f 72 65 61 63 68 20 77 20 7b 61 20 62 20 63  foreach w {a b c
06d0: 20 64 20 65 20 66 7d 20 7b 0a 20 20 64 6f 5f 65   d e f} {.  do_e
06e0: 78 65 63 73 71 6c 5f 74 65 73 74 20 32 2e 33 2e  xecsql_test 2.3.
06f0: 24 77 2e 61 73 63 20 7b 0a 20 20 20 20 53 45 4c  $w.asc {.    SEL
0700: 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 74  ECT rowid FROM t
0710: 31 20 57 48 45 52 45 20 74 31 20 4d 41 54 43 48  1 WHERE t1 MATCH
0720: 20 24 77 3b 0a 20 20 7d 20 7b 31 7d 0a 20 20 64   $w;.  } {1}.  d
0730: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32  o_execsql_test 2
0740: 2e 33 2e 24 77 2e 64 65 73 63 20 7b 0a 20 20 20  .3.$w.desc {.   
0750: 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52   SELECT rowid FR
0760: 4f 4d 20 74 31 20 57 48 45 52 45 20 74 31 20 4d  OM t1 WHERE t1 M
0770: 41 54 43 48 20 24 77 20 4f 52 44 45 52 20 42 59  ATCH $w ORDER BY
0780: 20 72 6f 77 69 64 20 44 45 53 43 3b 0a 20 20 7d   rowid DESC;.  }
0790: 20 7b 31 7d 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73   {1}.}..do_execs
07a0: 71 6c 5f 74 65 73 74 20 32 2e 34 20 7b 0a 20 20  ql_test 2.4 {.  
07b0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74  INSERT INTO t1(t
07c0: 31 29 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67  1) VALUES('integ
07d0: 72 69 74 79 2d 63 68 65 63 6b 27 29 3b 0a 7d 0a  rity-check');.}.
07e0: 0a 0a 23 2d 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 0a 23 0a 72  ------------.#.r
0830: 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73  eset_db.do_execs
0840: 71 6c 5f 74 65 73 74 20 33 2e 30 20 7b 0a 20 20  ql_test 3.0 {.  
0850: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
0860: 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74  ABLE t1 USING ft
0870: 73 35 28 78 2c 79 2c 20 64 65 74 61 69 6c 3d 25  s5(x,y, detail=%
0880: 44 45 54 41 49 4c 25 29 3b 0a 7d 0a 66 6f 72 65  DETAIL%);.}.fore
0890: 61 63 68 20 7b 69 20 78 20 79 7d 20 7b 0a 20 20  ach {i x y} {.  
08a0: 20 31 20 20 7b 67 20 66 20 64 20 62 20 66 7d 20   1  {g f d b f} 
08b0: 7b 68 20 68 20 65 20 69 20 61 7d 0a 20 20 20 32  {h h e i a}.   2
08c0: 20 20 7b 66 20 69 20 67 20 6a 20 65 7d 20 7b 69    {f i g j e} {i
08d0: 20 6a 20 63 20 66 20 66 7d 0a 20 20 20 33 20 20   j c f f}.   3  
08e0: 7b 65 20 65 20 69 20 66 20 61 7d 20 7b 65 20 68  {e e i f a} {e h
08f0: 20 66 20 64 20 66 7d 0a 20 20 20 34 20 20 7b 68   f d f}.   4  {h
0900: 20 6a 20 66 20 6a 20 69 7d 20 7b 68 20 61 20 63   j f j i} {h a c
0910: 20 66 20 6a 7d 0a 20 20 20 35 20 20 7b 64 20 62   f j}.   5  {d b
0920: 20 6a 20 63 20 67 7d 20 7b 66 20 65 20 69 20 62   j c g} {f e i b
0930: 20 65 7d 0a 20 20 20 36 20 20 7b 61 20 6a 20 61   e}.   6  {a j a
0940: 20 65 20 65 7d 20 7b 6a 20 64 20 66 20 64 20 65   e e} {j d f d e
0950: 7d 0a 20 20 20 37 20 20 7b 67 20 69 20 6a 20 63  }.   7  {g i j c
0960: 20 68 7d 20 7b 6a 20 64 20 68 20 63 20 61 7d 0a   h} {j d h c a}.
0970: 20 20 20 38 20 20 7b 6a 20 6a 20 69 20 64 20 64     8  {j j i d d
0980: 7d 20 7b 65 20 65 20 64 20 66 20 62 7d 0a 20 20  } {e e d f b}.  
0990: 20 39 20 20 7b 63 20 6a 20 6a 20 64 20 63 7d 20   9  {c j j d c} 
09a0: 7b 68 20 6a 20 69 20 66 20 67 7d 0a 20 20 20 31  {h j i f g}.   1
09b0: 30 20 7b 62 20 66 20 68 20 69 20 61 7d 20 7b 63  0 {b f h i a} {c
09c0: 20 66 20 62 20 62 20 6a 7d 0a 7d 20 7b 0a 20 20   f b b j}.} {.  
09d0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
09e0: 33 2e 24 69 2e 31 20 7b 20 49 4e 53 45 52 54 20  3.$i.1 { INSERT 
09f0: 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 24  INTO t1 VALUES($
0a00: 78 2c 20 24 79 29 20 7d 0a 20 20 64 6f 5f 65 78  x, $y) }.  do_ex
0a10: 65 63 73 71 6c 5f 74 65 73 74 20 33 2e 24 69 2e  ecsql_test 3.$i.
0a20: 32 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  2 { INSERT INTO 
0a30: 74 31 28 74 31 29 20 56 41 4c 55 45 53 28 27 69  t1(t1) VALUES('i
0a40: 6e 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29  ntegrity-check')
0a50: 20 7d 0a 20 20 69 66 20 7b 5b 73 65 74 5f 74 65   }.  if {[set_te
0a60: 73 74 5f 63 6f 75 6e 74 65 72 20 65 72 72 6f 72  st_counter error
0a70: 73 5d 7d 20 62 72 65 61 6b 0a 7d 0a 0a 23 2d 2d  s]} 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 0a 23 0a 72 65 73 65 74 5f  -------.#.reset_
0ad0: 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  db.do_execsql_te
0ae0: 73 74 20 34 2e 30 20 7b 0a 20 20 43 52 45 41 54  st 4.0 {.  CREAT
0af0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
0b00: 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 78 2c  t1 USING fts5(x,
0b10: 79 2c 20 64 65 74 61 69 6c 3d 25 44 45 54 41 49  y, detail=%DETAI
0b20: 4c 25 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  L%);.  INSERT IN
0b30: 54 4f 20 74 31 28 74 31 2c 20 72 61 6e 6b 29 20  TO t1(t1, rank) 
0b40: 56 41 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33  VALUES('pgsz', 3
0b50: 32 29 3b 0a 7d 0a 66 6f 72 65 61 63 68 20 7b 69  2);.}.foreach {i
0b60: 20 78 20 79 7d 20 7b 0a 20 20 20 31 20 20 7b 67   x y} {.   1  {g
0b70: 20 66 20 64 20 62 20 66 7d 20 7b 68 20 68 20 65   f d b f} {h h e
0b80: 20 69 20 61 7d 0a 20 20 20 32 20 20 7b 66 20 69   i a}.   2  {f i
0b90: 20 67 20 6a 20 65 7d 20 7b 69 20 6a 20 63 20 66   g j e} {i j c f
0ba0: 20 66 7d 0a 20 20 20 33 20 20 7b 65 20 65 20 69   f}.   3  {e e i
0bb0: 20 66 20 61 7d 20 7b 65 20 68 20 66 20 64 20 66   f a} {e h f d f
0bc0: 7d 0a 20 20 20 34 20 20 7b 68 20 6a 20 66 20 6a  }.   4  {h j f j
0bd0: 20 69 7d 20 7b 68 20 61 20 63 20 66 20 6a 7d 0a   i} {h a c f j}.
0be0: 20 20 20 35 20 20 7b 64 20 62 20 6a 20 63 20 67     5  {d b j c g
0bf0: 7d 20 7b 66 20 65 20 69 20 62 20 65 7d 0a 20 20  } {f e i b e}.  
0c00: 20 36 20 20 7b 61 20 6a 20 61 20 65 20 65 7d 20   6  {a j a e e} 
0c10: 7b 6a 20 64 20 66 20 64 20 65 7d 0a 20 20 20 37  {j d f d e}.   7
0c20: 20 20 7b 67 20 69 20 6a 20 63 20 68 7d 20 7b 6a    {g i j c h} {j
0c30: 20 64 20 68 20 63 20 61 7d 0a 20 20 20 38 20 20   d h c a}.   8  
0c40: 7b 6a 20 6a 20 69 20 64 20 64 7d 20 7b 65 20 65  {j j i d d} {e e
0c50: 20 64 20 66 20 62 7d 0a 20 20 20 39 20 20 7b 63   d f b}.   9  {c
0c60: 20 6a 20 6a 20 64 20 63 7d 20 7b 68 20 6a 20 69   j j d c} {h j i
0c70: 20 66 20 67 7d 0a 20 20 20 31 30 20 7b 62 20 66   f g}.   10 {b f
0c80: 20 68 20 69 20 61 7d 20 7b 63 20 66 20 62 20 62   h i a} {c f b b
0c90: 20 6a 7d 0a 7d 20 7b 0a 20 20 64 6f 5f 65 78 65   j}.} {.  do_exe
0ca0: 63 73 71 6c 5f 74 65 73 74 20 34 2e 24 69 2e 31  csql_test 4.$i.1
0cb0: 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74   { INSERT INTO t
0cc0: 31 20 56 41 4c 55 45 53 28 24 78 2c 20 24 79 29  1 VALUES($x, $y)
0cd0: 20 7d 0a 20 20 64 6f 5f 65 78 65 63 73 71 6c 5f   }.  do_execsql_
0ce0: 74 65 73 74 20 34 2e 24 69 2e 32 20 7b 20 49 4e  test 4.$i.2 { IN
0cf0: 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29  SERT INTO t1(t1)
0d00: 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69   VALUES('integri
0d10: 74 79 2d 63 68 65 63 6b 27 29 20 7d 0a 20 20 69  ty-check') }.  i
0d20: 66 20 7b 5b 73 65 74 5f 74 65 73 74 5f 63 6f 75  f {[set_test_cou
0d30: 6e 74 65 72 20 65 72 72 6f 72 73 5d 7d 20 62 72  nter errors]} br
0d40: 65 61 6b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  eak.}..#--------
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 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f  -.#.reset_db.do_
0da0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 30  execsql_test 5.0
0db0: 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54   {.  CREATE VIRT
0dc0: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49  UAL TABLE t1 USI
0dd0: 4e 47 20 66 74 73 35 28 78 2c 79 2c 20 64 65 74  NG fts5(x,y, det
0de0: 61 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20  ail=%DETAIL%);. 
0df0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28   INSERT INTO t1(
0e00: 74 31 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45 53  t1, rank) VALUES
0e10: 28 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a 7d 0a  ('pgsz', 32);.}.
0e20: 66 6f 72 65 61 63 68 20 7b 69 20 78 20 79 7d 20  foreach {i x y} 
0e30: 7b 0a 20 20 20 31 20 20 7b 64 64 20 61 62 63 20  {.   1  {dd abc 
0e40: 61 62 63 20 61 62 63 20 61 62 63 64 65 7d 20 7b  abc abc abcde} {
0e50: 61 61 61 20 64 64 20 64 64 64 20 64 64 64 20 61  aaa dd ddd ddd a
0e60: 61 62 7d 0a 20 20 20 32 20 20 7b 64 64 20 61 61  ab}.   2  {dd aa
0e70: 62 20 64 20 61 61 61 20 62 7d 20 7b 61 62 63 64  b d aaa b} {abcd
0e80: 65 20 63 20 61 61 61 20 61 61 61 20 61 61 61 7d  e c aaa aaa aaa}
0e90: 0a 20 20 20 33 20 20 7b 61 62 63 64 65 20 64 64  .   3  {abcde dd
0ea0: 20 62 20 62 20 64 64 7d 20 7b 61 62 63 20 61 62   b b dd} {abc ab
0eb0: 63 20 64 20 61 62 63 20 64 64 64 64 64 7d 0a 20  c d abc ddddd}. 
0ec0: 20 20 34 20 20 7b 61 61 61 20 61 62 63 64 65 20    4  {aaa abcde 
0ed0: 64 64 64 64 20 64 64 64 64 20 61 62 63 64 65 7d  dddd dddd abcde}
0ee0: 20 7b 61 62 63 20 62 20 62 20 61 62 63 64 65 20   {abc b b abcde 
0ef0: 61 62 63 7d 0a 20 20 20 35 20 20 7b 61 61 62 20  abc}.   5  {aab 
0f00: 64 64 64 64 20 64 20 64 64 64 64 20 63 7d 20 7b  dddd d dddd c} {
0f10: 64 64 64 20 61 62 63 64 65 20 64 64 64 64 20 61  ddd abcde dddd a
0f20: 62 63 64 65 20 63 7d 0a 20 20 20 36 20 20 7b 64  bcde c}.   6  {d
0f30: 64 64 20 64 64 20 62 20 61 61 62 20 61 62 63 64  dd dd b aab abcd
0f40: 65 7d 20 7b 64 20 64 64 64 64 64 20 64 64 64 64  e} {d ddddd dddd
0f50: 20 63 20 61 62 63 7d 0a 20 20 20 37 20 20 7b 64   c abc}.   7  {d
0f60: 20 64 64 64 64 64 20 64 64 64 20 63 20 61 62 63   ddddd ddd c abc
0f70: 64 65 7d 20 7b 63 20 61 61 62 20 64 20 61 62 63  de} {c aab d abc
0f80: 64 65 20 64 64 64 7d 0a 20 20 20 38 20 20 7b 61  de ddd}.   8  {a
0f90: 62 63 64 65 20 61 61 61 20 61 61 62 20 63 20 63  bcde aaa aab c c
0fa0: 7d 20 7b 64 64 64 20 63 20 64 64 64 64 20 62 20  } {ddd c dddd b 
0fb0: 61 61 61 7d 0a 20 20 20 39 20 20 7b 61 62 63 64  aaa}.   9  {abcd
0fc0: 65 20 61 61 62 20 64 64 64 64 64 20 63 20 61 61  e aab ddddd c aa
0fd0: 62 7d 20 7b 64 64 64 64 20 64 64 64 64 20 62 20  b} {dddd dddd b 
0fe0: 63 20 64 64 7d 0a 20 20 20 31 30 20 7b 64 64 64  c dd}.   10 {ddd
0ff0: 20 61 62 63 64 65 20 64 64 64 64 20 64 64 20 63   abcde dddd dd c
1000: 7d 20 7b 64 64 64 64 20 63 20 63 20 64 20 61 62  } {dddd c c d ab
1010: 63 64 65 7d 0a 7d 20 7b 0a 20 20 64 6f 5f 65 78  cde}.} {.  do_ex
1020: 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 24 69 2e  ecsql_test 5.$i.
1030: 31 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  1 { INSERT INTO 
1040: 74 31 20 56 41 4c 55 45 53 28 24 78 2c 20 24 79  t1 VALUES($x, $y
1050: 29 20 7d 0a 20 20 64 6f 5f 65 78 65 63 73 71 6c  ) }.  do_execsql
1060: 5f 74 65 73 74 20 35 2e 24 69 2e 32 20 7b 20 49  _test 5.$i.2 { I
1070: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31  NSERT INTO t1(t1
1080: 29 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72  ) VALUES('integr
1090: 69 74 79 2d 63 68 65 63 6b 27 29 20 7d 0a 20 20  ity-check') }.  
10a0: 69 66 20 7b 5b 73 65 74 5f 74 65 73 74 5f 63 6f  if {[set_test_co
10b0: 75 6e 74 65 72 20 65 72 72 6f 72 73 5d 7d 20 62  unter errors]} b
10c0: 72 65 61 6b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  reak.}..#-------
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 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f  --.#.reset_db.do
1120: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 36 2e  _execsql_test 6.
1130: 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52  0 {.  CREATE VIR
1140: 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53  TUAL TABLE t1 US
1150: 49 4e 47 20 66 74 73 35 28 78 2c 79 2c 20 64 65  ING fts5(x,y, de
1160: 74 61 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a  tail=%DETAIL%);.
1170: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
1180: 28 74 31 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45  (t1, rank) VALUE
1190: 53 28 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a 7d  S('pgsz', 32);.}
11a0: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
11b0: 74 20 36 2e 31 20 7b 0a 20 20 49 4e 53 45 52 54  t 6.1 {.  INSERT
11c0: 20 20 49 4e 54 4f 20 74 31 28 72 6f 77 69 64 2c    INTO t1(rowid,
11d0: 20 78 2c 20 79 29 20 56 41 4c 55 45 53 28 32 32   x, y) VALUES(22
11e0: 2c 20 27 61 20 62 20 63 27 2c 20 27 63 20 62 20  , 'a b c', 'c b 
11f0: 61 27 29 3b 0a 20 20 52 45 50 4c 41 43 45 20 49  a');.  REPLACE I
1200: 4e 54 4f 20 74 31 28 72 6f 77 69 64 2c 20 78 2c  NTO t1(rowid, x,
1210: 20 79 29 20 56 41 4c 55 45 53 28 32 32 2c 20 27   y) VALUES(22, '
1220: 64 20 65 20 66 27 2c 20 27 66 20 65 20 64 27 29  d e f', 'f e d')
1230: 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  ;.}..do_execsql_
1240: 74 65 73 74 20 36 2e 32 20 7b 0a 20 20 49 4e 53  test 6.2 {.  INS
1250: 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20  ERT INTO t1(t1) 
1260: 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74  VALUES('integrit
1270: 79 2d 63 68 65 63 6b 27 29 20 0a 7d 0a 0a 64 6f  y-check') .}..do
1280: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 36 2e  _execsql_test 6.
1290: 33 20 7b 0a 20 20 52 45 50 4c 41 43 45 20 49 4e  3 {.  REPLACE IN
12a0: 54 4f 20 74 31 28 72 6f 77 69 64 2c 20 78 2c 20  TO t1(rowid, x, 
12b0: 79 29 20 56 41 4c 55 45 53 28 27 32 32 27 2c 20  y) VALUES('22', 
12c0: 27 6c 20 6c 20 6c 27 2c 20 27 6c 20 6c 20 6c 27  'l l l', 'l l l'
12d0: 29 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  );.}..do_execsql
12e0: 5f 74 65 73 74 20 36 2e 34 20 7b 0a 20 20 52 45  _test 6.4 {.  RE
12f0: 50 4c 41 43 45 20 49 4e 54 4f 20 74 31 28 78 2c  PLACE INTO t1(x,
1300: 20 79 29 20 56 41 4c 55 45 53 28 27 78 20 79 20   y) VALUES('x y 
1310: 7a 27 2c 20 27 78 20 79 20 7a 27 29 3b 0a 7d 0a  z', 'x y z');.}.
1320: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
1330: 20 36 2e 35 20 7b 0a 20 20 49 4e 53 45 52 54 20   6.5 {.  INSERT 
1340: 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55  INTO t1(t1) VALU
1350: 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d 63 68  ES('integrity-ch
1360: 65 63 6b 27 29 20 0a 7d 0a 0a 64 6f 5f 65 78 65  eck') .}..do_exe
1370: 63 73 71 6c 5f 74 65 73 74 20 36 2e 36 20 7b 0a  csql_test 6.6 {.
1380: 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20    SELECT rowid, 
1390: 2a 20 46 52 4f 4d 20 74 31 3b 0a 7d 20 7b 0a 20  * FROM t1;.} {. 
13a0: 20 32 32 20 7b 6c 20 6c 20 6c 7d 20 7b 6c 20 6c   22 {l l l} {l l
13b0: 20 6c 7d 0a 20 20 32 33 20 7b 78 20 79 20 7a 7d   l}.  23 {x y z}
13c0: 20 7b 78 20 79 20 7a 7d 0a 7d 0a 0a 23 2d 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 0a 23 0a 72 65 73 65 74 5f 64  ------.#.reset_d
1420: 62 0a 65 78 70 72 20 73 72 61 6e 64 28 30 29 0a  b.expr srand(0).
1430: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
1440: 37 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56  7.0 {.  CREATE V
1450: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20  IRTUAL TABLE t1 
1460: 55 53 49 4e 47 20 66 74 73 35 28 78 2c 79 2c 7a  USING fts5(x,y,z
1470: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
1480: 20 74 31 28 74 31 2c 20 72 61 6e 6b 29 20 56 41   t1(t1, rank) VA
1490: 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32 29  LUES('pgsz', 32)
14a0: 3b 0a 7d 0a 0a 70 72 6f 63 20 64 6f 63 20 7b 7d  ;.}..proc doc {}
14b0: 20 7b 0a 20 20 73 65 74 20 76 20 5b 6c 69 73 74   {.  set v [list
14c0: 20 61 61 61 20 61 61 62 20 61 62 63 20 61 62 63   aaa aab abc abc
14d0: 64 65 20 62 20 63 20 64 20 64 64 20 64 64 64 20  de b c d dd ddd 
14e0: 64 64 64 64 20 64 64 64 64 64 5d 0a 20 20 73 65  dddd ddddd].  se
14f0: 74 20 72 65 74 20 5b 6c 69 73 74 5d 0a 20 20 66  t ret [list].  f
1500: 6f 72 20 7b 73 65 74 20 6a 20 30 7d 20 7b 24 6a  or {set j 0} {$j
1510: 20 3c 20 32 30 7d 20 7b 69 6e 63 72 20 6a 7d 20   < 20} {incr j} 
1520: 7b 0a 20 20 20 20 6c 61 70 70 65 6e 64 20 72 65  {.    lappend re
1530: 74 20 5b 6c 69 6e 64 65 78 20 24 76 20 5b 65 78  t [lindex $v [ex
1540: 70 72 20 69 6e 74 28 72 61 6e 64 28 29 2a 5b 6c  pr int(rand()*[l
1550: 6c 65 6e 67 74 68 20 24 76 5d 29 5d 5d 0a 20 20  length $v])]].  
1560: 7d 0a 20 20 72 65 74 75 72 6e 20 24 72 65 74 0a  }.  return $ret.
1570: 7d 0a 0a 70 72 6f 63 20 64 75 6d 70 5f 73 74 72  }..proc dump_str
1580: 75 63 74 75 72 65 20 7b 7d 20 7b 0a 20 20 64 62  ucture {} {.  db
1590: 20 65 76 61 6c 20 7b 53 45 4c 45 43 54 20 66 74   eval {SELECT ft
15a0: 73 35 5f 64 65 63 6f 64 65 28 69 64 2c 20 62 6c  s5_decode(id, bl
15b0: 6f 63 6b 29 20 41 53 20 74 20 46 52 4f 4d 20 74  ock) AS t FROM t
15c0: 31 5f 64 61 74 61 20 57 48 45 52 45 20 69 64 3d  1_data WHERE id=
15d0: 31 30 7d 20 7b 0a 20 20 20 20 66 6f 72 65 61 63  10} {.    foreac
15e0: 68 20 6c 76 6c 20 5b 6c 72 61 6e 67 65 20 24 74  h lvl [lrange $t
15f0: 20 31 20 65 6e 64 5d 20 7b 0a 20 20 20 20 20 20   1 end] {.      
1600: 73 65 74 20 73 65 67 20 5b 73 74 72 69 6e 67 20  set seg [string 
1610: 72 65 70 65 61 74 20 2e 20 5b 65 78 70 72 20 5b  repeat . [expr [
1620: 6c 6c 65 6e 67 74 68 20 24 6c 76 6c 5d 2d 32 5d  llength $lvl]-2]
1630: 5d 0a 20 20 20 20 20 20 70 75 74 73 20 22 5b 6c  ].      puts "[l
1640: 72 61 6e 67 65 20 24 6c 76 6c 20 30 20 31 5d 20  range $lvl 0 1] 
1650: 24 73 65 67 22 0a 20 20 20 20 7d 0a 20 20 7d 0a  $seg".    }.  }.
1660: 7d 0a 0a 66 6f 72 20 7b 73 65 74 20 69 20 31 7d  }..for {set i 1}
1670: 20 7b 24 69 20 3c 3d 20 31 30 7d 20 7b 69 6e 63   {$i <= 10} {inc
1680: 72 20 69 7d 20 7b 0a 20 20 64 6f 5f 74 65 73 74  r i} {.  do_test
1690: 20 37 2e 24 69 20 7b 0a 20 20 20 20 66 6f 72 20   7.$i {.    for 
16a0: 7b 73 65 74 20 6a 20 30 7d 20 7b 24 6a 20 3c 20  {set j 0} {$j < 
16b0: 31 30 7d 20 7b 69 6e 63 72 20 6a 7d 20 7b 0a 20  10} {incr j} {. 
16c0: 20 20 20 20 20 73 65 74 20 78 20 5b 64 6f 63 5d       set x [doc]
16d0: 0a 20 20 20 20 20 20 73 65 74 20 79 20 5b 64 6f  .      set y [do
16e0: 63 5d 0a 20 20 20 20 20 20 73 65 74 20 7a 20 5b  c].      set z [
16f0: 64 6f 63 5d 0a 20 20 20 20 20 20 73 65 74 20 72  doc].      set r
1700: 6f 77 69 64 20 5b 65 78 70 72 20 69 6e 74 28 72  owid [expr int(r
1710: 61 6e 64 28 29 20 2a 20 31 30 30 29 5d 0a 20 20  and() * 100)].  
1720: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 52 45      execsql { RE
1730: 50 4c 41 43 45 20 49 4e 54 4f 20 74 31 28 72 6f  PLACE INTO t1(ro
1740: 77 69 64 2c 78 2c 79 2c 7a 29 20 56 41 4c 55 45  wid,x,y,z) VALUE
1750: 53 28 24 72 6f 77 69 64 2c 20 24 78 2c 20 24 79  S($rowid, $x, $y
1760: 2c 20 24 7a 29 20 7d 0a 20 20 20 20 7d 0a 20 20  , $z) }.    }.  
1770: 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53 45    execsql { INSE
1780: 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56  RT INTO t1(t1) V
1790: 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74 79  ALUES('integrity
17a0: 2d 63 68 65 63 6b 27 29 3b 20 7d 0a 20 20 7d 20  -check'); }.  } 
17b0: 7b 7d 0a 20 20 69 66 20 7b 5b 73 65 74 5f 74 65  {}.  if {[set_te
17c0: 73 74 5f 63 6f 75 6e 74 65 72 20 65 72 72 6f 72  st_counter error
17d0: 73 5d 7d 20 62 72 65 61 6b 0a 7d 0a 0a 23 2d 2d  s]} 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 0a 23 0a 72 65 73 65 74 5f  -------.#.reset_
1830: 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  db.do_execsql_te
1840: 73 74 20 38 2e 30 20 7b 0a 20 20 43 52 45 41 54  st 8.0 {.  CREAT
1850: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
1860: 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 78 2c  t1 USING fts5(x,
1870: 20 70 72 65 66 69 78 3d 22 31 2c 32 2c 33 22 29   prefix="1,2,3")
1880: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
1890: 74 31 28 74 31 2c 20 72 61 6e 6b 29 20 56 41 4c  t1(t1, rank) VAL
18a0: 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32 29 3b  UES('pgsz', 32);
18b0: 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  .}..do_execsql_t
18c0: 65 73 74 20 38 2e 31 20 7b 0a 20 20 49 4e 53 45  est 8.1 {.  INSE
18d0: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
18e0: 53 28 27 74 68 65 20 71 75 69 63 6b 20 62 72 6f  S('the quick bro
18f0: 77 6e 20 66 6f 78 27 29 3b 0a 20 20 49 4e 53 45  wn fox');.  INSE
1900: 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56  RT INTO t1(t1) V
1910: 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74 79  ALUES('integrity
1920: 2d 63 68 65 63 6b 27 29 3b 0a 7d 0a 0a 0a 23 2d  -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 0a 23 0a 72 65 73 65 74  --------.#.reset
1980: 5f 64 62 0a 0a 65 78 70 72 20 73 72 61 6e 64 28  _db..expr srand(
1990: 30 29 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  0)..do_execsql_t
19a0: 65 73 74 20 39 2e 30 20 7b 0a 20 20 43 52 45 41  est 9.0 {.  CREA
19b0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
19c0: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 78   t1 USING fts5(x
19d0: 2c 79 2c 7a 2c 20 70 72 65 66 69 78 3d 22 31 2c  ,y,z, prefix="1,
19e0: 32 2c 33 22 29 3b 0a 20 20 49 4e 53 45 52 54 20  2,3");.  INSERT 
19f0: 49 4e 54 4f 20 74 31 28 74 31 2c 20 72 61 6e 6b  INTO t1(t1, rank
1a00: 29 20 56 41 4c 55 45 53 28 27 70 67 73 7a 27 2c  ) VALUES('pgsz',
1a10: 20 33 32 29 3b 0a 7d 0a 0a 70 72 6f 63 20 64 6f   32);.}..proc do
1a20: 63 20 7b 7d 20 7b 0a 20 20 73 65 74 20 76 20 5b  c {} {.  set v [
1a30: 6c 69 73 74 20 61 61 61 20 61 61 62 20 61 62 63  list aaa aab abc
1a40: 20 61 62 63 64 65 20 62 20 63 20 64 20 64 64 20   abcde b c d dd 
1a50: 64 64 64 20 64 64 64 64 20 64 64 64 64 64 5d 0a  ddd dddd ddddd].
1a60: 20 20 73 65 74 20 72 65 74 20 5b 6c 69 73 74 5d    set ret [list]
1a70: 0a 20 20 66 6f 72 20 7b 73 65 74 20 6a 20 30 7d  .  for {set j 0}
1a80: 20 7b 24 6a 20 3c 20 32 30 7d 20 7b 69 6e 63 72   {$j < 20} {incr
1a90: 20 6a 7d 20 7b 0a 20 20 20 20 6c 61 70 70 65 6e   j} {.    lappen
1aa0: 64 20 72 65 74 20 5b 6c 69 6e 64 65 78 20 24 76  d ret [lindex $v
1ab0: 20 5b 65 78 70 72 20 69 6e 74 28 72 61 6e 64 28   [expr int(rand(
1ac0: 29 2a 5b 6c 6c 65 6e 67 74 68 20 24 76 5d 29 5d  )*[llength $v])]
1ad0: 5d 0a 20 20 7d 0a 20 20 72 65 74 75 72 6e 20 24  ].  }.  return $
1ae0: 72 65 74 0a 7d 0a 0a 70 72 6f 63 20 64 75 6d 70  ret.}..proc dump
1af0: 5f 73 74 72 75 63 74 75 72 65 20 7b 7d 20 7b 0a  _structure {} {.
1b00: 20 20 64 62 20 65 76 61 6c 20 7b 53 45 4c 45 43    db eval {SELEC
1b10: 54 20 66 74 73 35 5f 64 65 63 6f 64 65 28 69 64  T fts5_decode(id
1b20: 2c 20 62 6c 6f 63 6b 29 20 41 53 20 74 20 46 52  , block) AS t FR
1b30: 4f 4d 20 74 31 5f 64 61 74 61 20 57 48 45 52 45  OM t1_data WHERE
1b40: 20 69 64 3d 31 30 7d 20 7b 0a 20 20 20 20 66 6f   id=10} {.    fo
1b50: 72 65 61 63 68 20 6c 76 6c 20 5b 6c 72 61 6e 67  reach lvl [lrang
1b60: 65 20 24 74 20 31 20 65 6e 64 5d 20 7b 0a 20 20  e $t 1 end] {.  
1b70: 20 20 20 20 73 65 74 20 73 65 67 20 5b 73 74 72      set seg [str
1b80: 69 6e 67 20 72 65 70 65 61 74 20 2e 20 5b 65 78  ing repeat . [ex
1b90: 70 72 20 5b 6c 6c 65 6e 67 74 68 20 24 6c 76 6c  pr [llength $lvl
1ba0: 5d 2d 32 5d 5d 0a 20 20 20 20 20 20 70 75 74 73  ]-2]].      puts
1bb0: 20 22 5b 6c 72 61 6e 67 65 20 24 6c 76 6c 20 30   "[lrange $lvl 0
1bc0: 20 31 5d 20 24 73 65 67 22 0a 20 20 20 20 7d 0a   1] $seg".    }.
1bd0: 20 20 7d 0a 7d 0a 0a 66 6f 72 20 7b 73 65 74 20    }.}..for {set 
1be0: 69 20 31 7d 20 7b 24 69 20 3c 3d 20 31 30 7d 20  i 1} {$i <= 10} 
1bf0: 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 64 6f 5f  {incr i} {.  do_
1c00: 74 65 73 74 20 39 2e 24 69 20 7b 0a 20 20 20 20  test 9.$i {.    
1c10: 66 6f 72 20 7b 73 65 74 20 6a 20 30 7d 20 7b 24  for {set j 0} {$
1c20: 6a 20 3c 20 31 30 30 7d 20 7b 69 6e 63 72 20 6a  j < 100} {incr j
1c30: 7d 20 7b 0a 20 20 20 20 20 20 73 65 74 20 78 20  } {.      set x 
1c40: 5b 64 6f 63 5d 0a 20 20 20 20 20 20 73 65 74 20  [doc].      set 
1c50: 79 20 5b 64 6f 63 5d 0a 20 20 20 20 20 20 73 65  y [doc].      se
1c60: 74 20 7a 20 5b 64 6f 63 5d 0a 20 20 20 20 20 20  t z [doc].      
1c70: 73 65 74 20 72 6f 77 69 64 20 5b 65 78 70 72 20  set rowid [expr 
1c80: 69 6e 74 28 72 61 6e 64 28 29 20 2a 20 31 30 30  int(rand() * 100
1c90: 29 5d 0a 20 20 20 20 20 20 65 78 65 63 73 71 6c  )].      execsql
1ca0: 20 7b 20 52 45 50 4c 41 43 45 20 49 4e 54 4f 20   { REPLACE INTO 
1cb0: 74 31 28 72 6f 77 69 64 2c 78 2c 79 2c 7a 29 20  t1(rowid,x,y,z) 
1cc0: 56 41 4c 55 45 53 28 24 72 6f 77 69 64 2c 20 24  VALUES($rowid, $
1cd0: 78 2c 20 24 79 2c 20 24 7a 29 20 7d 0a 20 20 20  x, $y, $z) }.   
1ce0: 20 7d 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b   }.    execsql {
1cf0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28   INSERT INTO t1(
1d00: 74 31 29 20 56 41 4c 55 45 53 28 27 69 6e 74 65  t1) VALUES('inte
1d10: 67 72 69 74 79 2d 63 68 65 63 6b 27 29 3b 20 7d  grity-check'); }
1d20: 0a 20 20 7d 20 7b 7d 0a 20 20 69 66 20 7b 5b 73  .  } {}.  if {[s
1d30: 65 74 5f 74 65 73 74 5f 63 6f 75 6e 74 65 72 20  et_test_counter 
1d40: 65 72 72 6f 72 73 5d 7d 20 62 72 65 61 6b 0a 7d  errors]} break.}
1d50: 0a 0a 0a 23 2d 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 0a 23 0a  -------------.#.
1da0: 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63  reset_db.do_exec
1db0: 73 71 6c 5f 74 65 73 74 20 31 30 2e 30 20 7b 0a  sql_test 10.0 {.
1dc0: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
1dd0: 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20   TABLE t1 USING 
1de0: 66 74 73 35 28 78 2c 79 2c 20 64 65 74 61 69 6c  fts5(x,y, detail
1df0: 3d 25 44 45 54 41 49 4c 25 29 3b 0a 7d 0a 73 65  =%DETAIL%);.}.se
1e00: 74 20 64 31 30 20 7b 0a 20 20 20 31 20 20 7b 67  t d10 {.   1  {g
1e10: 20 66 20 64 20 62 20 66 7d 20 7b 68 20 68 20 65   f d b f} {h h e
1e20: 20 69 20 61 7d 0a 20 20 20 32 20 20 7b 66 20 69   i a}.   2  {f i
1e30: 20 67 20 6a 20 65 7d 20 7b 69 20 6a 20 63 20 66   g j e} {i j c f
1e40: 20 66 7d 0a 20 20 20 33 20 20 7b 65 20 65 20 69   f}.   3  {e e i
1e50: 20 66 20 61 7d 20 7b 65 20 68 20 66 20 64 20 66   f a} {e h f d f
1e60: 7d 0a 20 20 20 34 20 20 7b 68 20 6a 20 66 20 6a  }.   4  {h j f j
1e70: 20 69 7d 20 7b 68 20 61 20 63 20 66 20 6a 7d 0a   i} {h a c f j}.
1e80: 20 20 20 35 20 20 7b 64 20 62 20 6a 20 63 20 67     5  {d b j c g
1e90: 7d 20 7b 66 20 65 20 69 20 62 20 65 7d 0a 20 20  } {f e i b e}.  
1ea0: 20 36 20 20 7b 61 20 6a 20 61 20 65 20 65 7d 20   6  {a j a e e} 
1eb0: 7b 6a 20 64 20 66 20 64 20 65 7d 0a 20 20 20 37  {j d f d e}.   7
1ec0: 20 20 7b 67 20 69 20 6a 20 63 20 68 7d 20 7b 6a    {g i j c h} {j
1ed0: 20 64 20 68 20 63 20 61 7d 0a 20 20 20 38 20 20   d h c a}.   8  
1ee0: 7b 6a 20 6a 20 69 20 64 20 64 7d 20 7b 65 20 65  {j j i d d} {e e
1ef0: 20 64 20 66 20 62 7d 0a 20 20 20 39 20 20 7b 63   d f b}.   9  {c
1f00: 20 6a 20 6a 20 64 20 63 7d 20 7b 68 20 6a 20 69   j j d c} {h j i
1f10: 20 66 20 67 7d 0a 20 20 31 30 20 20 7b 62 20 66   f g}.  10  {b f
1f20: 20 68 20 69 20 61 7d 20 7b 63 20 66 20 62 20 62   h i a} {c f b b
1f30: 20 6a 7d 0a 7d 0a 66 6f 72 65 61 63 68 20 7b 72   j}.}.foreach {r
1f40: 6f 77 69 64 20 78 20 79 7d 20 24 64 31 30 20 7b  owid x y} $d10 {
1f50: 0a 20 20 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  .  do_execsql_te
1f60: 73 74 20 31 30 2e 31 2e 24 72 6f 77 69 64 2e 31  st 10.1.$rowid.1
1f70: 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74   { INSERT INTO t
1f80: 31 20 56 41 4c 55 45 53 28 24 78 2c 20 24 79 29  1 VALUES($x, $y)
1f90: 20 7d 0a 20 20 64 6f 5f 65 78 65 63 73 71 6c 5f   }.  do_execsql_
1fa0: 74 65 73 74 20 31 30 2e 31 2e 24 72 6f 77 69 64  test 10.1.$rowid
1fb0: 2e 32 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f  .2 { INSERT INTO
1fc0: 20 74 31 28 74 31 29 20 56 41 4c 55 45 53 28 27   t1(t1) VALUES('
1fd0: 69 6e 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27  integrity-check'
1fe0: 29 20 7d 0a 7d 0a 66 6f 72 65 61 63 68 20 72 6f  ) }.}.foreach ro
1ff0: 77 69 64 20 7b 35 20 39 20 38 20 31 20 32 20 34  wid {5 9 8 1 2 4
2000: 20 31 30 20 37 20 33 20 35 20 36 7d 20 7b 0a 20   10 7 3 5 6} {. 
2010: 20 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74   do_execsql_test
2020: 20 31 30 2e 32 2e 24 72 6f 77 69 64 2e 31 20 7b   10.2.$rowid.1 {
2030: 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31 20   DELETE FROM t1 
2040: 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20 24 72  WHERE rowid = $r
2050: 6f 77 69 64 20 7d 0a 20 20 64 6f 5f 65 78 65 63  owid }.  do_exec
2060: 73 71 6c 5f 74 65 73 74 20 31 30 2e 32 2e 24 72  sql_test 10.2.$r
2070: 6f 77 69 64 2e 32 20 7b 20 49 4e 53 45 52 54 20  owid.2 { INSERT 
2080: 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55  INTO t1(t1) VALU
2090: 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d 63 68  ES('integrity-ch
20a0: 65 63 6b 27 29 20 7d 0a 7d 0a 66 6f 72 65 61 63  eck') }.}.foreac
20b0: 68 20 7b 72 6f 77 69 64 20 78 20 79 7d 20 24 64  h {rowid x y} $d
20c0: 31 30 20 7b 0a 20 20 64 6f 5f 65 78 65 63 73 71  10 {.  do_execsq
20d0: 6c 5f 74 65 73 74 20 31 30 2e 33 2e 24 72 6f 77  l_test 10.3.$row
20e0: 69 64 2e 31 20 7b 20 49 4e 53 45 52 54 20 49 4e  id.1 { INSERT IN
20f0: 54 4f 20 74 31 20 56 41 4c 55 45 53 28 24 78 2c  TO t1 VALUES($x,
2100: 20 24 79 29 20 7d 0a 20 20 64 6f 5f 65 78 65 63   $y) }.  do_exec
2110: 73 71 6c 5f 74 65 73 74 20 31 30 2e 33 2e 24 72  sql_test 10.3.$r
2120: 6f 77 69 64 2e 32 20 7b 20 49 4e 53 45 52 54 20  owid.2 { INSERT 
2130: 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55  INTO t1(t1) VALU
2140: 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d 63 68  ES('integrity-ch
2150: 65 63 6b 27 29 20 7d 0a 7d 0a 0a 64 6f 5f 65 78  eck') }.}..do_ex
2160: 65 63 73 71 6c 5f 74 65 73 74 20 31 30 2e 34 2e  ecsql_test 10.4.
2170: 31 20 7b 20 44 45 4c 45 54 45 20 46 52 4f 4d 20  1 { DELETE FROM 
2180: 74 31 20 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  t1 }.do_execsql_
2190: 74 65 73 74 20 31 30 2e 34 2e 32 20 7b 20 49 4e  test 10.4.2 { IN
21a0: 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29  SERT INTO t1(t1)
21b0: 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69   VALUES('integri
21c0: 74 79 2d 63 68 65 63 6b 27 29 20 7d 0a 0a 23 2d  ty-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 0a 23 0a 64 6f 5f 63 61  --------.#.do_ca
2220: 74 63 68 73 71 6c 5f 74 65 73 74 20 31 31 2e 31  tchsql_test 11.1
2230: 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54   {.  CREATE VIRT
2240: 55 41 4c 20 54 41 42 4c 45 20 74 32 20 55 53 49  UAL TABLE t2 USI
2250: 4e 47 20 66 74 73 35 28 61 2c 20 62 2c 20 63 2c  NG fts5(a, b, c,
2260: 20 72 61 6e 6b 2c 20 64 65 74 61 69 6c 3d 25 44   rank, detail=%D
2270: 45 54 41 49 4c 25 29 3b 0a 7d 20 7b 31 20 7b 72  ETAIL%);.} {1 {r
2280: 65 73 65 72 76 65 64 20 66 74 73 35 20 63 6f 6c  eserved fts5 col
2290: 75 6d 6e 20 6e 61 6d 65 3a 20 72 61 6e 6b 7d 7d  umn name: rank}}
22a0: 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73  .do_catchsql_tes
22b0: 74 20 31 31 2e 32 20 7b 0a 20 20 43 52 45 41 54  t 11.2 {.  CREAT
22c0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
22d0: 72 61 6e 6b 20 55 53 49 4e 47 20 66 74 73 35 28  rank USING fts5(
22e0: 61 2c 20 62 2c 20 63 2c 20 64 65 74 61 69 6c 3d  a, b, c, detail=
22f0: 25 44 45 54 41 49 4c 25 29 3b 0a 7d 20 7b 31 20  %DETAIL%);.} {1 
2300: 7b 72 65 73 65 72 76 65 64 20 66 74 73 35 20 74  {reserved fts5 t
2310: 61 62 6c 65 20 6e 61 6d 65 3a 20 72 61 6e 6b 7d  able name: rank}
2320: 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65  }.do_catchsql_te
2330: 73 74 20 31 31 2e 33 20 7b 0a 20 20 43 52 45 41  st 11.3 {.  CREA
2340: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
2350: 20 74 32 20 55 53 49 4e 47 20 66 74 73 35 28 61   t2 USING fts5(a
2360: 2c 20 62 2c 20 63 2c 20 72 6f 77 69 64 2c 20 64  , b, c, rowid, d
2370: 65 74 61 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b  etail=%DETAIL%);
2380: 0a 7d 20 7b 31 20 7b 72 65 73 65 72 76 65 64 20  .} {1 {reserved 
2390: 66 74 73 35 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65  fts5 column name
23a0: 3a 20 72 6f 77 69 64 7d 7d 0a 0a 23 2d 2d 2d 2d  : 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 0a 23 0a 64 6f 5f 65 78 65 63 73  -----.#.do_execs
2400: 71 6c 5f 74 65 73 74 20 31 32 2e 31 20 7b 0a 20  ql_test 12.1 {. 
2410: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
2420: 54 41 42 4c 45 20 74 32 20 55 53 49 4e 47 20 66  TABLE t2 USING f
2430: 74 73 35 28 78 2c 79 2c 20 64 65 74 61 69 6c 3d  ts5(x,y, detail=
2440: 25 44 45 54 41 49 4c 25 29 3b 0a 7d 20 7b 7d 0a  %DETAIL%);.} {}.
2450: 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73  .do_catchsql_tes
2460: 74 20 31 32 2e 32 20 7b 0a 20 20 53 45 4c 45 43  t 12.2 {.  SELEC
2470: 54 20 74 32 20 46 52 4f 4d 20 74 32 20 57 48 45  T t2 FROM t2 WHE
2480: 52 45 20 74 32 20 4d 41 54 43 48 20 27 2a 73 74  RE t2 MATCH '*st
2490: 75 66 66 27 0a 7d 20 7b 31 20 7b 75 6e 6b 6e 6f  uff'.} {1 {unkno
24a0: 77 6e 20 73 70 65 63 69 61 6c 20 71 75 65 72 79  wn special query
24b0: 3a 20 73 74 75 66 66 7d 7d 0a 0a 64 6f 5f 74 65  : stuff}}..do_te
24c0: 73 74 20 31 32 2e 33 20 7b 0a 20 20 73 65 74 20  st 12.3 {.  set 
24d0: 72 65 73 20 5b 64 62 20 65 76 61 6c 20 7b 20 53  res [db eval { S
24e0: 45 4c 45 43 54 20 74 32 20 46 52 4f 4d 20 74 32  ELECT t2 FROM t2
24f0: 20 57 48 45 52 45 20 74 32 20 4d 41 54 43 48 20   WHERE t2 MATCH 
2500: 27 2a 20 72 65 61 64 73 20 27 20 7d 5d 0a 20 20  '* reads ' }].  
2510: 73 74 72 69 6e 67 20 69 73 20 69 6e 74 65 67 65  string is intege
2520: 72 20 24 72 65 73 0a 7d 20 7b 31 7d 0a 0a 23 2d  r $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 0a 23 0a 72 65 73 65 74  --------.#.reset
2580: 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  _db.do_execsql_t
2590: 65 73 74 20 31 33 2e 31 20 7b 0a 20 20 43 52 45  est 13.1 {.  CRE
25a0: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
25b0: 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28  E t1 USING fts5(
25c0: 78 2c 20 64 65 74 61 69 6c 3d 25 44 45 54 41 49  x, detail=%DETAI
25d0: 4c 25 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  L%);.  INSERT IN
25e0: 54 4f 20 74 31 28 72 6f 77 69 64 2c 20 78 29 20  TO t1(rowid, x) 
25f0: 56 41 4c 55 45 53 28 31 2c 20 27 6f 20 6e 20 65  VALUES(1, 'o n e
2600: 27 29 2c 20 28 32 2c 20 27 74 20 77 20 6f 27 29  '), (2, 't w o')
2610: 3b 0a 7d 20 7b 7d 0a 0a 64 6f 5f 65 78 65 63 73  ;.} {}..do_execs
2620: 71 6c 5f 74 65 73 74 20 31 33 2e 32 20 7b 0a 20  ql_test 13.2 {. 
2630: 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52   SELECT rowid FR
2640: 4f 4d 20 74 31 20 57 48 45 52 45 20 74 31 20 4d  OM t1 WHERE t1 M
2650: 41 54 43 48 20 27 6f 27 3b 0a 7d 20 7b 31 20 32  ATCH 'o';.} {1 2
2660: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
2670: 73 74 20 31 33 2e 34 20 7b 0a 20 20 44 45 4c 45  st 13.4 {.  DELE
2680: 54 45 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45  TE FROM t1 WHERE
2690: 20 72 6f 77 69 64 3d 32 3b 0a 7d 20 7b 7d 0a 0a   rowid=2;.} {}..
26a0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
26b0: 31 33 2e 35 20 7b 0a 20 20 53 45 4c 45 43 54 20  13.5 {.  SELECT 
26c0: 72 6f 77 69 64 20 46 52 4f 4d 20 74 31 20 57 48  rowid FROM t1 WH
26d0: 45 52 45 20 74 31 20 4d 41 54 43 48 20 27 6f 27  ERE t1 MATCH 'o'
26e0: 3b 0a 7d 20 7b 31 7d 0a 0a 64 6f 5f 65 78 65 63  ;.} {1}..do_exec
26f0: 73 71 6c 5f 74 65 73 74 20 31 33 2e 36 20 7b 0a  sql_test 13.6 {.
2700: 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46    SELECT rowid F
2710: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 74 31 20  ROM t1 WHERE t1 
2720: 4d 41 54 43 48 20 27 22 22 27 3b 0a 7d 20 7b 7d  MATCH '""';.} {}
2730: 0a 0a 23 2d 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 0a 23 0a 72  ------------.#.r
2780: 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73  eset_db.do_execs
2790: 71 6c 5f 74 65 73 74 20 31 34 2e 31 20 7b 0a 20  ql_test 14.1 {. 
27a0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
27b0: 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66  TABLE t1 USING f
27c0: 74 73 35 28 78 2c 20 79 2c 20 64 65 74 61 69 6c  ts5(x, y, detail
27d0: 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20 20 49 4e  =%DETAIL%);.  IN
27e0: 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 2c  SERT INTO t1(t1,
27f0: 20 72 61 6e 6b 29 20 56 41 4c 55 45 53 28 27 70   rank) VALUES('p
2800: 67 73 7a 27 2c 20 33 32 29 3b 0a 20 20 57 49 54  gsz', 32);.  WIT
2810: 48 20 64 28 78 2c 79 29 20 41 53 20 28 0a 20 20  H d(x,y) AS (.  
2820: 20 20 53 45 4c 45 43 54 20 4e 55 4c 4c 2c 20 27    SELECT NULL, '
2830: 78 79 7a 20 78 79 7a 20 78 79 7a 20 78 79 7a 20  xyz xyz xyz xyz 
2840: 78 79 7a 20 78 79 7a 27 0a 20 20 20 20 55 4e 49  xyz xyz'.    UNI
2850: 4f 4e 20 41 4c 4c 20 0a 20 20 20 20 53 45 4c 45  ON ALL .    SELE
2860: 43 54 20 4e 55 4c 4c 2c 20 27 78 79 7a 20 78 79  CT NULL, 'xyz xy
2870: 7a 20 78 79 7a 20 78 79 7a 20 78 79 7a 20 78 79  z xyz xyz xyz xy
2880: 7a 27 20 46 52 4f 4d 20 64 0a 20 20 29 0a 20 20  z' FROM d.  ).  
2890: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 53  INSERT INTO t1 S
28a0: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 64 20 4c  ELECT * FROM d L
28b0: 49 4d 49 54 20 32 30 30 3b 0a 7d 0a 0a 64 6f 5f  IMIT 200;.}..do_
28c0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 35 2e  execsql_test 15.
28d0: 78 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  x {.  INSERT INT
28e0: 4f 20 74 31 28 74 31 29 20 56 41 4c 55 45 53 28  O t1(t1) VALUES(
28f0: 27 69 6e 74 65 67 72 69 74 79 2d 63 68 65 63 6b  'integrity-check
2900: 27 29 3b 0a 7d 0a 0a 64 6f 5f 74 65 73 74 20 31  ');.}..do_test 1
2910: 34 2e 32 20 7b 0a 20 20 73 65 74 20 6e 52 6f 77  4.2 {.  set nRow
2920: 20 30 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 53   0.  db eval { S
2930: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20  ELECT * FROM t1 
2940: 57 48 45 52 45 20 74 31 20 4d 41 54 43 48 20 27  WHERE t1 MATCH '
2950: 78 79 7a 27 20 7d 20 7b 0a 20 20 20 20 64 62 20  xyz' } {.    db 
2960: 65 76 61 6c 20 7b 0a 20 20 20 20 20 20 42 45 47  eval {.      BEG
2970: 49 4e 3b 0a 20 20 20 20 20 20 20 20 43 52 45 41  IN;.        CREA
2980: 54 45 20 54 41 42 4c 45 20 74 32 28 61 2c 20 62  TE TABLE t2(a, b
2990: 29 3b 0a 20 20 20 20 20 20 52 4f 4c 4c 42 41 43  );.      ROLLBAC
29a0: 4b 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 6e 63  K;.    }.    inc
29b0: 72 20 6e 52 6f 77 0a 20 20 7d 0a 20 20 73 65 74  r nRow.  }.  set
29c0: 20 6e 52 6f 77 0a 7d 20 7b 32 30 30 7d 0a 0a 64   nRow.} {200}..d
29d0: 6f 5f 74 65 73 74 20 31 34 2e 33 20 7b 0a 20 20  o_test 14.3 {.  
29e0: 73 65 74 20 6e 52 6f 77 20 30 0a 20 20 64 62 20  set nRow 0.  db 
29f0: 65 76 61 6c 20 7b 20 42 45 47 49 4e 3b 20 7d 0a  eval { BEGIN; }.
2a00: 20 20 64 62 20 65 76 61 6c 20 7b 20 53 45 4c 45    db eval { SELE
2a10: 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45  CT * FROM t1 WHE
2a20: 52 45 20 74 31 20 4d 41 54 43 48 20 27 78 79 7a  RE t1 MATCH 'xyz
2a30: 27 20 7d 20 7b 0a 20 20 20 20 64 62 20 65 76 61  ' } {.    db eva
2a40: 6c 20 7b 0a 20 20 20 20 20 20 53 41 56 45 50 4f  l {.      SAVEPO
2a50: 49 4e 54 20 61 61 61 3b 0a 20 20 20 20 20 20 20  INT aaa;.       
2a60: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32   CREATE TABLE t2
2a70: 28 61 2c 20 62 29 3b 0a 20 20 20 20 20 20 52 4f  (a, b);.      RO
2a80: 4c 4c 42 41 43 4b 20 54 4f 20 61 61 61 3b 0a 20  LLBACK TO aaa;. 
2a90: 20 20 20 20 20 52 45 4c 45 41 53 45 20 61 61 61       RELEASE aaa
2aa0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 6e 63 72  ;.    }.    incr
2ab0: 20 6e 52 6f 77 0a 20 20 7d 0a 20 20 73 65 74 20   nRow.  }.  set 
2ac0: 6e 52 6f 77 0a 7d 20 7b 32 30 30 7d 0a 0a 64 6f  nRow.} {200}..do
2ad0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 35  _execsql_test 15
2ae0: 2e 30 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e  .0 {.  INSERT IN
2af0: 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55 45 53  TO t1(t1) VALUES
2b00: 28 27 69 6e 74 65 67 72 69 74 79 2d 63 68 65 63  ('integrity-chec
2b10: 6b 27 29 3b 0a 7d 0a 73 71 6c 69 74 65 33 5f 64  k');.}.sqlite3_d
2b20: 62 5f 63 6f 6e 66 69 67 20 64 62 20 44 45 46 45  b_config db DEFE
2b30: 4e 53 49 56 45 20 30 0a 64 6f 5f 65 78 65 63 73  NSIVE 0.do_execs
2b40: 71 6c 5f 74 65 73 74 20 31 35 2e 31 20 7b 0a 20  ql_test 15.1 {. 
2b50: 20 55 50 44 41 54 45 20 74 31 5f 63 6f 6e 74 65   UPDATE t1_conte
2b60: 6e 74 20 53 45 54 20 63 31 20 3d 20 27 78 79 7a  nt SET c1 = 'xyz
2b70: 20 78 79 7a 20 78 79 7a 20 78 79 7a 20 78 79 7a   xyz xyz xyz xyz
2b80: 20 61 62 63 27 20 57 48 45 52 45 20 72 6f 77 69   abc' WHERE rowi
2b90: 64 20 3d 20 31 3b 0a 7d 0a 64 6f 5f 63 61 74 63  d = 1;.}.do_catc
2ba0: 68 73 71 6c 5f 74 65 73 74 20 31 35 2e 32 20 7b  hsql_test 15.2 {
2bb0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
2bc0: 31 28 74 31 29 20 56 41 4c 55 45 53 28 27 69 6e  1(t1) VALUES('in
2bd0: 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29 3b  tegrity-check');
2be0: 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20  .} {1 {database 
2bf0: 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61  disk image is ma
2c00: 6c 66 6f 72 6d 65 64 7d 7d 0a 0a 23 2d 2d 2d 2d  lformed}}..#----
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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c50: 2d 2d 2d 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63 73  -----.#.do_execs
2c60: 71 6c 5f 74 65 73 74 20 31 36 2e 31 20 7b 0a 20  ql_test 16.1 {. 
2c70: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
2c80: 54 41 42 4c 45 20 6e 31 20 55 53 49 4e 47 20 66  TABLE n1 USING f
2c90: 74 73 35 28 61 29 3b 0a 20 20 49 4e 53 45 52 54  ts5(a);.  INSERT
2ca0: 20 49 4e 54 4f 20 6e 31 20 56 41 4c 55 45 53 28   INTO n1 VALUES(
2cb0: 27 61 20 62 20 63 20 64 27 29 3b 0a 7d 0a 0a 70  'a b c d');.}..p
2cc0: 72 6f 63 20 66 75 6e 6b 20 7b 7d 20 7b 0a 20 20  roc funk {} {.  
2cd0: 64 62 20 65 76 61 6c 20 7b 20 55 50 44 41 54 45  db eval { UPDATE
2ce0: 20 6e 31 5f 63 6f 6e 66 69 67 20 53 45 54 20 76   n1_config SET v
2cf0: 3d 35 30 20 57 48 45 52 45 20 6b 3d 27 76 65 72  =50 WHERE k='ver
2d00: 73 69 6f 6e 27 20 7d 0a 20 20 73 65 74 20 66 64  sion' }.  set fd
2d10: 20 5b 64 62 20 69 6e 63 72 62 6c 6f 62 20 6d 61   [db incrblob ma
2d20: 69 6e 20 6e 31 5f 64 61 74 61 20 62 6c 6f 63 6b  in n1_data block
2d30: 20 31 30 5d 0a 20 20 66 63 6f 6e 66 69 67 75 72   10].  fconfigur
2d40: 65 20 24 66 64 20 2d 65 6e 63 6f 64 69 6e 67 20  e $fd -encoding 
2d50: 62 69 6e 61 72 79 20 2d 74 72 61 6e 73 6c 61 74  binary -translat
2d60: 69 6f 6e 20 62 69 6e 61 72 79 0a 23 20 20 70 75  ion binary.#  pu
2d70: 74 73 20 2d 6e 6f 6e 65 77 6c 69 6e 65 20 24 66  ts -nonewline $f
2d80: 64 20 22 5c 78 34 34 5c 78 34 35 22 0a 20 20 63  d "\x44\x45".  c
2d90: 6c 6f 73 65 20 24 66 64 0a 7d 0a 64 62 20 66 75  lose $fd.}.db fu
2da0: 6e 63 20 66 75 6e 6b 20 66 75 6e 6b 0a 0a 23 20  nc funk funk..# 
2db0: 54 68 69 73 20 74 65 73 74 20 63 61 73 65 20 63  This test case c
2dc0: 6f 72 72 75 70 74 73 20 74 68 65 20 73 74 72 75  orrupts the stru
2dd0: 63 74 75 72 65 20 72 65 63 6f 72 64 20 77 69 74  cture record wit
2de0: 68 69 6e 20 74 68 65 20 66 69 72 73 74 20 69 6e  hin the first in
2df0: 76 6f 63 61 74 69 6f 6e 0a 23 20 6f 66 20 66 75  vocation.# of fu
2e00: 6e 63 74 69 6f 6e 20 66 75 6e 6b 28 29 2e 20 57  nction funk(). W
2e10: 68 69 63 68 20 75 73 65 64 20 74 6f 20 63 61 75  hich used to cau
2e20: 73 65 20 74 68 65 20 62 6d 32 35 28 29 20 66 75  se the bm25() fu
2e30: 6e 63 74 69 6f 6e 20 74 6f 20 74 68 72 6f 77 20  nction to throw 
2e40: 61 6e 0a 23 20 65 78 63 65 70 74 69 6f 6e 2e 20  an.# exception. 
2e50: 42 75 74 20 73 69 6e 63 65 20 62 6d 32 35 28 29  But since bm25()
2e60: 20 63 61 6e 20 6e 6f 77 20 75 73 65 64 20 74 68   can now used th
2e70: 65 20 63 61 63 68 65 64 20 73 74 72 75 63 74 75  e cached structu
2e80: 72 65 20 72 65 63 6f 72 64 2c 0a 23 20 69 74 20  re record,.# it 
2e90: 6e 65 76 65 72 20 73 65 65 73 20 74 68 65 20 63  never sees the c
2ea0: 6f 72 72 75 70 74 69 6f 6e 20 69 6e 74 72 6f 64  orruption introd
2eb0: 75 63 65 64 20 62 79 20 66 75 6e 6b 28 29 20 61  uced by funk() a
2ec0: 6e 64 20 73 6f 20 74 68 65 20 66 6f 6c 6c 6f 77  nd so the follow
2ed0: 69 6e 67 20 0a 23 20 73 74 61 74 65 6d 65 6e 74  ing .# statement
2ee0: 20 6e 6f 20 6c 6f 6e 67 65 72 20 66 61 69 6c 73   no longer fails
2ef0: 2e 0a 23 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f  ..#.do_catchsql_
2f00: 74 65 73 74 20 31 36 2e 32 20 7b 0a 20 20 53 45  test 16.2 {.  SE
2f10: 4c 45 43 54 20 66 75 6e 6b 28 29 2c 20 62 6d 32  LECT funk(), bm2
2f20: 35 28 6e 31 29 2c 20 66 75 6e 6b 28 29 20 46 52  5(n1), funk() FR
2f30: 4f 4d 20 6e 31 20 57 48 45 52 45 20 6e 31 20 4d  OM n1 WHERE n1 M
2f40: 41 54 43 48 20 27 61 2b 62 2b 63 2b 64 27 0a 7d  ATCH 'a+b+c+d'.}
2f50: 20 7b 30 20 7b 7b 7d 20 2d 31 65 2d 30 36 20 7b   {0 {{} -1e-06 {
2f60: 7d 7d 7d 0a 23 20 7b 31 20 7b 53 51 4c 20 6c 6f  }}}.# {1 {SQL lo
2f70: 67 69 63 20 65 72 72 6f 72 7d 7d 0a 0a 23 2d 2d  gic error}}..#--
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 2d 2d 2d 2d 2d 2d  ----------------
2fc0: 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65 73 65 74 5f  -------.#.reset_
2fd0: 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  db.do_execsql_te
2fe0: 73 74 20 31 37 2e 31 20 7b 0a 20 20 43 52 45 41  st 17.1 {.  CREA
2ff0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
3000: 20 62 32 20 55 53 49 4e 47 20 66 74 73 35 28 78   b2 USING fts5(x
3010: 2c 20 64 65 74 61 69 6c 3d 25 44 45 54 41 49 4c  , detail=%DETAIL
3020: 25 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  %);.  INSERT INT
3030: 4f 20 62 32 20 56 41 4c 55 45 53 28 27 61 27 29  O b2 VALUES('a')
3040: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
3050: 62 32 20 56 41 4c 55 45 53 28 27 62 27 29 3b 0a  b2 VALUES('b');.
3060: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 62 32    INSERT INTO b2
3070: 20 56 41 4c 55 45 53 28 27 63 27 29 3b 0a 7d 0a   VALUES('c');.}.
3080: 0a 64 6f 5f 74 65 73 74 20 31 37 2e 32 20 7b 0a  .do_test 17.2 {.
3090: 20 20 73 65 74 20 72 65 73 20 5b 6c 69 73 74 5d    set res [list]
30a0: 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 53 45 4c  .  db eval { SEL
30b0: 45 43 54 20 2a 20 46 52 4f 4d 20 62 32 20 4f 52  ECT * FROM b2 OR
30c0: 44 45 52 20 42 59 20 72 6f 77 69 64 20 41 53 43  DER BY rowid ASC
30d0: 20 7d 20 7b 0a 20 20 20 20 6c 61 70 70 65 6e 64   } {.    lappend
30e0: 20 72 65 73 20 5b 65 78 65 63 73 71 6c 20 7b 20   res [execsql { 
30f0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 62 32  SELECT * FROM b2
3100: 20 4f 52 44 45 52 20 42 59 20 72 6f 77 69 64 20   ORDER BY rowid 
3110: 41 53 43 20 7d 5d 0a 20 20 7d 0a 20 20 73 65 74  ASC }].  }.  set
3120: 20 72 65 73 0a 7d 20 7b 7b 61 20 62 20 63 7d 20   res.} {{a b c} 
3130: 7b 61 20 62 20 63 7d 20 7b 61 20 62 20 63 7d 7d  {a b c} {a b c}}
3140: 0a 0a 69 66 20 7b 5b 73 74 72 69 6e 67 20 6d 61  ..if {[string ma
3150: 74 63 68 20 6e 2a 20 25 44 45 54 41 49 4c 25 5d  tch n* %DETAIL%]
3160: 3d 3d 30 7d 20 7b 0a 20 20 72 65 73 65 74 5f 64  ==0} {.  reset_d
3170: 62 0a 20 20 64 6f 5f 65 78 65 63 73 71 6c 5f 74  b.  do_execsql_t
3180: 65 73 74 20 31 37 2e 33 20 7b 0a 20 20 20 20 43  est 17.3 {.    C
3190: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
31a0: 42 4c 45 20 63 32 20 55 53 49 4e 47 20 66 74 73  BLE c2 USING fts
31b0: 35 28 78 2c 20 79 2c 20 64 65 74 61 69 6c 3d 25  5(x, y, detail=%
31c0: 44 45 54 41 49 4c 25 29 3b 0a 20 20 20 20 49 4e  DETAIL%);.    IN
31d0: 53 45 52 54 20 49 4e 54 4f 20 63 32 20 56 41 4c  SERT INTO c2 VAL
31e0: 55 45 53 28 27 78 20 78 20 78 27 2c 20 27 78 20  UES('x x x', 'x 
31f0: 78 20 78 27 29 3b 0a 20 20 20 20 53 45 4c 45 43  x x');.    SELEC
3200: 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 63 32 20  T rowid FROM c2 
3210: 57 48 45 52 45 20 63 32 20 4d 41 54 43 48 20 27  WHERE c2 MATCH '
3220: 79 3a 78 27 3b 0a 20 20 7d 20 7b 31 7d 0a 7d 0a  y:x';.  } {1}.}.
3230: 0a 23 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 2d 2d  ----------------
3270: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65  -----------.#.re
3280: 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71  set_db.do_execsq
3290: 6c 5f 74 65 73 74 20 31 37 2e 31 20 7b 0a 20 20  l_test 17.1 {.  
32a0: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
32b0: 41 42 4c 45 20 75 69 6f 20 55 53 49 4e 47 20 66  ABLE uio USING f
32c0: 74 73 35 28 74 74 74 2c 20 64 65 74 61 69 6c 3d  ts5(ttt, detail=
32d0: 25 44 45 54 41 49 4c 25 29 3b 0a 20 20 49 4e 53  %DETAIL%);.  INS
32e0: 45 52 54 20 49 4e 54 4f 20 75 69 6f 20 56 41 4c  ERT INTO uio VAL
32f0: 55 45 53 28 4e 55 4c 4c 29 3b 0a 20 20 49 4e 53  UES(NULL);.  INS
3300: 45 52 54 20 49 4e 54 4f 20 75 69 6f 20 53 45 4c  ERT INTO uio SEL
3310: 45 43 54 20 4e 55 4c 4c 20 46 52 4f 4d 20 75 69  ECT NULL FROM ui
3320: 6f 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  o;.  INSERT INTO
3330: 20 75 69 6f 20 53 45 4c 45 43 54 20 4e 55 4c 4c   uio SELECT NULL
3340: 20 46 52 4f 4d 20 75 69 6f 3b 0a 20 20 49 4e 53   FROM uio;.  INS
3350: 45 52 54 20 49 4e 54 4f 20 75 69 6f 20 53 45 4c  ERT INTO uio SEL
3360: 45 43 54 20 4e 55 4c 4c 20 46 52 4f 4d 20 75 69  ECT NULL FROM ui
3370: 6f 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  o;.  INSERT INTO
3380: 20 75 69 6f 20 53 45 4c 45 43 54 20 4e 55 4c 4c   uio SELECT NULL
3390: 20 46 52 4f 4d 20 75 69 6f 3b 0a 20 20 49 4e 53   FROM uio;.  INS
33a0: 45 52 54 20 49 4e 54 4f 20 75 69 6f 20 53 45 4c  ERT INTO uio SEL
33b0: 45 43 54 20 4e 55 4c 4c 20 46 52 4f 4d 20 75 69  ECT NULL FROM ui
33c0: 6f 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  o;.  INSERT INTO
33d0: 20 75 69 6f 20 53 45 4c 45 43 54 20 4e 55 4c 4c   uio SELECT NULL
33e0: 20 46 52 4f 4d 20 75 69 6f 3b 0a 20 20 49 4e 53   FROM uio;.  INS
33f0: 45 52 54 20 49 4e 54 4f 20 75 69 6f 20 53 45 4c  ERT INTO uio SEL
3400: 45 43 54 20 4e 55 4c 4c 20 46 52 4f 4d 20 75 69  ECT NULL FROM ui
3410: 6f 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  o;.  INSERT INTO
3420: 20 75 69 6f 20 53 45 4c 45 43 54 20 4e 55 4c 4c   uio SELECT NULL
3430: 20 46 52 4f 4d 20 75 69 6f 3b 0a 20 20 53 45 4c   FROM uio;.  SEL
3440: 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f  ECT count(*) FRO
3450: 4d 20 75 69 6f 3b 0a 7d 20 7b 32 35 36 7d 0a 0a  M uio;.} {256}..
3460: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
3470: 31 37 2e 32 20 7b 0a 20 20 53 45 4c 45 43 54 20  17.2 {.  SELECT 
3480: 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 75 69  count(*) FROM ui
3490: 6f 20 57 48 45 52 45 20 72 6f 77 69 64 20 42 45  o WHERE rowid BE
34a0: 54 57 45 45 4e 20 38 20 41 4e 44 20 31 37 0a 7d  TWEEN 8 AND 17.}
34b0: 20 7b 31 30 7d 0a 64 6f 5f 65 78 65 63 73 71 6c   {10}.do_execsql
34c0: 5f 74 65 73 74 20 31 37 2e 33 20 7b 0a 20 20 53  _test 17.3 {.  S
34d0: 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d  ELECT rowid FROM
34e0: 20 75 69 6f 20 57 48 45 52 45 20 72 6f 77 69 64   uio WHERE rowid
34f0: 20 42 45 54 57 45 45 4e 20 38 20 41 4e 44 20 31   BETWEEN 8 AND 1
3500: 37 0a 7d 20 7b 38 20 39 20 31 30 20 31 31 20 31  7.} {8 9 10 11 1
3510: 32 20 31 33 20 31 34 20 31 35 20 31 36 20 31 37  2 13 14 15 16 17
3520: 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  }.do_execsql_tes
3530: 74 20 31 37 2e 34 20 7b 0a 20 20 53 45 4c 45 43  t 17.4 {.  SELEC
3540: 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 75 69 6f  T rowid FROM uio
3550: 20 57 48 45 52 45 20 72 6f 77 69 64 20 42 45 54   WHERE rowid BET
3560: 57 45 45 4e 20 38 20 41 4e 44 20 31 37 20 4f 52  WEEN 8 AND 17 OR
3570: 44 45 52 20 42 59 20 72 6f 77 69 64 20 44 45 53  DER BY rowid DES
3580: 43 0a 7d 20 7b 31 37 20 31 36 20 31 35 20 31 34  C.} {17 16 15 14
3590: 20 31 33 20 31 32 20 31 31 20 31 30 20 39 20 38   13 12 11 10 9 8
35a0: 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  }.do_execsql_tes
35b0: 74 20 31 37 2e 35 20 7b 0a 20 20 53 45 4c 45 43  t 17.5 {.  SELEC
35c0: 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20  T count(*) FROM 
35d0: 75 69 6f 0a 7d 20 7b 32 35 36 7d 0a 0a 64 6f 5f  uio.} {256}..do_
35e0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 37 2e  execsql_test 17.
35f0: 36 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  6 {.  INSERT INT
3600: 4f 20 75 69 6f 28 72 6f 77 69 64 29 20 56 41 4c  O uio(rowid) VAL
3610: 55 45 53 28 39 32 32 33 33 37 32 30 33 36 38 35  UES(922337203685
3620: 34 37 37 35 38 30 37 29 3b 0a 20 20 49 4e 53 45  4775807);.  INSE
3630: 52 54 20 49 4e 54 4f 20 75 69 6f 28 72 6f 77 69  RT INTO uio(rowi
3640: 64 29 20 56 41 4c 55 45 53 28 2d 39 32 32 33 33  d) VALUES(-92233
3650: 37 32 30 33 36 38 35 34 37 37 35 38 30 38 29 3b  72036854775808);
3660: 0a 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28  .  SELECT count(
3670: 2a 29 20 46 52 4f 4d 20 75 69 6f 3b 0a 7d 20 7b  *) FROM uio;.} {
3680: 32 35 38 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  258}.do_execsql_
3690: 74 65 73 74 20 31 37 2e 37 20 7b 0a 20 20 53 45  test 17.7 {.  SE
36a0: 4c 45 43 54 20 6d 69 6e 28 72 6f 77 69 64 29 2c  LECT min(rowid),
36b0: 20 6d 61 78 28 72 6f 77 69 64 29 20 46 52 4f 4d   max(rowid) FROM
36c0: 20 75 69 6f 3b 0a 7d 20 7b 2d 39 32 32 33 33 37   uio;.} {-922337
36d0: 32 30 33 36 38 35 34 37 37 35 38 30 38 20 39 32  2036854775808 92
36e0: 32 33 33 37 32 30 33 36 38 35 34 37 37 35 38 30  2337203685477580
36f0: 37 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  7}..do_execsql_t
3700: 65 73 74 20 31 37 2e 38 20 7b 0a 20 20 49 4e 53  est 17.8 {.  INS
3710: 45 52 54 20 49 4e 54 4f 20 75 69 6f 20 44 45 46  ERT INTO uio DEF
3720: 41 55 4c 54 20 56 41 4c 55 45 53 3b 0a 20 20 53  AULT VALUES;.  S
3730: 45 4c 45 43 54 20 6d 69 6e 28 72 6f 77 69 64 29  ELECT min(rowid)
3740: 2c 20 6d 61 78 28 72 6f 77 69 64 29 2c 20 63 6f  , max(rowid), co
3750: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 75 69 6f 3b  unt(*) FROM uio;
3760: 0a 7d 20 7b 2d 39 32 32 33 33 37 32 30 33 36 38  .} {-92233720368
3770: 35 34 37 37 35 38 30 38 20 39 32 32 33 33 37 32  54775808 9223372
3780: 30 33 36 38 35 34 37 37 35 38 30 37 20 32 35 39  036854775807 259
3790: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
37a0: 73 74 20 31 37 2e 39 20 7b 0a 20 20 53 45 4c 45  st 17.9 {.  SELE
37b0: 43 54 20 6d 69 6e 28 72 6f 77 69 64 29 2c 20 6d  CT min(rowid), m
37c0: 61 78 28 72 6f 77 69 64 29 2c 20 63 6f 75 6e 74  ax(rowid), count
37d0: 28 2a 29 20 46 52 4f 4d 20 75 69 6f 20 57 48 45  (*) FROM uio WHE
37e0: 52 45 20 72 6f 77 69 64 20 3c 20 31 30 3b 0a 7d  RE rowid < 10;.}
37f0: 20 7b 2d 39 32 32 33 33 37 32 30 33 36 38 35 34   {-9223372036854
3800: 37 37 35 38 30 38 20 39 20 31 30 7d 0a 0a 23 2d  775808 9 10}..#-
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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3850: 2d 2d 2d 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c  ---.#.do_execsql
3860: 5f 74 65 73 74 20 31 38 2e 31 20 7b 0a 20 20 43  _test 18.1 {.  C
3870: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
3880: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73  BLE t1 USING fts
3890: 35 28 61 2c 20 62 2c 20 64 65 74 61 69 6c 3d 25  5(a, b, detail=%
38a0: 44 45 54 41 49 4c 25 29 3b 0a 20 20 43 52 45 41  DETAIL%);.  CREA
38b0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
38c0: 20 74 32 20 55 53 49 4e 47 20 66 74 73 35 28 63   t2 USING fts5(c
38d0: 2c 20 64 2c 20 64 65 74 61 69 6c 3d 25 44 45 54  , d, detail=%DET
38e0: 41 49 4c 25 29 3b 0a 20 20 49 4e 53 45 52 54 20  AIL%);.  INSERT 
38f0: 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27  INTO t1 VALUES('
3900: 61 62 63 2a 27 2c 20 4e 55 4c 4c 29 3b 0a 20 20  abc*', NULL);.  
3910: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 32 20 56  INSERT INTO t2 V
3920: 41 4c 55 45 53 28 31 2c 20 27 61 62 63 64 65 66  ALUES(1, 'abcdef
3930: 67 27 29 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73 71  g');.}.do_execsq
3940: 6c 5f 74 65 73 74 20 31 38 2e 32 20 7b 0a 20 20  l_test 18.2 {.  
3950: 53 45 4c 45 43 54 20 74 31 2e 72 6f 77 69 64 2c  SELECT t1.rowid,
3960: 20 74 32 2e 72 6f 77 69 64 20 46 52 4f 4d 20 74   t2.rowid FROM t
3970: 31 2c 20 74 32 20 57 48 45 52 45 20 74 32 20 4d  1, t2 WHERE t2 M
3980: 41 54 43 48 20 74 31 2e 61 20 41 4e 44 20 74 31  ATCH t1.a AND t1
3990: 2e 72 6f 77 69 64 20 3d 20 74 32 2e 63 0a 7d 20  .rowid = t2.c.} 
39a0: 7b 31 20 31 7d 0a 64 6f 5f 65 78 65 63 73 71 6c  {1 1}.do_execsql
39b0: 5f 74 65 73 74 20 31 38 2e 33 20 7b 0a 20 20 53  _test 18.3 {.  S
39c0: 45 4c 45 43 54 20 74 31 2e 72 6f 77 69 64 2c 20  ELECT t1.rowid, 
39d0: 74 32 2e 72 6f 77 69 64 20 46 52 4f 4d 20 74 32  t2.rowid FROM t2
39e0: 2c 20 74 31 20 57 48 45 52 45 20 74 32 20 4d 41  , t1 WHERE t2 MA
39f0: 54 43 48 20 74 31 2e 61 20 41 4e 44 20 74 31 2e  TCH t1.a AND t1.
3a00: 72 6f 77 69 64 20 3d 20 74 32 2e 63 0a 7d 20 7b  rowid = t2.c.} {
3a10: 31 20 31 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  1 1}..#---------
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 2d 2d  ----------------
3a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 66 74  -----------.# ft
3a60: 73 35 20 74 61 62 6c 65 20 69 6e 20 74 68 65 20  s5 table in the 
3a70: 74 65 6d 70 20 73 63 68 65 6d 61 2e 0a 23 0a 72  temp schema..#.r
3a80: 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73  eset_db.do_execs
3a90: 71 6c 5f 74 65 73 74 20 31 39 2e 30 20 7b 0a 20  ql_test 19.0 {. 
3aa0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
3ab0: 54 41 42 4c 45 20 74 65 6d 70 2e 74 31 20 55 53  TABLE temp.t1 US
3ac0: 49 4e 47 20 66 74 73 35 28 78 2c 20 64 65 74 61  ING fts5(x, deta
3ad0: 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20 20  il=%DETAIL%);.  
3ae0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56  INSERT INTO t1 V
3af0: 41 4c 55 45 53 28 27 78 20 79 20 7a 27 29 3b 0a  ALUES('x y z');.
3b00: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
3b10: 20 56 41 4c 55 45 53 28 27 77 20 78 20 31 27 29   VALUES('w x 1')
3b20: 3b 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64  ;.  SELECT rowid
3b30: 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 74   FROM t1 WHERE t
3b40: 31 20 4d 41 54 43 48 20 27 78 27 3b 0a 7d 20 7b  1 MATCH 'x';.} {
3b50: 31 20 32 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  1 2}..#---------
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 2d 2d  ----------------
3b90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65  -----------.# Te
3ba0: 73 74 20 74 68 61 74 20 36 20 61 6e 64 20 37 20  st that 6 and 7 
3bb0: 62 79 74 65 20 76 61 72 69 6e 74 73 20 63 61 6e  byte varints can
3bc0: 20 62 65 20 72 65 61 64 2e 0a 23 0a 72 65 73 65   be read..#.rese
3bd0: 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  t_db.do_execsql_
3be0: 74 65 73 74 20 32 30 2e 30 20 7b 0a 20 20 43 52  test 20.0 {.  CR
3bf0: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42  EATE VIRTUAL TAB
3c00: 4c 45 20 74 65 6d 70 2e 74 6d 70 20 55 53 49 4e  LE temp.tmp USIN
3c10: 47 20 66 74 73 35 28 78 2c 20 64 65 74 61 69 6c  G fts5(x, detail
3c20: 3d 25 44 45 54 41 49 4c 25 29 3b 0a 7d 0a 73 65  =%DETAIL%);.}.se
3c30: 74 20 3a 3a 69 64 73 20 5b 6c 69 73 74 20 5c 0a  t ::ids [list \.
3c40: 20 20 30 20 5b 65 78 70 72 20 31 3c 3c 33 36 5d    0 [expr 1<<36]
3c50: 20 5b 65 78 70 72 20 32 3c 3c 33 36 5d 20 5b 65   [expr 2<<36] [e
3c60: 78 70 72 20 31 3c 3c 34 33 5d 20 5b 65 78 70 72  xpr 1<<43] [expr
3c70: 20 32 3c 3c 34 33 5d 0a 5d 0a 64 6f 5f 74 65 73   2<<43].].do_tes
3c80: 74 20 32 30 2e 31 20 7b 0a 20 20 66 6f 72 65 61  t 20.1 {.  forea
3c90: 63 68 20 69 64 20 24 3a 3a 69 64 73 20 7b 0a 20  ch id $::ids {. 
3ca0: 20 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53     execsql { INS
3cb0: 45 52 54 20 49 4e 54 4f 20 74 6d 70 28 72 6f 77  ERT INTO tmp(row
3cc0: 69 64 2c 20 78 29 20 56 41 4c 55 45 53 28 24 69  id, x) VALUES($i
3cd0: 64 2c 20 27 78 20 79 20 7a 27 29 20 7d 0a 20 20  d, 'x y z') }.  
3ce0: 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45  }.  execsql { SE
3cf0: 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20  LECT rowid FROM 
3d00: 74 6d 70 20 57 48 45 52 45 20 74 6d 70 20 4d 41  tmp WHERE tmp MA
3d10: 54 43 48 20 27 79 27 20 7d 0a 7d 20 24 3a 3a 69  TCH 'y' }.} $::i
3d20: 64 73 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ds..#-----------
3d30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3d40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3d50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74  ---------.# Test
3d70: 20 74 68 61 74 20 61 20 44 52 4f 50 20 54 41 42   that a DROP TAB
3d80: 4c 45 20 6d 61 79 20 62 65 20 65 78 65 63 75 74  LE may be execut
3d90: 65 64 20 77 69 74 68 69 6e 20 61 20 74 72 61 6e  ed within a tran
3da0: 73 61 63 74 69 6f 6e 20 74 68 61 74 0a 23 20 77  saction that.# w
3db0: 72 69 74 65 73 20 74 6f 20 61 6e 20 46 54 53 35  rites to an FTS5
3dc0: 20 74 61 62 6c 65 2e 0a 23 0a 64 6f 5f 65 78 65   table..#.do_exe
3dd0: 63 73 71 6c 5f 74 65 73 74 20 32 31 2e 30 20 7b  csql_test 21.0 {
3de0: 0a 20 20 43 52 45 41 54 45 20 54 45 4d 50 20 54  .  CREATE TEMP T
3df0: 41 42 4c 45 20 74 38 28 61 2c 20 62 29 3b 0a 20  ABLE t8(a, b);. 
3e00: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
3e10: 54 41 42 4c 45 20 66 74 20 55 53 49 4e 47 20 66  TABLE ft USING f
3e20: 74 73 35 28 78 2c 20 64 65 74 61 69 6c 3d 25 44  ts5(x, detail=%D
3e30: 45 54 41 49 4c 25 29 3b 0a 7d 0a 0a 64 6f 5f 65  ETAIL%);.}..do_e
3e40: 78 65 63 73 71 6c 5f 74 65 73 74 20 32 31 2e 31  xecsql_test 21.1
3e50: 20 7b 0a 20 20 42 45 47 49 4e 3b 0a 20 20 20 20   {.  BEGIN;.    
3e60: 49 4e 53 45 52 54 20 49 4e 54 4f 20 66 74 20 56  INSERT INTO ft V
3e70: 41 4c 55 45 53 28 27 61 20 62 20 63 27 29 3b 0a  ALUES('a b c');.
3e80: 20 20 20 20 44 52 4f 50 20 54 41 42 4c 45 20 74      DROP TABLE t
3e90: 38 3b 0a 20 20 43 4f 4d 4d 49 54 3b 0a 7d 0a 0a  8;.  COMMIT;.}..
3ea0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
3eb0: 32 32 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20  22.0 {.  CREATE 
3ec0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 39  VIRTUAL TABLE t9
3ed0: 20 55 53 49 4e 47 20 66 74 73 35 28 78 2c 20 64   USING fts5(x, d
3ee0: 65 74 61 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b  etail=%DETAIL%);
3ef0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
3f00: 39 28 72 6f 77 69 64 2c 20 78 29 20 56 41 4c 55  9(rowid, x) VALU
3f10: 45 53 28 32 2c 20 27 62 62 62 27 29 3b 0a 20 20  ES(2, 'bbb');.  
3f20: 42 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53 45 52  BEGIN;.    INSER
3f30: 54 20 49 4e 54 4f 20 74 39 28 72 6f 77 69 64 2c  T INTO t9(rowid,
3f40: 20 78 29 20 56 41 4c 55 45 53 28 31 2c 20 27 61   x) VALUES(1, 'a
3f50: 61 61 27 29 3b 0a 20 20 20 20 44 45 4c 45 54 45  aa');.    DELETE
3f60: 20 46 52 4f 4d 20 74 39 20 57 48 45 52 45 20 72   FROM t9 WHERE r
3f70: 6f 77 69 64 20 3d 20 32 3b 0a 20 20 20 20 49 4e  owid = 2;.    IN
3f80: 53 45 52 54 20 49 4e 54 4f 20 74 39 28 72 6f 77  SERT INTO t9(row
3f90: 69 64 2c 20 78 29 20 56 41 4c 55 45 53 28 33 2c  id, x) VALUES(3,
3fa0: 20 27 62 62 62 27 29 3b 0a 20 20 43 4f 4d 4d 49   'bbb');.  COMMI
3fb0: 54 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  T;.}..do_execsql
3fc0: 5f 74 65 73 74 20 32 32 2e 31 20 7b 0a 20 20 53  _test 22.1 {.  S
3fd0: 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d  ELECT rowid FROM
3fe0: 20 74 39 28 27 61 2a 27 29 0a 7d 20 7b 31 7d 0a   t9('a*').} {1}.
3ff0: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
4000: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 64 6f 5f 65  -----------.do_e
4040: 78 65 63 73 71 6c 5f 74 65 73 74 20 32 33 2e 30  xecsql_test 23.0
4050: 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54   {.  CREATE VIRT
4060: 55 41 4c 20 54 41 42 4c 45 20 74 31 30 20 55 53  UAL TABLE t10 US
4070: 49 4e 47 20 66 74 73 35 28 78 2c 20 64 65 74 61  ING fts5(x, deta
4080: 69 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20 20  il=%DETAIL%);.  
4090: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 31  CREATE TABLE t11
40a0: 28 78 29 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73 71  (x);.}.do_execsq
40b0: 6c 5f 74 65 73 74 20 32 33 2e 31 20 7b 0a 20 20  l_test 23.1 {.  
40c0: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
40d0: 31 2c 20 74 31 30 20 57 48 45 52 45 20 74 31 31  1, t10 WHERE t11
40e0: 2e 78 20 3d 20 74 31 30 2e 78 20 41 4e 44 20 74  .x = t10.x AND t
40f0: 31 30 2e 72 6f 77 69 64 20 49 53 20 4e 55 4c 4c  10.rowid IS NULL
4100: 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  ;.}.do_execsql_t
4110: 65 73 74 20 32 33 2e 32 20 7b 0a 20 20 53 45 4c  est 23.2 {.  SEL
4120: 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 31 2c 20  ECT * FROM t11, 
4130: 74 31 30 20 57 48 45 52 45 20 74 31 30 2e 72 6f  t10 WHERE t10.ro
4140: 77 69 64 20 49 53 20 4e 55 4c 4c 3b 0a 7d 0a 0a  wid IS NULL;.}..
4150: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
4160: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4170: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4180: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 64 6f 5f 65 78  ----------.do_ex
41a0: 65 63 73 71 6c 5f 74 65 73 74 20 32 34 2e 30 20  ecsql_test 24.0 
41b0: 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55  {.  CREATE VIRTU
41c0: 41 4c 20 54 41 42 4c 45 20 74 31 32 20 55 53 49  AL TABLE t12 USI
41d0: 4e 47 20 66 74 73 35 28 78 2c 20 64 65 74 61 69  NG fts5(x, detai
41e0: 6c 3d 25 44 45 54 41 49 4c 25 29 3b 0a 20 20 49  l=%DETAIL%);.  I
41f0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 32 20 56  NSERT INTO t12 V
4200: 41 4c 55 45 53 28 27 61 61 61 61 27 29 3b 0a 7d  ALUES('aaaa');.}
4210: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
4220: 20 32 34 2e 31 20 7b 0a 20 20 42 45 47 49 4e 3b   24.1 {.  BEGIN;
4230: 0a 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d  .    DELETE FROM
4240: 20 74 31 32 20 57 48 45 52 45 20 72 6f 77 69 64   t12 WHERE rowid
4250: 3d 31 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 2a  =1;.    SELECT *
4260: 20 46 52 4f 4d 20 74 31 32 28 27 61 61 61 61 27   FROM t12('aaaa'
4270: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
4280: 54 4f 20 74 31 32 20 56 41 4c 55 45 53 28 27 61  TO t12 VALUES('a
4290: 61 61 61 27 29 3b 0a 20 20 45 4e 44 3b 0a 7d 0a  aaa');.  END;.}.
42a0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
42b0: 32 34 2e 32 20 7b 0a 20 20 49 4e 53 45 52 54 20  24.2 {.  INSERT 
42c0: 49 4e 54 4f 20 74 31 32 28 74 31 32 29 20 56 41  INTO t12(t12) VA
42d0: 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d  LUES('integrity-
42e0: 63 68 65 63 6b 27 29 3b 0a 7d 0a 64 6f 5f 65 78  check');.}.do_ex
42f0: 65 63 73 71 6c 5f 74 65 73 74 20 32 34 2e 33 20  ecsql_test 24.3 
4300: 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 2a 20 46  {.    SELECT * F
4310: 52 4f 4d 20 74 31 32 28 27 61 61 61 61 27 29 3b  ROM t12('aaaa');
4320: 0a 7d 20 7b 61 61 61 61 7d 0a 0a 23 2d 2d 2d 2d  .} {aaaa}..#----
4330: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4340: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4350: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4360: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4370: 2d 2d 2d 2d 2d 0a 64 6f 5f 65 78 65 63 73 71 6c  -----.do_execsql
4380: 5f 74 65 73 74 20 32 35 2e 30 20 7b 0a 20 20 43  _test 25.0 {.  C
4390: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
43a0: 42 4c 45 20 74 31 33 20 55 53 49 4e 47 20 66 74  BLE t13 USING ft
43b0: 73 35 28 78 2c 20 64 65 74 61 69 6c 3d 25 44 45  s5(x, detail=%DE
43c0: 54 41 49 4c 25 29 3b 0a 7d 0a 64 6f 5f 65 78 65  TAIL%);.}.do_exe
43d0: 63 73 71 6c 5f 74 65 73 74 20 32 35 2e 31 20 7b  csql_test 25.1 {
43e0: 0a 20 20 42 45 47 49 4e 3b 0a 20 20 49 4e 53 45  .  BEGIN;.  INSE
43f0: 52 54 20 49 4e 54 4f 20 74 31 33 20 56 41 4c 55  RT INTO t13 VALU
4400: 45 53 28 27 41 41 41 41 27 29 3b 0a 53 45 4c 45  ES('AAAA');.SELE
4410: 43 54 20 2a 20 46 52 4f 4d 20 74 31 33 28 27 42  CT * FROM t13('B
4420: 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42  BBBBBBBBBBBBBBBB
4430: 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42  BBBBBBBBBBBBBBBB
4440: 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42  BBBBBBBBBBBBBBBB
4450: 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42  BBBBBBBBBBBBBBBB
4460: 42 42 42 42 42 42 42 42 42 42 42 42 42 42 42 2a  BBBBBBBBBBBBBBB*
4470: 27 29 3b 0a 0a 20 20 45 4e 44 3b 0a 7d 0a 0a 0a  ');..  END;.}...
4480: 7d 0a 0a 65 78 70 61 6e 64 5f 61 6c 6c 5f 73 71  }..expand_all_sq
4490: 6c 20 64 62 0a 66 69 6e 69 73 68 5f 74 65 73 74  l db.finish_test
44a0: 0a                                               .