/ Hex Artifact Content
Login

Artifact 54cf1f98c72abee246447cd688590898c9ecbaf7:


0000: 23 20 32 30 30 39 20 44 65 63 65 6d 62 65 72 20  # 2009 December 
0010: 30 33 0a 23 0a 23 20 20 20 20 4d 61 79 20 79 6f  03.#.#    May yo
0020: 75 20 64 6f 20 67 6f 6f 64 20 61 6e 64 20 6e 6f  u do good and no
0030: 74 20 65 76 69 6c 2e 0a 23 20 20 20 20 4d 61 79  t evil..#    May
0040: 20 79 6f 75 20 66 69 6e 64 20 66 6f 72 67 69 76   you find forgiv
0050: 65 6e 65 73 73 20 66 6f 72 20 79 6f 75 72 73 65  eness for yourse
0060: 6c 66 20 61 6e 64 20 66 6f 72 67 69 76 65 20 6f  lf and forgive o
0070: 74 68 65 72 73 2e 0a 23 20 20 20 20 4d 61 79 20  thers..#    May 
0080: 79 6f 75 20 73 68 61 72 65 20 66 72 65 65 6c 79  you share freely
0090: 2c 20 6e 65 76 65 72 20 74 61 6b 69 6e 67 20 6d  , never taking m
00a0: 6f 72 65 20 74 68 61 6e 20 79 6f 75 20 67 69 76  ore than you giv
00b0: 65 2e 0a 23 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  e..#.#**********
00c0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
00d0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
00e0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
00f0: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 0a  *************.#.
0100: 23 20 54 68 65 20 74 65 73 74 73 20 69 6e 20 74  # The tests in t
0110: 68 69 73 20 66 69 6c 65 20 61 72 65 20 73 74 72  his file are str
0120: 75 63 74 75 72 61 6c 20 63 6f 76 65 72 61 67 65  uctural coverage
0130: 20 74 65 73 74 73 20 66 6f 72 20 46 54 53 33 2e   tests for FTS3.
0140: 0a 23 0a 0a 73 65 74 20 74 65 73 74 64 69 72 20  .#..set testdir 
0150: 5b 66 69 6c 65 20 64 69 72 6e 61 6d 65 20 24 61  [file dirname $a
0160: 72 67 76 30 5d 0a 73 6f 75 72 63 65 20 24 74 65  rgv0].source $te
0170: 73 74 64 69 72 2f 74 65 73 74 65 72 2e 74 63 6c  stdir/tester.tcl
0180: 0a 0a 23 20 49 66 20 74 68 69 73 20 62 75 69 6c  ..# If this buil
0190: 64 20 64 6f 65 73 20 6e 6f 74 20 69 6e 63 6c 75  d does not inclu
01a0: 64 65 20 46 54 53 33 2c 20 73 6b 69 70 20 74 68  de FTS3, skip th
01b0: 65 20 74 65 73 74 73 20 69 6e 20 74 68 69 73 20  e tests in this 
01c0: 66 69 6c 65 2e 0a 23 0a 69 66 63 61 70 61 62 6c  file..#.ifcapabl
01d0: 65 20 21 66 74 73 33 20 7b 20 66 69 6e 69 73 68  e !fts3 { finish
01e0: 5f 74 65 73 74 20 3b 20 72 65 74 75 72 6e 20 7d  _test ; return }
01f0: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72  .source $testdir
0200: 2f 66 74 73 33 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c  /fts3_common.tcl
0210: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72  .source $testdir
0220: 2f 6d 61 6c 6c 6f 63 5f 63 6f 6d 6d 6f 6e 2e 74  /malloc_common.t
0230: 63 6c 0a 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f  cl..set DO_MALLO
0240: 43 5f 54 45 53 54 20 30 0a 0a 23 2d 2d 2d 2d 2d  C_TEST 0..#-----
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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0280: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0290: 2d 2d 2d 2d 2d 0a 23 20 57 68 65 6e 20 69 74 20  -----.# When it 
02a0: 66 69 72 73 74 20 6e 65 65 64 73 20 74 6f 20 72  first needs to r
02b0: 65 61 64 20 61 20 62 6c 6f 63 6b 20 66 72 6f 6d  ead a block from
02c0: 20 74 68 65 20 25 5f 73 65 67 6d 65 6e 74 73 20   the %_segments 
02d0: 74 61 62 6c 65 2c 20 74 68 65 20 46 54 53 33 20  table, the FTS3 
02e0: 0a 23 20 6d 6f 64 75 6c 65 20 63 6f 6d 70 69 6c  .# module compil
02f0: 65 73 20 61 6e 20 53 51 4c 20 73 74 61 74 65 6d  es an SQL statem
0300: 65 6e 74 20 66 6f 72 20 74 68 61 74 20 70 75 72  ent for that pur
0310: 70 6f 73 65 2e 20 54 68 65 20 73 74 61 74 65 6d  pose. The statem
0320: 65 6e 74 20 69 73 20 0a 23 20 73 74 6f 72 65 64  ent is .# stored
0330: 20 61 6e 64 20 72 65 75 73 65 64 20 65 61 63 68   and reused each
0340: 20 73 75 62 73 65 71 75 65 6e 74 20 74 69 6d 65   subsequent time
0350: 20 61 20 62 6c 6f 63 6b 20 69 73 20 72 65 61 64   a block is read
0360: 2e 20 54 68 69 73 20 74 65 73 74 20 63 61 73 65  . This test case
0370: 20 0a 23 20 74 65 73 74 73 20 74 68 65 20 65 66   .# tests the ef
0380: 66 65 63 74 73 20 6f 66 20 61 6e 20 4f 4f 4d 20  fects of an OOM 
0390: 65 72 72 6f 72 20 6f 63 63 75 72 69 6e 67 20 77  error occuring w
03a0: 68 69 6c 65 20 63 6f 6d 70 69 6c 69 6e 67 20 74  hile compiling t
03b0: 68 65 20 73 74 61 74 65 6d 65 6e 74 2e 0a 23 0a  he statement..#.
03c0: 23 20 53 69 6d 69 6c 61 72 6c 79 2c 20 77 68 65  # Similarly, whe
03d0: 6e 20 46 54 53 33 20 66 69 72 73 74 20 6e 65 65  n FTS3 first nee
03e0: 64 73 20 74 6f 20 73 63 61 6e 20 74 68 72 6f 75  ds to scan throu
03f0: 67 68 20 61 20 73 65 74 20 6f 66 20 73 65 67 6d  gh a set of segm
0400: 65 6e 74 20 6c 65 61 76 65 73 0a 23 20 74 6f 20  ent leaves.# to 
0410: 66 69 6e 64 20 61 20 73 65 74 20 6f 66 20 64 6f  find a set of do
0420: 63 75 6d 65 6e 74 73 20 74 68 61 74 20 6d 61 74  cuments that mat
0430: 63 68 65 73 20 61 20 74 65 72 6d 2c 20 69 74 20  ches a term, it 
0440: 61 6c 6c 6f 63 61 74 65 73 20 61 20 73 74 72 69  allocates a stri
0450: 6e 67 0a 23 20 63 6f 6e 74 61 69 6e 69 6e 67 20  ng.# containing 
0460: 74 68 65 20 74 65 78 74 20 6f 66 20 74 68 65 20  the text of the 
0470: 72 65 71 75 69 72 65 64 20 53 51 4c 2c 20 61 6e  required SQL, an
0480: 64 20 63 6f 6d 70 69 6c 65 73 20 6f 6e 65 20 6f  d compiles one o
0490: 72 20 6d 6f 72 65 20 0a 23 20 73 74 61 74 65 6d  r more .# statem
04a0: 65 6e 74 73 20 74 6f 20 74 72 61 76 65 72 73 65  ents to traverse
04b0: 20 74 68 65 20 6c 65 61 76 65 73 2e 20 54 68 69   the leaves. Thi
04c0: 73 20 74 65 73 74 20 63 61 73 65 20 74 65 73 74  s test case test
04d0: 73 20 74 68 61 74 20 4f 4f 4d 20 65 72 72 6f 72  s that OOM error
04e0: 73 0a 23 20 74 68 61 74 20 6f 63 63 75 72 20 77  s.# that occur w
04f0: 68 69 6c 65 20 61 6c 6c 6f 63 61 74 69 6e 67 20  hile allocating 
0500: 74 68 69 73 20 73 74 72 69 6e 67 20 61 6e 64 20  this string and 
0510: 73 74 61 74 65 6d 65 6e 74 20 61 72 65 20 68 61  statement are ha
0520: 6e 64 6c 65 64 20 63 6f 72 72 65 63 74 6c 79 0a  ndled correctly.
0530: 23 20 61 6c 73 6f 2e 0a 23 0a 64 6f 5f 74 65 73  # also..#.do_tes
0540: 74 20 66 74 73 33 63 6f 76 2d 31 2e 31 20 7b 0a  t fts3cov-1.1 {.
0550: 20 20 65 78 65 63 73 71 6c 20 7b 20 0a 20 20 20    execsql { .   
0560: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
0570: 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 66  TABLE t1 USING f
0580: 74 73 33 28 78 29 3b 0a 20 20 20 20 49 4e 53 45  ts3(x);.    INSE
0590: 52 54 20 49 4e 54 4f 20 74 31 28 74 31 29 20 56  RT INTO t1(t1) V
05a0: 41 4c 55 45 53 28 27 6e 6f 64 65 73 69 7a 65 3d  ALUES('nodesize=
05b0: 32 34 27 29 3b 0a 20 20 20 20 42 45 47 49 4e 3b  24');.    BEGIN;
05c0: 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e  .      INSERT IN
05d0: 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 49 73  TO t1 VALUES('Is
05e0: 20 74 68 65 20 6e 69 67 68 74 20 63 68 69 6c 6c   the night chill
05f0: 79 20 61 6e 64 20 64 61 72 6b 3f 27 29 3b 0a 20  y and dark?');. 
0600: 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f       INSERT INTO
0610: 20 74 31 20 56 41 4c 55 45 53 28 27 54 68 65 20   t1 VALUES('The 
0620: 6e 69 67 68 74 20 69 73 20 63 68 69 6c 6c 79 2c  night is chilly,
0630: 20 62 75 74 20 6e 6f 74 20 64 61 72 6b 2e 27 29   but not dark.')
0640: 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  ;.      INSERT I
0650: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 54  NTO t1 VALUES('T
0660: 68 65 20 74 68 69 6e 20 67 72 61 79 20 63 6c 6f  he thin gray clo
0670: 75 64 20 69 73 20 73 70 72 65 61 64 20 6f 6e 20  ud is spread on 
0680: 68 69 67 68 2c 27 29 3b 0a 20 20 20 20 20 20 49  high,');.      I
0690: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41  NSERT INTO t1 VA
06a0: 4c 55 45 53 28 27 49 74 20 63 6f 76 65 72 73 20  LUES('It covers 
06b0: 62 75 74 20 6e 6f 74 20 68 69 64 65 73 20 74 68  but not hides th
06c0: 65 20 73 6b 79 2e 27 29 3b 0a 20 20 20 20 43 4f  e sky.');.    CO
06d0: 4d 4d 49 54 3b 0a 20 20 20 20 53 45 4c 45 43 54  MMIT;.    SELECT
06e0: 20 63 6f 75 6e 74 28 2a 29 3e 30 20 46 52 4f 4d   count(*)>0 FROM
06f0: 20 74 31 5f 73 65 67 6d 65 6e 74 73 3b 0a 20 20   t1_segments;.  
0700: 7d 0a 7d 20 7b 31 7d 0a 0a 73 65 74 20 44 4f 5f  }.} {1}..set DO_
0710: 4d 41 4c 4c 4f 43 5f 54 45 53 54 20 31 0a 64 6f  MALLOC_TEST 1.do
0720: 5f 72 65 73 74 61 72 74 5f 73 65 6c 65 63 74 5f  _restart_select_
0730: 74 65 73 74 20 66 74 73 33 63 6f 76 2d 31 2e 32  test fts3cov-1.2
0740: 20 7b 0a 20 20 53 45 4c 45 43 54 20 64 6f 63 69   {.  SELECT doci
0750: 64 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20  d FROM t1 WHERE 
0760: 74 31 20 4d 41 54 43 48 20 27 63 68 69 6c 6c 79  t1 MATCH 'chilly
0770: 27 3b 0a 7d 20 7b 31 20 32 7d 0a 73 65 74 20 44  ';.} {1 2}.set D
0780: 4f 5f 4d 41 4c 4c 4f 43 5f 54 45 53 54 20 30 0a  O_MALLOC_TEST 0.
0790: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
07a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
07b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
07c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
07d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 57  ------------.# W
07e0: 68 65 6e 20 71 75 65 72 79 69 6e 67 20 74 68 65  hen querying the
07f0: 20 66 75 6c 6c 2d 74 65 78 74 20 69 6e 64 65 78   full-text index
0800: 2c 20 69 66 20 61 6e 20 65 78 70 65 63 74 65 64  , if an expected
0810: 20 69 6e 74 65 72 6e 61 6c 20 6e 6f 64 65 20 62   internal node b
0820: 6c 6f 63 6b 20 69 73 20 0a 23 20 6d 69 73 73 69  lock is .# missi
0830: 6e 67 20 66 72 6f 6d 20 74 68 65 20 25 5f 73 65  ng from the %_se
0840: 67 6d 65 6e 74 73 20 74 61 62 6c 65 2c 20 6f 72  gments table, or
0850: 20 69 66 20 61 20 4e 55 4c 4c 20 76 61 6c 75 65   if a NULL value
0860: 20 69 73 20 73 74 6f 72 65 64 20 69 6e 20 74 68   is stored in th
0870: 65 20 0a 23 20 25 5f 73 65 67 6d 65 6e 74 73 20  e .# %_segments 
0880: 74 61 62 6c 65 20 69 6e 73 74 65 61 64 20 6f 66  table instead of
0890: 20 61 20 62 69 6e 61 72 79 20 62 6c 6f 62 2c 20   a binary blob, 
08a0: 64 61 74 61 62 61 73 65 20 63 6f 72 72 75 70 74  database corrupt
08b0: 69 6f 6e 20 73 68 6f 75 6c 64 20 62 65 20 0a 23  ion should be .#
08c0: 20 72 65 70 6f 72 74 65 64 2e 0a 23 0a 23 20 45   reported..#.# E
08d0: 76 65 6e 20 77 69 74 68 20 74 69 6e 79 20 32 34  ven with tiny 24
08e0: 20 62 79 74 65 20 6e 6f 64 65 73 2c 20 69 74 20   byte nodes, it 
08f0: 74 61 6b 65 73 20 61 20 66 61 69 72 20 62 69 74  takes a fair bit
0900: 20 6f 66 20 64 61 74 61 20 74 6f 20 70 72 6f 64   of data to prod
0910: 75 63 65 20 61 0a 23 20 73 65 67 6d 65 6e 74 20  uce a.# segment 
0920: 62 2d 74 72 65 65 20 74 68 61 74 20 75 73 65 73  b-tree that uses
0930: 20 74 68 65 20 25 5f 73 65 67 6d 65 6e 74 73 20   the %_segments 
0940: 74 61 62 6c 65 20 74 6f 20 73 74 6f 72 65 20 69  table to store i
0950: 6e 74 65 72 6e 61 6c 20 6e 6f 64 65 73 2e 20 0a  nternal nodes. .
0960: 23 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f  #.do_test fts3co
0970: 76 2d 32 2e 31 20 7b 0a 20 20 65 78 65 63 73 71  v-2.1 {.  execsq
0980: 6c 20 7b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  l {.    INSERT I
0990: 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55 45  NTO t1(t1) VALUE
09a0: 53 28 27 6e 6f 64 65 73 69 7a 65 3d 32 34 27 29  S('nodesize=24')
09b0: 3b 0a 20 20 20 20 42 45 47 49 4e 3b 0a 20 20 20  ;.    BEGIN;.   
09c0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
09d0: 31 20 56 41 4c 55 45 53 28 27 54 68 65 20 6d 6f  1 VALUES('The mo
09e0: 6f 6e 20 69 73 20 62 65 68 69 6e 64 2c 20 61 6e  on is behind, an
09f0: 64 20 61 74 20 74 68 65 20 66 75 6c 6c 3b 27 29  d at the full;')
0a00: 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  ;.      INSERT I
0a10: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 41  NTO t1 VALUES('A
0a20: 6e 64 20 79 65 74 20 73 68 65 20 6c 6f 6f 6b 73  nd yet she looks
0a30: 20 62 6f 74 68 20 73 6d 61 6c 6c 20 61 6e 64 20   both small and 
0a40: 64 75 6c 6c 2e 27 29 3b 0a 20 20 20 20 20 20 49  dull.');.      I
0a50: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41  NSERT INTO t1 VA
0a60: 4c 55 45 53 28 27 54 68 65 20 6e 69 67 68 74 20  LUES('The night 
0a70: 69 73 20 63 68 69 6c 6c 2c 20 74 68 65 20 63 6c  is chill, the cl
0a80: 6f 75 64 20 69 73 20 67 72 61 79 3a 27 29 3b 0a  oud is gray:');.
0a90: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
0aa0: 4f 20 74 31 20 56 41 4c 55 45 53 28 27 27 27 54  O t1 VALUES('''T
0ab0: 20 69 73 20 61 20 6d 6f 6e 74 68 20 62 65 66 6f   is a month befo
0ac0: 72 65 20 74 68 65 20 6d 6f 6e 74 68 20 6f 66 20  re the month of 
0ad0: 4d 61 79 2c 27 29 3b 0a 20 20 20 20 20 20 49 4e  May,');.      IN
0ae0: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
0af0: 55 45 53 28 27 41 6e 64 20 74 68 65 20 53 70 72  UES('And the Spr
0b00: 69 6e 67 20 63 6f 6d 65 73 20 73 6c 6f 77 6c 79  ing comes slowly
0b10: 20 75 70 20 74 68 69 73 20 77 61 79 2e 27 29 3b   up this way.');
0b20: 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e  .      INSERT IN
0b30: 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 54 68  TO t1 VALUES('Th
0b40: 65 20 6c 6f 76 65 6c 79 20 6c 61 64 79 2c 20 43  e lovely lady, C
0b50: 68 72 69 73 74 61 62 65 6c 2c 27 29 3b 0a 20 20  hristabel,');.  
0b60: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
0b70: 74 31 20 56 41 4c 55 45 53 28 27 57 68 6f 6d 20  t1 VALUES('Whom 
0b80: 68 65 72 20 66 61 74 68 65 72 20 6c 6f 76 65 73  her father loves
0b90: 20 73 6f 20 77 65 6c 6c 2c 27 29 3b 0a 20 20 20   so well,');.   
0ba0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
0bb0: 31 20 56 41 4c 55 45 53 28 27 57 68 61 74 20 6d  1 VALUES('What m
0bc0: 61 6b 65 73 20 68 65 72 20 69 6e 20 74 68 65 20  akes her in the 
0bd0: 77 6f 6f 64 20 73 6f 20 6c 61 74 65 2c 27 29 3b  wood so late,');
0be0: 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e  .      INSERT IN
0bf0: 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 41 20  TO t1 VALUES('A 
0c00: 66 75 72 6c 6f 6e 67 20 66 72 6f 6d 20 74 68 65  furlong from the
0c10: 20 63 61 73 74 6c 65 20 67 61 74 65 3f 27 29 3b   castle gate?');
0c20: 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e  .      INSERT IN
0c30: 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 53 68  TO t1 VALUES('Sh
0c40: 65 20 68 61 64 20 64 72 65 61 6d 73 20 61 6c 6c  e had dreams all
0c50: 20 79 65 73 74 65 72 6e 69 67 68 74 27 29 3b 0a   yesternight');.
0c60: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
0c70: 4f 20 74 31 20 56 41 4c 55 45 53 28 27 4f 66 20  O t1 VALUES('Of 
0c80: 68 65 72 20 6f 77 6e 20 62 65 74 72 6f 74 68 65  her own betrothe
0c90: 64 20 6b 6e 69 67 68 74 3b 27 29 3b 0a 20 20 20  d knight;');.   
0ca0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
0cb0: 31 20 56 41 4c 55 45 53 28 27 41 6e 64 20 73 68  1 VALUES('And sh
0cc0: 65 20 69 6e 20 74 68 65 20 6d 69 64 6e 69 67 68  e in the midnigh
0cd0: 74 20 77 6f 6f 64 20 77 69 6c 6c 20 70 72 61 79  t wood will pray
0ce0: 27 29 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54  ');.      INSERT
0cf0: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
0d00: 27 46 6f 72 20 74 68 65 20 77 65 61 6c 20 6f 66  'For the weal of
0d10: 20 68 65 72 20 6c 6f 76 65 72 20 74 68 61 74 27   her lover that'
0d20: 27 73 20 66 61 72 20 61 77 61 79 2e 27 29 3b 0a  's far away.');.
0d30: 20 20 20 20 43 4f 4d 4d 49 54 3b 0a 20 20 7d 0a      COMMIT;.  }.
0d40: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
0d50: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74  INSERT INTO t1(t
0d60: 31 29 20 56 41 4c 55 45 53 28 27 6f 70 74 69 6d  1) VALUES('optim
0d70: 69 7a 65 27 29 3b 0a 20 20 20 20 53 45 4c 45 43  ize');.    SELEC
0d80: 54 20 73 75 62 73 74 72 28 68 65 78 28 72 6f 6f  T substr(hex(roo
0d90: 74 29 2c 20 31 2c 20 32 29 20 46 52 4f 4d 20 74  t), 1, 2) FROM t
0da0: 31 5f 73 65 67 64 69 72 3b 0a 20 20 7d 0a 7d 20  1_segdir;.  }.} 
0db0: 7b 30 33 7d 0a 0a 23 20 54 65 73 74 20 74 68 65  {03}..# Test the
0dc0: 20 22 6d 69 73 73 69 6e 67 20 65 6e 74 72 79 22   "missing entry"
0dd0: 20 63 61 73 65 3a 0a 64 6f 5f 74 65 73 74 20 66   case:.do_test f
0de0: 74 73 33 63 6f 76 2d 32 2e 32 20 7b 0a 20 20 73  ts3cov-2.2 {.  s
0df0: 65 74 20 72 6f 6f 74 20 5b 64 62 20 6f 6e 65 20  et root [db one 
0e00: 7b 53 45 4c 45 43 54 20 72 6f 6f 74 20 46 52 4f  {SELECT root FRO
0e10: 4d 20 74 31 5f 73 65 67 64 69 72 7d 5d 0a 20 20  M t1_segdir}].  
0e20: 72 65 61 64 5f 66 74 73 33 76 61 72 69 6e 74 20  read_fts3varint 
0e30: 5b 73 74 72 69 6e 67 20 72 61 6e 67 65 20 24 72  [string range $r
0e40: 6f 6f 74 20 31 20 65 6e 64 5d 20 6c 65 66 74 5f  oot 1 end] left_
0e50: 63 68 69 6c 64 0a 20 20 65 78 65 63 73 71 6c 20  child.  execsql 
0e60: 7b 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31  { DELETE FROM t1
0e70: 5f 73 65 67 6d 65 6e 74 73 20 57 48 45 52 45 20  _segments WHERE 
0e80: 62 6c 6f 63 6b 69 64 20 3d 20 24 6c 65 66 74 5f  blockid = $left_
0e90: 63 68 69 6c 64 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f  child }.} {}.do_
0ea0: 65 72 72 6f 72 5f 74 65 73 74 20 66 74 73 33 63  error_test fts3c
0eb0: 6f 76 2d 32 2e 33 20 7b 0a 20 20 53 45 4c 45 43  ov-2.3 {.  SELEC
0ec0: 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52  T * FROM t1 WHER
0ed0: 45 20 74 31 20 4d 41 54 43 48 20 27 63 2a 27 0a  E t1 MATCH 'c*'.
0ee0: 7d 20 7b 53 51 4c 20 6c 6f 67 69 63 20 65 72 72  } {SQL logic err
0ef0: 6f 72 20 6f 72 20 6d 69 73 73 69 6e 67 20 64 61  or or missing da
0f00: 74 61 62 61 73 65 7d 0a 0a 23 20 54 65 73 74 20  tabase}..# Test 
0f10: 74 68 65 20 22 72 65 70 6c 61 63 65 64 20 77 69  the "replaced wi
0f20: 74 68 20 4e 55 4c 4c 22 20 63 61 73 65 3a 0a 64  th NULL" case:.d
0f30: 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 32  o_test fts3cov-2
0f40: 2e 34 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .4 {.  execsql {
0f50: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 5f   INSERT INTO t1_
0f60: 73 65 67 6d 65 6e 74 73 20 56 41 4c 55 45 53 28  segments VALUES(
0f70: 24 6c 65 66 74 5f 63 68 69 6c 64 2c 20 4e 55 4c  $left_child, NUL
0f80: 4c 29 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 65 72 72  L) }.} {}.do_err
0f90: 6f 72 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  or_test fts3cov-
0fa0: 32 2e 35 20 7b 0a 20 20 53 45 4c 45 43 54 20 2a  2.5 {.  SELECT *
0fb0: 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 74   FROM t1 WHERE t
0fc0: 31 20 4d 41 54 43 48 20 27 63 6c 6f 75 64 27 0a  1 MATCH 'cloud'.
0fd0: 7d 20 7b 53 51 4c 20 6c 6f 67 69 63 20 65 72 72  } {SQL logic err
0fe0: 6f 72 20 6f 72 20 6d 69 73 73 69 6e 67 20 64 61  or or missing da
0ff0: 74 61 62 61 73 65 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  tabase}..#------
1000: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1040: 2d 2d 2d 2d 0a 23 20 54 68 65 20 66 6f 6c 6c 6f  ----.# The follo
1050: 77 69 6e 67 20 74 65 73 74 73 20 61 72 65 20 74  wing tests are t
1060: 6f 20 74 65 73 74 20 74 68 65 20 65 66 66 65 63  o test the effec
1070: 74 73 20 6f 66 20 4f 4f 4d 20 65 72 72 6f 72 73  ts of OOM errors
1080: 20 77 68 69 6c 65 20 73 74 6f 72 69 6e 67 0a 23   while storing.#
1090: 20 74 65 72 6d 73 20 69 6e 20 74 68 65 20 70 65   terms in the pe
10a0: 6e 64 69 6e 67 2d 68 61 73 68 20 74 61 62 6c 65  nding-hash table
10b0: 2e 20 53 70 65 63 69 66 69 63 61 6c 6c 79 2c 20  . Specifically, 
10c0: 77 68 69 6c 65 20 63 72 65 61 74 69 6e 67 20 64  while creating d
10d0: 6f 63 6c 69 73 74 0a 23 20 62 6c 6f 62 73 20 74  oclist.# blobs t
10e0: 6f 20 73 74 6f 72 65 20 69 6e 20 74 68 65 20 74  o store in the t
10f0: 61 62 6c 65 2e 20 4d 6f 72 65 20 73 70 65 63 69  able. More speci
1100: 66 69 63 61 6c 6c 79 2c 20 74 6f 20 74 65 73 74  fically, to test
1110: 20 4f 4f 4d 20 65 72 72 6f 72 73 20 77 68 69 6c   OOM errors whil
1120: 65 0a 23 20 61 70 70 65 6e 64 69 6e 67 20 63 6f  e.# appending co
1130: 6c 75 6d 6e 20 6e 75 6d 62 65 72 73 20 74 6f 20  lumn numbers to 
1140: 64 6f 63 6c 69 73 74 73 2e 20 46 6f 72 20 65 78  doclists. For ex
1150: 61 6d 70 6c 65 2c 20 69 66 20 61 20 64 6f 63 6c  ample, if a docl
1160: 69 73 74 20 63 6f 6e 73 69 73 74 73 0a 23 20 6f  ist consists.# o
1170: 66 3a 0a 23 0a 23 20 20 20 3c 64 6f 63 69 64 3e  f:.#.#   <docid>
1180: 20 3c 63 6f 6c 75 6d 6e 20 30 20 6f 66 66 73 65   <column 0 offse
1190: 74 2d 6c 69 73 74 3e 20 30 78 30 31 20 3c 63 6f  t-list> 0x01 <co
11a0: 6c 75 6d 6e 20 4e 3e 20 3c 63 6f 6c 75 6d 6e 20  lumn N> <column 
11b0: 4e 20 6f 66 66 73 65 74 2d 6c 69 73 74 3e 0a 23  N offset-list>.#
11c0: 0a 23 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67  .# The following
11d0: 20 74 65 73 74 73 20 63 68 65 63 6b 20 74 68 61   tests check tha
11e0: 74 20 6d 61 6c 6c 6f 63 20 65 72 72 6f 72 73 20  t malloc errors 
11f0: 65 6e 63 6f 75 6e 74 65 72 65 64 20 77 68 69 6c  encountered whil
1200: 65 20 61 70 70 65 6e 64 69 6e 67 0a 23 20 74 68  e appending.# th
1210: 65 20 22 30 78 30 31 20 3c 63 6f 6c 75 6d 6e 20  e "0x01 <column 
1220: 4e 3e 22 20 64 61 74 61 20 74 6f 20 74 68 65 20  N>" data to the 
1230: 64 79 6e 61 6d 69 63 61 6c 6c 79 20 67 72 6f 77  dynamically grow
1240: 61 62 6c 65 20 62 6c 6f 62 20 75 73 65 64 20 74  able blob used t
1250: 6f 20 0a 23 20 61 63 63 75 6d 75 6c 61 74 65 20  o .# accumulate 
1260: 74 68 65 20 64 6f 63 6c 69 73 74 20 69 6e 20 6d  the doclist in m
1270: 65 6d 6f 72 79 20 61 72 65 20 68 61 6e 64 6c 65  emory are handle
1280: 64 20 63 6f 72 72 65 63 74 6c 79 2e 0a 23 0a 64  d correctly..#.d
1290: 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 33  o_test fts3cov-3
12a0: 2e 31 20 7b 0a 20 20 73 65 74 20 63 6f 6c 73 20  .1 {.  set cols 
12b0: 5b 6c 69 73 74 5d 0a 20 20 73 65 74 20 76 61 6c  [list].  set val
12c0: 73 20 5b 6c 69 73 74 5d 0a 20 20 66 6f 72 20 7b  s [list].  for {
12d0: 73 65 74 20 69 20 30 7d 20 7b 24 69 20 3c 20 31  set i 0} {$i < 1
12e0: 32 30 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20  20} {incr i} {. 
12f0: 20 20 20 6c 61 70 70 65 6e 64 20 63 6f 6c 73 20     lappend cols 
1300: 22 63 6f 6c 24 69 22 0a 20 20 20 20 6c 61 70 70  "col$i".    lapp
1310: 65 6e 64 20 76 61 6c 73 20 22 27 77 6f 72 64 27  end vals "'word'
1320: 22 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20  ".  }.  execsql 
1330: 22 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20  "CREATE VIRTUAL 
1340: 54 41 42 4c 45 20 74 32 20 55 53 49 4e 47 20 66  TABLE t2 USING f
1350: 74 73 33 28 5b 6a 6f 69 6e 20 24 63 6f 6c 73 20  ts3([join $cols 
1360: 2c 5d 29 22 0a 7d 20 7b 7d 0a 73 65 74 20 44 4f  ,])".} {}.set DO
1370: 5f 4d 41 4c 4c 4f 43 5f 54 45 53 54 20 31 20 0a  _MALLOC_TEST 1 .
1380: 64 6f 5f 77 72 69 74 65 5f 74 65 73 74 20 66 74  do_write_test ft
1390: 73 33 63 6f 76 2d 33 2e 32 20 74 32 5f 63 6f 6e  s3cov-3.2 t2_con
13a0: 74 65 6e 74 20 22 0a 20 20 49 4e 53 45 52 54 20  tent ".  INSERT 
13b0: 49 4e 54 4f 20 74 32 28 64 6f 63 69 64 2c 20 5b  INTO t2(docid, [
13c0: 6a 6f 69 6e 20 24 63 6f 6c 73 20 2c 5d 29 20 56  join $cols ,]) V
13d0: 41 4c 55 45 53 28 31 2c 20 5b 6a 6f 69 6e 20 24  ALUES(1, [join $
13e0: 76 61 6c 73 20 2c 5d 29 0a 22 0a 64 6f 5f 77 72  vals ,]).".do_wr
13f0: 69 74 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76  ite_test fts3cov
1400: 2d 33 2e 33 20 74 32 5f 63 6f 6e 74 65 6e 74 20  -3.3 t2_content 
1410: 22 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ".  INSERT INTO 
1420: 74 32 28 64 6f 63 69 64 2c 20 5b 6a 6f 69 6e 20  t2(docid, [join 
1430: 24 63 6f 6c 73 20 2c 5d 29 20 56 41 4c 55 45 53  $cols ,]) VALUES
1440: 28 32 30 30 2c 20 5b 6a 6f 69 6e 20 24 76 61 6c  (200, [join $val
1450: 73 20 2c 5d 29 0a 22 0a 64 6f 5f 77 72 69 74 65  s ,]).".do_write
1460: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 33 2e  _test fts3cov-3.
1470: 34 20 74 32 5f 63 6f 6e 74 65 6e 74 20 22 0a 20  4 t2_content ". 
1480: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 32 28   INSERT INTO t2(
1490: 64 6f 63 69 64 2c 20 5b 6a 6f 69 6e 20 24 63 6f  docid, [join $co
14a0: 6c 73 20 2c 5d 29 20 56 41 4c 55 45 53 28 36 30  ls ,]) VALUES(60
14b0: 30 30 30 2c 20 5b 6a 6f 69 6e 20 24 76 61 6c 73  000, [join $vals
14c0: 20 2c 5d 29 0a 22 0a 0a 23 2d 2d 2d 2d 2d 2d 2d   ,])."..#-------
14d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1500: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1510: 2d 2d 0a 23 20 49 66 20 74 6f 6f 20 6d 75 63 68  --.# If too much
1520: 20 64 61 74 61 20 61 63 63 75 6d 75 6c 61 74 65   data accumulate
1530: 73 20 69 6e 20 74 68 65 20 70 65 6e 64 69 6e 67  s in the pending
1540: 2d 74 65 72 6d 73 20 68 61 73 68 20 74 61 62 6c  -terms hash tabl
1550: 65 2c 20 69 74 20 69 73 0a 23 20 66 6c 75 73 68  e, it is.# flush
1560: 65 64 20 74 6f 20 74 68 65 20 64 61 74 61 62 61  ed to the databa
1570: 73 65 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79  se automatically
1580: 2c 20 65 76 65 6e 20 69 66 20 74 68 65 20 74 72  , even if the tr
1590: 61 6e 73 61 63 74 69 6f 6e 20 68 61 73 20 6e 6f  ansaction has no
15a0: 74 0a 23 20 66 69 6e 69 73 68 65 64 2e 20 54 68  t.# finished. Th
15b0: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74  e following test
15c0: 73 20 63 68 65 63 6b 20 74 68 65 20 65 66 66 65  s check the effe
15d0: 63 74 73 20 6f 66 20 65 6e 63 6f 75 6e 74 65 72  cts of encounter
15e0: 69 6e 67 20 61 6e 20 4f 4f 4d 20 0a 23 20 77 68  ing an OOM .# wh
15f0: 69 6c 65 20 64 6f 69 6e 67 20 74 68 69 73 2e 0a  ile doing this..
1600: 23 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f  #.do_test fts3co
1610: 76 2d 34 2e 31 20 7b 0a 20 20 65 78 65 63 73 71  v-4.1 {.  execsq
1620: 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 56  l {.    CREATE V
1630: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 33 20  IRTUAL TABLE t3 
1640: 55 53 49 4e 47 20 66 74 73 33 28 78 29 3b 0a 20  USING fts3(x);. 
1650: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
1660: 33 28 74 33 29 20 56 41 4c 55 45 53 28 27 6e 6f  3(t3) VALUES('no
1670: 64 65 73 69 7a 65 3d 32 34 27 29 3b 0a 20 20 20  desize=24');.   
1680: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 33 28   INSERT INTO t3(
1690: 74 33 29 20 56 41 4c 55 45 53 28 27 6d 61 78 70  t3) VALUES('maxp
16a0: 65 6e 64 69 6e 67 3d 31 30 30 27 29 3b 0a 20 20  ending=100');.  
16b0: 7d 0a 7d 20 7b 7d 0a 73 65 74 20 44 4f 5f 4d 41  }.} {}.set DO_MA
16c0: 4c 4c 4f 43 5f 54 45 53 54 20 31 20 0a 64 6f 5f  LLOC_TEST 1 .do_
16d0: 77 72 69 74 65 5f 74 65 73 74 20 66 74 73 33 63  write_test fts3c
16e0: 6f 76 2d 34 2e 32 20 74 33 5f 63 6f 6e 74 65 6e  ov-4.2 t3_conten
16f0: 74 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  t {.  INSERT INT
1700: 4f 20 74 33 28 64 6f 63 69 64 2c 20 78 29 0a 20  O t3(docid, x). 
1710: 20 20 20 53 45 4c 45 43 54 20 31 2c 20 27 54 68     SELECT 1, 'Th
1720: 65 6e 20 43 68 72 69 73 74 61 62 65 6c 20 73 74  en Christabel st
1730: 72 65 74 63 68 65 64 20 66 6f 72 74 68 20 68 65  retched forth he
1740: 72 20 68 61 6e 64 2c 27 20 55 4e 49 4f 4e 20 41  r hand,' UNION A
1750: 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 33 2c  LL.    SELECT 3,
1760: 20 27 41 6e 64 20 63 6f 6d 66 6f 72 74 65 64 20   'And comforted 
1770: 66 61 69 72 20 47 65 72 61 6c 64 69 6e 65 3a 27  fair Geraldine:'
1780: 20 20 20 20 20 20 20 20 20 20 20 20 20 55 4e 49               UNI
1790: 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43  ON ALL.    SELEC
17a0: 54 20 34 2c 20 27 27 27 4f 20 77 65 6c 6c 2c 20  T 4, '''O well, 
17b0: 62 72 69 67 68 74 20 64 61 6d 65 2c 20 6d 61 79  bright dame, may
17c0: 20 79 6f 75 20 63 6f 6d 6d 61 6e 64 27 20 20 20   you command'   
17d0: 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53   UNION ALL.    S
17e0: 45 4c 45 43 54 20 35 2c 20 27 54 68 65 20 73 65  ELECT 5, 'The se
17f0: 72 76 69 63 65 20 6f 66 20 53 69 72 20 4c 65 6f  rvice of Sir Leo
1800: 6c 69 6e 65 3b 27 20 20 20 20 20 20 20 20 20 20  line;'          
1810: 20 20 20 20 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20       UNION ALL. 
1820: 20 20 20 53 45 4c 45 43 54 20 32 2c 20 27 41 6e     SELECT 2, 'An
1830: 64 20 67 6c 61 64 6c 79 20 6f 75 72 20 73 74 6f  d gladly our sto
1840: 75 74 20 63 68 69 76 61 6c 72 79 27 20 20 20 20  ut chivalry'    
1850: 20 20 20 20 20 20 20 20 20 55 4e 49 4f 4e 20 41           UNION A
1860: 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 37 2c  LL.    SELECT 7,
1870: 20 27 57 69 6c 6c 20 68 65 20 73 65 6e 64 20 66   'Will he send f
1880: 6f 72 74 68 2c 20 61 6e 64 20 66 72 69 65 6e 64  orth, and friend
1890: 73 20 77 69 74 68 61 6c 2c 27 20 20 20 55 4e 49  s withal,'   UNI
18a0: 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43  ON ALL.    SELEC
18b0: 54 20 38 2c 20 27 54 6f 20 67 75 69 64 65 20 61  T 8, 'To guide a
18c0: 6e 64 20 67 75 61 72 64 20 79 6f 75 20 73 61 66  nd guard you saf
18d0: 65 20 61 6e 64 20 66 72 65 65 27 20 20 20 20 20  e and free'     
18e0: 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53   UNION ALL.    S
18f0: 45 4c 45 43 54 20 36 2c 20 27 48 6f 6d 65 20 74  ELECT 6, 'Home t
1900: 6f 20 79 6f 75 72 20 6e 6f 62 6c 65 20 66 61 74  o your noble fat
1910: 68 65 72 27 27 73 20 68 61 6c 6c 2e 27 27 27 0a  her''s hall.'''.
1920: 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }..#------------
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 0a 23 20  -------------.# 
1970: 57 68 65 6e 20 62 75 69 6c 64 69 6e 67 20 74 68  When building th
1980: 65 20 69 6e 74 65 72 6e 61 6c 20 74 72 65 65 20  e internal tree 
1990: 73 74 72 75 63 74 75 72 65 20 66 6f 72 20 65 61  structure for ea
19a0: 63 68 20 73 65 67 6d 65 6e 74 20 62 2d 74 72 65  ch segment b-tre
19b0: 65 2c 20 46 54 53 33 0a 23 20 61 73 73 75 6d 65  e, FTS3.# assume
19c0: 73 20 74 68 61 74 20 74 68 65 20 63 6f 6e 74 65  s that the conte
19d0: 6e 74 20 6f 66 20 65 61 63 68 20 69 6e 74 65 72  nt of each inter
19e0: 6e 61 6c 20 6e 6f 64 65 20 77 69 6c 6c 20 62 65  nal node will be
19f0: 20 6c 65 73 73 20 74 68 61 6e 0a 23 20 24 6e 6f   less than.# $no
1a00: 64 65 73 69 7a 65 20 62 79 74 65 73 2c 20 77 68  desize bytes, wh
1a10: 65 72 65 20 24 6e 6f 64 65 73 69 7a 65 20 69 73  ere $nodesize is
1a20: 20 74 68 65 20 61 64 76 69 73 6f 72 79 20 6e 6f   the advisory no
1a30: 64 65 20 73 69 7a 65 2e 20 49 66 20 74 68 69 73  de size. If this
1a40: 20 74 75 72 6e 73 0a 23 20 6f 75 74 20 74 6f 20   turns.# out to 
1a50: 62 65 20 75 6e 74 72 75 65 2c 20 74 68 65 6e 20  be untrue, then 
1a60: 61 6e 20 65 78 74 72 61 20 62 75 66 66 65 72 20  an extra buffer 
1a70: 6d 75 73 74 20 62 65 20 6d 61 6c 6c 6f 63 27 64  must be malloc'd
1a80: 20 66 6f 72 20 65 61 63 68 20 74 65 72 6d 2e 0a   for each term..
1a90: 23 20 54 68 69 73 20 74 65 73 74 20 63 61 73 65  # This test case
1aa0: 20 74 65 73 74 73 20 74 68 65 73 65 20 70 61 74   tests these pat
1ab0: 68 73 20 61 6e 64 20 74 68 65 20 65 66 66 65 63  hs and the effec
1ac0: 74 73 20 6f 66 20 73 61 69 64 20 6d 61 6c 6c 6f  ts of said mallo
1ad0: 63 73 20 66 61 69 6c 69 6e 67 0a 23 20 62 79 20  cs failing.# by 
1ae0: 69 6e 73 65 72 74 69 6e 67 20 69 6e 73 65 72 74  inserting insert
1af0: 20 61 20 64 6f 63 75 6d 65 6e 74 20 77 69 74 68   a document with
1b00: 20 73 6f 6d 65 20 66 61 69 72 6c 79 20 6c 61 72   some fairly lar
1b10: 67 65 20 74 65 72 6d 73 20 69 6e 74 6f 20 61 0a  ge terms into a.
1b20: 23 20 66 75 6c 6c 2d 74 65 78 74 20 74 61 62 6c  # full-text tabl
1b30: 65 20 77 69 74 68 20 61 20 76 65 72 79 20 73 6d  e with a very sm
1b40: 61 6c 6c 20 6e 6f 64 65 2d 73 69 7a 65 2e 20 0a  all node-size. .
1b50: 23 0a 23 20 54 65 73 74 20 74 68 69 73 20 68 61  #.# Test this ha
1b60: 6e 64 6c 69 6e 67 20 6f 66 20 6c 61 72 67 65 20  ndling of large 
1b70: 74 65 72 6d 73 20 69 6e 20 74 68 72 65 65 20 63  terms in three c
1b80: 6f 6e 74 65 78 74 73 3a 0a 23 0a 23 20 20 20 31  ontexts:.#.#   1
1b90: 2e 20 57 68 65 6e 20 66 6c 75 73 68 69 6e 67 20  . When flushing 
1ba0: 74 68 65 20 70 65 6e 64 69 6e 67 2d 74 65 72 6d  the pending-term
1bb0: 73 20 74 61 62 6c 65 2e 0a 23 20 20 20 32 2e 20  s table..#   2. 
1bc0: 57 68 65 6e 20 6f 70 74 69 6d 69 7a 69 6e 67 20  When optimizing 
1bd0: 74 68 65 20 64 61 74 61 20 73 74 72 75 63 74 75  the data structu
1be0: 72 65 73 20 75 73 69 6e 67 20 74 68 65 20 49 4e  res using the IN
1bf0: 53 45 52 54 20 73 79 6e 74 61 78 2e 20 0a 23 20  SERT syntax. .# 
1c00: 20 20 32 2e 20 57 68 65 6e 20 6f 70 74 69 6d 69    2. When optimi
1c10: 7a 69 6e 67 20 74 68 65 20 64 61 74 61 20 73 74  zing the data st
1c20: 72 75 63 74 75 72 65 73 20 75 73 69 6e 67 20 74  ructures using t
1c30: 68 65 20 64 65 70 72 65 63 61 74 65 64 20 53 45  he deprecated SE
1c40: 4c 45 43 54 20 73 79 6e 74 61 78 2e 20 0a 23 0a  LECT syntax. .#.
1c50: 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  do_test fts3cov-
1c60: 35 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  5.1 {.  execsql 
1c70: 7b 0a 20 20 20 20 43 52 45 41 54 45 20 56 49 52  {.    CREATE VIR
1c80: 54 55 41 4c 20 54 41 42 4c 45 20 74 34 20 55 53  TUAL TABLE t4 US
1c90: 49 4e 47 20 66 74 73 33 28 78 29 3b 0a 20 20 20  ING fts3(x);.   
1ca0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 34 28   INSERT INTO t4(
1cb0: 74 34 29 20 56 41 4c 55 45 53 28 27 6e 6f 64 65  t4) VALUES('node
1cc0: 73 69 7a 65 3d 32 34 27 29 3b 0a 20 20 7d 0a 7d  size=24');.  }.}
1cd0: 20 7b 7d 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f   {}.set DO_MALLO
1ce0: 43 5f 54 45 53 54 20 31 0a 0a 23 20 54 65 73 74  C_TEST 1..# Test
1cf0: 20 77 68 65 6e 20 66 6c 75 73 68 69 6e 67 20 70   when flushing p
1d00: 65 6e 64 69 6e 67 2d 74 65 72 6d 73 20 74 61 62  ending-terms tab
1d10: 6c 65 2e 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73  le..do_write_tes
1d20: 74 20 66 74 73 33 63 6f 76 2d 35 2e 32 20 74 34  t fts3cov-5.2 t4
1d30: 5f 63 6f 6e 74 65 6e 74 20 7b 0a 20 20 49 4e 53  _content {.  INS
1d40: 45 52 54 20 49 4e 54 4f 20 74 34 0a 20 20 20 20  ERT INTO t4.    
1d50: 53 45 4c 45 43 54 20 27 49 74 69 73 61 6e 61 6e  SELECT 'Itisanan
1d60: 63 69 65 6e 74 4d 61 72 69 6e 65 72 41 6e 64 68  cientMarinerAndh
1d70: 65 73 74 6f 70 70 65 74 68 6f 6e 65 6f 66 74 68  estoppethoneofth
1d80: 72 65 65 41 41 27 20 55 4e 49 4f 4e 20 41 4c 4c  reeAA' UNION ALL
1d90: 0a 20 20 20 20 53 45 4c 45 43 54 20 27 49 74 69  .    SELECT 'Iti
1da0: 73 61 6e 61 6e 63 69 65 6e 74 4d 61 72 69 6e 65  sanancientMarine
1db0: 72 41 6e 64 68 65 73 74 6f 70 70 65 74 68 6f 6e  rAndhestoppethon
1dc0: 65 6f 66 74 68 72 65 65 42 42 27 20 55 4e 49 4f  eofthreeBB' UNIO
1dd0: 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54  N ALL.    SELECT
1de0: 20 27 49 74 69 73 61 6e 61 6e 63 69 65 6e 74 4d   'ItisanancientM
1df0: 61 72 69 6e 65 72 41 6e 64 68 65 73 74 6f 70 70  arinerAndhestopp
1e00: 65 74 68 6f 6e 65 6f 66 74 68 72 65 65 43 43 27  ethoneofthreeCC'
1e10: 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53   UNION ALL.    S
1e20: 45 4c 45 43 54 20 27 42 79 74 68 79 6c 6f 6e 67  ELECT 'Bythylong
1e30: 67 72 65 79 62 65 61 72 64 61 6e 64 67 6c 69 74  greybeardandglit
1e40: 74 65 72 69 6e 67 65 79 65 4e 6f 77 77 68 65 72  teringeyeNowwher
1e50: 65 66 6f 72 65 73 74 6f 70 70 73 74 41 41 27 20  eforestoppstAA' 
1e60: 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45  UNION ALL.    SE
1e70: 4c 45 43 54 20 27 42 79 74 68 79 6c 6f 6e 67 67  LECT 'Bythylongg
1e80: 72 65 79 62 65 61 72 64 61 6e 64 67 6c 69 74 74  reybeardandglitt
1e90: 65 72 69 6e 67 65 79 65 4e 6f 77 77 68 65 72 65  eringeyeNowwhere
1ea0: 66 6f 72 65 73 74 6f 70 70 73 74 42 42 27 20 55  forestoppstBB' U
1eb0: 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c  NION ALL.    SEL
1ec0: 45 43 54 20 27 42 79 74 68 79 6c 6f 6e 67 67 72  ECT 'Bythylonggr
1ed0: 65 79 62 65 61 72 64 61 6e 64 67 6c 69 74 74 65  eybeardandglitte
1ee0: 72 69 6e 67 65 79 65 4e 6f 77 77 68 65 72 65 66  ringeyeNowwheref
1ef0: 6f 72 65 73 74 6f 70 70 73 74 43 43 27 0a 7d 0a  orestoppstCC'.}.
1f00: 0a 23 20 54 65 73 74 20 77 68 65 6e 20 6f 70 74  .# Test when opt
1f10: 69 6d 69 7a 69 6e 67 20 76 69 61 20 49 4e 53 45  imizing via INSE
1f20: 52 54 2e 0a 64 6f 5f 74 65 73 74 20 66 74 73 33  RT..do_test fts3
1f30: 63 6f 76 2d 35 2e 33 20 7b 20 65 78 65 63 73 71  cov-5.3 { execsq
1f40: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
1f50: 74 34 20 56 41 4c 55 45 53 28 27 65 78 74 72 61  t4 VALUES('extra
1f60: 21 27 29 20 7d 20 7d 20 7b 7d 0a 64 6f 5f 77 72  !') } } {}.do_wr
1f70: 69 74 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76  ite_test fts3cov
1f80: 2d 35 2e 32 20 74 34 5f 73 65 67 6d 65 6e 74 73  -5.2 t4_segments
1f90: 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74   { INSERT INTO t
1fa0: 34 28 74 34 29 20 56 41 4c 55 45 53 28 27 6f 70  4(t4) VALUES('op
1fb0: 74 69 6d 69 7a 65 27 29 20 7d 0a 0a 23 20 54 65  timize') }..# Te
1fc0: 73 74 20 77 68 65 6e 20 6f 70 74 69 6d 69 7a 69  st when optimizi
1fd0: 6e 67 20 76 69 61 20 53 45 4c 45 43 54 2e 0a 64  ng via SELECT..d
1fe0: 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 35  o_test fts3cov-5
1ff0: 2e 35 20 7b 20 65 78 65 63 73 71 6c 20 7b 20 49  .5 { execsql { I
2000: 4e 53 45 52 54 20 49 4e 54 4f 20 74 34 20 56 41  NSERT INTO t4 VA
2010: 4c 55 45 53 28 27 6d 6f 72 65 20 65 78 74 72 61  LUES('more extra
2020: 21 27 29 20 7d 20 7d 20 7b 7d 0a 64 6f 5f 77 72  !') } } {}.do_wr
2030: 69 74 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76  ite_test fts3cov
2040: 2d 35 2e 36 20 74 34 5f 73 65 67 6d 65 6e 74 73  -5.6 t4_segments
2050: 20 7b 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52   {.  SELECT * FR
2060: 4f 4d 20 28 53 45 4c 45 43 54 20 6f 70 74 69 6d  OM (SELECT optim
2070: 69 7a 65 28 74 34 29 20 46 52 4f 4d 20 74 34 20  ize(t4) FROM t4 
2080: 4c 49 4d 49 54 20 31 29 0a 20 20 45 58 43 45 50  LIMIT 1).  EXCEP
2090: 54 20 53 45 4c 45 43 54 20 27 49 6e 64 65 78 20  T SELECT 'Index 
20a0: 6f 70 74 69 6d 69 7a 65 64 27 0a 7d 0a 0a 23 2d  optimized'.}..#-
20b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
20c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
20d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
20e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
20f0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 57 68 65 6e 20  --------.# When 
2100: 6d 65 72 67 69 6e 67 20 61 6c 6c 20 73 65 67 6d  merging all segm
2110: 65 6e 74 73 20 61 74 20 61 20 67 69 76 65 6e 20  ents at a given 
2120: 6c 65 76 65 6c 20 74 6f 20 63 72 65 61 74 65 20  level to create 
2130: 61 20 73 69 6e 67 6c 65 20 73 65 67 6d 65 6e 74  a single segment
2140: 0a 23 20 61 74 20 6c 65 76 65 6c 2b 31 2c 20 46  .# at level+1, F
2150: 54 53 33 20 72 75 6e 73 20 61 20 71 75 65 72 79  TS3 runs a query
2160: 20 6f 66 20 74 68 65 20 66 6f 72 6d 3a 0a 23 0a   of the form:.#.
2170: 23 20 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74  #   SELECT count
2180: 28 2a 29 20 46 52 4f 4d 20 25 5f 73 65 67 64 69  (*) FROM %_segdi
2190: 72 20 57 48 45 52 45 20 6c 65 76 65 6c 20 3d 20  r WHERE level = 
21a0: 3f 0a 23 0a 23 20 54 68 65 20 71 75 65 72 79 20  ?.#.# The query 
21b0: 69 73 20 63 6f 6d 70 69 6c 65 64 20 74 68 65 20  is compiled the 
21c0: 66 69 72 73 74 20 74 69 6d 65 20 74 68 69 73 20  first time this 
21d0: 6f 70 65 72 61 74 69 6f 6e 20 69 73 20 72 65 71  operation is req
21e0: 75 69 72 65 64 20 61 6e 64 0a 23 20 72 65 75 73  uired and.# reus
21f0: 65 64 20 74 68 65 72 65 61 66 74 65 72 2e 20 54  ed thereafter. T
2200: 68 69 73 20 74 65 73 74 20 61 69 6d 73 20 74 6f  his test aims to
2210: 20 74 65 73 74 20 74 68 65 20 65 66 66 65 63 74   test the effect
2220: 73 20 6f 66 20 61 6e 20 4f 4f 4d 20 77 68 69 6c  s of an OOM whil
2230: 65 0a 23 20 70 72 65 70 61 72 69 6e 67 20 61 6e  e.# preparing an
2240: 64 20 65 78 65 63 75 74 69 6e 67 20 74 68 69 73  d executing this
2250: 20 71 75 65 72 79 20 66 6f 72 20 74 68 65 20 66   query for the f
2260: 69 72 73 74 20 74 69 6d 65 2e 0a 23 0a 23 20 54  irst time..#.# T
2270: 68 65 6e 2c 20 6b 65 65 70 20 69 6e 73 65 72 74  hen, keep insert
2280: 69 6e 67 20 72 6f 77 73 20 69 6e 74 6f 20 74 68  ing rows into th
2290: 65 20 74 61 62 6c 65 20 73 6f 20 74 68 61 74 20  e table so that 
22a0: 74 68 65 20 65 66 66 65 63 74 73 20 6f 66 20 61  the effects of a
22b0: 6e 20 4f 4f 4d 0a 23 20 77 68 69 6c 65 20 72 65  n OOM.# while re
22c0: 2d 65 78 65 63 75 74 69 6e 67 20 74 68 65 20 73  -executing the s
22d0: 61 6d 65 20 71 75 65 72 79 20 63 61 6e 20 61 6c  ame query can al
22e0: 73 6f 20 62 65 20 74 65 73 74 65 64 2e 0a 23 0a  so be tested..#.
22f0: 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  do_test fts3cov-
2300: 36 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  6.1 {.  execsql 
2310: 7b 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c  { CREATE VIRTUAL
2320: 20 54 41 42 4c 45 20 74 35 20 55 53 49 4e 47 20   TABLE t5 USING 
2330: 66 74 73 33 28 78 29 20 7d 0a 20 20 66 6f 72 20  fts3(x) }.  for 
2340: 7b 73 65 74 20 69 20 30 7d 20 7b 24 69 3c 31 36  {set i 0} {$i<16
2350: 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 20 65 78 65  } {incr i} { exe
2360: 63 73 71 6c 20 22 49 4e 53 45 52 54 20 49 4e 54  csql "INSERT INT
2370: 4f 20 74 35 20 56 41 4c 55 45 53 28 27 74 65 72  O t5 VALUES('ter
2380: 6d 24 69 27 29 22 20 7d 0a 20 20 65 78 65 63 73  m$i')" }.  execs
2390: 71 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f 75 6e  ql { SELECT coun
23a0: 74 28 2a 29 20 46 52 4f 4d 20 74 35 5f 73 65 67  t(*) FROM t5_seg
23b0: 64 69 72 20 7d 0a 7d 20 7b 31 36 7d 0a 0a 23 20  dir }.} {16}..# 
23c0: 46 69 72 73 74 20 74 69 6d 65 2e 0a 64 62 20 63  First time..db c
23d0: 6c 6f 73 65 0a 73 71 6c 69 74 65 33 20 64 62 20  lose.sqlite3 db 
23e0: 74 65 73 74 2e 64 62 0a 64 6f 5f 77 72 69 74 65  test.db.do_write
23f0: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 36 2e  _test fts3cov-6.
2400: 32 20 74 35 5f 63 6f 6e 74 65 6e 74 20 7b 0a 20  2 t5_content {. 
2410: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 35 20   INSERT INTO t5 
2420: 56 41 4c 55 45 53 28 27 73 65 67 6d 65 6e 74 20  VALUES('segment 
2430: 6e 75 6d 62 65 72 20 31 36 21 27 29 3b 0a 7d 0a  number 16!');.}.
2440: 0a 23 20 53 65 63 6f 6e 64 20 74 69 6d 65 2e 0a  .# Second time..
2450: 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  do_test fts3cov-
2460: 36 2e 33 20 7b 0a 20 20 66 6f 72 20 7b 73 65 74  6.3 {.  for {set
2470: 20 69 20 31 7d 20 7b 24 69 3c 31 36 7d 20 7b 69   i 1} {$i<16} {i
2480: 6e 63 72 20 69 7d 20 7b 20 65 78 65 63 73 71 6c  ncr i} { execsql
2490: 20 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 35   "INSERT INTO t5
24a0: 20 56 41 4c 55 45 53 28 27 74 65 72 6d 24 69 27   VALUES('term$i'
24b0: 29 22 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b  )" }.  execsql {
24c0: 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29   SELECT count(*)
24d0: 20 46 52 4f 4d 20 74 35 5f 73 65 67 64 69 72 20   FROM t5_segdir 
24e0: 7d 0a 7d 20 7b 31 37 7d 0a 64 6f 5f 77 72 69 74  }.} {17}.do_writ
24f0: 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 36  e_test fts3cov-6
2500: 2e 34 20 74 35 5f 63 6f 6e 74 65 6e 74 20 7b 0a  .4 t5_content {.
2510: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 35    INSERT INTO t5
2520: 20 56 41 4c 55 45 53 28 27 73 65 67 6d 65 6e 74   VALUES('segment
2530: 20 6e 75 6d 62 65 72 20 31 36 21 27 29 3b 0a 7d   number 16!');.}
2540: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
2550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2560: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2570: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2580: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 55  ------------.# U
2590: 70 64 61 74 65 20 74 68 65 20 64 6f 63 69 64 20  pdate the docid 
25a0: 6f 66 20 61 20 72 6f 77 2e 20 54 65 73 74 20 74  of a row. Test t
25b0: 68 69 73 20 69 6e 20 74 77 6f 20 73 63 65 6e 61  his in two scena
25c0: 72 69 6f 73 3a 0a 23 0a 23 20 20 20 31 2e 20 57  rios:.#.#   1. W
25d0: 68 65 6e 20 74 68 65 20 72 6f 77 20 62 65 69 6e  hen the row bein
25e0: 67 20 75 70 64 61 74 65 64 20 69 73 20 74 68 65  g updated is the
25f0: 20 6f 6e 6c 79 20 72 6f 77 20 69 6e 20 74 68 65   only row in the
2600: 20 74 61 62 6c 65 2e 0a 23 20 20 20 32 2e 20 57   table..#   2. W
2610: 68 65 6e 20 69 74 20 69 73 20 6e 6f 74 2e 0a 23  hen it is not..#
2620: 0a 23 20 54 68 65 20 74 77 6f 20 63 61 73 65 73  .# The two cases
2630: 20 61 62 6f 76 65 20 74 61 6b 65 20 64 69 66 66   above take diff
2640: 65 72 65 6e 74 20 70 61 74 68 73 20 62 65 63 61  erent paths beca
2650: 75 73 65 20 69 6e 20 63 61 73 65 20 31 20 61 6c  use in case 1 al
2660: 6c 20 64 61 74 61 20 0a 23 20 73 74 72 75 63 74  l data .# struct
2670: 75 72 65 73 20 63 61 6e 20 73 69 6d 70 6c 79 20  ures can simply 
2680: 62 65 20 65 6d 70 74 69 65 64 20 62 65 66 6f 72  be emptied befor
2690: 65 20 69 6e 73 65 72 74 69 6e 67 20 74 68 65 20  e inserting the 
26a0: 6e 65 77 20 72 6f 77 20 72 65 63 6f 72 64 2e 0a  new row record..
26b0: 23 20 49 6e 20 63 61 73 65 20 32 2c 20 74 68 65  # In case 2, the
26c0: 20 64 61 74 61 20 73 74 72 75 63 74 75 72 65 73   data structures
26d0: 20 61 63 74 75 61 6c 6c 79 20 68 61 76 65 20 74   actually have t
26e0: 6f 20 62 65 20 75 70 64 61 74 65 64 2e 0a 23 0a  o be updated..#.
26f0: 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  do_test fts3cov-
2700: 37 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  7.1 {.  execsql 
2710: 7b 0a 20 20 20 20 43 52 45 41 54 45 20 56 49 52  {.    CREATE VIR
2720: 54 55 41 4c 20 54 41 42 4c 45 20 74 37 20 55 53  TUAL TABLE t7 US
2730: 49 4e 47 20 66 74 73 33 28 61 2c 20 62 2c 20 63  ING fts3(a, b, c
2740: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
2750: 54 4f 20 74 37 20 56 41 4c 55 45 53 28 27 41 27  TO t7 VALUES('A'
2760: 2c 20 27 42 27 2c 20 27 43 27 29 3b 0a 20 20 20  , 'B', 'C');.   
2770: 20 55 50 44 41 54 45 20 74 37 20 53 45 54 20 64   UPDATE t7 SET d
2780: 6f 63 69 64 20 3d 20 35 3b 0a 20 20 20 20 53 45  ocid = 5;.    SE
2790: 4c 45 43 54 20 64 6f 63 69 64 2c 20 2a 20 46 52  LECT docid, * FR
27a0: 4f 4d 20 74 37 3b 0a 20 20 7d 0a 7d 20 7b 35 20  OM t7;.  }.} {5 
27b0: 41 20 42 20 43 7d 0a 64 6f 5f 74 65 73 74 20 66  A B C}.do_test f
27c0: 74 73 33 63 6f 76 2d 37 2e 32 20 7b 0a 20 20 65  ts3cov-7.2 {.  e
27d0: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53  xecsql {.    INS
27e0: 45 52 54 20 49 4e 54 4f 20 74 37 20 56 41 4c 55  ERT INTO t7 VALU
27f0: 45 53 28 27 44 27 2c 20 27 45 27 2c 20 27 46 27  ES('D', 'E', 'F'
2800: 29 3b 0a 20 20 20 20 55 50 44 41 54 45 20 74 37  );.    UPDATE t7
2810: 20 53 45 54 20 64 6f 63 69 64 20 3d 20 31 20 57   SET docid = 1 W
2820: 48 45 52 45 20 64 6f 63 69 64 20 3d 20 36 3b 0a  HERE docid = 6;.
2830: 20 20 20 20 53 45 4c 45 43 54 20 64 6f 63 69 64      SELECT docid
2840: 2c 20 2a 20 46 52 4f 4d 20 74 37 3b 0a 20 20 7d  , * FROM t7;.  }
2850: 0a 7d 20 7b 31 20 44 20 45 20 46 20 35 20 41 20  .} {1 D E F 5 A 
2860: 42 20 43 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  B C}..#---------
2870: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2880: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2890: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
28a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
28b0: 0a 23 20 49 66 20 61 20 73 65 74 20 6f 66 20 64  .# If a set of d
28c0: 6f 63 75 6d 65 6e 74 73 20 61 72 65 20 6d 6f 64  ocuments are mod
28d0: 69 66 69 65 64 20 77 69 74 68 69 6e 20 61 20 74  ified within a t
28e0: 72 61 6e 73 61 63 74 69 6f 6e 2c 20 74 68 65 20  ransaction, the 
28f0: 0a 23 20 70 65 6e 64 69 6e 67 2d 74 65 72 6d 73  .# pending-terms
2900: 20 74 61 62 6c 65 20 6d 75 73 74 20 62 65 20 66   table must be f
2910: 6c 75 73 68 65 64 20 65 61 63 68 20 74 69 6d 65  lushed each time
2920: 20 61 20 64 6f 63 75 6d 65 6e 74 20 77 69 74 68   a document with
2930: 20 61 20 64 6f 63 69 64 0a 23 20 6c 65 73 73 20   a docid.# less 
2940: 74 68 61 6e 20 6f 72 20 65 71 75 61 6c 20 74 6f  than or equal to
2950: 20 74 68 65 20 70 72 65 76 69 6f 75 73 20 64 6f   the previous do
2960: 63 69 64 20 69 73 20 6d 6f 64 69 66 69 65 64 2e  cid is modified.
2970: 20 0a 23 0a 23 20 54 68 69 73 20 74 65 73 74 20   .#.# This test 
2980: 63 68 65 63 6b 73 20 74 68 65 20 65 66 66 65 63  checks the effec
2990: 74 73 20 6f 66 20 61 6e 20 4f 4f 4d 20 65 72 72  ts of an OOM err
29a0: 6f 72 20 6f 63 63 75 72 69 6e 67 20 77 68 65 6e  or occuring when
29b0: 20 74 68 65 20 0a 23 20 70 65 6e 64 69 6e 67 2d   the .# pending-
29c0: 74 65 72 6d 73 20 74 61 62 6c 65 20 69 73 20 66  terms table is f
29d0: 6c 75 73 68 65 64 20 66 6f 72 20 74 68 69 73 20  lushed for this 
29e0: 72 65 61 73 6f 6e 20 61 73 20 70 61 72 74 20 6f  reason as part o
29f0: 66 20 61 20 44 45 4c 45 54 45 20 0a 23 20 73 74  f a DELETE .# st
2a00: 61 74 65 6d 65 6e 74 2e 0a 23 0a 64 6f 5f 6d 61  atement..#.do_ma
2a10: 6c 6c 6f 63 5f 74 65 73 74 20 66 74 73 33 63 6f  lloc_test fts3co
2a20: 76 2d 38 20 2d 73 71 6c 70 72 65 70 20 7b 0a 20  v-8 -sqlprep {. 
2a30: 20 42 45 47 49 4e 3b 0a 20 20 20 20 43 52 45 41   BEGIN;.    CREA
2a40: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
2a50: 20 74 38 20 55 53 49 4e 47 20 66 74 73 33 3b 0a   t8 USING fts3;.
2a60: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
2a70: 74 38 20 56 41 4c 55 45 53 28 27 74 68 65 20 6f  t8 VALUES('the o
2a80: 75 74 70 75 74 20 6f 66 20 65 61 63 68 20 62 61  utput of each ba
2a90: 74 63 68 20 72 75 6e 27 29 3b 0a 20 20 20 20 49  tch run');.    I
2aa0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 38 20 56 41  NSERT INTO t8 VA
2ab0: 4c 55 45 53 28 27 28 70 6f 73 73 69 62 6c 79 20  LUES('(possibly 
2ac0: 61 20 64 61 79 27 27 73 20 77 6f 72 6b 29 27 29  a day''s work)')
2ad0: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
2ae0: 4f 20 74 38 20 56 41 4c 55 45 53 28 27 77 61 73  O t8 VALUES('was
2af0: 20 77 72 69 74 74 65 6e 20 74 6f 20 74 77 6f 20   written to two 
2b00: 73 65 70 61 72 61 74 65 20 64 69 73 6b 73 27 29  separate disks')
2b10: 3b 0a 20 20 43 4f 4d 4d 49 54 3b 0a 7d 20 2d 73  ;.  COMMIT;.} -s
2b20: 71 6c 62 6f 64 79 20 7b 0a 20 20 42 45 47 49 4e  qlbody {.  BEGIN
2b30: 3b 0a 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f  ;.    DELETE FRO
2b40: 4d 20 74 38 20 57 48 45 52 45 20 72 6f 77 69 64  M t8 WHERE rowid
2b50: 20 3d 20 33 3b 0a 20 20 20 20 44 45 4c 45 54 45   = 3;.    DELETE
2b60: 20 46 52 4f 4d 20 74 38 20 57 48 45 52 45 20 72   FROM t8 WHERE r
2b70: 6f 77 69 64 20 3d 20 32 3b 0a 20 20 20 20 44 45  owid = 2;.    DE
2b80: 4c 45 54 45 20 46 52 4f 4d 20 74 38 20 57 48 45  LETE FROM t8 WHE
2b90: 52 45 20 72 6f 77 69 64 20 3d 20 31 3b 0a 20 20  RE rowid = 1;.  
2ba0: 43 4f 4d 4d 49 54 3b 0a 7d 0a 0a 23 2d 2d 2d 2d  COMMIT;.}..#----
2bb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2bc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2bd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2be0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2bf0: 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 73 6f 6d  -----.# Test som
2c00: 65 20 62 72 61 6e 63 68 65 73 20 69 6e 20 74 68  e branches in th
2c10: 65 20 63 6f 64 65 20 74 68 61 74 20 68 61 6e 64  e code that hand
2c20: 6c 65 73 20 22 73 70 65 63 69 61 6c 22 20 69 6e  les "special" in
2c30: 73 65 72 74 73 20 6c 69 6b 65 3a 0a 23 0a 23 20  serts like:.#.# 
2c40: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
2c50: 28 74 31 29 20 56 41 4c 55 45 53 28 27 6f 70 74  (t1) VALUES('opt
2c60: 69 6d 69 7a 65 27 29 3b 0a 23 0a 23 20 41 6c 73  imize');.#.# Als
2c70: 6f 20 74 65 73 74 20 74 68 61 74 20 61 6e 20 6f  o test that an o
2c80: 70 74 69 6d 69 7a 65 20 28 49 4e 53 45 52 54 20  ptimize (INSERT 
2c90: 6d 65 74 68 6f 64 29 20 77 6f 72 6b 73 20 6f 6e  method) works on
2ca0: 20 61 6e 20 65 6d 70 74 79 20 74 61 62 6c 65 2e   an empty table.
2cb0: 0a 23 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43  .#.set DO_MALLOC
2cc0: 5f 54 45 53 54 20 30 0a 64 6f 5f 74 65 73 74 20  _TEST 0.do_test 
2cd0: 66 74 73 33 63 6f 76 2d 39 2e 31 20 7b 0a 20 20  fts3cov-9.1 {.  
2ce0: 65 78 65 63 73 71 6c 20 7b 20 43 52 45 41 54 45  execsql { CREATE
2cf0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78   VIRTUAL TABLE x
2d00: 78 20 55 53 49 4e 47 20 66 74 73 33 20 7d 0a 7d  x USING fts3 }.}
2d10: 20 7b 7d 0a 64 6f 5f 65 72 72 6f 72 5f 74 65 73   {}.do_error_tes
2d20: 74 20 66 74 73 33 63 6f 76 2d 39 2e 32 20 7b 0a  t fts3cov-9.2 {.
2d30: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 78    INSERT INTO xx
2d40: 28 78 78 29 20 56 41 4c 55 45 53 28 27 6f 70 74  (xx) VALUES('opt
2d50: 69 6d 69 73 65 27 29 3b 20 20 20 2d 2d 20 42 72  imise');   -- Br
2d60: 69 74 69 73 68 20 73 70 65 6c 6c 69 6e 67 0a 7d  itish spelling.}
2d70: 20 7b 53 51 4c 20 6c 6f 67 69 63 20 65 72 72 6f   {SQL logic erro
2d80: 72 20 6f 72 20 6d 69 73 73 69 6e 67 20 64 61 74  r or missing dat
2d90: 61 62 61 73 65 7d 0a 64 6f 5f 65 72 72 6f 72 5f  abase}.do_error_
2da0: 74 65 73 74 20 66 74 73 33 63 6f 76 2d 39 2e 33  test fts3cov-9.3
2db0: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
2dc0: 20 78 78 28 78 78 29 20 56 41 4c 55 45 53 28 27   xx(xx) VALUES('
2dd0: 73 68 6f 72 74 27 29 3b 0a 7d 20 7b 53 51 4c 20  short');.} {SQL 
2de0: 6c 6f 67 69 63 20 65 72 72 6f 72 20 6f 72 20 6d  logic error or m
2df0: 69 73 73 69 6e 67 20 64 61 74 61 62 61 73 65 7d  issing database}
2e00: 0a 64 6f 5f 65 72 72 6f 72 5f 74 65 73 74 20 66  .do_error_test f
2e10: 74 73 33 63 6f 76 2d 39 2e 34 20 7b 0a 20 20 49  ts3cov-9.4 {.  I
2e20: 4e 53 45 52 54 20 49 4e 54 4f 20 78 78 28 78 78  NSERT INTO xx(xx
2e30: 29 20 56 41 4c 55 45 53 28 27 77 61 79 74 6f 6f  ) VALUES('waytoo
2e40: 6c 6f 6e 67 74 6f 62 65 63 6f 72 72 65 63 74 27  longtobecorrect'
2e50: 29 3b 0a 7d 20 7b 53 51 4c 20 6c 6f 67 69 63 20  );.} {SQL logic 
2e60: 65 72 72 6f 72 20 6f 72 20 6d 69 73 73 69 6e 67  error or missing
2e70: 20 64 61 74 61 62 61 73 65 7d 0a 64 6f 5f 74 65   database}.do_te
2e80: 73 74 20 66 74 73 33 63 6f 76 2d 39 2e 35 20 7b  st fts3cov-9.5 {
2e90: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53  .  execsql { INS
2ea0: 45 52 54 20 49 4e 54 4f 20 78 78 28 78 78 29 20  ERT INTO xx(xx) 
2eb0: 56 41 4c 55 45 53 28 27 6f 70 74 69 6d 69 7a 65  VALUES('optimize
2ec0: 27 29 20 7d 0a 7d 20 7b 7d 0a 0a 23 2d 2d 2d 2d  ') }.} {}..#----
2ed0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ee0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ef0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f10: 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 74 68 61  -----.# Test tha
2f20: 74 20 61 20 74 61 62 6c 65 20 63 61 6e 20 62 65  t a table can be
2f30: 20 6f 70 74 69 6d 69 7a 65 64 20 69 6e 20 74 68   optimized in th
2f40: 65 20 6d 69 64 64 6c 65 20 6f 66 20 61 20 74 72  e middle of a tr
2f50: 61 6e 73 61 63 74 69 6f 6e 20 77 68 65 6e 0a 23  ansaction when.#
2f60: 20 74 68 65 20 70 65 6e 64 69 6e 67 2d 74 65 72   the pending-ter
2f70: 6d 73 20 74 61 62 6c 65 20 69 73 20 6e 6f 6e 2d  ms table is non-
2f80: 65 6d 70 74 79 2e 20 54 68 69 73 20 63 61 73 65  empty. This case
2f90: 20 69 6e 76 6f 6c 76 65 73 20 73 6f 6d 65 20 65   involves some e
2fa0: 78 74 72 61 0a 23 20 62 72 61 6e 63 68 65 73 20  xtra.# branches 
2fb0: 62 65 63 61 75 73 65 20 64 61 74 61 20 6d 75 73  because data mus
2fc0: 74 20 62 65 20 72 65 61 64 20 6e 6f 74 20 6f 6e  t be read not on
2fd0: 6c 79 20 66 72 6f 6d 20 74 68 65 20 64 61 74 61  ly from the data
2fe0: 62 61 73 65 2c 20 62 75 74 0a 23 20 61 6c 73 6f  base, but.# also
2ff0: 20 66 72 6f 6d 20 74 68 65 20 70 65 6e 64 69 6e   from the pendin
3000: 67 2d 74 65 72 6d 73 20 74 61 62 6c 65 2e 0a 23  g-terms table..#
3010: 0a 64 6f 5f 6d 61 6c 6c 6f 63 5f 74 65 73 74 20  .do_malloc_test 
3020: 66 74 73 33 63 6f 76 2d 31 30 20 2d 73 71 6c 70  fts3cov-10 -sqlp
3030: 72 65 70 20 7b 0a 20 20 43 52 45 41 54 45 20 56  rep {.  CREATE V
3040: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31 30  IRTUAL TABLE t10
3050: 20 55 53 49 4e 47 20 66 74 73 33 3b 0a 20 20 49   USING fts3;.  I
3060: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 30 20 56  NSERT INTO t10 V
3070: 41 4c 55 45 53 28 27 4f 70 74 69 6d 69 73 69 6e  ALUES('Optimisin
3080: 67 20 69 6d 61 67 65 73 20 66 6f 72 20 74 68 65  g images for the
3090: 20 77 65 62 20 69 73 20 61 20 74 72 69 63 6b 79   web is a tricky
30a0: 20 62 75 73 69 6e 65 73 73 27 29 3b 0a 20 20 42   business');.  B
30b0: 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53 45 52 54  EGIN;.    INSERT
30c0: 20 49 4e 54 4f 20 74 31 30 20 56 41 4c 55 45 53   INTO t10 VALUES
30d0: 28 27 59 6f 75 20 68 61 76 65 20 74 6f 20 67 65  ('You have to ge
30e0: 74 20 74 68 65 20 72 69 67 68 74 20 62 61 6c 61  t the right bala
30f0: 6e 63 65 20 62 65 74 77 65 65 6e 27 29 3b 0a 7d  nce between');.}
3100: 20 2d 73 71 6c 62 6f 64 79 20 7b 0a 20 20 49 4e   -sqlbody {.  IN
3110: 53 45 52 54 20 49 4e 54 4f 20 74 31 30 28 74 31  SERT INTO t10(t1
3120: 30 29 20 56 41 4c 55 45 53 28 27 6f 70 74 69 6d  0) VALUES('optim
3130: 69 7a 65 27 29 3b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d  ize');.}..#-----
3140: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3150: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3160: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3170: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3180: 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 61 20 66 75  ----.# Test a fu
3190: 6c 6c 2d 74 65 78 74 20 71 75 65 72 79 20 66 6f  ll-text query fo
31a0: 72 20 61 20 74 65 72 6d 20 74 68 61 74 20 77 61  r a term that wa
31b0: 73 20 6f 6e 63 65 20 69 6e 20 74 68 65 20 69 6e  s once in the in
31c0: 64 65 78 2c 20 62 75 74 20 69 73 0a 23 20 6e 6f  dex, but is.# no
31d0: 20 6c 6f 6e 67 65 72 2e 0a 23 0a 64 6f 5f 74 65   longer..#.do_te
31e0: 73 74 20 66 74 73 33 63 6f 76 2d 31 31 2e 31 20  st fts3cov-11.1 
31f0: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 0a 20  {.  execsql { . 
3200: 20 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41     CREATE VIRTUA
3210: 4c 20 54 41 42 4c 45 20 78 78 20 55 53 49 4e 47  L TABLE xx USING
3220: 20 66 74 73 33 3b 0a 20 20 20 20 49 4e 53 45 52   fts3;.    INSER
3230: 54 20 49 4e 54 4f 20 78 78 20 56 41 4c 55 45 53  T INTO xx VALUES
3240: 28 27 6f 6e 65 20 74 77 6f 20 74 68 72 65 65 27  ('one two three'
3250: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
3260: 54 4f 20 78 78 20 56 41 4c 55 45 53 28 27 66 6f  TO xx VALUES('fo
3270: 75 72 20 66 69 76 65 20 73 69 78 27 29 3b 0a 20  ur five six');. 
3280: 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 78     DELETE FROM x
3290: 78 20 57 48 45 52 45 20 64 6f 63 69 64 20 3d 20  x WHERE docid = 
32a0: 31 3b 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c  1;.  }.  execsql
32b0: 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d   { SELECT * FROM
32c0: 20 78 78 20 57 48 45 52 45 20 78 78 20 4d 41 54   xx WHERE xx MAT
32d0: 43 48 20 27 74 77 6f 27 20 7d 0a 7d 20 7b 7d 0a  CH 'two' }.} {}.
32e0: 0a 0a 64 6f 5f 6d 61 6c 6c 6f 63 5f 74 65 73 74  ..do_malloc_test
32f0: 20 66 74 73 33 63 6f 76 2d 31 32 20 2d 73 71 6c   fts3cov-12 -sql
3300: 70 72 65 70 20 7b 0a 20 20 43 52 45 41 54 45 20  prep {.  CREATE 
3310: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31  VIRTUAL TABLE t1
3320: 32 20 55 53 49 4e 47 20 66 74 73 33 3b 0a 20 20  2 USING fts3;.  
3330: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 32 20  INSERT INTO t12 
3340: 56 41 4c 55 45 53 28 27 69 73 20 6f 6e 65 20 6f  VALUES('is one o
3350: 66 20 74 68 65 20 74 77 6f 20 74 6f 67 74 68 65  f the two togthe
3360: 72 27 29 3b 0a 20 20 42 45 47 49 4e 3b 0a 20 20  r');.  BEGIN;.  
3370: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
3380: 32 20 56 41 4c 55 45 53 28 27 6f 6e 65 20 77 68  2 VALUES('one wh
3390: 69 63 68 20 77 61 73 20 61 70 70 72 6f 70 72 69  ich was appropri
33a0: 61 74 65 20 61 74 20 74 68 65 20 74 69 6d 65 27  ate at the time'
33b0: 29 3b 0a 7d 20 2d 73 71 6c 62 6f 64 79 20 7b 0a  );.} -sqlbody {.
33c0: 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20    SELECT * FROM 
33d0: 74 31 32 20 57 48 45 52 45 20 74 31 32 20 4d 41  t12 WHERE t12 MA
33e0: 54 43 48 20 27 6f 6e 65 27 0a 7d 0a 0a 64 6f 5f  TCH 'one'.}..do_
33f0: 6d 61 6c 6c 6f 63 5f 74 65 73 74 20 66 74 73 33  malloc_test fts3
3400: 63 6f 76 2d 31 33 20 2d 73 71 6c 70 72 65 70 20  cov-13 -sqlprep 
3410: 7b 0a 20 20 50 52 41 47 4d 41 20 65 6e 63 6f 64  {.  PRAGMA encod
3420: 69 6e 67 20 3d 20 27 55 54 46 2d 31 36 27 3b 0a  ing = 'UTF-16';.
3430: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
3440: 20 54 41 42 4c 45 20 74 31 33 20 55 53 49 4e 47   TABLE t13 USING
3450: 20 66 74 73 33 3b 0a 20 20 49 4e 53 45 52 54 20   fts3;.  INSERT 
3460: 49 4e 54 4f 20 74 31 33 20 56 41 4c 55 45 53 28  INTO t13 VALUES(
3470: 27 74 77 6f 20 73 63 61 6c 61 72 20 66 75 6e 63  'two scalar func
3480: 74 69 6f 6e 73 27 29 3b 0a 20 20 49 4e 53 45 52  tions');.  INSER
3490: 54 20 49 4e 54 4f 20 74 31 33 20 56 41 4c 55 45  T INTO t13 VALUE
34a0: 53 28 27 73 63 61 6c 61 72 20 74 77 6f 20 66 75  S('scalar two fu
34b0: 6e 63 74 69 6f 6e 73 27 29 3b 0a 20 20 49 4e 53  nctions');.  INS
34c0: 45 52 54 20 49 4e 54 4f 20 74 31 33 20 56 41 4c  ERT INTO t13 VAL
34d0: 55 45 53 28 27 66 75 6e 63 74 69 6f 6e 73 20 73  UES('functions s
34e0: 63 61 6c 61 72 20 74 77 6f 27 29 3b 0a 7d 20 2d  calar two');.} -
34f0: 73 71 6c 62 6f 64 79 20 7b 0a 20 20 53 45 4c 45  sqlbody {.  SELE
3500: 43 54 20 73 6e 69 70 70 65 74 28 74 31 33 2c 20  CT snippet(t13, 
3510: 27 25 25 27 2c 20 27 25 25 27 2c 20 27 23 27 29  '%%', '%%', '#')
3520: 20 46 52 4f 4d 20 74 31 33 20 57 48 45 52 45 20   FROM t13 WHERE 
3530: 74 31 33 20 4d 41 54 43 48 20 27 74 77 6f 27 3b  t13 MATCH 'two';
3540: 0a 20 20 53 45 4c 45 43 54 20 73 6e 69 70 70 65  .  SELECT snippe
3550: 74 28 74 31 33 2c 20 27 25 25 27 2c 20 27 25 25  t(t13, '%%', '%%
3560: 27 29 20 46 52 4f 4d 20 74 31 33 20 57 48 45 52  ') FROM t13 WHER
3570: 45 20 74 31 33 20 4d 41 54 43 48 20 27 74 77 6f  E t13 MATCH 'two
3580: 27 3b 0a 20 20 53 45 4c 45 43 54 20 73 6e 69 70  ';.  SELECT snip
3590: 70 65 74 28 74 31 33 2c 20 27 25 25 27 29 20 46  pet(t13, '%%') F
35a0: 52 4f 4d 20 74 31 33 20 57 48 45 52 45 20 74 31  ROM t13 WHERE t1
35b0: 33 20 4d 41 54 43 48 20 27 74 77 6f 27 3b 0a 7d  3 MATCH 'two';.}
35c0: 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a        ..finish_test.