/ Hex Artifact Content
Login

Artifact 9bded45827b4ab8933c87b7b3bcc3cd47f7378a4:


0000: 23 20 32 30 31 35 20 53 65 70 74 65 6d 62 65 72  # 2015 September
0010: 20 30 35 0a 23 0a 23 20 54 68 65 20 61 75 74 68   05.#.# The auth
0020: 6f 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70  or disclaims cop
0030: 79 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73  yright to this s
0040: 6f 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20  ource code.  In 
0050: 70 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67  place of.# a leg
0060: 61 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20  al notice, here 
0070: 69 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23  is a blessing:.#
0080: 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f  .#    May you do
0090: 20 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76   good and not ev
00a0: 69 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75  il..#    May you
00b0: 20 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73   find forgivenes
00c0: 73 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61  s for yourself a
00d0: 6e 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72  nd forgive other
00e0: 73 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20  s..#    May you 
00f0: 73 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65  share freely, ne
0100: 76 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20  ver taking more 
0110: 74 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23  than you give..#
0120: 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  .#**************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 0a 0a 73  ***********.#..s
0170: 6f 75 72 63 65 20 5b 66 69 6c 65 20 6a 6f 69 6e  ource [file join
0180: 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20 5b   [file dirname [
0190: 69 6e 66 6f 20 73 63 72 69 70 74 5d 5d 20 66 74  info script]] ft
01a0: 73 35 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c 5d 0a 73  s5_common.tcl].s
01b0: 65 74 20 74 65 73 74 70 72 65 66 69 78 20 66 74  et testprefix ft
01c0: 73 35 73 69 6d 70 6c 65 0a 0a 23 20 49 66 20 53  s5simple..# If S
01d0: 51 4c 49 54 45 5f 45 4e 41 42 4c 45 5f 46 54 53  QLITE_ENABLE_FTS
01e0: 35 20 69 73 20 64 65 66 69 6e 65 64 2c 20 6f 6d  5 is defined, om
01f0: 69 74 20 74 68 69 73 20 66 69 6c 65 2e 0a 69 66  it this file..if
0200: 63 61 70 61 62 6c 65 20 21 66 74 73 35 20 7b 0a  capable !fts5 {.
0210: 20 20 66 69 6e 69 73 68 5f 74 65 73 74 0a 20 20    finish_test.  
0220: 72 65 74 75 72 6e 0a 7d 0a 20 0a 23 2d 2d 2d 2d  return.}. .#----
0230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0260: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0270: 2d 2d 2d 2d 2d 0a 23 0a 73 65 74 20 64 6f 63 20  -----.#.set doc 
0280: 22 78 20 78 20 5b 73 74 72 69 6e 67 20 72 65 70  "x x [string rep
0290: 65 61 74 20 7b 79 20 7d 20 35 30 5d 7a 20 7a 22  eat {y } 50]z z"
02a0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
02b0: 20 31 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20   1.0 {.  CREATE 
02c0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31  VIRTUAL TABLE t1
02d0: 20 55 53 49 4e 47 20 66 74 73 35 28 78 29 3b 0a   USING fts5(x);.
02e0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
02f0: 28 74 31 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45  (t1, rank) VALUE
0300: 53 28 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a 20  S('pgsz', 32);. 
0310: 20 42 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53 45   BEGIN;.    INSE
0320: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
0330: 53 28 24 64 6f 63 29 3b 0a 20 20 43 4f 4d 4d 49  S($doc);.  COMMI
0340: 54 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  T;.}..do_execsql
0350: 5f 74 65 73 74 20 31 2e 31 20 7b 0a 20 20 49 4e  _test 1.1 {.  IN
0360: 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29  SERT INTO t1(t1)
0370: 20 56 41 4c 55 45 53 28 27 69 6e 74 65 67 72 69   VALUES('integri
0380: 74 79 2d 63 68 65 63 6b 27 29 3b 0a 7d 0a 0a 23  ty-check');.}..#
0390: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65 73 65  ---------.#.rese
03e0: 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  t_db.do_execsql_
03f0: 74 65 73 74 20 32 2e 30 20 7b 0a 20 20 43 52 45  test 2.0 {.  CRE
0400: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
0410: 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28  E t1 USING fts5(
0420: 78 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  x);.  INSERT INT
0430: 4f 20 74 31 28 74 31 2c 20 72 61 6e 6b 29 20 56  O t1(t1, rank) V
0440: 41 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32  ALUES('pgsz', 32
0450: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
0460: 20 74 31 20 56 41 4c 55 45 53 28 27 61 20 62 20   t1 VALUES('a b 
0470: 63 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  c');.  INSERT IN
0480: 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 64 20  TO t1 VALUES('d 
0490: 65 20 66 27 29 3b 0a 20 20 49 4e 53 45 52 54 20  e f');.  INSERT 
04a0: 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55  INTO t1(t1) VALU
04b0: 45 53 28 27 6f 70 74 69 6d 69 7a 65 27 29 3b 0a  ES('optimize');.
04c0: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
04d0: 73 74 20 32 2e 31 20 7b 0a 20 20 49 4e 53 45 52  st 2.1 {.  INSER
04e0: 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41  T INTO t1(t1) VA
04f0: 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d  LUES('integrity-
0500: 63 68 65 63 6b 27 29 3b 0a 7d 20 7b 7d 0a 0a 0a  check');.} {}...
0510: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
0520: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0530: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 0a 72 65 73  ----------.#.res
0560: 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c  et_db.do_execsql
0570: 5f 74 65 73 74 20 33 2e 30 20 7b 0a 20 20 43 52  _test 3.0 {.  CR
0580: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42  EATE VIRTUAL TAB
0590: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35  LE t1 USING fts5
05a0: 28 78 2c 20 70 72 65 66 69 78 3d 27 31 2c 32 27  (x, prefix='1,2'
05b0: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
05c0: 20 74 31 28 74 31 2c 20 72 61 6e 6b 29 20 56 41   t1(t1, rank) VA
05d0: 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32 29  LUES('pgsz', 32)
05e0: 3b 0a 20 20 42 45 47 49 4e 3b 0a 20 20 49 4e 53  ;.  BEGIN;.  INS
05f0: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
0600: 45 53 28 27 6f 6e 65 27 29 3b 0a 20 20 53 45 4c  ES('one');.  SEL
0610: 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48  ECT * FROM t1 WH
0620: 45 52 45 20 74 31 20 4d 41 54 43 48 20 27 6f 2a  ERE t1 MATCH 'o*
0630: 27 3b 0a 7d 20 7b 6f 6e 65 7d 0a 0a 64 6f 5f 65  ';.} {one}..do_e
0640: 78 65 63 73 71 6c 5f 74 65 73 74 20 33 2e 31 20  xecsql_test 3.1 
0650: 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  {.  INSERT INTO 
0660: 74 31 28 74 31 29 20 56 41 4c 55 45 53 28 27 69  t1(t1) VALUES('i
0670: 6e 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29  ntegrity-check')
0680: 3b 0a 7d 20 7b 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  ;.} {}..#-------
0690: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
06a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
06b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
06c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
06d0: 2d 2d 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65  --.reset_db.do_e
06e0: 78 65 63 73 71 6c 5f 74 65 73 74 20 34 2e 31 20  xecsql_test 4.1 
06f0: 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55  {.  CREATE VIRTU
0700: 41 4c 20 54 41 42 4c 45 20 74 31 31 20 55 53 49  AL TABLE t11 USI
0710: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29  NG fts5(content)
0720: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
0730: 74 31 31 28 74 31 31 2c 20 72 61 6e 6b 29 20 56  t11(t11, rank) V
0740: 41 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32  ALUES('pgsz', 32
0750: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
0760: 20 74 31 31 20 56 41 4c 55 45 53 28 27 61 6e 6f   t11 VALUES('ano
0770: 74 68 65 72 27 29 3b 0a 20 20 49 4e 53 45 52 54  ther');.  INSERT
0780: 20 49 4e 54 4f 20 74 31 31 20 56 41 4c 55 45 53   INTO t11 VALUES
0790: 28 27 73 74 72 69 6e 67 27 29 3b 0a 20 20 49 4e  ('string');.  IN
07a0: 53 45 52 54 20 49 4e 54 4f 20 74 31 31 20 56 41  SERT INTO t11 VA
07b0: 4c 55 45 53 28 27 6f 66 27 29 3b 0a 20 20 49 4e  LUES('of');.  IN
07c0: 53 45 52 54 20 49 4e 54 4f 20 74 31 31 20 56 41  SERT INTO t11 VA
07d0: 4c 55 45 53 28 27 74 65 78 74 27 29 3b 0a 7d 0a  LUES('text');.}.
07e0: 64 6f 5f 74 65 73 74 20 34 2e 32 20 7b 0a 20 20  do_test 4.2 {.  
07f0: 65 78 65 63 73 71 6c 20 7b 20 49 4e 53 45 52 54  execsql { INSERT
0800: 20 49 4e 54 4f 20 74 31 31 28 74 31 31 29 20 56   INTO t11(t11) V
0810: 41 4c 55 45 53 28 27 6f 70 74 69 6d 69 7a 65 27  ALUES('optimize'
0820: 29 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 65 78 65 63  ) }.} {}.do_exec
0830: 73 71 6c 5f 74 65 73 74 20 34 2e 33 20 7b 0a 20  sql_test 4.3 {. 
0840: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 31   INSERT INTO t11
0850: 28 74 31 31 29 20 56 41 4c 55 45 53 28 27 69 6e  (t11) VALUES('in
0860: 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29 3b  tegrity-check');
0870: 0a 7d 20 7b 7d 0a 0a 23 64 62 20 65 76 61 6c 20  .} {}..#db eval 
0880: 7b 20 53 45 4c 45 43 54 20 66 74 73 35 5f 64 65  { SELECT fts5_de
0890: 63 6f 64 65 28 72 6f 77 69 64 2c 20 62 6c 6f 63  code(rowid, bloc
08a0: 6b 29 20 61 73 20 78 20 46 52 4f 4d 20 74 31 31  k) as x FROM t11
08b0: 5f 64 61 74 61 20 7d 20 7b 20 70 75 74 73 20 24  _data } { puts $
08c0: 78 20 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  x }..#----------
08d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
08e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
08f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0900: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
0910: 72 65 73 65 74 5f 64 62 0a 73 65 74 20 64 6f 63  reset_db.set doc
0920: 20 5b 73 74 72 69 6e 67 20 72 65 70 65 61 74 20   [string repeat 
0930: 22 78 20 79 20 22 20 35 5d 0a 64 6f 5f 65 78 65  "x y " 5].do_exe
0940: 63 73 71 6c 5f 74 65 73 74 20 35 2e 31 20 7b 0a  csql_test 5.1 {.
0950: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
0960: 20 54 41 42 4c 45 20 79 79 20 55 53 49 4e 47 20   TABLE yy USING 
0970: 66 74 73 35 28 63 6f 6e 74 65 6e 74 29 3b 0a 20  fts5(content);. 
0980: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 79 79 28   INSERT INTO yy(
0990: 79 79 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45 53  yy, rank) VALUES
09a0: 28 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a 20 20  ('pgsz', 32);.  
09b0: 42 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53 45 52  BEGIN;.    INSER
09c0: 54 20 49 4e 54 4f 20 79 79 20 56 41 4c 55 45 53  T INTO yy VALUES
09d0: 28 24 64 6f 63 29 3b 0a 20 20 20 20 49 4e 53 45  ($doc);.    INSE
09e0: 52 54 20 49 4e 54 4f 20 79 79 20 56 41 4c 55 45  RT INTO yy VALUE
09f0: 53 28 24 64 6f 63 29 3b 0a 20 20 20 20 49 4e 53  S($doc);.    INS
0a00: 45 52 54 20 49 4e 54 4f 20 79 79 20 56 41 4c 55  ERT INTO yy VALU
0a10: 45 53 28 24 64 6f 63 29 3b 0a 20 20 20 20 49 4e  ES($doc);.    IN
0a20: 53 45 52 54 20 49 4e 54 4f 20 79 79 20 56 41 4c  SERT INTO yy VAL
0a30: 55 45 53 28 24 64 6f 63 29 3b 0a 20 20 20 20 49  UES($doc);.    I
0a40: 4e 53 45 52 54 20 49 4e 54 4f 20 79 79 20 56 41  NSERT INTO yy VA
0a50: 4c 55 45 53 28 24 64 6f 63 29 3b 0a 20 20 20 20  LUES($doc);.    
0a60: 49 4e 53 45 52 54 20 49 4e 54 4f 20 79 79 20 56  INSERT INTO yy V
0a70: 41 4c 55 45 53 28 24 64 6f 63 29 3b 0a 20 20 20  ALUES($doc);.   
0a80: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 79 79 20   INSERT INTO yy 
0a90: 56 41 4c 55 45 53 28 24 64 6f 63 29 3b 0a 20 20  VALUES($doc);.  
0aa0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 79 79    INSERT INTO yy
0ab0: 20 56 41 4c 55 45 53 28 24 64 6f 63 29 3b 0a 20   VALUES($doc);. 
0ac0: 20 43 4f 4d 4d 49 54 3b 0a 7d 0a 0a 64 6f 5f 65   COMMIT;.}..do_e
0ad0: 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 32 20  xecsql_test 5.2 
0ae0: 7b 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64  {.  SELECT rowid
0af0: 20 46 52 4f 4d 20 79 79 20 57 48 45 52 45 20 79   FROM yy WHERE y
0b00: 79 20 4d 41 54 43 48 20 27 79 27 20 4f 52 44 45  y MATCH 'y' ORDE
0b10: 52 20 42 59 20 72 6f 77 69 64 20 41 53 43 0a 7d  R BY rowid ASC.}
0b20: 20 7b 31 20 32 20 33 20 34 20 35 20 36 20 37 20   {1 2 3 4 5 6 7 
0b30: 38 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  8}..do_execsql_t
0b40: 65 73 74 20 35 2e 33 20 7b 0a 20 20 53 45 4c 45  est 5.3 {.  SELE
0b50: 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 79 79  CT rowid FROM yy
0b60: 20 57 48 45 52 45 20 79 79 20 4d 41 54 43 48 20   WHERE yy MATCH 
0b70: 27 79 27 20 4f 52 44 45 52 20 42 59 20 72 6f 77  'y' ORDER BY row
0b80: 69 64 20 44 45 53 43 0a 7d 20 7b 38 20 37 20 36  id DESC.} {8 7 6
0b90: 20 35 20 34 20 33 20 32 20 31 7d 0a 0a 23 64 62   5 4 3 2 1}..#db
0ba0: 20 65 76 61 6c 20 7b 20 53 45 4c 45 43 54 20 66   eval { SELECT f
0bb0: 74 73 35 5f 64 65 63 6f 64 65 28 72 6f 77 69 64  ts5_decode(rowid
0bc0: 2c 20 62 6c 6f 63 6b 29 20 61 73 20 78 20 46 52  , block) as x FR
0bd0: 4f 4d 20 79 79 5f 64 61 74 61 20 7d 20 7b 20 70  OM yy_data } { p
0be0: 75 74 73 20 24 78 20 7d 0a 0a 23 2d 2d 2d 2d 2d  uts $x }..#-----
0bf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0c00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0c10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0c20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0c30: 2d 2d 2d 2d 0a 72 65 73 65 74 5f 64 62 0a 64 6f  ----.reset_db.do
0c40: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e  _execsql_test 5.
0c50: 31 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52  1 {.  CREATE VIR
0c60: 54 55 41 4c 20 54 41 42 4c 45 20 74 74 20 55 53  TUAL TABLE tt US
0c70: 49 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74  ING fts5(content
0c80: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
0c90: 20 74 74 28 74 74 2c 20 72 61 6e 6b 29 20 56 41   tt(tt, rank) VA
0ca0: 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32 29  LUES('pgsz', 32)
0cb0: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
0cc0: 74 74 20 56 41 4c 55 45 53 28 27 61 61 27 29 3b  tt VALUES('aa');
0cd0: 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  .}..do_execsql_t
0ce0: 65 73 74 20 35 2e 32 20 7b 0a 20 20 53 45 4c 45  est 5.2 {.  SELE
0cf0: 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 74 74  CT rowid FROM tt
0d00: 20 57 48 45 52 45 20 74 74 20 4d 41 54 43 48 20   WHERE tt MATCH 
0d10: 27 61 2a 27 3b 0a 7d 20 7b 31 7d 0a 0a 64 6f 5f  'a*';.} {1}..do_
0d20: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 33  execsql_test 5.3
0d30: 20 7b 0a 20 20 44 45 4c 45 54 45 20 46 52 4f 4d   {.  DELETE FROM
0d40: 20 74 74 3b 0a 20 20 42 45 47 49 4e 3b 0a 20 20   tt;.  BEGIN;.  
0d50: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74    INSERT INTO tt
0d60: 20 56 41 4c 55 45 53 28 27 61 61 27 29 3b 0a 20   VALUES('aa');. 
0d70: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
0d80: 74 20 56 41 4c 55 45 53 28 27 61 62 27 29 3b 0a  t VALUES('ab');.
0d90: 20 20 43 4f 4d 4d 49 54 3b 0a 7d 20 7b 7d 0a 0a    COMMIT;.} {}..
0da0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
0db0: 35 2e 34 20 7b 0a 20 20 53 45 4c 45 43 54 20 72  5.4 {.  SELECT r
0dc0: 6f 77 69 64 20 46 52 4f 4d 20 74 74 20 57 48 45  owid FROM tt WHE
0dd0: 52 45 20 74 74 20 4d 41 54 43 48 20 27 61 2a 27  RE tt MATCH 'a*'
0de0: 3b 0a 7d 20 7b 31 20 32 7d 0a 0a 64 6f 5f 65 78  ;.} {1 2}..do_ex
0df0: 65 63 73 71 6c 5f 74 65 73 74 20 35 2e 35 20 7b  ecsql_test 5.5 {
0e00: 0a 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74  .  DELETE FROM t
0e10: 74 3b 0a 20 20 42 45 47 49 4e 3b 0a 20 20 20 20  t;.  BEGIN;.    
0e20: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 20 56  INSERT INTO tt V
0e30: 41 4c 55 45 53 28 27 61 61 27 29 3b 0a 20 20 20  ALUES('aa');.   
0e40: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 20   INSERT INTO tt 
0e50: 56 41 4c 55 45 53 28 27 61 62 27 29 3b 0a 20 20  VALUES('ab');.  
0e60: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74    INSERT INTO tt
0e70: 20 56 41 4c 55 45 53 28 27 61 61 27 29 3b 0a 20   VALUES('aa');. 
0e80: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
0e90: 74 20 56 41 4c 55 45 53 28 27 61 62 27 29 3b 0a  t VALUES('ab');.
0ea0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
0eb0: 74 74 20 56 41 4c 55 45 53 28 27 61 61 27 29 3b  tt VALUES('aa');
0ec0: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
0ed0: 20 74 74 20 56 41 4c 55 45 53 28 27 61 62 27 29   tt VALUES('ab')
0ee0: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
0ef0: 4f 20 74 74 20 56 41 4c 55 45 53 28 27 61 61 27  O tt VALUES('aa'
0f00: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
0f10: 54 4f 20 74 74 20 56 41 4c 55 45 53 28 27 61 62  TO tt VALUES('ab
0f20: 27 29 3b 0a 20 20 43 4f 4d 4d 49 54 3b 0a 20 20  ');.  COMMIT;.  
0f30: 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f  SELECT rowid FRO
0f40: 4d 20 74 74 20 57 48 45 52 45 20 74 74 20 4d 41  M tt WHERE tt MA
0f50: 54 43 48 20 27 61 2a 27 3b 0a 7d 20 7b 31 20 32  TCH 'a*';.} {1 2
0f60: 20 33 20 34 20 35 20 36 20 37 20 38 7d 0a 0a 64   3 4 5 6 7 8}..d
0f70: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 35  o_execsql_test 5
0f80: 2e 36 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e  .6 {.  INSERT IN
0f90: 54 4f 20 74 74 28 74 74 29 20 56 41 4c 55 45 53  TO tt(tt) VALUES
0fa0: 28 27 69 6e 74 65 67 72 69 74 79 2d 63 68 65 63  ('integrity-chec
0fb0: 6b 27 29 3b 0a 7d 0a 0a 72 65 73 65 74 5f 64 62  k');.}..reset_db
0fc0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
0fd0: 20 35 2e 37 20 7b 0a 20 20 43 52 45 41 54 45 20   5.7 {.  CREATE 
0fe0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 74  VIRTUAL TABLE tt
0ff0: 20 55 53 49 4e 47 20 66 74 73 35 28 63 6f 6e 74   USING fts5(cont
1000: 65 6e 74 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  ent);.  INSERT I
1010: 4e 54 4f 20 74 74 28 74 74 2c 20 72 61 6e 6b 29  NTO tt(tt, rank)
1020: 20 56 41 4c 55 45 53 28 27 70 67 73 7a 27 2c 20   VALUES('pgsz', 
1030: 33 32 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  32);.  INSERT IN
1040: 54 4f 20 74 74 20 56 41 4c 55 45 53 28 27 61 61  TO tt VALUES('aa
1050: 20 61 62 20 61 63 20 61 64 20 61 65 20 61 66 27   ab ac ad ae af'
1060: 29 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  );.}..do_execsql
1070: 5f 74 65 73 74 20 35 2e 38 20 7b 0a 20 20 53 45  _test 5.8 {.  SE
1080: 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20  LECT rowid FROM 
1090: 74 74 20 57 48 45 52 45 20 74 74 20 4d 41 54 43  tt WHERE tt MATC
10a0: 48 20 27 61 2a 27 3b 0a 7d 20 7b 31 7d 0a 0a 23  H 'a*';.} {1}..#
10b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
10d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 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 0a 0a 72 65 73 65 74  ---------..reset
1100: 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  _db.do_execsql_t
1110: 65 73 74 20 36 2e 31 20 7b 0a 20 20 43 52 45 41  est 6.1 {.  CREA
1120: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
1130: 20 78 79 7a 20 55 53 49 4e 47 20 66 74 73 35 28   xyz USING fts5(
1140: 78 2c 20 79 2c 20 7a 29 3b 0a 20 20 49 4e 53 45  x, y, z);.  INSE
1150: 52 54 20 49 4e 54 4f 20 78 79 7a 20 56 41 4c 55  RT INTO xyz VALU
1160: 45 53 28 27 78 27 2c 20 27 79 27 2c 20 27 7a 27  ES('x', 'y', 'z'
1170: 29 3b 0a 7d 0a 0a 64 6f 5f 63 61 74 63 68 73 71  );.}..do_catchsq
1180: 6c 5f 74 65 73 74 20 36 2e 32 20 7b 20 0a 20 20  l_test 6.2 { .  
1190: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 78 79  SELECT * FROM xy
11a0: 7a 20 57 48 45 52 45 20 78 79 7a 20 4d 41 54 43  z WHERE xyz MATC
11b0: 48 20 27 27 20 0a 7d 20 7b 31 20 7b 66 74 73 35  H '' .} {1 {fts5
11c0: 3a 20 73 79 6e 74 61 78 20 65 72 72 6f 72 20 6e  : syntax error n
11d0: 65 61 72 20 22 22 7d 7d 0a 64 6f 5f 63 61 74 63  ear ""}}.do_catc
11e0: 68 73 71 6c 5f 74 65 73 74 20 36 2e 33 20 7b 20  hsql_test 6.3 { 
11f0: 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d  .  SELECT * FROM
1200: 20 78 79 7a 20 57 48 45 52 45 20 78 79 7a 20 4d   xyz WHERE xyz M
1210: 41 54 43 48 20 4e 55 4c 4c 20 0a 7d 20 7b 31 20  ATCH NULL .} {1 
1220: 7b 66 74 73 35 3a 20 73 79 6e 74 61 78 20 65 72  {fts5: syntax er
1230: 72 6f 72 20 6e 65 61 72 20 22 22 7d 7d 0a 0a 23  ror near ""}}..#
1240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1260: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1270: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1280: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 64 6f 5f 65 78  ---------..do_ex
1290: 65 63 73 71 6c 5f 74 65 73 74 20 37 2e 31 20 7b  ecsql_test 7.1 {
12a0: 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41  .  CREATE VIRTUA
12b0: 4c 20 54 41 42 4c 45 20 66 74 32 20 55 53 49 4e  L TABLE ft2 USIN
12c0: 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29 3b  G fts5(content);
12d0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 66  .  INSERT INTO f
12e0: 74 32 28 72 6f 77 69 64 2c 20 63 6f 6e 74 65 6e  t2(rowid, conten
12f0: 74 29 20 56 41 4c 55 45 53 28 31 2c 20 27 61 20  t) VALUES(1, 'a 
1300: 62 20 63 27 29 3b 0a 20 20 49 4e 53 45 52 54 20  b c');.  INSERT 
1310: 49 4e 54 4f 20 66 74 32 28 72 6f 77 69 64 2c 20  INTO ft2(rowid, 
1320: 63 6f 6e 74 65 6e 74 29 20 56 41 4c 55 45 53 28  content) VALUES(
1330: 32 2c 20 27 61 20 62 20 64 27 29 3b 0a 7d 20 0a  2, 'a b d');.} .
1340: 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73  .do_catchsql_tes
1350: 74 20 37 2e 32 20 7b 0a 20 20 42 45 47 49 4e 3b  t 7.2 {.  BEGIN;
1360: 0a 20 20 20 20 55 50 44 41 54 45 20 66 74 32 20  .    UPDATE ft2 
1370: 53 45 54 20 72 6f 77 69 64 3d 32 20 57 48 45 52  SET rowid=2 WHER
1380: 45 20 72 6f 77 69 64 3d 31 3b 0a 7d 20 7b 31 20  E rowid=1;.} {1 
1390: 7b 63 6f 6e 73 74 72 61 69 6e 74 20 66 61 69 6c  {constraint fail
13a0: 65 64 7d 7d 20 0a 0a 64 6f 5f 65 78 65 63 73 71  ed}} ..do_execsq
13b0: 6c 5f 74 65 73 74 20 37 2e 33 20 7b 0a 20 20 43  l_test 7.3 {.  C
13c0: 4f 4d 4d 49 54 3b 0a 20 20 49 4e 53 45 52 54 20  OMMIT;.  INSERT 
13d0: 49 4e 54 4f 20 66 74 32 28 66 74 32 29 20 56 41  INTO ft2(ft2) VA
13e0: 4c 55 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d  LUES('integrity-
13f0: 63 68 65 63 6b 27 29 3b 0a 7d 20 7b 7d 0a 0a 64  check');.} {}..d
1400: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 37  o_execsql_test 7
1410: 2e 34 20 7b 0a 20 20 53 45 4c 45 43 54 20 2a 20  .4 {.  SELECT * 
1420: 46 52 4f 4d 20 66 74 32 3b 0a 7d 20 7b 7b 61 20  FROM ft2;.} {{a 
1430: 62 20 63 7d 20 7b 61 20 62 20 64 7d 7d 0a 0a 23  b c} {a b d}}..#
1440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1450: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1460: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1470: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1480: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 72 65 73 65  ---------.#.rese
1490: 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  t_db.do_execsql_
14a0: 74 65 73 74 20 38 2e 31 20 7b 0a 20 20 43 52 45  test 8.1 {.  CRE
14b0: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
14c0: 45 20 66 74 32 20 55 53 49 4e 47 20 66 74 73 35  E ft2 USING fts5
14d0: 28 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 49 4e 53  (content);.  INS
14e0: 45 52 54 20 49 4e 54 4f 20 66 74 32 28 72 6f 77  ERT INTO ft2(row
14f0: 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20 56 41 4c  id, content) VAL
1500: 55 45 53 28 31 2c 20 27 61 20 62 27 29 3b 0a 7d  UES(1, 'a b');.}
1510: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
1520: 74 20 38 2e 32 20 7b 0a 20 20 42 45 47 49 4e 3b  t 8.2 {.  BEGIN;
1530: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
1540: 20 66 74 32 28 72 6f 77 69 64 2c 20 63 6f 6e 74   ft2(rowid, cont
1550: 65 6e 74 29 20 56 41 4c 55 45 53 28 34 2c 20 27  ent) VALUES(4, '
1560: 61 20 78 27 29 3b 0a 7d 0a 0a 64 6f 5f 65 78 65  a x');.}..do_exe
1570: 63 73 71 6c 5f 74 65 73 74 20 38 2e 33 20 7b 0a  csql_test 8.3 {.
1580: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 66 74    INSERT INTO ft
1590: 32 28 66 74 32 29 20 56 41 4c 55 45 53 28 27 69  2(ft2) VALUES('i
15a0: 6e 74 65 67 72 69 74 79 2d 63 68 65 63 6b 27 29  ntegrity-check')
15b0: 3b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ;.}..#----------
15c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
15d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
15e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
15f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
1600: 23 20 43 68 65 63 6b 20 74 68 61 74 20 74 68 65  # Check that the
1610: 20 22 74 61 62 6c 65 20 66 75 6e 63 74 69 6f 6e   "table function
1620: 22 20 73 79 6e 74 61 78 20 77 6f 72 6b 73 2e 0a  " syntax works..
1630: 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78  #.reset_db.do_ex
1640: 65 63 73 71 6c 5f 74 65 73 74 20 39 2e 31 20 7b  ecsql_test 9.1 {
1650: 0a 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41  .  CREATE VIRTUA
1660: 4c 20 54 41 42 4c 45 20 66 74 32 20 55 53 49 4e  L TABLE ft2 USIN
1670: 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29 3b  G fts5(content);
1680: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 66  .  INSERT INTO f
1690: 74 32 28 72 6f 77 69 64 2c 20 63 6f 6e 74 65 6e  t2(rowid, conten
16a0: 74 29 20 56 41 4c 55 45 53 28 31 2c 20 27 61 20  t) VALUES(1, 'a 
16b0: 62 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  b');.  INSERT IN
16c0: 54 4f 20 66 74 32 28 72 6f 77 69 64 2c 20 63 6f  TO ft2(rowid, co
16d0: 6e 74 65 6e 74 29 20 56 41 4c 55 45 53 28 32 2c  ntent) VALUES(2,
16e0: 20 27 61 20 62 20 63 20 64 27 29 3b 0a 20 20 49   'a b c d');.  I
16f0: 4e 53 45 52 54 20 49 4e 54 4f 20 66 74 32 28 72  NSERT INTO ft2(r
1700: 6f 77 69 64 2c 20 63 6f 6e 74 65 6e 74 29 20 56  owid, content) V
1710: 41 4c 55 45 53 28 33 2c 20 27 63 20 64 20 65 20  ALUES(3, 'c d e 
1720: 66 27 29 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73  f');.}..do_execs
1730: 71 6c 5f 74 65 73 74 20 39 2e 32 20 7b 0a 20 20  ql_test 9.2 {.  
1740: 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f  SELECT rowid FRO
1750: 4d 20 66 74 32 28 27 61 27 29 3b 0a 7d 20 7b 31  M ft2('a');.} {1
1760: 20 32 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f   2}..do_execsql_
1770: 74 65 73 74 20 39 2e 33 20 7b 0a 20 20 53 45 4c  test 9.3 {.  SEL
1780: 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 66  ECT rowid FROM f
1790: 74 32 28 27 62 20 41 4e 44 20 63 27 29 3b 0a 7d  t2('b AND c');.}
17a0: 20 7b 32 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d   {2}..#---------
17b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
17f0: 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  .#.do_execsql_te
1800: 73 74 20 31 30 2e 30 20 7b 0a 20 20 43 52 45 41  st 10.0 {.  CREA
1810: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
1820: 20 74 33 20 55 53 49 4e 47 20 66 74 73 35 28 61   t3 USING fts5(a
1830: 2c 20 62 2c 20 63 29 3b 0a 20 20 49 4e 53 45 52  , b, c);.  INSER
1840: 54 20 49 4e 54 4f 20 74 33 20 56 41 4c 55 45 53  T INTO t3 VALUES
1850: 28 27 62 61 63 20 61 61 62 20 62 61 62 27 2c 20  ('bac aab bab', 
1860: 27 63 20 62 61 63 20 63 27 2c 20 27 61 63 62 20  'c bac c', 'acb 
1870: 61 62 61 20 61 62 62 27 29 3b 20 2d 2d 20 31 0a  aba abb'); -- 1.
1880: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 33    INSERT INTO t3
1890: 20 56 41 4c 55 45 53 28 27 62 61 62 20 61 62 63   VALUES('bab abc
18a0: 20 63 27 2c 20 27 61 63 62 20 63 20 61 62 62 27   c', 'acb c abb'
18b0: 2c 20 27 63 20 61 61 61 20 63 27 29 3b 20 20 20  , 'c aaa c');   
18c0: 20 20 2d 2d 20 32 0a 7d 0a 0a 64 6f 5f 65 78 65    -- 2.}..do_exe
18d0: 63 73 71 6c 5f 74 65 73 74 20 31 30 2e 31 20 7b  csql_test 10.1 {
18e0: 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20  .  SELECT rowid 
18f0: 46 52 4f 4d 20 74 33 28 27 63 3a 20 63 2a 27 29  FROM t3('c: c*')
1900: 3b 0a 7d 20 7b 32 7d 0a 0a 64 6f 5f 65 78 65 63  ;.} {2}..do_exec
1910: 73 71 6c 5f 74 65 73 74 20 31 30 2e 32 20 7b 0a  sql_test 10.2 {.
1920: 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46    SELECT rowid F
1930: 52 4f 4d 20 74 33 28 27 62 3a 20 61 63 62 27 29  ROM t3('b: acb')
1940: 3b 0a 7d 20 7b 32 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  ;.} {2}..#------
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 2d 2d 2d 2d 2d 2d 2d  ----------------
1980: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1990: 2d 2d 2d 0a 23 20 54 65 73 74 20 74 68 61 74 20  ---.# Test that 
19a0: 63 68 61 72 61 63 74 65 72 20 30 78 31 41 20 69  character 0x1A i
19b0: 73 20 61 6c 6c 6f 77 65 64 20 69 6e 20 66 74 73  s allowed in fts
19c0: 35 20 62 61 72 65 77 6f 72 64 73 2e 0a 23 0a 64  5 barewords..#.d
19d0: 6f 5f 74 65 73 74 20 31 31 2e 30 20 7b 0a 20 20  o_test 11.0 {.  
19e0: 65 78 65 63 73 71 6c 20 22 43 52 45 41 54 45 20  execsql "CREATE 
19f0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 34  VIRTUAL TABLE t4
1a00: 20 55 53 49 4e 47 20 66 74 73 35 28 78 2c 20 74   USING fts5(x, t
1a10: 6f 6b 65 6e 69 7a 65 3d 5c 22 61 73 63 69 69 20  okenize=\"ascii 
1a20: 74 6f 6b 65 6e 63 68 61 72 73 20 27 5c 78 31 41  tokenchars '\x1A
1a30: 27 5c 22 29 22 0a 20 20 65 78 65 63 73 71 6c 20  '\")".  execsql 
1a40: 22 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ".    INSERT INT
1a50: 4f 20 74 34 20 56 41 4c 55 45 53 28 27 61 20 62  O t4 VALUES('a b
1a60: 20 63 20 5c 78 31 41 27 29 3b 0a 20 20 20 20 49   c \x1A');.    I
1a70: 4e 53 45 52 54 20 49 4e 54 4f 20 74 34 20 56 41  NSERT INTO t4 VA
1a80: 4c 55 45 53 28 27 61 20 62 20 63 20 64 5c 78 31  LUES('a b c d\x1
1a90: 41 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20  A');.    INSERT 
1aa0: 49 4e 54 4f 20 74 34 20 56 41 4c 55 45 53 28 27  INTO t4 VALUES('
1ab0: 61 20 62 20 63 20 5c 78 31 41 64 27 29 3b 0a 20  a b c \x1Ad');. 
1ac0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
1ad0: 34 20 56 41 4c 55 45 53 28 27 61 20 62 20 63 20  4 VALUES('a b c 
1ae0: 64 27 29 3b 0a 20 20 22 0a 7d 20 7b 7d 0a 0a 64  d');.  ".} {}..d
1af0: 6f 5f 74 65 73 74 20 31 31 2e 31 20 7b 0a 20 20  o_test 11.1 {.  
1b00: 65 78 65 63 73 71 6c 20 22 53 45 4c 45 43 54 20  execsql "SELECT 
1b10: 72 6f 77 69 64 20 46 52 4f 4d 20 74 34 28 27 5c  rowid FROM t4('\
1b20: 78 31 41 27 29 22 0a 7d 20 7b 31 7d 0a 64 6f 5f  x1A')".} {1}.do_
1b30: 74 65 73 74 20 31 31 2e 32 20 7b 0a 20 20 65 78  test 11.2 {.  ex
1b40: 65 63 73 71 6c 20 22 53 45 4c 45 43 54 20 72 6f  ecsql "SELECT ro
1b50: 77 69 64 20 46 52 4f 4d 20 74 34 28 27 5c 78 31  wid FROM t4('\x1
1b60: 41 2a 27 29 22 0a 7d 20 7b 31 20 33 7d 0a 64 6f  A*')".} {1 3}.do
1b70: 5f 74 65 73 74 20 31 31 2e 33 20 7b 0a 20 20 65  _test 11.3 {.  e
1b80: 78 65 63 73 71 6c 20 22 53 45 4c 45 43 54 20 72  xecsql "SELECT r
1b90: 6f 77 69 64 20 46 52 4f 4d 20 74 34 28 27 64 5c  owid FROM t4('d\
1ba0: 78 31 41 27 29 22 0a 7d 20 7b 32 7d 0a 0a 64 6f  x1A')".} {2}..do
1bb0: 5f 74 65 73 74 20 31 31 2e 34 20 7b 0a 20 20 63  _test 11.4 {.  c
1bc0: 61 74 63 68 73 71 6c 20 22 53 45 4c 45 43 54 20  atchsql "SELECT 
1bd0: 72 6f 77 69 64 20 46 52 4f 4d 20 74 34 28 27 64  rowid FROM t4('d
1be0: 5c 78 31 42 27 29 22 0a 7d 20 7b 2f 66 74 73 35  \x1B')".} {/fts5
1bf0: 3a 20 73 79 6e 74 61 78 20 65 72 72 6f 72 2f 7d  : syntax error/}
1c00: 0a 64 6f 5f 74 65 73 74 20 31 31 2e 35 20 7b 0a  .do_test 11.5 {.
1c10: 20 20 63 61 74 63 68 73 71 6c 20 22 53 45 4c 45    catchsql "SELE
1c20: 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 74 34  CT rowid FROM t4
1c30: 28 27 64 5c 78 31 39 27 29 22 0a 7d 20 7b 2f 66  ('d\x19')".} {/f
1c40: 74 73 35 3a 20 73 79 6e 74 61 78 20 65 72 72 6f  ts5: syntax erro
1c50: 72 2f 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  r/}..#----------
1c60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1c70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1c80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1c90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
1ca0: 23 0a 64 6f 5f 74 65 73 74 20 31 32 2e 31 20 7b  #.do_test 12.1 {
1cb0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
1cc0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
1cd0: 54 41 42 4c 45 20 78 78 20 55 53 49 4e 47 20 66  TABLE xx USING f
1ce0: 74 73 35 28 78 2c 79 29 3b 0a 20 20 20 20 42 45  ts5(x,y);.    BE
1cf0: 47 49 4e 3b 0a 20 20 20 20 20 20 49 4e 53 45 52  GIN;.      INSER
1d00: 54 20 49 4e 54 4f 20 78 78 20 56 41 4c 55 45 53  T INTO xx VALUES
1d10: 28 27 31 20 32 20 33 27 2c 20 27 61 20 62 20 63  ('1 2 3', 'a b c
1d20: 27 29 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 64 6f  ');.  }.} {}..do
1d30: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 32  _execsql_test 12
1d40: 2e 32 20 7b 0a 20 20 53 45 4c 45 43 54 20 72 6f  .2 {.  SELECT ro
1d50: 77 69 64 20 46 52 4f 4d 20 78 78 28 27 78 3a 61  wid FROM xx('x:a
1d60: 27 29 3b 0a 20 20 43 4f 4d 4d 49 54 3b 0a 7d 20  ');.  COMMIT;.} 
1d70: 7b 7d 0a 0a 23 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 2d 2d  ----------------
1da0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1db0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
1dc0: 20 54 72 79 20 61 6e 20 55 50 44 41 54 45 20 4f   Try an UPDATE O
1dd0: 52 20 52 45 50 4c 41 43 45 20 71 75 65 72 79 2e  R REPLACE query.
1de0: 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  .#.do_execsql_te
1df0: 73 74 20 31 33 2e 31 20 7b 0a 20 20 43 52 45 41  st 13.1 {.  CREA
1e00: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
1e10: 20 78 79 20 55 53 49 4e 47 20 66 74 73 35 28 78   xy USING fts5(x
1e20: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
1e30: 20 78 79 28 72 6f 77 69 64 2c 20 78 29 20 56 41   xy(rowid, x) VA
1e40: 4c 55 45 53 28 31 2c 20 27 31 20 32 20 33 27 29  LUES(1, '1 2 3')
1e50: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
1e60: 78 79 28 72 6f 77 69 64 2c 20 78 29 20 56 41 4c  xy(rowid, x) VAL
1e70: 55 45 53 28 32 2c 20 27 32 20 33 20 34 27 29 3b  UES(2, '2 3 4');
1e80: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78  .  INSERT INTO x
1e90: 79 28 72 6f 77 69 64 2c 20 78 29 20 56 41 4c 55  y(rowid, x) VALU
1ea0: 45 53 28 33 2c 20 27 33 20 34 20 35 27 29 3b 0a  ES(3, '3 4 5');.
1eb0: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
1ec0: 73 74 20 31 33 2e 32 20 7b 0a 20 20 55 50 44 41  st 13.2 {.  UPDA
1ed0: 54 45 20 4f 52 20 52 45 50 4c 41 43 45 20 78 79  TE OR REPLACE xy
1ee0: 20 53 45 54 20 72 6f 77 69 64 3d 33 20 57 48 45   SET rowid=3 WHE
1ef0: 52 45 20 72 6f 77 69 64 20 3d 20 32 3b 0a 20 20  RE rowid = 2;.  
1f00: 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 78 20  SELECT rowid, x 
1f10: 46 52 4f 4d 20 78 79 3b 0a 7d 20 7b 0a 20 20 31  FROM xy;.} {.  1
1f20: 20 7b 31 20 32 20 33 7d 0a 20 20 33 20 7b 32 20   {1 2 3}.  3 {2 
1f30: 33 20 34 7d 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73  3 4}.}..do_execs
1f40: 71 6c 5f 74 65 73 74 20 31 33 2e 33 20 7b 0a 20  ql_test 13.3 {. 
1f50: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 79 28   INSERT INTO xy(
1f60: 78 79 29 20 56 41 4c 55 45 53 28 27 69 6e 74 65  xy) VALUES('inte
1f70: 67 72 69 74 79 2d 63 68 65 63 6b 27 29 3b 0a 7d  grity-check');.}
1f80: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
1f90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1fa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1fb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1fc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 0a 64  ------------.#.d
1fd0: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31  o_execsql_test 1
1fe0: 34 2e 31 20 7b 0a 20 20 43 52 45 41 54 45 20 56  4.1 {.  CREATE V
1ff0: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 74 74  IRTUAL TABLE ttt
2000: 20 55 53 49 4e 47 20 66 74 73 35 28 78 29 3b 0a   USING fts5(x);.
2010: 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53    BEGIN;.    INS
2020: 45 52 54 20 49 4e 54 4f 20 74 74 74 28 72 6f 77  ERT INTO ttt(row
2030: 69 64 2c 20 78 29 20 56 41 4c 55 45 53 28 31 2c  id, x) VALUES(1,
2040: 20 27 61 20 62 20 63 27 29 3b 0a 20 20 20 20 49   'a b c');.    I
2050: 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 74 28 72  NSERT INTO ttt(r
2060: 6f 77 69 64 2c 20 78 29 20 56 41 4c 55 45 53 28  owid, x) VALUES(
2070: 32 2c 20 27 61 20 62 20 63 27 29 3b 0a 20 20 20  2, 'a b c');.   
2080: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 74   INSERT INTO ttt
2090: 28 72 6f 77 69 64 2c 20 78 29 20 56 41 4c 55 45  (rowid, x) VALUE
20a0: 53 28 33 2c 20 27 61 20 62 20 63 27 29 3b 0a 20  S(3, 'a b c');. 
20b0: 20 43 4f 4d 4d 49 54 3b 0a 7d 0a 64 6f 5f 74 65   COMMIT;.}.do_te
20c0: 73 74 20 31 34 2e 32 20 7b 20 0a 20 20 66 74 73  st 14.2 { .  fts
20d0: 35 5f 6c 65 76 65 6c 5f 73 65 67 73 20 74 74 74  5_level_segs ttt
20e0: 20 0a 7d 20 7b 31 7d 0a 0a 23 2d 2d 2d 2d 2d 2d   .} {1}..#------
20f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2100: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2110: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2130: 2d 2d 2d 0a 64 62 20 66 75 6e 63 20 72 6e 64 64  ---.db func rndd
2140: 6f 63 20 66 74 73 35 5f 72 6e 64 64 6f 63 0a 64  oc fts5_rnddoc.d
2150: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 34  o_execsql_test 4
2160: 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49  .0 {.  CREATE VI
2170: 52 54 55 41 4c 20 54 41 42 4c 45 20 78 31 20 55  RTUAL TABLE x1 U
2180: 53 49 4e 47 20 66 74 73 35 28 78 29 3b 0a 20 20  SING fts5(x);.  
2190: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 31 28 78  INSERT INTO x1(x
21a0: 31 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45 53 28  1, rank) VALUES(
21b0: 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a 0a 20 20  'pgsz', 32);..  
21c0: 57 49 54 48 20 69 69 28 69 29 20 41 53 20 28 20  WITH ii(i) AS ( 
21d0: 53 45 4c 45 43 54 20 31 20 55 4e 49 4f 4e 20 41  SELECT 1 UNION A
21e0: 4c 4c 20 53 45 4c 45 43 54 20 69 2b 31 20 46 52  LL SELECT i+1 FR
21f0: 4f 4d 20 69 69 20 57 48 45 52 45 20 69 3c 31 30  OM ii WHERE i<10
2200: 20 29 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   ).  INSERT INTO
2210: 20 78 31 20 53 45 4c 45 43 54 20 72 6e 64 64 6f   x1 SELECT rnddo
2220: 63 28 35 29 20 46 52 4f 4d 20 69 69 3b 0a 7d 0a  c(5) FROM ii;.}.
2230: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
2240: 20 34 2e 31 20 7b 0a 20 20 53 45 4c 45 43 54 20   4.1 {.  SELECT 
2250: 72 6f 77 69 64 2c 20 78 2c 20 78 31 20 46 52 4f  rowid, x, x1 FRO
2260: 4d 20 78 31 20 57 48 45 52 45 20 78 31 20 4d 41  M x1 WHERE x1 MA
2270: 54 43 48 20 27 2a 72 65 61 64 73 27 0a 7d 20 7b  TCH '*reads'.} {
2280: 30 20 7b 7d 20 34 7d 0a 0a 0a 66 69 6e 69 73 68  0 {} 4}...finish
2290: 5f 74 65 73 74 0a 0a                             _test..