/ Hex Artifact Content
Login

Artifact e0fb00d8b715ddae4a94c305992dfc3ef70353d7:


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 73 65 74 20 74 65 73  C_TEST 0.set tes
0250: 74 70 72 65 66 69 78 20 66 74 73 33 63 6f 76 0a  tprefix fts3cov.
0260: 0a 23 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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
02a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 57  ------------.# W
02b0: 68 65 6e 20 69 74 20 66 69 72 73 74 20 6e 65 65  hen it first nee
02c0: 64 73 20 74 6f 20 72 65 61 64 20 61 20 62 6c 6f  ds to read a blo
02d0: 63 6b 20 66 72 6f 6d 20 74 68 65 20 25 5f 73 65  ck from the %_se
02e0: 67 6d 65 6e 74 73 20 74 61 62 6c 65 2c 20 74 68  gments table, th
02f0: 65 20 46 54 53 33 20 0a 23 20 6d 6f 64 75 6c 65  e FTS3 .# module
0300: 20 63 6f 6d 70 69 6c 65 73 20 61 6e 20 53 51 4c   compiles an SQL
0310: 20 73 74 61 74 65 6d 65 6e 74 20 66 6f 72 20 74   statement for t
0320: 68 61 74 20 70 75 72 70 6f 73 65 2e 20 54 68 65  hat purpose. The
0330: 20 73 74 61 74 65 6d 65 6e 74 20 69 73 20 0a 23   statement is .#
0340: 20 73 74 6f 72 65 64 20 61 6e 64 20 72 65 75 73   stored and reus
0350: 65 64 20 65 61 63 68 20 73 75 62 73 65 71 75 65  ed each subseque
0360: 6e 74 20 74 69 6d 65 20 61 20 62 6c 6f 63 6b 20  nt time a block 
0370: 69 73 20 72 65 61 64 2e 20 54 68 69 73 20 74 65  is read. This te
0380: 73 74 20 63 61 73 65 20 0a 23 20 74 65 73 74 73  st case .# tests
0390: 20 74 68 65 20 65 66 66 65 63 74 73 20 6f 66 20   the effects of 
03a0: 61 6e 20 4f 4f 4d 20 65 72 72 6f 72 20 6f 63 63  an OOM error occ
03b0: 75 72 69 6e 67 20 77 68 69 6c 65 20 63 6f 6d 70  uring while comp
03c0: 69 6c 69 6e 67 20 74 68 65 20 73 74 61 74 65 6d  iling the statem
03d0: 65 6e 74 2e 0a 23 0a 23 20 53 69 6d 69 6c 61 72  ent..#.# Similar
03e0: 6c 79 2c 20 77 68 65 6e 20 46 54 53 33 20 66 69  ly, when FTS3 fi
03f0: 72 73 74 20 6e 65 65 64 73 20 74 6f 20 73 63 61  rst needs to sca
0400: 6e 20 74 68 72 6f 75 67 68 20 61 20 73 65 74 20  n through a set 
0410: 6f 66 20 73 65 67 6d 65 6e 74 20 6c 65 61 76 65  of segment leave
0420: 73 0a 23 20 74 6f 20 66 69 6e 64 20 61 20 73 65  s.# to find a se
0430: 74 20 6f 66 20 64 6f 63 75 6d 65 6e 74 73 20 74  t of documents t
0440: 68 61 74 20 6d 61 74 63 68 65 73 20 61 20 74 65  hat matches a te
0450: 72 6d 2c 20 69 74 20 61 6c 6c 6f 63 61 74 65 73  rm, it allocates
0460: 20 61 20 73 74 72 69 6e 67 0a 23 20 63 6f 6e 74   a string.# cont
0470: 61 69 6e 69 6e 67 20 74 68 65 20 74 65 78 74 20  aining the text 
0480: 6f 66 20 74 68 65 20 72 65 71 75 69 72 65 64 20  of the required 
0490: 53 51 4c 2c 20 61 6e 64 20 63 6f 6d 70 69 6c 65  SQL, and compile
04a0: 73 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 0a 23  s one or more .#
04b0: 20 73 74 61 74 65 6d 65 6e 74 73 20 74 6f 20 74   statements to t
04c0: 72 61 76 65 72 73 65 20 74 68 65 20 6c 65 61 76  raverse the leav
04d0: 65 73 2e 20 54 68 69 73 20 74 65 73 74 20 63 61  es. This test ca
04e0: 73 65 20 74 65 73 74 73 20 74 68 61 74 20 4f 4f  se tests that OO
04f0: 4d 20 65 72 72 6f 72 73 0a 23 20 74 68 61 74 20  M errors.# that 
0500: 6f 63 63 75 72 20 77 68 69 6c 65 20 61 6c 6c 6f  occur while allo
0510: 63 61 74 69 6e 67 20 74 68 69 73 20 73 74 72 69  cating this stri
0520: 6e 67 20 61 6e 64 20 73 74 61 74 65 6d 65 6e 74  ng and statement
0530: 20 61 72 65 20 68 61 6e 64 6c 65 64 20 63 6f 72   are handled cor
0540: 72 65 63 74 6c 79 0a 23 20 61 6c 73 6f 2e 0a 23  rectly.# also..#
0550: 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76  .do_test fts3cov
0560: 2d 31 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c  -1.1 {.  execsql
0570: 20 7b 20 0a 20 20 20 20 43 52 45 41 54 45 20 56   { .    CREATE V
0580: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31 20  IRTUAL TABLE t1 
0590: 55 53 49 4e 47 20 66 74 73 33 28 78 29 3b 0a 20  USING fts3(x);. 
05a0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
05b0: 31 28 74 31 29 20 56 41 4c 55 45 53 28 27 6e 6f  1(t1) VALUES('no
05c0: 64 65 73 69 7a 65 3d 32 34 27 29 3b 0a 20 20 20  desize=24');.   
05d0: 20 42 45 47 49 4e 3b 0a 20 20 20 20 20 20 49 4e   BEGIN;.      IN
05e0: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
05f0: 55 45 53 28 27 49 73 20 74 68 65 20 6e 69 67 68  UES('Is the nigh
0600: 74 20 63 68 69 6c 6c 79 20 61 6e 64 20 64 61 72  t chilly and dar
0610: 6b 3f 27 29 3b 0a 20 20 20 20 20 20 49 4e 53 45  k?');.      INSE
0620: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
0630: 53 28 27 54 68 65 20 6e 69 67 68 74 20 69 73 20  S('The night is 
0640: 63 68 69 6c 6c 79 2c 20 62 75 74 20 6e 6f 74 20  chilly, but not 
0650: 64 61 72 6b 2e 27 29 3b 0a 20 20 20 20 20 20 49  dark.');.      I
0660: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41  NSERT INTO t1 VA
0670: 4c 55 45 53 28 27 54 68 65 20 74 68 69 6e 20 67  LUES('The thin g
0680: 72 61 79 20 63 6c 6f 75 64 20 69 73 20 73 70 72  ray cloud is spr
0690: 65 61 64 20 6f 6e 20 68 69 67 68 2c 27 29 3b 0a  ead on high,');.
06a0: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
06b0: 4f 20 74 31 20 56 41 4c 55 45 53 28 27 49 74 20  O t1 VALUES('It 
06c0: 63 6f 76 65 72 73 20 62 75 74 20 6e 6f 74 20 68  covers but not h
06d0: 69 64 65 73 20 74 68 65 20 73 6b 79 2e 27 29 3b  ides the sky.');
06e0: 0a 20 20 20 20 43 4f 4d 4d 49 54 3b 0a 20 20 20  .    COMMIT;.   
06f0: 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29   SELECT count(*)
0700: 3e 30 20 46 52 4f 4d 20 74 31 5f 73 65 67 6d 65  >0 FROM t1_segme
0710: 6e 74 73 3b 0a 20 20 7d 0a 7d 20 7b 31 7d 0a 0a  nts;.  }.} {1}..
0720: 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43 5f 54 45  set DO_MALLOC_TE
0730: 53 54 20 31 0a 64 6f 5f 72 65 73 74 61 72 74 5f  ST 1.do_restart_
0740: 73 65 6c 65 63 74 5f 74 65 73 74 20 66 74 73 33  select_test fts3
0750: 63 6f 76 2d 31 2e 32 20 7b 0a 20 20 53 45 4c 45  cov-1.2 {.  SELE
0760: 43 54 20 64 6f 63 69 64 20 46 52 4f 4d 20 74 31  CT docid FROM t1
0770: 20 57 48 45 52 45 20 74 31 20 4d 41 54 43 48 20   WHERE t1 MATCH 
0780: 27 63 68 69 6c 6c 79 27 3b 0a 7d 20 7b 31 20 32  'chilly';.} {1 2
0790: 7d 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43 5f  }.set DO_MALLOC_
07a0: 54 45 53 54 20 30 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  TEST 0..#-------
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 2d 2d 2d 2d  ----------------
07e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
07f0: 2d 2d 2d 0a 23 20 57 68 65 6e 20 71 75 65 72 79  ---.# When query
0800: 69 6e 67 20 74 68 65 20 66 75 6c 6c 2d 74 65 78  ing the full-tex
0810: 74 20 69 6e 64 65 78 2c 20 69 66 20 61 6e 20 65  t index, if an e
0820: 78 70 65 63 74 65 64 20 69 6e 74 65 72 6e 61 6c  xpected internal
0830: 20 6e 6f 64 65 20 62 6c 6f 63 6b 20 69 73 20 0a   node block is .
0840: 23 20 6d 69 73 73 69 6e 67 20 66 72 6f 6d 20 74  # missing from t
0850: 68 65 20 25 5f 73 65 67 6d 65 6e 74 73 20 74 61  he %_segments ta
0860: 62 6c 65 2c 20 6f 72 20 69 66 20 61 20 4e 55 4c  ble, or if a NUL
0870: 4c 20 76 61 6c 75 65 20 69 73 20 73 74 6f 72 65  L value is store
0880: 64 20 69 6e 20 74 68 65 20 0a 23 20 25 5f 73 65  d in the .# %_se
0890: 67 6d 65 6e 74 73 20 74 61 62 6c 65 20 69 6e 73  gments table ins
08a0: 74 65 61 64 20 6f 66 20 61 20 62 69 6e 61 72 79  tead of a binary
08b0: 20 62 6c 6f 62 2c 20 64 61 74 61 62 61 73 65 20   blob, database 
08c0: 63 6f 72 72 75 70 74 69 6f 6e 20 73 68 6f 75 6c  corruption shoul
08d0: 64 20 62 65 20 0a 23 20 72 65 70 6f 72 74 65 64  d be .# reported
08e0: 2e 0a 23 0a 23 20 45 76 65 6e 20 77 69 74 68 20  ..#.# Even with 
08f0: 74 69 6e 79 20 32 34 20 62 79 74 65 20 6e 6f 64  tiny 24 byte nod
0900: 65 73 2c 20 69 74 20 74 61 6b 65 73 20 61 20 66  es, it takes a f
0910: 61 69 72 20 62 69 74 20 6f 66 20 64 61 74 61 20  air bit of data 
0920: 74 6f 20 70 72 6f 64 75 63 65 20 61 0a 23 20 73  to produce a.# s
0930: 65 67 6d 65 6e 74 20 62 2d 74 72 65 65 20 74 68  egment b-tree th
0940: 61 74 20 75 73 65 73 20 74 68 65 20 25 5f 73 65  at uses the %_se
0950: 67 6d 65 6e 74 73 20 74 61 62 6c 65 20 74 6f 20  gments table to 
0960: 73 74 6f 72 65 20 69 6e 74 65 72 6e 61 6c 20 6e  store internal n
0970: 6f 64 65 73 2e 20 0a 23 0a 64 6f 5f 74 65 73 74  odes. .#.do_test
0980: 20 66 74 73 33 63 6f 76 2d 32 2e 31 20 7b 0a 20   fts3cov-2.1 {. 
0990: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 49   execsql {.    I
09a0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28 74 31  NSERT INTO t1(t1
09b0: 29 20 56 41 4c 55 45 53 28 27 6e 6f 64 65 73 69  ) VALUES('nodesi
09c0: 7a 65 3d 32 34 27 29 3b 0a 20 20 20 20 42 45 47  ze=24');.    BEG
09d0: 49 4e 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54  IN;.      INSERT
09e0: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
09f0: 27 54 68 65 20 6d 6f 6f 6e 20 69 73 20 62 65 68  'The moon is beh
0a00: 69 6e 64 2c 20 61 6e 64 20 61 74 20 74 68 65 20  ind, and at the 
0a10: 66 75 6c 6c 3b 27 29 3b 0a 20 20 20 20 20 20 49  full;');.      I
0a20: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41  NSERT INTO t1 VA
0a30: 4c 55 45 53 28 27 41 6e 64 20 79 65 74 20 73 68  LUES('And yet sh
0a40: 65 20 6c 6f 6f 6b 73 20 62 6f 74 68 20 73 6d 61  e looks both sma
0a50: 6c 6c 20 61 6e 64 20 64 75 6c 6c 2e 27 29 3b 0a  ll and dull.');.
0a60: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
0a70: 4f 20 74 31 20 56 41 4c 55 45 53 28 27 54 68 65  O t1 VALUES('The
0a80: 20 6e 69 67 68 74 20 69 73 20 63 68 69 6c 6c 2c   night is chill,
0a90: 20 74 68 65 20 63 6c 6f 75 64 20 69 73 20 67 72   the cloud is gr
0aa0: 61 79 3a 27 29 3b 0a 20 20 20 20 20 20 49 4e 53  ay:');.      INS
0ab0: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
0ac0: 45 53 28 27 27 27 54 20 69 73 20 61 20 6d 6f 6e  ES('''T is a mon
0ad0: 74 68 20 62 65 66 6f 72 65 20 74 68 65 20 6d 6f  th before the mo
0ae0: 6e 74 68 20 6f 66 20 4d 61 79 2c 27 29 3b 0a 20  nth of May,');. 
0af0: 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f       INSERT INTO
0b00: 20 74 31 20 56 41 4c 55 45 53 28 27 41 6e 64 20   t1 VALUES('And 
0b10: 74 68 65 20 53 70 72 69 6e 67 20 63 6f 6d 65 73  the Spring comes
0b20: 20 73 6c 6f 77 6c 79 20 75 70 20 74 68 69 73 20   slowly up this 
0b30: 77 61 79 2e 27 29 3b 0a 20 20 20 20 20 20 49 4e  way.');.      IN
0b40: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
0b50: 55 45 53 28 27 54 68 65 20 6c 6f 76 65 6c 79 20  UES('The lovely 
0b60: 6c 61 64 79 2c 20 43 68 72 69 73 74 61 62 65 6c  lady, Christabel
0b70: 2c 27 29 3b 0a 20 20 20 20 20 20 49 4e 53 45 52  ,');.      INSER
0b80: 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53  T INTO t1 VALUES
0b90: 28 27 57 68 6f 6d 20 68 65 72 20 66 61 74 68 65  ('Whom her fathe
0ba0: 72 20 6c 6f 76 65 73 20 73 6f 20 77 65 6c 6c 2c  r loves so well,
0bb0: 27 29 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54  ');.      INSERT
0bc0: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
0bd0: 27 57 68 61 74 20 6d 61 6b 65 73 20 68 65 72 20  'What makes her 
0be0: 69 6e 20 74 68 65 20 77 6f 6f 64 20 73 6f 20 6c  in the wood so l
0bf0: 61 74 65 2c 27 29 3b 0a 20 20 20 20 20 20 49 4e  ate,');.      IN
0c00: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
0c10: 55 45 53 28 27 41 20 66 75 72 6c 6f 6e 67 20 66  UES('A furlong f
0c20: 72 6f 6d 20 74 68 65 20 63 61 73 74 6c 65 20 67  rom the castle g
0c30: 61 74 65 3f 27 29 3b 0a 20 20 20 20 20 20 49 4e  ate?');.      IN
0c40: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
0c50: 55 45 53 28 27 53 68 65 20 68 61 64 20 64 72 65  UES('She had dre
0c60: 61 6d 73 20 61 6c 6c 20 79 65 73 74 65 72 6e 69  ams all yesterni
0c70: 67 68 74 27 29 3b 0a 20 20 20 20 20 20 49 4e 53  ght');.      INS
0c80: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
0c90: 45 53 28 27 4f 66 20 68 65 72 20 6f 77 6e 20 62  ES('Of her own b
0ca0: 65 74 72 6f 74 68 65 64 20 6b 6e 69 67 68 74 3b  etrothed knight;
0cb0: 27 29 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54  ');.      INSERT
0cc0: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
0cd0: 27 41 6e 64 20 73 68 65 20 69 6e 20 74 68 65 20  'And she in the 
0ce0: 6d 69 64 6e 69 67 68 74 20 77 6f 6f 64 20 77 69  midnight wood wi
0cf0: 6c 6c 20 70 72 61 79 27 29 3b 0a 20 20 20 20 20  ll pray');.     
0d00: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
0d10: 56 41 4c 55 45 53 28 27 46 6f 72 20 74 68 65 20  VALUES('For the 
0d20: 77 65 61 6c 20 6f 66 20 68 65 72 20 6c 6f 76 65  weal of her love
0d30: 72 20 74 68 61 74 27 27 73 20 66 61 72 20 61 77  r that''s far aw
0d40: 61 79 2e 27 29 3b 0a 20 20 20 20 43 4f 4d 4d 49  ay.');.    COMMI
0d50: 54 3b 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c  T;.  }.  execsql
0d60: 20 7b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e   {.    INSERT IN
0d70: 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55 45 53  TO t1(t1) VALUES
0d80: 28 27 6f 70 74 69 6d 69 7a 65 27 29 3b 0a 20 20  ('optimize');.  
0d90: 20 20 53 45 4c 45 43 54 20 73 75 62 73 74 72 28    SELECT substr(
0da0: 68 65 78 28 72 6f 6f 74 29 2c 20 31 2c 20 32 29  hex(root), 1, 2)
0db0: 20 46 52 4f 4d 20 74 31 5f 73 65 67 64 69 72 3b   FROM t1_segdir;
0dc0: 0a 20 20 7d 0a 7d 20 7b 30 33 7d 0a 0a 23 20 54  .  }.} {03}..# T
0dd0: 65 73 74 20 74 68 65 20 22 6d 69 73 73 69 6e 67  est the "missing
0de0: 20 65 6e 74 72 79 22 20 63 61 73 65 3a 0a 64 6f   entry" case:.do
0df0: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 32 2e  _test fts3cov-2.
0e00: 32 20 7b 0a 20 20 73 65 74 20 72 6f 6f 74 20 5b  2 {.  set root [
0e10: 64 62 20 6f 6e 65 20 7b 53 45 4c 45 43 54 20 72  db one {SELECT r
0e20: 6f 6f 74 20 46 52 4f 4d 20 74 31 5f 73 65 67 64  oot FROM t1_segd
0e30: 69 72 7d 5d 0a 20 20 72 65 61 64 5f 66 74 73 33  ir}].  read_fts3
0e40: 76 61 72 69 6e 74 20 5b 73 74 72 69 6e 67 20 72  varint [string r
0e50: 61 6e 67 65 20 24 72 6f 6f 74 20 31 20 65 6e 64  ange $root 1 end
0e60: 5d 20 6c 65 66 74 5f 63 68 69 6c 64 0a 20 20 65  ] left_child.  e
0e70: 78 65 63 73 71 6c 20 7b 20 44 45 4c 45 54 45 20  xecsql { DELETE 
0e80: 46 52 4f 4d 20 74 31 5f 73 65 67 6d 65 6e 74 73  FROM t1_segments
0e90: 20 57 48 45 52 45 20 62 6c 6f 63 6b 69 64 20 3d   WHERE blockid =
0ea0: 20 24 6c 65 66 74 5f 63 68 69 6c 64 20 7d 0a 7d   $left_child }.}
0eb0: 20 7b 7d 0a 64 6f 5f 65 72 72 6f 72 5f 74 65 73   {}.do_error_tes
0ec0: 74 20 66 74 73 33 63 6f 76 2d 32 2e 33 20 7b 0a  t fts3cov-2.3 {.
0ed0: 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20    SELECT * FROM 
0ee0: 74 31 20 57 48 45 52 45 20 74 31 20 4d 41 54 43  t1 WHERE t1 MATC
0ef0: 48 20 27 63 2a 27 0a 7d 20 7b 53 51 4c 20 6c 6f  H 'c*'.} {SQL lo
0f00: 67 69 63 20 65 72 72 6f 72 20 6f 72 20 6d 69 73  gic error or mis
0f10: 73 69 6e 67 20 64 61 74 61 62 61 73 65 7d 0a 0a  sing database}..
0f20: 23 20 54 65 73 74 20 74 68 65 20 22 72 65 70 6c  # Test the "repl
0f30: 61 63 65 64 20 77 69 74 68 20 4e 55 4c 4c 22 20  aced with NULL" 
0f40: 63 61 73 65 3a 0a 64 6f 5f 74 65 73 74 20 66 74  case:.do_test ft
0f50: 73 33 63 6f 76 2d 32 2e 34 20 7b 0a 20 20 65 78  s3cov-2.4 {.  ex
0f60: 65 63 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49  ecsql { INSERT I
0f70: 4e 54 4f 20 74 31 5f 73 65 67 6d 65 6e 74 73 20  NTO t1_segments 
0f80: 56 41 4c 55 45 53 28 24 6c 65 66 74 5f 63 68 69  VALUES($left_chi
0f90: 6c 64 2c 20 4e 55 4c 4c 29 20 7d 0a 7d 20 7b 7d  ld, NULL) }.} {}
0fa0: 0a 64 6f 5f 65 72 72 6f 72 5f 74 65 73 74 20 66  .do_error_test f
0fb0: 74 73 33 63 6f 76 2d 32 2e 35 20 7b 0a 20 20 53  ts3cov-2.5 {.  S
0fc0: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20  ELECT * FROM t1 
0fd0: 57 48 45 52 45 20 74 31 20 4d 41 54 43 48 20 27  WHERE t1 MATCH '
0fe0: 63 6c 6f 75 64 27 0a 7d 20 7b 53 51 4c 20 6c 6f  cloud'.} {SQL lo
0ff0: 67 69 63 20 65 72 72 6f 72 20 6f 72 20 6d 69 73  gic error or mis
1000: 73 69 6e 67 20 64 61 74 61 62 61 73 65 7d 0a 0a  sing database}..
1010: 23 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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1050: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 68  -----------.# Th
1060: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74  e following test
1070: 73 20 61 72 65 20 74 6f 20 74 65 73 74 20 74 68  s are to test th
1080: 65 20 65 66 66 65 63 74 73 20 6f 66 20 4f 4f 4d  e effects of OOM
1090: 20 65 72 72 6f 72 73 20 77 68 69 6c 65 20 73 74   errors while st
10a0: 6f 72 69 6e 67 0a 23 20 74 65 72 6d 73 20 69 6e  oring.# terms in
10b0: 20 74 68 65 20 70 65 6e 64 69 6e 67 2d 68 61 73   the pending-has
10c0: 68 20 74 61 62 6c 65 2e 20 53 70 65 63 69 66 69  h table. Specifi
10d0: 63 61 6c 6c 79 2c 20 77 68 69 6c 65 20 63 72 65  cally, while cre
10e0: 61 74 69 6e 67 20 64 6f 63 6c 69 73 74 0a 23 20  ating doclist.# 
10f0: 62 6c 6f 62 73 20 74 6f 20 73 74 6f 72 65 20 69  blobs to store i
1100: 6e 20 74 68 65 20 74 61 62 6c 65 2e 20 4d 6f 72  n the table. Mor
1110: 65 20 73 70 65 63 69 66 69 63 61 6c 6c 79 2c 20  e specifically, 
1120: 74 6f 20 74 65 73 74 20 4f 4f 4d 20 65 72 72 6f  to test OOM erro
1130: 72 73 20 77 68 69 6c 65 0a 23 20 61 70 70 65 6e  rs while.# appen
1140: 64 69 6e 67 20 63 6f 6c 75 6d 6e 20 6e 75 6d 62  ding column numb
1150: 65 72 73 20 74 6f 20 64 6f 63 6c 69 73 74 73 2e  ers to doclists.
1160: 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 69 66   For example, if
1170: 20 61 20 64 6f 63 6c 69 73 74 20 63 6f 6e 73 69   a doclist consi
1180: 73 74 73 0a 23 20 6f 66 3a 0a 23 0a 23 20 20 20  sts.# of:.#.#   
1190: 3c 64 6f 63 69 64 3e 20 3c 63 6f 6c 75 6d 6e 20  <docid> <column 
11a0: 30 20 6f 66 66 73 65 74 2d 6c 69 73 74 3e 20 30  0 offset-list> 0
11b0: 78 30 31 20 3c 63 6f 6c 75 6d 6e 20 4e 3e 20 3c  x01 <column N> <
11c0: 63 6f 6c 75 6d 6e 20 4e 20 6f 66 66 73 65 74 2d  column N offset-
11d0: 6c 69 73 74 3e 0a 23 0a 23 20 54 68 65 20 66 6f  list>.#.# The fo
11e0: 6c 6c 6f 77 69 6e 67 20 74 65 73 74 73 20 63 68  llowing tests ch
11f0: 65 63 6b 20 74 68 61 74 20 6d 61 6c 6c 6f 63 20  eck that malloc 
1200: 65 72 72 6f 72 73 20 65 6e 63 6f 75 6e 74 65 72  errors encounter
1210: 65 64 20 77 68 69 6c 65 20 61 70 70 65 6e 64 69  ed while appendi
1220: 6e 67 0a 23 20 74 68 65 20 22 30 78 30 31 20 3c  ng.# the "0x01 <
1230: 63 6f 6c 75 6d 6e 20 4e 3e 22 20 64 61 74 61 20  column N>" data 
1240: 74 6f 20 74 68 65 20 64 79 6e 61 6d 69 63 61 6c  to the dynamical
1250: 6c 79 20 67 72 6f 77 61 62 6c 65 20 62 6c 6f 62  ly growable blob
1260: 20 75 73 65 64 20 74 6f 20 0a 23 20 61 63 63 75   used to .# accu
1270: 6d 75 6c 61 74 65 20 74 68 65 20 64 6f 63 6c 69  mulate the docli
1280: 73 74 20 69 6e 20 6d 65 6d 6f 72 79 20 61 72 65  st in memory are
1290: 20 68 61 6e 64 6c 65 64 20 63 6f 72 72 65 63 74   handled correct
12a0: 6c 79 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 66 74  ly..#.do_test ft
12b0: 73 33 63 6f 76 2d 33 2e 31 20 7b 0a 20 20 73 65  s3cov-3.1 {.  se
12c0: 74 20 63 6f 6c 73 20 5b 6c 69 73 74 5d 0a 20 20  t cols [list].  
12d0: 73 65 74 20 76 61 6c 73 20 5b 6c 69 73 74 5d 0a  set vals [list].
12e0: 20 20 66 6f 72 20 7b 73 65 74 20 69 20 30 7d 20    for {set i 0} 
12f0: 7b 24 69 20 3c 20 31 32 30 7d 20 7b 69 6e 63 72  {$i < 120} {incr
1300: 20 69 7d 20 7b 0a 20 20 20 20 6c 61 70 70 65 6e   i} {.    lappen
1310: 64 20 63 6f 6c 73 20 22 63 6f 6c 24 69 22 0a 20  d cols "col$i". 
1320: 20 20 20 6c 61 70 70 65 6e 64 20 76 61 6c 73 20     lappend vals 
1330: 22 27 77 6f 72 64 27 22 0a 20 20 7d 0a 20 20 65  "'word'".  }.  e
1340: 78 65 63 73 71 6c 20 22 43 52 45 41 54 45 20 56  xecsql "CREATE V
1350: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 32 20  IRTUAL TABLE t2 
1360: 55 53 49 4e 47 20 66 74 73 33 28 5b 6a 6f 69 6e  USING fts3([join
1370: 20 24 63 6f 6c 73 20 2c 5d 29 22 0a 7d 20 7b 7d   $cols ,])".} {}
1380: 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43 5f 54  .set DO_MALLOC_T
1390: 45 53 54 20 31 20 0a 64 6f 5f 77 72 69 74 65 5f  EST 1 .do_write_
13a0: 74 65 73 74 20 66 74 73 33 63 6f 76 2d 33 2e 32  test fts3cov-3.2
13b0: 20 74 32 5f 63 6f 6e 74 65 6e 74 20 22 0a 20 20   t2_content ".  
13c0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 32 28 64  INSERT INTO t2(d
13d0: 6f 63 69 64 2c 20 5b 6a 6f 69 6e 20 24 63 6f 6c  ocid, [join $col
13e0: 73 20 2c 5d 29 20 56 41 4c 55 45 53 28 31 2c 20  s ,]) VALUES(1, 
13f0: 5b 6a 6f 69 6e 20 24 76 61 6c 73 20 2c 5d 29 0a  [join $vals ,]).
1400: 22 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73 74 20  ".do_write_test 
1410: 66 74 73 33 63 6f 76 2d 33 2e 33 20 74 32 5f 63  fts3cov-3.3 t2_c
1420: 6f 6e 74 65 6e 74 20 22 0a 20 20 49 4e 53 45 52  ontent ".  INSER
1430: 54 20 49 4e 54 4f 20 74 32 28 64 6f 63 69 64 2c  T INTO t2(docid,
1440: 20 5b 6a 6f 69 6e 20 24 63 6f 6c 73 20 2c 5d 29   [join $cols ,])
1450: 20 56 41 4c 55 45 53 28 32 30 30 2c 20 5b 6a 6f   VALUES(200, [jo
1460: 69 6e 20 24 76 61 6c 73 20 2c 5d 29 0a 22 0a 64  in $vals ,]).".d
1470: 6f 5f 77 72 69 74 65 5f 74 65 73 74 20 66 74 73  o_write_test fts
1480: 33 63 6f 76 2d 33 2e 34 20 74 32 5f 63 6f 6e 74  3cov-3.4 t2_cont
1490: 65 6e 74 20 22 0a 20 20 49 4e 53 45 52 54 20 49  ent ".  INSERT I
14a0: 4e 54 4f 20 74 32 28 64 6f 63 69 64 2c 20 5b 6a  NTO t2(docid, [j
14b0: 6f 69 6e 20 24 63 6f 6c 73 20 2c 5d 29 20 56 41  oin $cols ,]) VA
14c0: 4c 55 45 53 28 36 30 30 30 30 2c 20 5b 6a 6f 69  LUES(60000, [joi
14d0: 6e 20 24 76 61 6c 73 20 2c 5d 29 0a 22 0a 0a 23  n $vals ,])."..#
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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1520: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 49 66 20 74  ---------.# If t
1530: 6f 6f 20 6d 75 63 68 20 64 61 74 61 20 61 63 63  oo much data acc
1540: 75 6d 75 6c 61 74 65 73 20 69 6e 20 74 68 65 20  umulates in the 
1550: 70 65 6e 64 69 6e 67 2d 74 65 72 6d 73 20 68 61  pending-terms ha
1560: 73 68 20 74 61 62 6c 65 2c 20 69 74 20 69 73 0a  sh table, it is.
1570: 23 20 66 6c 75 73 68 65 64 20 74 6f 20 74 68 65  # flushed to the
1580: 20 64 61 74 61 62 61 73 65 20 61 75 74 6f 6d 61   database automa
1590: 74 69 63 61 6c 6c 79 2c 20 65 76 65 6e 20 69 66  tically, even if
15a0: 20 74 68 65 20 74 72 61 6e 73 61 63 74 69 6f 6e   the transaction
15b0: 20 68 61 73 20 6e 6f 74 0a 23 20 66 69 6e 69 73   has not.# finis
15c0: 68 65 64 2e 20 54 68 65 20 66 6f 6c 6c 6f 77 69  hed. The followi
15d0: 6e 67 20 74 65 73 74 73 20 63 68 65 63 6b 20 74  ng tests check t
15e0: 68 65 20 65 66 66 65 63 74 73 20 6f 66 20 65 6e  he effects of en
15f0: 63 6f 75 6e 74 65 72 69 6e 67 20 61 6e 20 4f 4f  countering an OO
1600: 4d 20 0a 23 20 77 68 69 6c 65 20 64 6f 69 6e 67  M .# while doing
1610: 20 74 68 69 73 2e 0a 23 0a 64 6f 5f 74 65 73 74   this..#.do_test
1620: 20 66 74 73 33 63 6f 76 2d 34 2e 31 20 7b 0a 20   fts3cov-4.1 {. 
1630: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43   execsql {.    C
1640: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
1650: 42 4c 45 20 74 33 20 55 53 49 4e 47 20 66 74 73  BLE t3 USING fts
1660: 33 28 78 29 3b 0a 20 20 20 20 49 4e 53 45 52 54  3(x);.    INSERT
1670: 20 49 4e 54 4f 20 74 33 28 74 33 29 20 56 41 4c   INTO t3(t3) VAL
1680: 55 45 53 28 27 6e 6f 64 65 73 69 7a 65 3d 32 34  UES('nodesize=24
1690: 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  ');.    INSERT I
16a0: 4e 54 4f 20 74 33 28 74 33 29 20 56 41 4c 55 45  NTO t3(t3) VALUE
16b0: 53 28 27 6d 61 78 70 65 6e 64 69 6e 67 3d 31 30  S('maxpending=10
16c0: 30 27 29 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 73 65  0');.  }.} {}.se
16d0: 74 20 44 4f 5f 4d 41 4c 4c 4f 43 5f 54 45 53 54  t DO_MALLOC_TEST
16e0: 20 31 20 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73   1 .do_write_tes
16f0: 74 20 66 74 73 33 63 6f 76 2d 34 2e 32 20 74 33  t fts3cov-4.2 t3
1700: 5f 63 6f 6e 74 65 6e 74 20 7b 0a 20 20 49 4e 53  _content {.  INS
1710: 45 52 54 20 49 4e 54 4f 20 74 33 28 64 6f 63 69  ERT INTO t3(doci
1720: 64 2c 20 78 29 0a 20 20 20 20 53 45 4c 45 43 54  d, x).    SELECT
1730: 20 31 2c 20 27 54 68 65 6e 20 43 68 72 69 73 74   1, 'Then Christ
1740: 61 62 65 6c 20 73 74 72 65 74 63 68 65 64 20 66  abel stretched f
1750: 6f 72 74 68 20 68 65 72 20 68 61 6e 64 2c 27 20  orth her hand,' 
1760: 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45  UNION ALL.    SE
1770: 4c 45 43 54 20 33 2c 20 27 41 6e 64 20 63 6f 6d  LECT 3, 'And com
1780: 66 6f 72 74 65 64 20 66 61 69 72 20 47 65 72 61  forted fair Gera
1790: 6c 64 69 6e 65 3a 27 20 20 20 20 20 20 20 20 20  ldine:'         
17a0: 20 20 20 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20      UNION ALL.  
17b0: 20 20 53 45 4c 45 43 54 20 34 2c 20 27 27 27 4f    SELECT 4, '''O
17c0: 20 77 65 6c 6c 2c 20 62 72 69 67 68 74 20 64 61   well, bright da
17d0: 6d 65 2c 20 6d 61 79 20 79 6f 75 20 63 6f 6d 6d  me, may you comm
17e0: 61 6e 64 27 20 20 20 20 55 4e 49 4f 4e 20 41 4c  and'    UNION AL
17f0: 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 35 2c 20  L.    SELECT 5, 
1800: 27 54 68 65 20 73 65 72 76 69 63 65 20 6f 66 20  'The service of 
1810: 53 69 72 20 4c 65 6f 6c 69 6e 65 3b 27 20 20 20  Sir Leoline;'   
1820: 20 20 20 20 20 20 20 20 20 20 20 20 55 4e 49 4f              UNIO
1830: 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54  N ALL.    SELECT
1840: 20 32 2c 20 27 41 6e 64 20 67 6c 61 64 6c 79 20   2, 'And gladly 
1850: 6f 75 72 20 73 74 6f 75 74 20 63 68 69 76 61 6c  our stout chival
1860: 72 79 27 20 20 20 20 20 20 20 20 20 20 20 20 20  ry'             
1870: 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45  UNION ALL.    SE
1880: 4c 45 43 54 20 37 2c 20 27 57 69 6c 6c 20 68 65  LECT 7, 'Will he
1890: 20 73 65 6e 64 20 66 6f 72 74 68 2c 20 61 6e 64   send forth, and
18a0: 20 66 72 69 65 6e 64 73 20 77 69 74 68 61 6c 2c   friends withal,
18b0: 27 20 20 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20  '   UNION ALL.  
18c0: 20 20 53 45 4c 45 43 54 20 38 2c 20 27 54 6f 20    SELECT 8, 'To 
18d0: 67 75 69 64 65 20 61 6e 64 20 67 75 61 72 64 20  guide and guard 
18e0: 79 6f 75 20 73 61 66 65 20 61 6e 64 20 66 72 65  you safe and fre
18f0: 65 27 20 20 20 20 20 20 55 4e 49 4f 4e 20 41 4c  e'      UNION AL
1900: 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 36 2c 20  L.    SELECT 6, 
1910: 27 48 6f 6d 65 20 74 6f 20 79 6f 75 72 20 6e 6f  'Home to your no
1920: 62 6c 65 20 66 61 74 68 65 72 27 27 73 20 68 61  ble father''s ha
1930: 6c 6c 2e 27 27 27 0a 7d 0a 0a 23 2d 2d 2d 2d 2d  ll.'''.}..#-----
1940: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1950: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1960: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1970: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1980: 2d 2d 2d 2d 0a 23 20 57 68 65 6e 20 62 75 69 6c  ----.# When buil
1990: 64 69 6e 67 20 74 68 65 20 69 6e 74 65 72 6e 61  ding the interna
19a0: 6c 20 74 72 65 65 20 73 74 72 75 63 74 75 72 65  l tree structure
19b0: 20 66 6f 72 20 65 61 63 68 20 73 65 67 6d 65 6e   for each segmen
19c0: 74 20 62 2d 74 72 65 65 2c 20 46 54 53 33 0a 23  t b-tree, FTS3.#
19d0: 20 61 73 73 75 6d 65 73 20 74 68 61 74 20 74 68   assumes that th
19e0: 65 20 63 6f 6e 74 65 6e 74 20 6f 66 20 65 61 63  e content of eac
19f0: 68 20 69 6e 74 65 72 6e 61 6c 20 6e 6f 64 65 20  h internal node 
1a00: 77 69 6c 6c 20 62 65 20 6c 65 73 73 20 74 68 61  will be less tha
1a10: 6e 0a 23 20 24 6e 6f 64 65 73 69 7a 65 20 62 79  n.# $nodesize by
1a20: 74 65 73 2c 20 77 68 65 72 65 20 24 6e 6f 64 65  tes, where $node
1a30: 73 69 7a 65 20 69 73 20 74 68 65 20 61 64 76 69  size is the advi
1a40: 73 6f 72 79 20 6e 6f 64 65 20 73 69 7a 65 2e 20  sory node size. 
1a50: 49 66 20 74 68 69 73 20 74 75 72 6e 73 0a 23 20  If this turns.# 
1a60: 6f 75 74 20 74 6f 20 62 65 20 75 6e 74 72 75 65  out to be untrue
1a70: 2c 20 74 68 65 6e 20 61 6e 20 65 78 74 72 61 20  , then an extra 
1a80: 62 75 66 66 65 72 20 6d 75 73 74 20 62 65 20 6d  buffer must be m
1a90: 61 6c 6c 6f 63 27 64 20 66 6f 72 20 65 61 63 68  alloc'd for each
1aa0: 20 74 65 72 6d 2e 0a 23 20 54 68 69 73 20 74 65   term..# This te
1ab0: 73 74 20 63 61 73 65 20 74 65 73 74 73 20 74 68  st case tests th
1ac0: 65 73 65 20 70 61 74 68 73 20 61 6e 64 20 74 68  ese paths and th
1ad0: 65 20 65 66 66 65 63 74 73 20 6f 66 20 73 61 69  e effects of sai
1ae0: 64 20 6d 61 6c 6c 6f 63 73 20 66 61 69 6c 69 6e  d mallocs failin
1af0: 67 0a 23 20 62 79 20 69 6e 73 65 72 74 69 6e 67  g.# by inserting
1b00: 20 69 6e 73 65 72 74 20 61 20 64 6f 63 75 6d 65   insert a docume
1b10: 6e 74 20 77 69 74 68 20 73 6f 6d 65 20 66 61 69  nt with some fai
1b20: 72 6c 79 20 6c 61 72 67 65 20 74 65 72 6d 73 20  rly large terms 
1b30: 69 6e 74 6f 20 61 0a 23 20 66 75 6c 6c 2d 74 65  into a.# full-te
1b40: 78 74 20 74 61 62 6c 65 20 77 69 74 68 20 61 20  xt table with a 
1b50: 76 65 72 79 20 73 6d 61 6c 6c 20 6e 6f 64 65 2d  very small node-
1b60: 73 69 7a 65 2e 20 0a 23 0a 23 20 54 65 73 74 20  size. .#.# Test 
1b70: 74 68 69 73 20 68 61 6e 64 6c 69 6e 67 20 6f 66  this handling of
1b80: 20 6c 61 72 67 65 20 74 65 72 6d 73 20 69 6e 20   large terms in 
1b90: 74 68 72 65 65 20 63 6f 6e 74 65 78 74 73 3a 0a  three contexts:.
1ba0: 23 0a 23 20 20 20 31 2e 20 57 68 65 6e 20 66 6c  #.#   1. When fl
1bb0: 75 73 68 69 6e 67 20 74 68 65 20 70 65 6e 64 69  ushing the pendi
1bc0: 6e 67 2d 74 65 72 6d 73 20 74 61 62 6c 65 2e 0a  ng-terms table..
1bd0: 23 20 20 20 32 2e 20 57 68 65 6e 20 6f 70 74 69  #   2. When opti
1be0: 6d 69 7a 69 6e 67 20 74 68 65 20 64 61 74 61 20  mizing the data 
1bf0: 73 74 72 75 63 74 75 72 65 73 20 75 73 69 6e 67  structures using
1c00: 20 74 68 65 20 49 4e 53 45 52 54 20 73 79 6e 74   the INSERT synt
1c10: 61 78 2e 20 0a 23 20 20 20 32 2e 20 57 68 65 6e  ax. .#   2. When
1c20: 20 6f 70 74 69 6d 69 7a 69 6e 67 20 74 68 65 20   optimizing the 
1c30: 64 61 74 61 20 73 74 72 75 63 74 75 72 65 73 20  data structures 
1c40: 75 73 69 6e 67 20 74 68 65 20 64 65 70 72 65 63  using the deprec
1c50: 61 74 65 64 20 53 45 4c 45 43 54 20 73 79 6e 74  ated SELECT synt
1c60: 61 78 2e 20 0a 23 0a 64 6f 5f 74 65 73 74 20 66  ax. .#.do_test f
1c70: 74 73 33 63 6f 76 2d 35 2e 31 20 7b 0a 20 20 65  ts3cov-5.1 {.  e
1c80: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45  xecsql {.    CRE
1c90: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
1ca0: 45 20 74 34 20 55 53 49 4e 47 20 66 74 73 33 28  E t4 USING fts3(
1cb0: 78 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  x);.    INSERT I
1cc0: 4e 54 4f 20 74 34 28 74 34 29 20 56 41 4c 55 45  NTO t4(t4) VALUE
1cd0: 53 28 27 6e 6f 64 65 73 69 7a 65 3d 32 34 27 29  S('nodesize=24')
1ce0: 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 73 65 74 20 44  ;.  }.} {}.set D
1cf0: 4f 5f 4d 41 4c 4c 4f 43 5f 54 45 53 54 20 31 0a  O_MALLOC_TEST 1.
1d00: 0a 23 20 54 65 73 74 20 77 68 65 6e 20 66 6c 75  .# Test when flu
1d10: 73 68 69 6e 67 20 70 65 6e 64 69 6e 67 2d 74 65  shing pending-te
1d20: 72 6d 73 20 74 61 62 6c 65 2e 0a 64 6f 5f 77 72  rms table..do_wr
1d30: 69 74 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76  ite_test fts3cov
1d40: 2d 35 2e 32 20 74 34 5f 63 6f 6e 74 65 6e 74 20  -5.2 t4_content 
1d50: 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  {.  INSERT INTO 
1d60: 74 34 0a 20 20 20 20 53 45 4c 45 43 54 20 27 49  t4.    SELECT 'I
1d70: 74 69 73 61 6e 61 6e 63 69 65 6e 74 4d 61 72 69  tisanancientMari
1d80: 6e 65 72 41 6e 64 68 65 73 74 6f 70 70 65 74 68  nerAndhestoppeth
1d90: 6f 6e 65 6f 66 74 68 72 65 65 41 41 27 20 55 4e  oneofthreeAA' UN
1da0: 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45  ION ALL.    SELE
1db0: 43 54 20 27 49 74 69 73 61 6e 61 6e 63 69 65 6e  CT 'Itisanancien
1dc0: 74 4d 61 72 69 6e 65 72 41 6e 64 68 65 73 74 6f  tMarinerAndhesto
1dd0: 70 70 65 74 68 6f 6e 65 6f 66 74 68 72 65 65 42  ppethoneofthreeB
1de0: 42 27 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20  B' UNION ALL.   
1df0: 20 53 45 4c 45 43 54 20 27 49 74 69 73 61 6e 61   SELECT 'Itisana
1e00: 6e 63 69 65 6e 74 4d 61 72 69 6e 65 72 41 6e 64  ncientMarinerAnd
1e10: 68 65 73 74 6f 70 70 65 74 68 6f 6e 65 6f 66 74  hestoppethoneoft
1e20: 68 72 65 65 43 43 27 20 55 4e 49 4f 4e 20 41 4c  hreeCC' UNION AL
1e30: 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 27 42 79  L.    SELECT 'By
1e40: 74 68 79 6c 6f 6e 67 67 72 65 79 62 65 61 72 64  thylonggreybeard
1e50: 61 6e 64 67 6c 69 74 74 65 72 69 6e 67 65 79 65  andglitteringeye
1e60: 4e 6f 77 77 68 65 72 65 66 6f 72 65 73 74 6f 70  Nowwhereforestop
1e70: 70 73 74 41 41 27 20 55 4e 49 4f 4e 20 41 4c 4c  pstAA' UNION ALL
1e80: 0a 20 20 20 20 53 45 4c 45 43 54 20 27 42 79 74  .    SELECT 'Byt
1e90: 68 79 6c 6f 6e 67 67 72 65 79 62 65 61 72 64 61  hylonggreybearda
1ea0: 6e 64 67 6c 69 74 74 65 72 69 6e 67 65 79 65 4e  ndglitteringeyeN
1eb0: 6f 77 77 68 65 72 65 66 6f 72 65 73 74 6f 70 70  owwhereforestopp
1ec0: 73 74 42 42 27 20 55 4e 49 4f 4e 20 41 4c 4c 0a  stBB' UNION ALL.
1ed0: 20 20 20 20 53 45 4c 45 43 54 20 27 42 79 74 68      SELECT 'Byth
1ee0: 79 6c 6f 6e 67 67 72 65 79 62 65 61 72 64 61 6e  ylonggreybeardan
1ef0: 64 67 6c 69 74 74 65 72 69 6e 67 65 79 65 4e 6f  dglitteringeyeNo
1f00: 77 77 68 65 72 65 66 6f 72 65 73 74 6f 70 70 73  wwhereforestopps
1f10: 74 43 43 27 0a 7d 0a 0a 23 20 54 65 73 74 20 77  tCC'.}..# Test w
1f20: 68 65 6e 20 6f 70 74 69 6d 69 7a 69 6e 67 20 76  hen optimizing v
1f30: 69 61 20 49 4e 53 45 52 54 2e 0a 64 6f 5f 74 65  ia INSERT..do_te
1f40: 73 74 20 66 74 73 33 63 6f 76 2d 35 2e 33 20 7b  st fts3cov-5.3 {
1f50: 20 65 78 65 63 73 71 6c 20 7b 20 49 4e 53 45 52   execsql { INSER
1f60: 54 20 49 4e 54 4f 20 74 34 20 56 41 4c 55 45 53  T INTO t4 VALUES
1f70: 28 27 65 78 74 72 61 21 27 29 20 7d 20 7d 20 7b  ('extra!') } } {
1f80: 7d 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73 74 20  }.do_write_test 
1f90: 66 74 73 33 63 6f 76 2d 35 2e 32 20 74 34 5f 73  fts3cov-5.2 t4_s
1fa0: 65 67 6d 65 6e 74 73 20 7b 20 49 4e 53 45 52 54  egments { INSERT
1fb0: 20 49 4e 54 4f 20 74 34 28 74 34 29 20 56 41 4c   INTO t4(t4) VAL
1fc0: 55 45 53 28 27 6f 70 74 69 6d 69 7a 65 27 29 20  UES('optimize') 
1fd0: 7d 0a 0a 23 20 54 65 73 74 20 77 68 65 6e 20 6f  }..# Test when o
1fe0: 70 74 69 6d 69 7a 69 6e 67 20 76 69 61 20 53 45  ptimizing via SE
1ff0: 4c 45 43 54 2e 0a 64 6f 5f 74 65 73 74 20 66 74  LECT..do_test ft
2000: 73 33 63 6f 76 2d 35 2e 35 20 7b 20 65 78 65 63  s3cov-5.5 { exec
2010: 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54  sql { INSERT INT
2020: 4f 20 74 34 20 56 41 4c 55 45 53 28 27 6d 6f 72  O t4 VALUES('mor
2030: 65 20 65 78 74 72 61 21 27 29 20 7d 20 7d 20 7b  e extra!') } } {
2040: 7d 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73 74 20  }.do_write_test 
2050: 66 74 73 33 63 6f 76 2d 35 2e 36 20 74 34 5f 73  fts3cov-5.6 t4_s
2060: 65 67 6d 65 6e 74 73 20 7b 0a 20 20 53 45 4c 45  egments {.  SELE
2070: 43 54 20 2a 20 46 52 4f 4d 20 28 53 45 4c 45 43  CT * FROM (SELEC
2080: 54 20 6f 70 74 69 6d 69 7a 65 28 74 34 29 20 46  T optimize(t4) F
2090: 52 4f 4d 20 74 34 20 4c 49 4d 49 54 20 31 29 0a  ROM t4 LIMIT 1).
20a0: 20 20 45 58 43 45 50 54 20 53 45 4c 45 43 54 20    EXCEPT SELECT 
20b0: 27 49 6e 64 65 78 20 6f 70 74 69 6d 69 7a 65 64  'Index optimized
20c0: 27 0a 7d 0a 0a 23 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 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2100: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
2110: 23 20 57 68 65 6e 20 6d 65 72 67 69 6e 67 20 61  # When merging a
2120: 6c 6c 20 73 65 67 6d 65 6e 74 73 20 61 74 20 61  ll segments at a
2130: 20 67 69 76 65 6e 20 6c 65 76 65 6c 20 74 6f 20   given level to 
2140: 63 72 65 61 74 65 20 61 20 73 69 6e 67 6c 65 20  create a single 
2150: 73 65 67 6d 65 6e 74 0a 23 20 61 74 20 6c 65 76  segment.# at lev
2160: 65 6c 2b 31 2c 20 46 54 53 33 20 72 75 6e 73 20  el+1, FTS3 runs 
2170: 61 20 71 75 65 72 79 20 6f 66 20 74 68 65 20 66  a query of the f
2180: 6f 72 6d 3a 0a 23 0a 23 20 20 20 53 45 4c 45 43  orm:.#.#   SELEC
2190: 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20  T count(*) FROM 
21a0: 25 5f 73 65 67 64 69 72 20 57 48 45 52 45 20 6c  %_segdir WHERE l
21b0: 65 76 65 6c 20 3d 20 3f 0a 23 0a 23 20 54 68 65  evel = ?.#.# The
21c0: 20 71 75 65 72 79 20 69 73 20 63 6f 6d 70 69 6c   query is compil
21d0: 65 64 20 74 68 65 20 66 69 72 73 74 20 74 69 6d  ed the first tim
21e0: 65 20 74 68 69 73 20 6f 70 65 72 61 74 69 6f 6e  e this operation
21f0: 20 69 73 20 72 65 71 75 69 72 65 64 20 61 6e 64   is required and
2200: 0a 23 20 72 65 75 73 65 64 20 74 68 65 72 65 61  .# reused therea
2210: 66 74 65 72 2e 20 54 68 69 73 20 74 65 73 74 20  fter. This test 
2220: 61 69 6d 73 20 74 6f 20 74 65 73 74 20 74 68 65  aims to test the
2230: 20 65 66 66 65 63 74 73 20 6f 66 20 61 6e 20 4f   effects of an O
2240: 4f 4d 20 77 68 69 6c 65 0a 23 20 70 72 65 70 61  OM while.# prepa
2250: 72 69 6e 67 20 61 6e 64 20 65 78 65 63 75 74 69  ring and executi
2260: 6e 67 20 74 68 69 73 20 71 75 65 72 79 20 66 6f  ng this query fo
2270: 72 20 74 68 65 20 66 69 72 73 74 20 74 69 6d 65  r the first time
2280: 2e 0a 23 0a 23 20 54 68 65 6e 2c 20 6b 65 65 70  ..#.# Then, keep
2290: 20 69 6e 73 65 72 74 69 6e 67 20 72 6f 77 73 20   inserting rows 
22a0: 69 6e 74 6f 20 74 68 65 20 74 61 62 6c 65 20 73  into the table s
22b0: 6f 20 74 68 61 74 20 74 68 65 20 65 66 66 65 63  o that the effec
22c0: 74 73 20 6f 66 20 61 6e 20 4f 4f 4d 0a 23 20 77  ts of an OOM.# w
22d0: 68 69 6c 65 20 72 65 2d 65 78 65 63 75 74 69 6e  hile re-executin
22e0: 67 20 74 68 65 20 73 61 6d 65 20 71 75 65 72 79  g the same query
22f0: 20 63 61 6e 20 61 6c 73 6f 20 62 65 20 74 65 73   can also be tes
2300: 74 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 66  ted..#.do_test f
2310: 74 73 33 63 6f 76 2d 36 2e 31 20 7b 0a 20 20 65  ts3cov-6.1 {.  e
2320: 78 65 63 73 71 6c 20 7b 20 43 52 45 41 54 45 20  xecsql { CREATE 
2330: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 35  VIRTUAL TABLE t5
2340: 20 55 53 49 4e 47 20 66 74 73 33 28 78 29 20 7d   USING fts3(x) }
2350: 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20 30 7d  .  for {set i 0}
2360: 20 7b 24 69 3c 31 36 7d 20 7b 69 6e 63 72 20 69   {$i<16} {incr i
2370: 7d 20 7b 20 65 78 65 63 73 71 6c 20 22 49 4e 53  } { execsql "INS
2380: 45 52 54 20 49 4e 54 4f 20 74 35 20 56 41 4c 55  ERT INTO t5 VALU
2390: 45 53 28 27 74 65 72 6d 24 69 27 29 22 20 7d 0a  ES('term$i')" }.
23a0: 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45    execsql { SELE
23b0: 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d  CT count(*) FROM
23c0: 20 74 35 5f 73 65 67 64 69 72 20 7d 0a 7d 20 7b   t5_segdir }.} {
23d0: 31 36 7d 0a 0a 23 20 46 69 72 73 74 20 74 69 6d  16}..# First tim
23e0: 65 2e 0a 64 62 20 63 6c 6f 73 65 0a 73 71 6c 69  e..db close.sqli
23f0: 74 65 33 20 64 62 20 74 65 73 74 2e 64 62 0a 64  te3 db test.db.d
2400: 6f 5f 77 72 69 74 65 5f 74 65 73 74 20 66 74 73  o_write_test fts
2410: 33 63 6f 76 2d 36 2e 32 20 74 35 5f 63 6f 6e 74  3cov-6.2 t5_cont
2420: 65 6e 74 20 7b 0a 20 20 49 4e 53 45 52 54 20 49  ent {.  INSERT I
2430: 4e 54 4f 20 74 35 20 56 41 4c 55 45 53 28 27 73  NTO t5 VALUES('s
2440: 65 67 6d 65 6e 74 20 6e 75 6d 62 65 72 20 31 36  egment number 16
2450: 21 27 29 3b 0a 7d 0a 0a 23 20 53 65 63 6f 6e 64  !');.}..# Second
2460: 20 74 69 6d 65 2e 0a 64 6f 5f 74 65 73 74 20 66   time..do_test f
2470: 74 73 33 63 6f 76 2d 36 2e 33 20 7b 0a 20 20 66  ts3cov-6.3 {.  f
2480: 6f 72 20 7b 73 65 74 20 69 20 31 7d 20 7b 24 69  or {set i 1} {$i
2490: 3c 31 36 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 20  <16} {incr i} { 
24a0: 65 78 65 63 73 71 6c 20 22 49 4e 53 45 52 54 20  execsql "INSERT 
24b0: 49 4e 54 4f 20 74 35 20 56 41 4c 55 45 53 28 27  INTO t5 VALUES('
24c0: 74 65 72 6d 24 69 27 29 22 20 7d 0a 20 20 65 78  term$i')" }.  ex
24d0: 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 63  ecsql { SELECT c
24e0: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74 35 5f  ount(*) FROM t5_
24f0: 73 65 67 64 69 72 20 7d 0a 7d 20 7b 31 37 7d 0a  segdir }.} {17}.
2500: 64 6f 5f 77 72 69 74 65 5f 74 65 73 74 20 66 74  do_write_test ft
2510: 73 33 63 6f 76 2d 36 2e 34 20 74 35 5f 63 6f 6e  s3cov-6.4 t5_con
2520: 74 65 6e 74 20 7b 0a 20 20 49 4e 53 45 52 54 20  tent {.  INSERT 
2530: 49 4e 54 4f 20 74 35 20 56 41 4c 55 45 53 28 27  INTO t5 VALUES('
2540: 73 65 67 6d 65 6e 74 20 6e 75 6d 62 65 72 20 31  segment number 1
2550: 36 21 27 29 3b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  6!');.}..#------
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 2d 2d 2d 2d  ----------------
2590: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
25a0: 2d 2d 2d 0a 23 20 55 70 64 61 74 65 20 74 68 65  ---.# Update the
25b0: 20 64 6f 63 69 64 20 6f 66 20 61 20 72 6f 77 2e   docid of a row.
25c0: 20 54 65 73 74 20 74 68 69 73 20 69 6e 20 74 77   Test this in tw
25d0: 6f 20 73 63 65 6e 61 72 69 6f 73 3a 0a 23 0a 23  o scenarios:.#.#
25e0: 20 20 20 31 2e 20 57 68 65 6e 20 74 68 65 20 72     1. When the r
25f0: 6f 77 20 62 65 69 6e 67 20 75 70 64 61 74 65 64  ow being updated
2600: 20 69 73 20 74 68 65 20 6f 6e 6c 79 20 72 6f 77   is the only row
2610: 20 69 6e 20 74 68 65 20 74 61 62 6c 65 2e 0a 23   in the table..#
2620: 20 20 20 32 2e 20 57 68 65 6e 20 69 74 20 69 73     2. When it is
2630: 20 6e 6f 74 2e 0a 23 0a 23 20 54 68 65 20 74 77   not..#.# The tw
2640: 6f 20 63 61 73 65 73 20 61 62 6f 76 65 20 74 61  o cases above ta
2650: 6b 65 20 64 69 66 66 65 72 65 6e 74 20 70 61 74  ke different pat
2660: 68 73 20 62 65 63 61 75 73 65 20 69 6e 20 63 61  hs because in ca
2670: 73 65 20 31 20 61 6c 6c 20 64 61 74 61 20 0a 23  se 1 all data .#
2680: 20 73 74 72 75 63 74 75 72 65 73 20 63 61 6e 20   structures can 
2690: 73 69 6d 70 6c 79 20 62 65 20 65 6d 70 74 69 65  simply be emptie
26a0: 64 20 62 65 66 6f 72 65 20 69 6e 73 65 72 74 69  d before inserti
26b0: 6e 67 20 74 68 65 20 6e 65 77 20 72 6f 77 20 72  ng the new row r
26c0: 65 63 6f 72 64 2e 0a 23 20 49 6e 20 63 61 73 65  ecord..# In case
26d0: 20 32 2c 20 74 68 65 20 64 61 74 61 20 73 74 72   2, the data str
26e0: 75 63 74 75 72 65 73 20 61 63 74 75 61 6c 6c 79  uctures actually
26f0: 20 68 61 76 65 20 74 6f 20 62 65 20 75 70 64 61   have to be upda
2700: 74 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 66  ted..#.do_test f
2710: 74 73 33 63 6f 76 2d 37 2e 31 20 7b 0a 20 20 65  ts3cov-7.1 {.  e
2720: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45  xecsql {.    CRE
2730: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
2740: 45 20 74 37 20 55 53 49 4e 47 20 66 74 73 33 28  E t7 USING fts3(
2750: 61 2c 20 62 2c 20 63 29 3b 0a 20 20 20 20 49 4e  a, b, c);.    IN
2760: 53 45 52 54 20 49 4e 54 4f 20 74 37 20 56 41 4c  SERT INTO t7 VAL
2770: 55 45 53 28 27 41 27 2c 20 27 42 27 2c 20 27 43  UES('A', 'B', 'C
2780: 27 29 3b 0a 20 20 20 20 55 50 44 41 54 45 20 74  ');.    UPDATE t
2790: 37 20 53 45 54 20 64 6f 63 69 64 20 3d 20 35 3b  7 SET docid = 5;
27a0: 0a 20 20 20 20 53 45 4c 45 43 54 20 64 6f 63 69  .    SELECT doci
27b0: 64 2c 20 2a 20 46 52 4f 4d 20 74 37 3b 0a 20 20  d, * FROM t7;.  
27c0: 7d 0a 7d 20 7b 35 20 41 20 42 20 43 7d 0a 64 6f  }.} {5 A B C}.do
27d0: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 37 2e  _test fts3cov-7.
27e0: 32 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  2 {.  execsql {.
27f0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
2800: 74 37 20 56 41 4c 55 45 53 28 27 44 27 2c 20 27  t7 VALUES('D', '
2810: 45 27 2c 20 27 46 27 29 3b 0a 20 20 20 20 55 50  E', 'F');.    UP
2820: 44 41 54 45 20 74 37 20 53 45 54 20 64 6f 63 69  DATE t7 SET doci
2830: 64 20 3d 20 31 20 57 48 45 52 45 20 64 6f 63 69  d = 1 WHERE doci
2840: 64 20 3d 20 36 3b 0a 20 20 20 20 53 45 4c 45 43  d = 6;.    SELEC
2850: 54 20 64 6f 63 69 64 2c 20 2a 20 46 52 4f 4d 20  T docid, * FROM 
2860: 74 37 3b 0a 20 20 7d 0a 7d 20 7b 31 20 44 20 45  t7;.  }.} {1 D E
2870: 20 46 20 35 20 41 20 42 20 43 7d 0a 0a 23 2d 2d   F 5 A B C}..#--
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: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
28c0: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 49 66 20 61 20 73  -------.# If a s
28d0: 65 74 20 6f 66 20 64 6f 63 75 6d 65 6e 74 73 20  et of documents 
28e0: 61 72 65 20 6d 6f 64 69 66 69 65 64 20 77 69 74  are modified wit
28f0: 68 69 6e 20 61 20 74 72 61 6e 73 61 63 74 69 6f  hin a transactio
2900: 6e 2c 20 74 68 65 20 0a 23 20 70 65 6e 64 69 6e  n, the .# pendin
2910: 67 2d 74 65 72 6d 73 20 74 61 62 6c 65 20 6d 75  g-terms table mu
2920: 73 74 20 62 65 20 66 6c 75 73 68 65 64 20 65 61  st be flushed ea
2930: 63 68 20 74 69 6d 65 20 61 20 64 6f 63 75 6d 65  ch time a docume
2940: 6e 74 20 77 69 74 68 20 61 20 64 6f 63 69 64 0a  nt with a docid.
2950: 23 20 6c 65 73 73 20 74 68 61 6e 20 6f 72 20 65  # less than or e
2960: 71 75 61 6c 20 74 6f 20 74 68 65 20 70 72 65 76  qual to the prev
2970: 69 6f 75 73 20 64 6f 63 69 64 20 69 73 20 6d 6f  ious docid is mo
2980: 64 69 66 69 65 64 2e 20 0a 23 0a 23 20 54 68 69  dified. .#.# Thi
2990: 73 20 74 65 73 74 20 63 68 65 63 6b 73 20 74 68  s test checks th
29a0: 65 20 65 66 66 65 63 74 73 20 6f 66 20 61 6e 20  e effects of an 
29b0: 4f 4f 4d 20 65 72 72 6f 72 20 6f 63 63 75 72 69  OOM error occuri
29c0: 6e 67 20 77 68 65 6e 20 74 68 65 20 0a 23 20 70  ng when the .# p
29d0: 65 6e 64 69 6e 67 2d 74 65 72 6d 73 20 74 61 62  ending-terms tab
29e0: 6c 65 20 69 73 20 66 6c 75 73 68 65 64 20 66 6f  le is flushed fo
29f0: 72 20 74 68 69 73 20 72 65 61 73 6f 6e 20 61 73  r this reason as
2a00: 20 70 61 72 74 20 6f 66 20 61 20 44 45 4c 45 54   part of a DELET
2a10: 45 20 0a 23 20 73 74 61 74 65 6d 65 6e 74 2e 0a  E .# statement..
2a20: 23 0a 64 6f 5f 6d 61 6c 6c 6f 63 5f 74 65 73 74  #.do_malloc_test
2a30: 20 66 74 73 33 63 6f 76 2d 38 20 2d 73 71 6c 70   fts3cov-8 -sqlp
2a40: 72 65 70 20 7b 0a 20 20 42 45 47 49 4e 3b 0a 20  rep {.  BEGIN;. 
2a50: 20 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41     CREATE VIRTUA
2a60: 4c 20 54 41 42 4c 45 20 74 38 20 55 53 49 4e 47  L TABLE t8 USING
2a70: 20 66 74 73 33 3b 0a 20 20 20 20 49 4e 53 45 52   fts3;.    INSER
2a80: 54 20 49 4e 54 4f 20 74 38 20 56 41 4c 55 45 53  T INTO t8 VALUES
2a90: 28 27 74 68 65 20 6f 75 74 70 75 74 20 6f 66 20  ('the output of 
2aa0: 65 61 63 68 20 62 61 74 63 68 20 72 75 6e 27 29  each batch run')
2ab0: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
2ac0: 4f 20 74 38 20 56 41 4c 55 45 53 28 27 28 70 6f  O t8 VALUES('(po
2ad0: 73 73 69 62 6c 79 20 61 20 64 61 79 27 27 73 20  ssibly a day''s 
2ae0: 77 6f 72 6b 29 27 29 3b 0a 20 20 20 20 49 4e 53  work)');.    INS
2af0: 45 52 54 20 49 4e 54 4f 20 74 38 20 56 41 4c 55  ERT INTO t8 VALU
2b00: 45 53 28 27 77 61 73 20 77 72 69 74 74 65 6e 20  ES('was written 
2b10: 74 6f 20 74 77 6f 20 73 65 70 61 72 61 74 65 20  to two separate 
2b20: 64 69 73 6b 73 27 29 3b 0a 20 20 43 4f 4d 4d 49  disks');.  COMMI
2b30: 54 3b 0a 7d 20 2d 73 71 6c 62 6f 64 79 20 7b 0a  T;.} -sqlbody {.
2b40: 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 44 45 4c    BEGIN;.    DEL
2b50: 45 54 45 20 46 52 4f 4d 20 74 38 20 57 48 45 52  ETE FROM t8 WHER
2b60: 45 20 72 6f 77 69 64 20 3d 20 33 3b 0a 20 20 20  E rowid = 3;.   
2b70: 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 38 20   DELETE FROM t8 
2b80: 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20 32 3b  WHERE rowid = 2;
2b90: 0a 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d  .    DELETE FROM
2ba0: 20 74 38 20 57 48 45 52 45 20 72 6f 77 69 64 20   t8 WHERE rowid 
2bb0: 3d 20 31 3b 0a 20 20 43 4f 4d 4d 49 54 3b 0a 7d  = 1;.  COMMIT;.}
2bc0: 0a 0a 23 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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54  ------------.# T
2c10: 65 73 74 20 73 6f 6d 65 20 62 72 61 6e 63 68 65  est some branche
2c20: 73 20 69 6e 20 74 68 65 20 63 6f 64 65 20 74 68  s in the code th
2c30: 61 74 20 68 61 6e 64 6c 65 73 20 22 73 70 65 63  at handles "spec
2c40: 69 61 6c 22 20 69 6e 73 65 72 74 73 20 6c 69 6b  ial" inserts lik
2c50: 65 3a 0a 23 0a 23 20 20 20 49 4e 53 45 52 54 20  e:.#.#   INSERT 
2c60: 49 4e 54 4f 20 74 31 28 74 31 29 20 56 41 4c 55  INTO t1(t1) VALU
2c70: 45 53 28 27 6f 70 74 69 6d 69 7a 65 27 29 3b 0a  ES('optimize');.
2c80: 23 0a 23 20 41 6c 73 6f 20 74 65 73 74 20 74 68  #.# Also test th
2c90: 61 74 20 61 6e 20 6f 70 74 69 6d 69 7a 65 20 28  at an optimize (
2ca0: 49 4e 53 45 52 54 20 6d 65 74 68 6f 64 29 20 77  INSERT method) w
2cb0: 6f 72 6b 73 20 6f 6e 20 61 6e 20 65 6d 70 74 79  orks on an empty
2cc0: 20 74 61 62 6c 65 2e 0a 23 0a 73 65 74 20 44 4f   table..#.set DO
2cd0: 5f 4d 41 4c 4c 4f 43 5f 54 45 53 54 20 30 0a 64  _MALLOC_TEST 0.d
2ce0: 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 39  o_test fts3cov-9
2cf0: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
2d00: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
2d10: 54 41 42 4c 45 20 78 78 20 55 53 49 4e 47 20 66  TABLE xx USING f
2d20: 74 73 33 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 65 72  ts3 }.} {}.do_er
2d30: 72 6f 72 5f 74 65 73 74 20 66 74 73 33 63 6f 76  ror_test fts3cov
2d40: 2d 39 2e 32 20 7b 0a 20 20 49 4e 53 45 52 54 20  -9.2 {.  INSERT 
2d50: 49 4e 54 4f 20 78 78 28 78 78 29 20 56 41 4c 55  INTO xx(xx) VALU
2d60: 45 53 28 27 6f 70 74 69 6d 69 73 65 27 29 3b 20  ES('optimise'); 
2d70: 20 20 2d 2d 20 42 72 69 74 69 73 68 20 73 70 65    -- British spe
2d80: 6c 6c 69 6e 67 0a 7d 20 7b 53 51 4c 20 6c 6f 67  lling.} {SQL log
2d90: 69 63 20 65 72 72 6f 72 20 6f 72 20 6d 69 73 73  ic error or miss
2da0: 69 6e 67 20 64 61 74 61 62 61 73 65 7d 0a 64 6f  ing database}.do
2db0: 5f 65 72 72 6f 72 5f 74 65 73 74 20 66 74 73 33  _error_test fts3
2dc0: 63 6f 76 2d 39 2e 33 20 7b 0a 20 20 49 4e 53 45  cov-9.3 {.  INSE
2dd0: 52 54 20 49 4e 54 4f 20 78 78 28 78 78 29 20 56  RT INTO xx(xx) V
2de0: 41 4c 55 45 53 28 27 73 68 6f 72 74 27 29 3b 0a  ALUES('short');.
2df0: 7d 20 7b 53 51 4c 20 6c 6f 67 69 63 20 65 72 72  } {SQL logic err
2e00: 6f 72 20 6f 72 20 6d 69 73 73 69 6e 67 20 64 61  or or missing da
2e10: 74 61 62 61 73 65 7d 0a 64 6f 5f 65 72 72 6f 72  tabase}.do_error
2e20: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 39 2e  _test fts3cov-9.
2e30: 34 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  4 {.  INSERT INT
2e40: 4f 20 78 78 28 78 78 29 20 56 41 4c 55 45 53 28  O xx(xx) VALUES(
2e50: 27 77 61 79 74 6f 6f 6c 6f 6e 67 74 6f 62 65 63  'waytoolongtobec
2e60: 6f 72 72 65 63 74 27 29 3b 0a 7d 20 7b 53 51 4c  orrect');.} {SQL
2e70: 20 6c 6f 67 69 63 20 65 72 72 6f 72 20 6f 72 20   logic error or 
2e80: 6d 69 73 73 69 6e 67 20 64 61 74 61 62 61 73 65  missing database
2e90: 7d 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f  }.do_test fts3co
2ea0: 76 2d 39 2e 35 20 7b 0a 20 20 65 78 65 63 73 71  v-9.5 {.  execsq
2eb0: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
2ec0: 78 78 28 78 78 29 20 56 41 4c 55 45 53 28 27 6f  xx(xx) VALUES('o
2ed0: 70 74 69 6d 69 7a 65 27 29 20 7d 0a 7d 20 7b 7d  ptimize') }.} {}
2ee0: 0a 0a 23 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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54  ------------.# T
2f30: 65 73 74 20 74 68 61 74 20 61 20 74 61 62 6c 65  est that a table
2f40: 20 63 61 6e 20 62 65 20 6f 70 74 69 6d 69 7a 65   can be optimize
2f50: 64 20 69 6e 20 74 68 65 20 6d 69 64 64 6c 65 20  d in the middle 
2f60: 6f 66 20 61 20 74 72 61 6e 73 61 63 74 69 6f 6e  of a transaction
2f70: 20 77 68 65 6e 0a 23 20 74 68 65 20 70 65 6e 64   when.# the pend
2f80: 69 6e 67 2d 74 65 72 6d 73 20 74 61 62 6c 65 20  ing-terms table 
2f90: 69 73 20 6e 6f 6e 2d 65 6d 70 74 79 2e 20 54 68  is non-empty. Th
2fa0: 69 73 20 63 61 73 65 20 69 6e 76 6f 6c 76 65 73  is case involves
2fb0: 20 73 6f 6d 65 20 65 78 74 72 61 0a 23 20 62 72   some extra.# br
2fc0: 61 6e 63 68 65 73 20 62 65 63 61 75 73 65 20 64  anches because d
2fd0: 61 74 61 20 6d 75 73 74 20 62 65 20 72 65 61 64  ata must be read
2fe0: 20 6e 6f 74 20 6f 6e 6c 79 20 66 72 6f 6d 20 74   not only from t
2ff0: 68 65 20 64 61 74 61 62 61 73 65 2c 20 62 75 74  he database, but
3000: 0a 23 20 61 6c 73 6f 20 66 72 6f 6d 20 74 68 65  .# also from the
3010: 20 70 65 6e 64 69 6e 67 2d 74 65 72 6d 73 20 74   pending-terms t
3020: 61 62 6c 65 2e 0a 23 0a 64 6f 5f 6d 61 6c 6c 6f  able..#.do_mallo
3030: 63 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 31  c_test fts3cov-1
3040: 30 20 2d 73 71 6c 70 72 65 70 20 7b 0a 20 20 43  0 -sqlprep {.  C
3050: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
3060: 42 4c 45 20 74 31 30 20 55 53 49 4e 47 20 66 74  BLE t10 USING ft
3070: 73 33 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  s3;.  INSERT INT
3080: 4f 20 74 31 30 20 56 41 4c 55 45 53 28 27 4f 70  O t10 VALUES('Op
3090: 74 69 6d 69 73 69 6e 67 20 69 6d 61 67 65 73 20  timising images 
30a0: 66 6f 72 20 74 68 65 20 77 65 62 20 69 73 20 61  for the web is a
30b0: 20 74 72 69 63 6b 79 20 62 75 73 69 6e 65 73 73   tricky business
30c0: 27 29 3b 0a 20 20 42 45 47 49 4e 3b 0a 20 20 20  ');.  BEGIN;.   
30d0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 30   INSERT INTO t10
30e0: 20 56 41 4c 55 45 53 28 27 59 6f 75 20 68 61 76   VALUES('You hav
30f0: 65 20 74 6f 20 67 65 74 20 74 68 65 20 72 69 67  e to get the rig
3100: 68 74 20 62 61 6c 61 6e 63 65 20 62 65 74 77 65  ht balance betwe
3110: 65 6e 27 29 3b 0a 7d 20 2d 73 71 6c 62 6f 64 79  en');.} -sqlbody
3120: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
3130: 20 74 31 30 28 74 31 30 29 20 56 41 4c 55 45 53   t10(t10) VALUES
3140: 28 27 6f 70 74 69 6d 69 7a 65 27 29 3b 0a 7d 0a  ('optimize');.}.
3150: 0a 23 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 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65  -----------.# Te
31a0: 73 74 20 61 20 66 75 6c 6c 2d 74 65 78 74 20 71  st a full-text q
31b0: 75 65 72 79 20 66 6f 72 20 61 20 74 65 72 6d 20  uery for a term 
31c0: 74 68 61 74 20 77 61 73 20 6f 6e 63 65 20 69 6e  that was once in
31d0: 20 74 68 65 20 69 6e 64 65 78 2c 20 62 75 74 20   the index, but 
31e0: 69 73 0a 23 20 6e 6f 20 6c 6f 6e 67 65 72 2e 0a  is.# no longer..
31f0: 23 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f  #.do_test fts3co
3200: 76 2d 31 31 2e 31 20 7b 0a 20 20 65 78 65 63 73  v-11.1 {.  execs
3210: 71 6c 20 7b 20 0a 20 20 20 20 43 52 45 41 54 45  ql { .    CREATE
3220: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78   VIRTUAL TABLE x
3230: 78 20 55 53 49 4e 47 20 66 74 73 33 3b 0a 20 20  x USING fts3;.  
3240: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 78    INSERT INTO xx
3250: 20 56 41 4c 55 45 53 28 27 6f 6e 65 20 74 77 6f   VALUES('one two
3260: 20 74 68 72 65 65 27 29 3b 0a 20 20 20 20 49 4e   three');.    IN
3270: 53 45 52 54 20 49 4e 54 4f 20 78 78 20 56 41 4c  SERT INTO xx VAL
3280: 55 45 53 28 27 66 6f 75 72 20 66 69 76 65 20 73  UES('four five s
3290: 69 78 27 29 3b 0a 20 20 20 20 44 45 4c 45 54 45  ix');.    DELETE
32a0: 20 46 52 4f 4d 20 78 78 20 57 48 45 52 45 20 64   FROM xx WHERE d
32b0: 6f 63 69 64 20 3d 20 31 3b 0a 20 20 7d 0a 20 20  ocid = 1;.  }.  
32c0: 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54  execsql { SELECT
32d0: 20 2a 20 46 52 4f 4d 20 78 78 20 57 48 45 52 45   * FROM xx WHERE
32e0: 20 78 78 20 4d 41 54 43 48 20 27 74 77 6f 27 20   xx MATCH 'two' 
32f0: 7d 0a 7d 20 7b 7d 0a 0a 0a 64 6f 5f 6d 61 6c 6c  }.} {}...do_mall
3300: 6f 63 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  oc_test fts3cov-
3310: 31 32 20 2d 73 71 6c 70 72 65 70 20 7b 0a 20 20  12 -sqlprep {.  
3320: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
3330: 41 42 4c 45 20 74 31 32 20 55 53 49 4e 47 20 66  ABLE t12 USING f
3340: 74 73 33 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  ts3;.  INSERT IN
3350: 54 4f 20 74 31 32 20 56 41 4c 55 45 53 28 27 69  TO t12 VALUES('i
3360: 73 20 6f 6e 65 20 6f 66 20 74 68 65 20 74 77 6f  s one of the two
3370: 20 74 6f 67 74 68 65 72 27 29 3b 0a 20 20 42 45   togther');.  BE
3380: 47 49 4e 3b 0a 20 20 20 20 49 4e 53 45 52 54 20  GIN;.    INSERT 
3390: 49 4e 54 4f 20 74 31 32 20 56 41 4c 55 45 53 28  INTO t12 VALUES(
33a0: 27 6f 6e 65 20 77 68 69 63 68 20 77 61 73 20 61  'one which was a
33b0: 70 70 72 6f 70 72 69 61 74 65 20 61 74 20 74 68  ppropriate at th
33c0: 65 20 74 69 6d 65 27 29 3b 0a 7d 20 2d 73 71 6c  e time');.} -sql
33d0: 62 6f 64 79 20 7b 0a 20 20 53 45 4c 45 43 54 20  body {.  SELECT 
33e0: 2a 20 46 52 4f 4d 20 74 31 32 20 57 48 45 52 45  * FROM t12 WHERE
33f0: 20 74 31 32 20 4d 41 54 43 48 20 27 6f 6e 65 27   t12 MATCH 'one'
3400: 0a 7d 0a 0a 64 6f 5f 6d 61 6c 6c 6f 63 5f 74 65  .}..do_malloc_te
3410: 73 74 20 66 74 73 33 63 6f 76 2d 31 33 20 2d 73  st fts3cov-13 -s
3420: 71 6c 70 72 65 70 20 7b 0a 20 20 50 52 41 47 4d  qlprep {.  PRAGM
3430: 41 20 65 6e 63 6f 64 69 6e 67 20 3d 20 27 55 54  A encoding = 'UT
3440: 46 2d 31 36 27 3b 0a 20 20 43 52 45 41 54 45 20  F-16';.  CREATE 
3450: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31  VIRTUAL TABLE t1
3460: 33 20 55 53 49 4e 47 20 66 74 73 33 3b 0a 20 20  3 USING fts3;.  
3470: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 33 20  INSERT INTO t13 
3480: 56 41 4c 55 45 53 28 27 74 77 6f 20 73 63 61 6c  VALUES('two scal
3490: 61 72 20 66 75 6e 63 74 69 6f 6e 73 27 29 3b 0a  ar functions');.
34a0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
34b0: 33 20 56 41 4c 55 45 53 28 27 73 63 61 6c 61 72  3 VALUES('scalar
34c0: 20 74 77 6f 20 66 75 6e 63 74 69 6f 6e 73 27 29   two functions')
34d0: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
34e0: 74 31 33 20 56 41 4c 55 45 53 28 27 66 75 6e 63  t13 VALUES('func
34f0: 74 69 6f 6e 73 20 73 63 61 6c 61 72 20 74 77 6f  tions scalar two
3500: 27 29 3b 0a 7d 20 2d 73 71 6c 62 6f 64 79 20 7b  ');.} -sqlbody {
3510: 0a 20 20 53 45 4c 45 43 54 20 73 6e 69 70 70 65  .  SELECT snippe
3520: 74 28 74 31 33 2c 20 27 25 25 27 2c 20 27 25 25  t(t13, '%%', '%%
3530: 27 2c 20 27 23 27 29 20 46 52 4f 4d 20 74 31 33  ', '#') FROM t13
3540: 20 57 48 45 52 45 20 74 31 33 20 4d 41 54 43 48   WHERE t13 MATCH
3550: 20 27 74 77 6f 27 3b 0a 20 20 53 45 4c 45 43 54   'two';.  SELECT
3560: 20 73 6e 69 70 70 65 74 28 74 31 33 2c 20 27 25   snippet(t13, '%
3570: 25 27 2c 20 27 25 25 27 29 20 46 52 4f 4d 20 74  %', '%%') FROM t
3580: 31 33 20 57 48 45 52 45 20 74 31 33 20 4d 41 54  13 WHERE t13 MAT
3590: 43 48 20 27 74 77 6f 27 3b 0a 20 20 53 45 4c 45  CH 'two';.  SELE
35a0: 43 54 20 73 6e 69 70 70 65 74 28 74 31 33 2c 20  CT snippet(t13, 
35b0: 27 25 25 27 29 20 46 52 4f 4d 20 74 31 33 20 57  '%%') FROM t13 W
35c0: 48 45 52 45 20 74 31 33 20 4d 41 54 43 48 20 27  HERE t13 MATCH '
35d0: 74 77 6f 27 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63  two';.}..do_exec
35e0: 73 71 6c 5f 74 65 73 74 20 31 34 2e 30 20 7b 0a  sql_test 14.0 {.
35f0: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
3600: 20 54 41 42 4c 45 20 74 31 34 20 55 53 49 4e 47   TABLE t14 USING
3610: 20 66 74 73 34 28 61 2c 20 62 29 3b 0a 20 20 49   fts4(a, b);.  I
3620: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 34 20 56  NSERT INTO t14 V
3630: 41 4c 55 45 53 28 27 6f 6e 65 20 74 77 6f 20 74  ALUES('one two t
3640: 68 72 65 65 27 2c 20 27 6f 6e 65 20 74 68 72 65  hree', 'one thre
3650: 65 20 66 6f 75 72 27 29 3b 0a 20 20 49 4e 53 45  e four');.  INSE
3660: 52 54 20 49 4e 54 4f 20 74 31 34 20 56 41 4c 55  RT INTO t14 VALU
3670: 45 53 28 27 61 20 62 20 63 27 2c 20 27 64 20 65  ES('a b c', 'd e
3680: 20 61 27 29 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73   a');.}.do_execs
3690: 71 6c 5f 74 65 73 74 20 31 34 2e 31 20 7b 0a 20  ql_test 14.1 {. 
36a0: 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52   SELECT rowid FR
36b0: 4f 4d 20 74 31 34 20 57 48 45 52 45 20 74 31 34  OM t14 WHERE t14
36c0: 20 4d 41 54 43 48 20 27 22 6f 6e 65 20 74 77 6f   MATCH '"one two
36d0: 20 74 68 72 65 65 22 27 0a 7d 20 7b 31 7d 0a 64   three"'.} {1}.d
36e0: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31  o_execsql_test 1
36f0: 34 2e 32 20 7b 0a 20 20 53 45 4c 45 43 54 20 72  4.2 {.  SELECT r
3700: 6f 77 69 64 20 46 52 4f 4d 20 74 31 34 20 57 48  owid FROM t14 WH
3710: 45 52 45 20 74 31 34 20 4d 41 54 43 48 20 27 22  ERE t14 MATCH '"
3720: 6f 6e 65 20 66 6f 75 72 22 27 0a 7d 20 7b 7d 0a  one four"'.} {}.
3730: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
3740: 31 34 2e 33 20 7b 0a 20 20 53 45 4c 45 43 54 20  14.3 {.  SELECT 
3750: 72 6f 77 69 64 20 46 52 4f 4d 20 74 31 34 20 57  rowid FROM t14 W
3760: 48 45 52 45 20 74 31 34 20 4d 41 54 43 48 20 27  HERE t14 MATCH '
3770: 22 65 20 61 22 27 0a 7d 20 7b 32 7d 0a 64 6f 5f  "e a"'.} {2}.do_
3780: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 34 2e  execsql_test 14.
3790: 35 20 7b 0a 20 20 53 45 4c 45 43 54 20 72 6f 77  5 {.  SELECT row
37a0: 69 64 20 46 52 4f 4d 20 74 31 34 20 57 48 45 52  id FROM t14 WHER
37b0: 45 20 74 31 34 20 4d 41 54 43 48 20 27 22 65 20  E t14 MATCH '"e 
37c0: 62 22 27 0a 7d 20 7b 7d 0a 64 6f 5f 63 61 74 63  b"'.} {}.do_catc
37d0: 68 73 71 6c 5f 74 65 73 74 20 31 34 2e 36 20 7b  hsql_test 14.6 {
37e0: 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20  .  SELECT rowid 
37f0: 46 52 4f 4d 20 74 31 34 20 57 48 45 52 45 20 72  FROM t14 WHERE r
3800: 6f 77 69 64 20 4d 41 54 43 48 20 27 6f 6e 65 27  owid MATCH 'one'
3810: 0a 7d 20 7b 31 20 7b 75 6e 61 62 6c 65 20 74 6f  .} {1 {unable to
3820: 20 75 73 65 20 66 75 6e 63 74 69 6f 6e 20 4d 41   use function MA
3830: 54 43 48 20 69 6e 20 74 68 65 20 72 65 71 75 65  TCH in the reque
3840: 73 74 65 64 20 63 6f 6e 74 65 78 74 7d 7d 0a 64  sted context}}.d
3850: 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20  o_catchsql_test 
3860: 31 34 2e 37 20 7b 0a 20 20 53 45 4c 45 43 54 20  14.7 {.  SELECT 
3870: 72 6f 77 69 64 20 46 52 4f 4d 20 74 31 34 20 57  rowid FROM t14 W
3880: 48 45 52 45 20 64 6f 63 69 64 20 4d 41 54 43 48  HERE docid MATCH
3890: 20 27 6f 6e 65 27 0a 7d 20 7b 31 20 7b 75 6e 61   'one'.} {1 {una
38a0: 62 6c 65 20 74 6f 20 75 73 65 20 66 75 6e 63 74  ble to use funct
38b0: 69 6f 6e 20 4d 41 54 43 48 20 69 6e 20 74 68 65  ion MATCH in the
38c0: 20 72 65 71 75 65 73 74 65 64 20 63 6f 6e 74 65   requested conte
38d0: 78 74 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c  xt}}..do_execsql
38e0: 5f 74 65 73 74 20 31 35 2e 30 20 7b 0a 20 20 43  _test 15.0 {.  C
38f0: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
3900: 42 4c 45 20 74 31 35 20 55 53 49 4e 47 20 66 74  BLE t15 USING ft
3910: 73 34 28 61 2c 20 62 2c 20 63 29 3b 0a 20 20 49  s4(a, b, c);.  I
3920: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 35 20 56  NSERT INTO t15 V
3930: 41 4c 55 45 53 28 27 61 62 63 20 64 65 66 20 67  ALUES('abc def g
3940: 68 69 27 2c 20 27 61 62 63 32 20 64 65 66 32 20  hi', 'abc2 def2 
3950: 67 68 69 32 27 2c 20 27 61 62 63 33 20 64 65 66  ghi2', 'abc3 def
3960: 33 20 67 68 69 33 27 29 3b 0a 20 20 49 4e 53 45  3 ghi3');.  INSE
3970: 52 54 20 49 4e 54 4f 20 74 31 35 20 56 41 4c 55  RT INTO t15 VALU
3980: 45 53 28 27 61 62 63 32 20 64 65 66 32 20 67 68  ES('abc2 def2 gh
3990: 69 32 27 2c 20 27 61 62 63 32 20 64 65 66 32 20  i2', 'abc2 def2 
39a0: 67 68 69 32 27 2c 20 27 61 62 63 20 64 65 66 33  ghi2', 'abc def3
39b0: 20 67 68 69 33 27 29 3b 0a 7d 0a 64 6f 5f 65 78   ghi3');.}.do_ex
39c0: 65 63 73 71 6c 5f 74 65 73 74 20 31 35 2e 31 20  ecsql_test 15.1 
39d0: 7b 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64  {.  SELECT rowid
39e0: 20 46 52 4f 4d 20 74 31 35 20 57 48 45 52 45 20   FROM t15 WHERE 
39f0: 74 31 35 20 4d 41 54 43 48 20 27 22 61 62 63 2a  t15 MATCH '"abc*
3a00: 20 64 65 66 32 22 27 0a 7d 20 7b 31 20 32 7d 0a   def2"'.} {1 2}.
3a10: 0a 23 20 54 65 73 74 20 61 20 63 6f 72 72 75 70  .# Test a corrup
3a20: 74 69 6f 6e 20 63 61 73 65 2e 0a 23 0a 64 6f 5f  tion case..#.do_
3a30: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 36 2e  execsql_test 16.
3a40: 31 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52  1 {.  CREATE VIR
3a50: 54 55 41 4c 20 54 41 42 4c 45 20 74 31 36 20 55  TUAL TABLE t16 U
3a60: 53 49 4e 47 20 66 74 73 34 3b 0a 20 20 49 4e 53  SING fts4;.  INS
3a70: 45 52 54 20 49 4e 54 4f 20 74 31 36 20 56 41 4c  ERT INTO t16 VAL
3a80: 55 45 53 28 27 74 68 65 6f 72 65 74 69 63 61 6c  UES('theoretical
3a90: 20 77 6f 72 6b 20 74 6f 20 65 78 61 6d 69 6e 65   work to examine
3aa0: 20 74 68 65 20 72 65 6c 61 74 69 6f 6e 73 68 69   the relationshi
3ab0: 70 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  p');.  INSERT IN
3ac0: 54 4f 20 74 31 36 20 56 41 4c 55 45 53 28 27 73  TO t16 VALUES('s
3ad0: 6f 6c 75 74 69 6f 6e 20 6f 66 20 6f 75 72 20 70  olution of our p
3ae0: 72 6f 62 6c 65 6d 73 20 6f 6e 20 74 68 65 20 69  roblems on the i
3af0: 6e 76 69 73 69 62 6c 65 27 29 3b 0a 20 20 44 45  nvisible');.  DE
3b00: 4c 45 54 45 20 46 52 4f 4d 20 74 31 36 5f 63 6f  LETE FROM t16_co
3b10: 6e 74 65 6e 74 20 57 48 45 52 45 20 72 6f 77 69  ntent WHERE rowi
3b20: 64 20 3d 20 32 3b 0a 7d 0a 64 6f 5f 63 61 74 63  d = 2;.}.do_catc
3b30: 68 73 71 6c 5f 74 65 73 74 20 31 36 2e 32 20 7b  hsql_test 16.2 {
3b40: 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d  .  SELECT * FROM
3b50: 20 74 31 36 20 57 48 45 52 45 20 74 31 36 20 4d   t16 WHERE t16 M
3b60: 41 54 43 48 20 27 69 6e 76 69 73 69 62 6c 65 27  ATCH 'invisible'
3b70: 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20  .} {1 {database 
3b80: 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61  disk image is ma
3b90: 6c 66 6f 72 6d 65 64 7d 7d 0a 0a 23 20 41 6e 64  lformed}}..# And
3ba0: 20 61 6e 6f 74 68 65 72 20 63 6f 72 72 75 70 74   another corrupt
3bb0: 69 6f 6e 20 74 65 73 74 20 63 61 73 65 2e 0a 23  ion test case..#
3bc0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
3bd0: 20 31 37 2e 31 20 7b 0a 20 20 43 52 45 41 54 45   17.1 {.  CREATE
3be0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74   VIRTUAL TABLE t
3bf0: 31 37 20 55 53 49 4e 47 20 66 74 73 34 3b 0a 20  17 USING fts4;. 
3c00: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 37   INSERT INTO t17
3c10: 28 63 6f 6e 74 65 6e 74 29 20 56 41 4c 55 45 53  (content) VALUES
3c20: 28 27 6f 6e 65 20 6f 6e 65 20 6f 6e 65 27 29 3b  ('one one one');
3c30: 0a 20 20 55 50 44 41 54 45 20 74 31 37 5f 73 65  .  UPDATE t17_se
3c40: 67 64 69 72 20 53 45 54 20 72 6f 6f 74 20 3d 20  gdir SET root = 
3c50: 58 27 30 30 30 33 36 46 36 45 36 35 46 46 46 46  X'00036F6E65FFFF
3c60: 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46 46  FFFFFFFFFFFFFFFF
3c70: 46 46 30 32 30 33 30 33 30 30 27 0a 7d 20 7b 7d  FF02030300'.} {}
3c80: 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73  .do_catchsql_tes
3c90: 74 20 31 37 2e 32 20 7b 0a 20 20 53 45 4c 45 43  t 17.2 {.  SELEC
3ca0: 54 20 2a 20 46 52 4f 4d 20 74 31 37 20 57 48 45  T * FROM t17 WHE
3cb0: 52 45 20 74 31 37 20 4d 41 54 43 48 20 27 6f 6e  RE t17 MATCH 'on
3cc0: 65 27 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73  e'.} {1 {databas
3cd0: 65 20 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20  e disk image is 
3ce0: 6d 61 6c 66 6f 72 6d 65 64 7d 7d 0a 0a 0a 0a 0a  malformed}}.....
3cf0: 66 69 6e 69 73 68 5f 74 65 73 74 0a              finish_test.