/ Hex Artifact Content
Login

Artifact 9c3681325b9a850bca8dd75cc29dde73e9a87972bb75204e97d826f13c7181f9:


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 7d 0a 0a 23 20 54 65  gic error}..# Te
0f10: 73 74 20 74 68 65 20 22 72 65 70 6c 61 63 65 64  st the "replaced
0f20: 20 77 69 74 68 20 4e 55 4c 4c 22 20 63 61 73 65   with NULL" case
0f30: 3a 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f  :.do_test fts3co
0f40: 76 2d 32 2e 34 20 7b 0a 20 20 65 78 65 63 73 71  v-2.4 {.  execsq
0f50: 6c 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  l { INSERT INTO 
0f60: 74 31 5f 73 65 67 6d 65 6e 74 73 20 56 41 4c 55  t1_segments VALU
0f70: 45 53 28 24 6c 65 66 74 5f 63 68 69 6c 64 2c 20  ES($left_child, 
0f80: 4e 55 4c 4c 29 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f  NULL) }.} {}.do_
0f90: 65 72 72 6f 72 5f 74 65 73 74 20 66 74 73 33 63  error_test fts3c
0fa0: 6f 76 2d 32 2e 35 20 7b 0a 20 20 53 45 4c 45 43  ov-2.5 {.  SELEC
0fb0: 54 20 2a 20 46 52 4f 4d 20 74 31 20 57 48 45 52  T * FROM t1 WHER
0fc0: 45 20 74 31 20 4d 41 54 43 48 20 27 63 6c 6f 75  E t1 MATCH 'clou
0fd0: 64 27 0a 7d 20 7b 53 51 4c 20 6c 6f 67 69 63 20  d'.} {SQL logic 
0fe0: 65 72 72 6f 72 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  error}..#-------
0ff0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 20 54 68 65 20 66 6f 6c 6c 6f 77  ---.# The follow
1040: 69 6e 67 20 74 65 73 74 73 20 61 72 65 20 74 6f  ing tests are to
1050: 20 74 65 73 74 20 74 68 65 20 65 66 66 65 63 74   test the effect
1060: 73 20 6f 66 20 4f 4f 4d 20 65 72 72 6f 72 73 20  s of OOM errors 
1070: 77 68 69 6c 65 20 73 74 6f 72 69 6e 67 0a 23 20  while storing.# 
1080: 74 65 72 6d 73 20 69 6e 20 74 68 65 20 70 65 6e  terms in the pen
1090: 64 69 6e 67 2d 68 61 73 68 20 74 61 62 6c 65 2e  ding-hash table.
10a0: 20 53 70 65 63 69 66 69 63 61 6c 6c 79 2c 20 77   Specifically, w
10b0: 68 69 6c 65 20 63 72 65 61 74 69 6e 67 20 64 6f  hile creating do
10c0: 63 6c 69 73 74 0a 23 20 62 6c 6f 62 73 20 74 6f  clist.# blobs to
10d0: 20 73 74 6f 72 65 20 69 6e 20 74 68 65 20 74 61   store in the ta
10e0: 62 6c 65 2e 20 4d 6f 72 65 20 73 70 65 63 69 66  ble. More specif
10f0: 69 63 61 6c 6c 79 2c 20 74 6f 20 74 65 73 74 20  ically, to test 
1100: 4f 4f 4d 20 65 72 72 6f 72 73 20 77 68 69 6c 65  OOM errors while
1110: 0a 23 20 61 70 70 65 6e 64 69 6e 67 20 63 6f 6c  .# appending col
1120: 75 6d 6e 20 6e 75 6d 62 65 72 73 20 74 6f 20 64  umn numbers to d
1130: 6f 63 6c 69 73 74 73 2e 20 46 6f 72 20 65 78 61  oclists. For exa
1140: 6d 70 6c 65 2c 20 69 66 20 61 20 64 6f 63 6c 69  mple, if a docli
1150: 73 74 20 63 6f 6e 73 69 73 74 73 0a 23 20 6f 66  st consists.# of
1160: 3a 0a 23 0a 23 20 20 20 3c 64 6f 63 69 64 3e 20  :.#.#   <docid> 
1170: 3c 63 6f 6c 75 6d 6e 20 30 20 6f 66 66 73 65 74  <column 0 offset
1180: 2d 6c 69 73 74 3e 20 30 78 30 31 20 3c 63 6f 6c  -list> 0x01 <col
1190: 75 6d 6e 20 4e 3e 20 3c 63 6f 6c 75 6d 6e 20 4e  umn N> <column N
11a0: 20 6f 66 66 73 65 74 2d 6c 69 73 74 3e 0a 23 0a   offset-list>.#.
11b0: 23 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20  # The following 
11c0: 74 65 73 74 73 20 63 68 65 63 6b 20 74 68 61 74  tests check that
11d0: 20 6d 61 6c 6c 6f 63 20 65 72 72 6f 72 73 20 65   malloc errors e
11e0: 6e 63 6f 75 6e 74 65 72 65 64 20 77 68 69 6c 65  ncountered while
11f0: 20 61 70 70 65 6e 64 69 6e 67 0a 23 20 74 68 65   appending.# the
1200: 20 22 30 78 30 31 20 3c 63 6f 6c 75 6d 6e 20 4e   "0x01 <column N
1210: 3e 22 20 64 61 74 61 20 74 6f 20 74 68 65 20 64  >" data to the d
1220: 79 6e 61 6d 69 63 61 6c 6c 79 20 67 72 6f 77 61  ynamically growa
1230: 62 6c 65 20 62 6c 6f 62 20 75 73 65 64 20 74 6f  ble blob used to
1240: 20 0a 23 20 61 63 63 75 6d 75 6c 61 74 65 20 74   .# accumulate t
1250: 68 65 20 64 6f 63 6c 69 73 74 20 69 6e 20 6d 65  he doclist in me
1260: 6d 6f 72 79 20 61 72 65 20 68 61 6e 64 6c 65 64  mory are handled
1270: 20 63 6f 72 72 65 63 74 6c 79 2e 0a 23 0a 64 6f   correctly..#.do
1280: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 33 2e  _test fts3cov-3.
1290: 31 20 7b 0a 20 20 73 65 74 20 63 6f 6c 73 20 5b  1 {.  set cols [
12a0: 6c 69 73 74 5d 0a 20 20 73 65 74 20 76 61 6c 73  list].  set vals
12b0: 20 5b 6c 69 73 74 5d 0a 20 20 66 6f 72 20 7b 73   [list].  for {s
12c0: 65 74 20 69 20 30 7d 20 7b 24 69 20 3c 20 31 32  et i 0} {$i < 12
12d0: 30 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20  0} {incr i} {.  
12e0: 20 20 6c 61 70 70 65 6e 64 20 63 6f 6c 73 20 22    lappend cols "
12f0: 63 6f 6c 24 69 22 0a 20 20 20 20 6c 61 70 70 65  col$i".    lappe
1300: 6e 64 20 76 61 6c 73 20 22 27 77 6f 72 64 27 22  nd vals "'word'"
1310: 0a 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 22  .  }.  execsql "
1320: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
1330: 41 42 4c 45 20 74 32 20 55 53 49 4e 47 20 66 74  ABLE t2 USING ft
1340: 73 33 28 5b 6a 6f 69 6e 20 24 63 6f 6c 73 20 2c  s3([join $cols ,
1350: 5d 29 22 0a 7d 20 7b 7d 0a 73 65 74 20 44 4f 5f  ])".} {}.set DO_
1360: 4d 41 4c 4c 4f 43 5f 54 45 53 54 20 31 20 0a 64  MALLOC_TEST 1 .d
1370: 6f 5f 77 72 69 74 65 5f 74 65 73 74 20 66 74 73  o_write_test fts
1380: 33 63 6f 76 2d 33 2e 32 20 74 32 5f 63 6f 6e 74  3cov-3.2 t2_cont
1390: 65 6e 74 20 22 0a 20 20 49 4e 53 45 52 54 20 49  ent ".  INSERT I
13a0: 4e 54 4f 20 74 32 28 64 6f 63 69 64 2c 20 5b 6a  NTO t2(docid, [j
13b0: 6f 69 6e 20 24 63 6f 6c 73 20 2c 5d 29 20 56 41  oin $cols ,]) VA
13c0: 4c 55 45 53 28 31 2c 20 5b 6a 6f 69 6e 20 24 76  LUES(1, [join $v
13d0: 61 6c 73 20 2c 5d 29 0a 22 0a 64 6f 5f 77 72 69  als ,]).".do_wri
13e0: 74 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  te_test fts3cov-
13f0: 33 2e 33 20 74 32 5f 63 6f 6e 74 65 6e 74 20 22  3.3 t2_content "
1400: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
1410: 32 28 64 6f 63 69 64 2c 20 5b 6a 6f 69 6e 20 24  2(docid, [join $
1420: 63 6f 6c 73 20 2c 5d 29 20 56 41 4c 55 45 53 28  cols ,]) VALUES(
1430: 32 30 30 2c 20 5b 6a 6f 69 6e 20 24 76 61 6c 73  200, [join $vals
1440: 20 2c 5d 29 0a 22 0a 64 6f 5f 77 72 69 74 65 5f   ,]).".do_write_
1450: 74 65 73 74 20 66 74 73 33 63 6f 76 2d 33 2e 34  test fts3cov-3.4
1460: 20 74 32 5f 63 6f 6e 74 65 6e 74 20 22 0a 20 20   t2_content ".  
1470: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 32 28 64  INSERT INTO t2(d
1480: 6f 63 69 64 2c 20 5b 6a 6f 69 6e 20 24 63 6f 6c  ocid, [join $col
1490: 73 20 2c 5d 29 20 56 41 4c 55 45 53 28 36 30 30  s ,]) VALUES(600
14a0: 30 30 2c 20 5b 6a 6f 69 6e 20 24 76 61 6c 73 20  00, [join $vals 
14b0: 2c 5d 29 0a 22 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  ,])."..#--------
14c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 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 0a 23 20 49 66 20 74 6f 6f 20 6d 75 63 68 20  -.# If too much 
1510: 64 61 74 61 20 61 63 63 75 6d 75 6c 61 74 65 73  data accumulates
1520: 20 69 6e 20 74 68 65 20 70 65 6e 64 69 6e 67 2d   in the pending-
1530: 74 65 72 6d 73 20 68 61 73 68 20 74 61 62 6c 65  terms hash table
1540: 2c 20 69 74 20 69 73 0a 23 20 66 6c 75 73 68 65  , it is.# flushe
1550: 64 20 74 6f 20 74 68 65 20 64 61 74 61 62 61 73  d to the databas
1560: 65 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 2c  e automatically,
1570: 20 65 76 65 6e 20 69 66 20 74 68 65 20 74 72 61   even if the tra
1580: 6e 73 61 63 74 69 6f 6e 20 68 61 73 20 6e 6f 74  nsaction has not
1590: 0a 23 20 66 69 6e 69 73 68 65 64 2e 20 54 68 65  .# finished. The
15a0: 20 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74 73   following tests
15b0: 20 63 68 65 63 6b 20 74 68 65 20 65 66 66 65 63   check the effec
15c0: 74 73 20 6f 66 20 65 6e 63 6f 75 6e 74 65 72 69  ts of encounteri
15d0: 6e 67 20 61 6e 20 4f 4f 4d 20 0a 23 20 77 68 69  ng an OOM .# whi
15e0: 6c 65 20 64 6f 69 6e 67 20 74 68 69 73 2e 0a 23  le doing this..#
15f0: 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76  .do_test fts3cov
1600: 2d 34 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c  -4.1 {.  execsql
1610: 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 56 49   {.    CREATE VI
1620: 52 54 55 41 4c 20 54 41 42 4c 45 20 74 33 20 55  RTUAL TABLE t3 U
1630: 53 49 4e 47 20 66 74 73 33 28 78 29 3b 0a 20 20  SING fts3(x);.  
1640: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 33    INSERT INTO t3
1650: 28 74 33 29 20 56 41 4c 55 45 53 28 27 6e 6f 64  (t3) VALUES('nod
1660: 65 73 69 7a 65 3d 32 34 27 29 3b 0a 20 20 20 20  esize=24');.    
1670: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 33 28 74  INSERT INTO t3(t
1680: 33 29 20 56 41 4c 55 45 53 28 27 6d 61 78 70 65  3) VALUES('maxpe
1690: 6e 64 69 6e 67 3d 31 30 30 27 29 3b 0a 20 20 7d  nding=100');.  }
16a0: 0a 7d 20 7b 7d 0a 73 65 74 20 44 4f 5f 4d 41 4c  .} {}.set DO_MAL
16b0: 4c 4f 43 5f 54 45 53 54 20 31 20 0a 64 6f 5f 77  LOC_TEST 1 .do_w
16c0: 72 69 74 65 5f 74 65 73 74 20 66 74 73 33 63 6f  rite_test fts3co
16d0: 76 2d 34 2e 32 20 74 33 5f 63 6f 6e 74 65 6e 74  v-4.2 t3_content
16e0: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
16f0: 20 74 33 28 64 6f 63 69 64 2c 20 78 29 0a 20 20   t3(docid, x).  
1700: 20 20 53 45 4c 45 43 54 20 31 2c 20 27 54 68 65    SELECT 1, 'The
1710: 6e 20 43 68 72 69 73 74 61 62 65 6c 20 73 74 72  n Christabel str
1720: 65 74 63 68 65 64 20 66 6f 72 74 68 20 68 65 72  etched forth her
1730: 20 68 61 6e 64 2c 27 20 55 4e 49 4f 4e 20 41 4c   hand,' UNION AL
1740: 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 33 2c 20  L.    SELECT 3, 
1750: 27 41 6e 64 20 63 6f 6d 66 6f 72 74 65 64 20 66  'And comforted f
1760: 61 69 72 20 47 65 72 61 6c 64 69 6e 65 3a 27 20  air Geraldine:' 
1770: 20 20 20 20 20 20 20 20 20 20 20 20 55 4e 49 4f              UNIO
1780: 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54  N ALL.    SELECT
1790: 20 34 2c 20 27 27 27 4f 20 77 65 6c 6c 2c 20 62   4, '''O well, b
17a0: 72 69 67 68 74 20 64 61 6d 65 2c 20 6d 61 79 20  right dame, may 
17b0: 79 6f 75 20 63 6f 6d 6d 61 6e 64 27 20 20 20 20  you command'    
17c0: 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45  UNION ALL.    SE
17d0: 4c 45 43 54 20 35 2c 20 27 54 68 65 20 73 65 72  LECT 5, 'The ser
17e0: 76 69 63 65 20 6f 66 20 53 69 72 20 4c 65 6f 6c  vice of Sir Leol
17f0: 69 6e 65 3b 27 20 20 20 20 20 20 20 20 20 20 20  ine;'           
1800: 20 20 20 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20      UNION ALL.  
1810: 20 20 53 45 4c 45 43 54 20 32 2c 20 27 41 6e 64    SELECT 2, 'And
1820: 20 67 6c 61 64 6c 79 20 6f 75 72 20 73 74 6f 75   gladly our stou
1830: 74 20 63 68 69 76 61 6c 72 79 27 20 20 20 20 20  t chivalry'     
1840: 20 20 20 20 20 20 20 20 55 4e 49 4f 4e 20 41 4c          UNION AL
1850: 4c 0a 20 20 20 20 53 45 4c 45 43 54 20 37 2c 20  L.    SELECT 7, 
1860: 27 57 69 6c 6c 20 68 65 20 73 65 6e 64 20 66 6f  'Will he send fo
1870: 72 74 68 2c 20 61 6e 64 20 66 72 69 65 6e 64 73  rth, and friends
1880: 20 77 69 74 68 61 6c 2c 27 20 20 20 55 4e 49 4f   withal,'   UNIO
1890: 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54  N ALL.    SELECT
18a0: 20 38 2c 20 27 54 6f 20 67 75 69 64 65 20 61 6e   8, 'To guide an
18b0: 64 20 67 75 61 72 64 20 79 6f 75 20 73 61 66 65  d guard you safe
18c0: 20 61 6e 64 20 66 72 65 65 27 20 20 20 20 20 20   and free'      
18d0: 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45  UNION ALL.    SE
18e0: 4c 45 43 54 20 36 2c 20 27 48 6f 6d 65 20 74 6f  LECT 6, 'Home to
18f0: 20 79 6f 75 72 20 6e 6f 62 6c 65 20 66 61 74 68   your noble fath
1900: 65 72 27 27 73 20 68 61 6c 6c 2e 27 27 27 0a 7d  er''s hall.'''.}
1910: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
1920: 2d 2d 2d 2d 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 0a 23 20 57  ------------.# W
1960: 68 65 6e 20 62 75 69 6c 64 69 6e 67 20 74 68 65  hen building the
1970: 20 69 6e 74 65 72 6e 61 6c 20 74 72 65 65 20 73   internal tree s
1980: 74 72 75 63 74 75 72 65 20 66 6f 72 20 65 61 63  tructure for eac
1990: 68 20 73 65 67 6d 65 6e 74 20 62 2d 74 72 65 65  h segment b-tree
19a0: 2c 20 46 54 53 33 0a 23 20 61 73 73 75 6d 65 73  , FTS3.# assumes
19b0: 20 74 68 61 74 20 74 68 65 20 63 6f 6e 74 65 6e   that the conten
19c0: 74 20 6f 66 20 65 61 63 68 20 69 6e 74 65 72 6e  t of each intern
19d0: 61 6c 20 6e 6f 64 65 20 77 69 6c 6c 20 62 65 20  al node will be 
19e0: 6c 65 73 73 20 74 68 61 6e 0a 23 20 24 6e 6f 64  less than.# $nod
19f0: 65 73 69 7a 65 20 62 79 74 65 73 2c 20 77 68 65  esize bytes, whe
1a00: 72 65 20 24 6e 6f 64 65 73 69 7a 65 20 69 73 20  re $nodesize is 
1a10: 74 68 65 20 61 64 76 69 73 6f 72 79 20 6e 6f 64  the advisory nod
1a20: 65 20 73 69 7a 65 2e 20 49 66 20 74 68 69 73 20  e size. If this 
1a30: 74 75 72 6e 73 0a 23 20 6f 75 74 20 74 6f 20 62  turns.# out to b
1a40: 65 20 75 6e 74 72 75 65 2c 20 74 68 65 6e 20 61  e untrue, then a
1a50: 6e 20 65 78 74 72 61 20 62 75 66 66 65 72 20 6d  n extra buffer m
1a60: 75 73 74 20 62 65 20 6d 61 6c 6c 6f 63 27 64 20  ust be malloc'd 
1a70: 66 6f 72 20 65 61 63 68 20 74 65 72 6d 2e 0a 23  for each term..#
1a80: 20 54 68 69 73 20 74 65 73 74 20 63 61 73 65 20   This test case 
1a90: 74 65 73 74 73 20 74 68 65 73 65 20 70 61 74 68  tests these path
1aa0: 73 20 61 6e 64 20 74 68 65 20 65 66 66 65 63 74  s and the effect
1ab0: 73 20 6f 66 20 73 61 69 64 20 6d 61 6c 6c 6f 63  s of said malloc
1ac0: 73 20 66 61 69 6c 69 6e 67 0a 23 20 62 79 20 69  s failing.# by i
1ad0: 6e 73 65 72 74 69 6e 67 20 69 6e 73 65 72 74 20  nserting insert 
1ae0: 61 20 64 6f 63 75 6d 65 6e 74 20 77 69 74 68 20  a document with 
1af0: 73 6f 6d 65 20 66 61 69 72 6c 79 20 6c 61 72 67  some fairly larg
1b00: 65 20 74 65 72 6d 73 20 69 6e 74 6f 20 61 0a 23  e terms into a.#
1b10: 20 66 75 6c 6c 2d 74 65 78 74 20 74 61 62 6c 65   full-text table
1b20: 20 77 69 74 68 20 61 20 76 65 72 79 20 73 6d 61   with a very sma
1b30: 6c 6c 20 6e 6f 64 65 2d 73 69 7a 65 2e 20 0a 23  ll node-size. .#
1b40: 0a 23 20 54 65 73 74 20 74 68 69 73 20 68 61 6e  .# Test this han
1b50: 64 6c 69 6e 67 20 6f 66 20 6c 61 72 67 65 20 74  dling of large t
1b60: 65 72 6d 73 20 69 6e 20 74 68 72 65 65 20 63 6f  erms in three co
1b70: 6e 74 65 78 74 73 3a 0a 23 0a 23 20 20 20 31 2e  ntexts:.#.#   1.
1b80: 20 57 68 65 6e 20 66 6c 75 73 68 69 6e 67 20 74   When flushing t
1b90: 68 65 20 70 65 6e 64 69 6e 67 2d 74 65 72 6d 73  he pending-terms
1ba0: 20 74 61 62 6c 65 2e 0a 23 20 20 20 32 2e 20 57   table..#   2. W
1bb0: 68 65 6e 20 6f 70 74 69 6d 69 7a 69 6e 67 20 74  hen optimizing t
1bc0: 68 65 20 64 61 74 61 20 73 74 72 75 63 74 75 72  he data structur
1bd0: 65 73 20 75 73 69 6e 67 20 74 68 65 20 49 4e 53  es using the INS
1be0: 45 52 54 20 73 79 6e 74 61 78 2e 20 0a 23 20 20  ERT syntax. .#  
1bf0: 20 32 2e 20 57 68 65 6e 20 6f 70 74 69 6d 69 7a   2. When optimiz
1c00: 69 6e 67 20 74 68 65 20 64 61 74 61 20 73 74 72  ing the data str
1c10: 75 63 74 75 72 65 73 20 75 73 69 6e 67 20 74 68  uctures using th
1c20: 65 20 64 65 70 72 65 63 61 74 65 64 20 53 45 4c  e deprecated SEL
1c30: 45 43 54 20 73 79 6e 74 61 78 2e 20 0a 23 0a 64  ECT syntax. .#.d
1c40: 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 35  o_test fts3cov-5
1c50: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
1c60: 0a 20 20 20 20 43 52 45 41 54 45 20 56 49 52 54  .    CREATE VIRT
1c70: 55 41 4c 20 54 41 42 4c 45 20 74 34 20 55 53 49  UAL TABLE t4 USI
1c80: 4e 47 20 66 74 73 33 28 78 29 3b 0a 20 20 20 20  NG fts3(x);.    
1c90: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 34 28 74  INSERT INTO t4(t
1ca0: 34 29 20 56 41 4c 55 45 53 28 27 6e 6f 64 65 73  4) VALUES('nodes
1cb0: 69 7a 65 3d 32 34 27 29 3b 0a 20 20 7d 0a 7d 20  ize=24');.  }.} 
1cc0: 7b 7d 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43  {}.set DO_MALLOC
1cd0: 5f 54 45 53 54 20 31 0a 0a 23 20 54 65 73 74 20  _TEST 1..# Test 
1ce0: 77 68 65 6e 20 66 6c 75 73 68 69 6e 67 20 70 65  when flushing pe
1cf0: 6e 64 69 6e 67 2d 74 65 72 6d 73 20 74 61 62 6c  nding-terms tabl
1d00: 65 2e 0a 64 6f 5f 77 72 69 74 65 5f 74 65 73 74  e..do_write_test
1d10: 20 66 74 73 33 63 6f 76 2d 35 2e 32 20 74 34 5f   fts3cov-5.2 t4_
1d20: 63 6f 6e 74 65 6e 74 20 7b 0a 20 20 49 4e 53 45  content {.  INSE
1d30: 52 54 20 49 4e 54 4f 20 74 34 0a 20 20 20 20 53  RT INTO t4.    S
1d40: 45 4c 45 43 54 20 27 49 74 69 73 61 6e 61 6e 63  ELECT 'Itisananc
1d50: 69 65 6e 74 4d 61 72 69 6e 65 72 41 6e 64 68 65  ientMarinerAndhe
1d60: 73 74 6f 70 70 65 74 68 6f 6e 65 6f 66 74 68 72  stoppethoneofthr
1d70: 65 65 41 41 27 20 55 4e 49 4f 4e 20 41 4c 4c 0a  eeAA' UNION ALL.
1d80: 20 20 20 20 53 45 4c 45 43 54 20 27 49 74 69 73      SELECT 'Itis
1d90: 61 6e 61 6e 63 69 65 6e 74 4d 61 72 69 6e 65 72  anancientMariner
1da0: 41 6e 64 68 65 73 74 6f 70 70 65 74 68 6f 6e 65  Andhestoppethone
1db0: 6f 66 74 68 72 65 65 42 42 27 20 55 4e 49 4f 4e  ofthreeBB' UNION
1dc0: 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54 20   ALL.    SELECT 
1dd0: 27 49 74 69 73 61 6e 61 6e 63 69 65 6e 74 4d 61  'ItisanancientMa
1de0: 72 69 6e 65 72 41 6e 64 68 65 73 74 6f 70 70 65  rinerAndhestoppe
1df0: 74 68 6f 6e 65 6f 66 74 68 72 65 65 43 43 27 20  thoneofthreeCC' 
1e00: 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45  UNION ALL.    SE
1e10: 4c 45 43 54 20 27 42 79 74 68 79 6c 6f 6e 67 67  LECT 'Bythylongg
1e20: 72 65 79 62 65 61 72 64 61 6e 64 67 6c 69 74 74  reybeardandglitt
1e30: 65 72 69 6e 67 65 79 65 4e 6f 77 77 68 65 72 65  eringeyeNowwhere
1e40: 66 6f 72 65 73 74 6f 70 70 73 74 41 41 27 20 55  forestoppstAA' U
1e50: 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c  NION ALL.    SEL
1e60: 45 43 54 20 27 42 79 74 68 79 6c 6f 6e 67 67 72  ECT 'Bythylonggr
1e70: 65 79 62 65 61 72 64 61 6e 64 67 6c 69 74 74 65  eybeardandglitte
1e80: 72 69 6e 67 65 79 65 4e 6f 77 77 68 65 72 65 66  ringeyeNowwheref
1e90: 6f 72 65 73 74 6f 70 70 73 74 42 42 27 20 55 4e  orestoppstBB' UN
1ea0: 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45  ION ALL.    SELE
1eb0: 43 54 20 27 42 79 74 68 79 6c 6f 6e 67 67 72 65  CT 'Bythylonggre
1ec0: 79 62 65 61 72 64 61 6e 64 67 6c 69 74 74 65 72  ybeardandglitter
1ed0: 69 6e 67 65 79 65 4e 6f 77 77 68 65 72 65 66 6f  ingeyeNowwherefo
1ee0: 72 65 73 74 6f 70 70 73 74 43 43 27 0a 7d 0a 0a  restoppstCC'.}..
1ef0: 23 20 54 65 73 74 20 77 68 65 6e 20 6f 70 74 69  # Test when opti
1f00: 6d 69 7a 69 6e 67 20 76 69 61 20 49 4e 53 45 52  mizing via INSER
1f10: 54 2e 0a 64 6f 5f 74 65 73 74 20 66 74 73 33 63  T..do_test fts3c
1f20: 6f 76 2d 35 2e 33 20 7b 20 65 78 65 63 73 71 6c  ov-5.3 { execsql
1f30: 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74   { INSERT INTO t
1f40: 34 20 56 41 4c 55 45 53 28 27 65 78 74 72 61 21  4 VALUES('extra!
1f50: 27 29 20 7d 20 7d 20 7b 7d 0a 64 6f 5f 77 72 69  ') } } {}.do_wri
1f60: 74 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  te_test fts3cov-
1f70: 35 2e 32 20 74 34 5f 73 65 67 6d 65 6e 74 73 20  5.2 t4_segments 
1f80: 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 34  { INSERT INTO t4
1f90: 28 74 34 29 20 56 41 4c 55 45 53 28 27 6f 70 74  (t4) VALUES('opt
1fa0: 69 6d 69 7a 65 27 29 20 7d 0a 0a 23 20 54 65 73  imize') }..# Tes
1fb0: 74 20 77 68 65 6e 20 6f 70 74 69 6d 69 7a 69 6e  t when optimizin
1fc0: 67 20 76 69 61 20 53 45 4c 45 43 54 2e 0a 64 6f  g via SELECT..do
1fd0: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 35 2e  _test fts3cov-5.
1fe0: 35 20 7b 20 65 78 65 63 73 71 6c 20 7b 20 49 4e  5 { execsql { IN
1ff0: 53 45 52 54 20 49 4e 54 4f 20 74 34 20 56 41 4c  SERT INTO t4 VAL
2000: 55 45 53 28 27 6d 6f 72 65 20 65 78 74 72 61 21  UES('more extra!
2010: 27 29 20 7d 20 7d 20 7b 7d 0a 64 6f 5f 77 72 69  ') } } {}.do_wri
2020: 74 65 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d  te_test fts3cov-
2030: 35 2e 36 20 74 34 5f 73 65 67 6d 65 6e 74 73 20  5.6 t4_segments 
2040: 7b 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f  {.  SELECT * FRO
2050: 4d 20 28 53 45 4c 45 43 54 20 6f 70 74 69 6d 69  M (SELECT optimi
2060: 7a 65 28 74 34 29 20 46 52 4f 4d 20 74 34 20 4c  ze(t4) FROM t4 L
2070: 49 4d 49 54 20 31 29 0a 20 20 45 58 43 45 50 54  IMIT 1).  EXCEPT
2080: 20 53 45 4c 45 43 54 20 27 49 6e 64 65 78 20 6f   SELECT 'Index o
2090: 70 74 69 6d 69 7a 65 64 27 0a 7d 0a 0a 23 2d 2d  ptimized'.}..#--
20a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 20 57 68 65 6e 20 6d  -------.# When m
20f0: 65 72 67 69 6e 67 20 61 6c 6c 20 73 65 67 6d 65  erging all segme
2100: 6e 74 73 20 61 74 20 61 20 67 69 76 65 6e 20 6c  nts at a given l
2110: 65 76 65 6c 20 74 6f 20 63 72 65 61 74 65 20 61  evel to create a
2120: 20 73 69 6e 67 6c 65 20 73 65 67 6d 65 6e 74 0a   single segment.
2130: 23 20 61 74 20 6c 65 76 65 6c 2b 31 2c 20 46 54  # at level+1, FT
2140: 53 33 20 72 75 6e 73 20 61 20 71 75 65 72 79 20  S3 runs a query 
2150: 6f 66 20 74 68 65 20 66 6f 72 6d 3a 0a 23 0a 23  of the form:.#.#
2160: 20 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28     SELECT count(
2170: 2a 29 20 46 52 4f 4d 20 25 5f 73 65 67 64 69 72  *) FROM %_segdir
2180: 20 57 48 45 52 45 20 6c 65 76 65 6c 20 3d 20 3f   WHERE level = ?
2190: 0a 23 0a 23 20 54 68 65 20 71 75 65 72 79 20 69  .#.# The query i
21a0: 73 20 63 6f 6d 70 69 6c 65 64 20 74 68 65 20 66  s compiled the f
21b0: 69 72 73 74 20 74 69 6d 65 20 74 68 69 73 20 6f  irst time this o
21c0: 70 65 72 61 74 69 6f 6e 20 69 73 20 72 65 71 75  peration is requ
21d0: 69 72 65 64 20 61 6e 64 0a 23 20 72 65 75 73 65  ired and.# reuse
21e0: 64 20 74 68 65 72 65 61 66 74 65 72 2e 20 54 68  d thereafter. Th
21f0: 69 73 20 74 65 73 74 20 61 69 6d 73 20 74 6f 20  is test aims to 
2200: 74 65 73 74 20 74 68 65 20 65 66 66 65 63 74 73  test the effects
2210: 20 6f 66 20 61 6e 20 4f 4f 4d 20 77 68 69 6c 65   of an OOM while
2220: 0a 23 20 70 72 65 70 61 72 69 6e 67 20 61 6e 64  .# preparing and
2230: 20 65 78 65 63 75 74 69 6e 67 20 74 68 69 73 20   executing this 
2240: 71 75 65 72 79 20 66 6f 72 20 74 68 65 20 66 69  query for the fi
2250: 72 73 74 20 74 69 6d 65 2e 0a 23 0a 23 20 54 68  rst time..#.# Th
2260: 65 6e 2c 20 6b 65 65 70 20 69 6e 73 65 72 74 69  en, keep inserti
2270: 6e 67 20 72 6f 77 73 20 69 6e 74 6f 20 74 68 65  ng rows into the
2280: 20 74 61 62 6c 65 20 73 6f 20 74 68 61 74 20 74   table so that t
2290: 68 65 20 65 66 66 65 63 74 73 20 6f 66 20 61 6e  he effects of an
22a0: 20 4f 4f 4d 0a 23 20 77 68 69 6c 65 20 72 65 2d   OOM.# while re-
22b0: 65 78 65 63 75 74 69 6e 67 20 74 68 65 20 73 61  executing the sa
22c0: 6d 65 20 71 75 65 72 79 20 63 61 6e 20 61 6c 73  me query can als
22d0: 6f 20 62 65 20 74 65 73 74 65 64 2e 0a 23 0a 64  o be tested..#.d
22e0: 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 36  o_test fts3cov-6
22f0: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
2300: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
2310: 54 41 42 4c 45 20 74 35 20 55 53 49 4e 47 20 66  TABLE t5 USING f
2320: 74 73 33 28 78 29 20 7d 0a 20 20 66 6f 72 20 7b  ts3(x) }.  for {
2330: 73 65 74 20 69 20 30 7d 20 7b 24 69 3c 31 36 7d  set i 0} {$i<16}
2340: 20 7b 69 6e 63 72 20 69 7d 20 7b 20 65 78 65 63   {incr i} { exec
2350: 73 71 6c 20 22 49 4e 53 45 52 54 20 49 4e 54 4f  sql "INSERT INTO
2360: 20 74 35 20 56 41 4c 55 45 53 28 27 74 65 72 6d   t5 VALUES('term
2370: 24 69 27 29 22 20 7d 0a 20 20 65 78 65 63 73 71  $i')" }.  execsq
2380: 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f 75 6e 74  l { SELECT count
2390: 28 2a 29 20 46 52 4f 4d 20 74 35 5f 73 65 67 64  (*) FROM t5_segd
23a0: 69 72 20 7d 0a 7d 20 7b 31 36 7d 0a 0a 23 20 46  ir }.} {16}..# F
23b0: 69 72 73 74 20 74 69 6d 65 2e 0a 64 62 20 63 6c  irst time..db cl
23c0: 6f 73 65 0a 73 71 6c 69 74 65 33 20 64 62 20 74  ose.sqlite3 db t
23d0: 65 73 74 2e 64 62 0a 64 6f 5f 77 72 69 74 65 5f  est.db.do_write_
23e0: 74 65 73 74 20 66 74 73 33 63 6f 76 2d 36 2e 32  test fts3cov-6.2
23f0: 20 74 35 5f 63 6f 6e 74 65 6e 74 20 7b 0a 20 20   t5_content {.  
2400: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 35 20 56  INSERT INTO t5 V
2410: 41 4c 55 45 53 28 27 73 65 67 6d 65 6e 74 20 6e  ALUES('segment n
2420: 75 6d 62 65 72 20 31 36 21 27 29 3b 0a 7d 0a 0a  umber 16!');.}..
2430: 23 20 53 65 63 6f 6e 64 20 74 69 6d 65 2e 0a 64  # Second time..d
2440: 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 36  o_test fts3cov-6
2450: 2e 33 20 7b 0a 20 20 66 6f 72 20 7b 73 65 74 20  .3 {.  for {set 
2460: 69 20 31 7d 20 7b 24 69 3c 31 36 7d 20 7b 69 6e  i 1} {$i<16} {in
2470: 63 72 20 69 7d 20 7b 20 65 78 65 63 73 71 6c 20  cr i} { execsql 
2480: 22 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 35 20  "INSERT INTO t5 
2490: 56 41 4c 55 45 53 28 27 74 65 72 6d 24 69 27 29  VALUES('term$i')
24a0: 22 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  " }.  execsql { 
24b0: 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20  SELECT count(*) 
24c0: 46 52 4f 4d 20 74 35 5f 73 65 67 64 69 72 20 7d  FROM t5_segdir }
24d0: 0a 7d 20 7b 31 37 7d 0a 64 6f 5f 77 72 69 74 65  .} {17}.do_write
24e0: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 36 2e  _test fts3cov-6.
24f0: 34 20 74 35 5f 63 6f 6e 74 65 6e 74 20 7b 0a 20  4 t5_content {. 
2500: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 35 20   INSERT INTO t5 
2510: 56 41 4c 55 45 53 28 27 73 65 67 6d 65 6e 74 20  VALUES('segment 
2520: 6e 75 6d 62 65 72 20 31 36 21 27 29 3b 0a 7d 0a  number 16!');.}.
2530: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
2540: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2550: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2560: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2570: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 55 70  -----------.# Up
2580: 64 61 74 65 20 74 68 65 20 64 6f 63 69 64 20 6f  date the docid o
2590: 66 20 61 20 72 6f 77 2e 20 54 65 73 74 20 74 68  f a row. Test th
25a0: 69 73 20 69 6e 20 74 77 6f 20 73 63 65 6e 61 72  is in two scenar
25b0: 69 6f 73 3a 0a 23 0a 23 20 20 20 31 2e 20 57 68  ios:.#.#   1. Wh
25c0: 65 6e 20 74 68 65 20 72 6f 77 20 62 65 69 6e 67  en the row being
25d0: 20 75 70 64 61 74 65 64 20 69 73 20 74 68 65 20   updated is the 
25e0: 6f 6e 6c 79 20 72 6f 77 20 69 6e 20 74 68 65 20  only row in the 
25f0: 74 61 62 6c 65 2e 0a 23 20 20 20 32 2e 20 57 68  table..#   2. Wh
2600: 65 6e 20 69 74 20 69 73 20 6e 6f 74 2e 0a 23 0a  en it is not..#.
2610: 23 20 54 68 65 20 74 77 6f 20 63 61 73 65 73 20  # The two cases 
2620: 61 62 6f 76 65 20 74 61 6b 65 20 64 69 66 66 65  above take diffe
2630: 72 65 6e 74 20 70 61 74 68 73 20 62 65 63 61 75  rent paths becau
2640: 73 65 20 69 6e 20 63 61 73 65 20 31 20 61 6c 6c  se in case 1 all
2650: 20 64 61 74 61 20 0a 23 20 73 74 72 75 63 74 75   data .# structu
2660: 72 65 73 20 63 61 6e 20 73 69 6d 70 6c 79 20 62  res can simply b
2670: 65 20 65 6d 70 74 69 65 64 20 62 65 66 6f 72 65  e emptied before
2680: 20 69 6e 73 65 72 74 69 6e 67 20 74 68 65 20 6e   inserting the n
2690: 65 77 20 72 6f 77 20 72 65 63 6f 72 64 2e 0a 23  ew row record..#
26a0: 20 49 6e 20 63 61 73 65 20 32 2c 20 74 68 65 20   In case 2, the 
26b0: 64 61 74 61 20 73 74 72 75 63 74 75 72 65 73 20  data structures 
26c0: 61 63 74 75 61 6c 6c 79 20 68 61 76 65 20 74 6f  actually have to
26d0: 20 62 65 20 75 70 64 61 74 65 64 2e 0a 23 0a 64   be updated..#.d
26e0: 6f 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 37  o_test fts3cov-7
26f0: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
2700: 0a 20 20 20 20 43 52 45 41 54 45 20 56 49 52 54  .    CREATE VIRT
2710: 55 41 4c 20 54 41 42 4c 45 20 74 37 20 55 53 49  UAL TABLE t7 USI
2720: 4e 47 20 66 74 73 33 28 61 2c 20 62 2c 20 63 29  NG fts3(a, b, c)
2730: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
2740: 4f 20 74 37 20 56 41 4c 55 45 53 28 27 41 27 2c  O t7 VALUES('A',
2750: 20 27 42 27 2c 20 27 43 27 29 3b 0a 20 20 20 20   'B', 'C');.    
2760: 55 50 44 41 54 45 20 74 37 20 53 45 54 20 64 6f  UPDATE t7 SET do
2770: 63 69 64 20 3d 20 35 3b 0a 20 20 20 20 53 45 4c  cid = 5;.    SEL
2780: 45 43 54 20 64 6f 63 69 64 2c 20 2a 20 46 52 4f  ECT docid, * FRO
2790: 4d 20 74 37 3b 0a 20 20 7d 0a 7d 20 7b 35 20 41  M t7;.  }.} {5 A
27a0: 20 42 20 43 7d 0a 64 6f 5f 74 65 73 74 20 66 74   B C}.do_test ft
27b0: 73 33 63 6f 76 2d 37 2e 32 20 7b 0a 20 20 65 78  s3cov-7.2 {.  ex
27c0: 65 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53 45  ecsql {.    INSE
27d0: 52 54 20 49 4e 54 4f 20 74 37 20 56 41 4c 55 45  RT INTO t7 VALUE
27e0: 53 28 27 44 27 2c 20 27 45 27 2c 20 27 46 27 29  S('D', 'E', 'F')
27f0: 3b 0a 20 20 20 20 55 50 44 41 54 45 20 74 37 20  ;.    UPDATE t7 
2800: 53 45 54 20 64 6f 63 69 64 20 3d 20 31 20 57 48  SET docid = 1 WH
2810: 45 52 45 20 64 6f 63 69 64 20 3d 20 36 3b 0a 20  ERE docid = 6;. 
2820: 20 20 20 53 45 4c 45 43 54 20 64 6f 63 69 64 2c     SELECT docid,
2830: 20 2a 20 46 52 4f 4d 20 74 37 3b 0a 20 20 7d 0a   * FROM t7;.  }.
2840: 7d 20 7b 31 20 44 20 45 20 46 20 35 20 41 20 42  } {1 D E F 5 A B
2850: 20 43 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   C}..#----------
2860: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a  ---------------.
28a0: 23 20 49 66 20 61 20 73 65 74 20 6f 66 20 64 6f  # If a set of do
28b0: 63 75 6d 65 6e 74 73 20 61 72 65 20 6d 6f 64 69  cuments are modi
28c0: 66 69 65 64 20 77 69 74 68 69 6e 20 61 20 74 72  fied within a tr
28d0: 61 6e 73 61 63 74 69 6f 6e 2c 20 74 68 65 20 0a  ansaction, the .
28e0: 23 20 70 65 6e 64 69 6e 67 2d 74 65 72 6d 73 20  # pending-terms 
28f0: 74 61 62 6c 65 20 6d 75 73 74 20 62 65 20 66 6c  table must be fl
2900: 75 73 68 65 64 20 65 61 63 68 20 74 69 6d 65 20  ushed each time 
2910: 61 20 64 6f 63 75 6d 65 6e 74 20 77 69 74 68 20  a document with 
2920: 61 20 64 6f 63 69 64 0a 23 20 6c 65 73 73 20 74  a docid.# less t
2930: 68 61 6e 20 6f 72 20 65 71 75 61 6c 20 74 6f 20  han or equal to 
2940: 74 68 65 20 70 72 65 76 69 6f 75 73 20 64 6f 63  the previous doc
2950: 69 64 20 69 73 20 6d 6f 64 69 66 69 65 64 2e 20  id is modified. 
2960: 0a 23 0a 23 20 54 68 69 73 20 74 65 73 74 20 63  .#.# This test c
2970: 68 65 63 6b 73 20 74 68 65 20 65 66 66 65 63 74  hecks the effect
2980: 73 20 6f 66 20 61 6e 20 4f 4f 4d 20 65 72 72 6f  s of an OOM erro
2990: 72 20 6f 63 63 75 72 69 6e 67 20 77 68 65 6e 20  r occuring when 
29a0: 74 68 65 20 0a 23 20 70 65 6e 64 69 6e 67 2d 74  the .# pending-t
29b0: 65 72 6d 73 20 74 61 62 6c 65 20 69 73 20 66 6c  erms table is fl
29c0: 75 73 68 65 64 20 66 6f 72 20 74 68 69 73 20 72  ushed for this r
29d0: 65 61 73 6f 6e 20 61 73 20 70 61 72 74 20 6f 66  eason as part of
29e0: 20 61 20 44 45 4c 45 54 45 20 0a 23 20 73 74 61   a DELETE .# sta
29f0: 74 65 6d 65 6e 74 2e 0a 23 0a 64 6f 5f 6d 61 6c  tement..#.do_mal
2a00: 6c 6f 63 5f 74 65 73 74 20 66 74 73 33 63 6f 76  loc_test fts3cov
2a10: 2d 38 20 2d 73 71 6c 70 72 65 70 20 7b 0a 20 20  -8 -sqlprep {.  
2a20: 42 45 47 49 4e 3b 0a 20 20 20 20 43 52 45 41 54  BEGIN;.    CREAT
2a30: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
2a40: 74 38 20 55 53 49 4e 47 20 66 74 73 33 3b 0a 20  t8 USING fts3;. 
2a50: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
2a60: 38 20 56 41 4c 55 45 53 28 27 74 68 65 20 6f 75  8 VALUES('the ou
2a70: 74 70 75 74 20 6f 66 20 65 61 63 68 20 62 61 74  tput of each bat
2a80: 63 68 20 72 75 6e 27 29 3b 0a 20 20 20 20 49 4e  ch run');.    IN
2a90: 53 45 52 54 20 49 4e 54 4f 20 74 38 20 56 41 4c  SERT INTO t8 VAL
2aa0: 55 45 53 28 27 28 70 6f 73 73 69 62 6c 79 20 61  UES('(possibly a
2ab0: 20 64 61 79 27 27 73 20 77 6f 72 6b 29 27 29 3b   day''s work)');
2ac0: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
2ad0: 20 74 38 20 56 41 4c 55 45 53 28 27 77 61 73 20   t8 VALUES('was 
2ae0: 77 72 69 74 74 65 6e 20 74 6f 20 74 77 6f 20 73  written to two s
2af0: 65 70 61 72 61 74 65 20 64 69 73 6b 73 27 29 3b  eparate disks');
2b00: 0a 20 20 43 4f 4d 4d 49 54 3b 0a 7d 20 2d 73 71  .  COMMIT;.} -sq
2b10: 6c 62 6f 64 79 20 7b 0a 20 20 42 45 47 49 4e 3b  lbody {.  BEGIN;
2b20: 0a 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d  .    DELETE FROM
2b30: 20 74 38 20 57 48 45 52 45 20 72 6f 77 69 64 20   t8 WHERE rowid 
2b40: 3d 20 33 3b 0a 20 20 20 20 44 45 4c 45 54 45 20  = 3;.    DELETE 
2b50: 46 52 4f 4d 20 74 38 20 57 48 45 52 45 20 72 6f  FROM t8 WHERE ro
2b60: 77 69 64 20 3d 20 32 3b 0a 20 20 20 20 44 45 4c  wid = 2;.    DEL
2b70: 45 54 45 20 46 52 4f 4d 20 74 38 20 57 48 45 52  ETE FROM t8 WHER
2b80: 45 20 72 6f 77 69 64 20 3d 20 31 3b 0a 20 20 43  E rowid = 1;.  C
2b90: 4f 4d 4d 49 54 3b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d  OMMIT;.}..#-----
2ba0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
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 0a 23 20 54 65 73 74 20 73 6f 6d 65  ----.# Test some
2bf0: 20 62 72 61 6e 63 68 65 73 20 69 6e 20 74 68 65   branches in the
2c00: 20 63 6f 64 65 20 74 68 61 74 20 68 61 6e 64 6c   code that handl
2c10: 65 73 20 22 73 70 65 63 69 61 6c 22 20 69 6e 73  es "special" ins
2c20: 65 72 74 73 20 6c 69 6b 65 3a 0a 23 0a 23 20 20  erts like:.#.#  
2c30: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 28   INSERT INTO t1(
2c40: 74 31 29 20 56 41 4c 55 45 53 28 27 6f 70 74 69  t1) VALUES('opti
2c50: 6d 69 7a 65 27 29 3b 0a 23 0a 23 20 41 6c 73 6f  mize');.#.# Also
2c60: 20 74 65 73 74 20 74 68 61 74 20 61 6e 20 6f 70   test that an op
2c70: 74 69 6d 69 7a 65 20 28 49 4e 53 45 52 54 20 6d  timize (INSERT m
2c80: 65 74 68 6f 64 29 20 77 6f 72 6b 73 20 6f 6e 20  ethod) works on 
2c90: 61 6e 20 65 6d 70 74 79 20 74 61 62 6c 65 2e 0a  an empty table..
2ca0: 23 0a 73 65 74 20 44 4f 5f 4d 41 4c 4c 4f 43 5f  #.set DO_MALLOC_
2cb0: 54 45 53 54 20 30 0a 64 6f 5f 74 65 73 74 20 66  TEST 0.do_test f
2cc0: 74 73 33 63 6f 76 2d 39 2e 31 20 7b 0a 20 20 65  ts3cov-9.1 {.  e
2cd0: 78 65 63 73 71 6c 20 7b 20 43 52 45 41 54 45 20  xecsql { CREATE 
2ce0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78 78  VIRTUAL TABLE xx
2cf0: 20 55 53 49 4e 47 20 66 74 73 33 20 7d 0a 7d 20   USING fts3 }.} 
2d00: 7b 7d 0a 64 6f 5f 65 72 72 6f 72 5f 74 65 73 74  {}.do_error_test
2d10: 20 66 74 73 33 63 6f 76 2d 39 2e 32 20 7b 0a 20   fts3cov-9.2 {. 
2d20: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 78 28   INSERT INTO xx(
2d30: 78 78 29 20 56 41 4c 55 45 53 28 27 6f 70 74 69  xx) VALUES('opti
2d40: 6d 69 73 65 27 29 3b 20 20 20 2d 2d 20 42 72 69  mise');   -- Bri
2d50: 74 69 73 68 20 73 70 65 6c 6c 69 6e 67 0a 7d 20  tish spelling.} 
2d60: 7b 53 51 4c 20 6c 6f 67 69 63 20 65 72 72 6f 72  {SQL logic error
2d70: 7d 0a 64 6f 5f 65 72 72 6f 72 5f 74 65 73 74 20  }.do_error_test 
2d80: 66 74 73 33 63 6f 76 2d 39 2e 33 20 7b 0a 20 20  fts3cov-9.3 {.  
2d90: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 78 28 78  INSERT INTO xx(x
2da0: 78 29 20 56 41 4c 55 45 53 28 27 73 68 6f 72 74  x) VALUES('short
2db0: 27 29 3b 0a 7d 20 7b 53 51 4c 20 6c 6f 67 69 63  ');.} {SQL logic
2dc0: 20 65 72 72 6f 72 7d 0a 64 6f 5f 65 72 72 6f 72   error}.do_error
2dd0: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 39 2e  _test fts3cov-9.
2de0: 34 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  4 {.  INSERT INT
2df0: 4f 20 78 78 28 78 78 29 20 56 41 4c 55 45 53 28  O xx(xx) VALUES(
2e00: 27 77 61 79 74 6f 6f 6c 6f 6e 67 74 6f 62 65 63  'waytoolongtobec
2e10: 6f 72 72 65 63 74 27 29 3b 0a 7d 20 7b 53 51 4c  orrect');.} {SQL
2e20: 20 6c 6f 67 69 63 20 65 72 72 6f 72 7d 0a 64 6f   logic error}.do
2e30: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 39 2e  _test fts3cov-9.
2e40: 35 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20  5 {.  execsql { 
2e50: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 78 28 78  INSERT INTO xx(x
2e60: 78 29 20 56 41 4c 55 45 53 28 27 6f 70 74 69 6d  x) VALUES('optim
2e70: 69 7a 65 27 29 20 7d 0a 7d 20 7b 7d 0a 0a 23 2d  ize') }.} {}..#-
2e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2e90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ea0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2eb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ec0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20  --------.# Test 
2ed0: 74 68 61 74 20 61 20 74 61 62 6c 65 20 63 61 6e  that a table can
2ee0: 20 62 65 20 6f 70 74 69 6d 69 7a 65 64 20 69 6e   be optimized in
2ef0: 20 74 68 65 20 6d 69 64 64 6c 65 20 6f 66 20 61   the middle of a
2f00: 20 74 72 61 6e 73 61 63 74 69 6f 6e 20 77 68 65   transaction whe
2f10: 6e 0a 23 20 74 68 65 20 70 65 6e 64 69 6e 67 2d  n.# the pending-
2f20: 74 65 72 6d 73 20 74 61 62 6c 65 20 69 73 20 6e  terms table is n
2f30: 6f 6e 2d 65 6d 70 74 79 2e 20 54 68 69 73 20 63  on-empty. This c
2f40: 61 73 65 20 69 6e 76 6f 6c 76 65 73 20 73 6f 6d  ase involves som
2f50: 65 20 65 78 74 72 61 0a 23 20 62 72 61 6e 63 68  e extra.# branch
2f60: 65 73 20 62 65 63 61 75 73 65 20 64 61 74 61 20  es because data 
2f70: 6d 75 73 74 20 62 65 20 72 65 61 64 20 6e 6f 74  must be read not
2f80: 20 6f 6e 6c 79 20 66 72 6f 6d 20 74 68 65 20 64   only from the d
2f90: 61 74 61 62 61 73 65 2c 20 62 75 74 0a 23 20 61  atabase, but.# a
2fa0: 6c 73 6f 20 66 72 6f 6d 20 74 68 65 20 70 65 6e  lso from the pen
2fb0: 64 69 6e 67 2d 74 65 72 6d 73 20 74 61 62 6c 65  ding-terms table
2fc0: 2e 0a 23 0a 64 6f 5f 6d 61 6c 6c 6f 63 5f 74 65  ..#.do_malloc_te
2fd0: 73 74 20 66 74 73 33 63 6f 76 2d 31 30 20 2d 73  st fts3cov-10 -s
2fe0: 71 6c 70 72 65 70 20 7b 0a 20 20 43 52 45 41 54  qlprep {.  CREAT
2ff0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
3000: 74 31 30 20 55 53 49 4e 47 20 66 74 73 33 3b 0a  t10 USING fts3;.
3010: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
3020: 30 20 56 41 4c 55 45 53 28 27 4f 70 74 69 6d 69  0 VALUES('Optimi
3030: 73 69 6e 67 20 69 6d 61 67 65 73 20 66 6f 72 20  sing images for 
3040: 74 68 65 20 77 65 62 20 69 73 20 61 20 74 72 69  the web is a tri
3050: 63 6b 79 20 62 75 73 69 6e 65 73 73 27 29 3b 0a  cky business');.
3060: 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53    BEGIN;.    INS
3070: 45 52 54 20 49 4e 54 4f 20 74 31 30 20 56 41 4c  ERT INTO t10 VAL
3080: 55 45 53 28 27 59 6f 75 20 68 61 76 65 20 74 6f  UES('You have to
3090: 20 67 65 74 20 74 68 65 20 72 69 67 68 74 20 62   get the right b
30a0: 61 6c 61 6e 63 65 20 62 65 74 77 65 65 6e 27 29  alance between')
30b0: 3b 0a 7d 20 2d 73 71 6c 62 6f 64 79 20 7b 0a 20  ;.} -sqlbody {. 
30c0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 30   INSERT INTO t10
30d0: 28 74 31 30 29 20 56 41 4c 55 45 53 28 27 6f 70  (t10) VALUES('op
30e0: 74 69 6d 69 7a 65 27 29 3b 0a 7d 0a 0a 23 2d 2d  timize');.}..#--
30f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3100: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3110: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3130: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 61  -------.# Test a
3140: 20 66 75 6c 6c 2d 74 65 78 74 20 71 75 65 72 79   full-text query
3150: 20 66 6f 72 20 61 20 74 65 72 6d 20 74 68 61 74   for a term that
3160: 20 77 61 73 20 6f 6e 63 65 20 69 6e 20 74 68 65   was once in the
3170: 20 69 6e 64 65 78 2c 20 62 75 74 20 69 73 0a 23   index, but is.#
3180: 20 6e 6f 20 6c 6f 6e 67 65 72 2e 0a 23 0a 64 6f   no longer..#.do
3190: 5f 74 65 73 74 20 66 74 73 33 63 6f 76 2d 31 31  _test fts3cov-11
31a0: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
31b0: 20 0a 20 20 20 20 43 52 45 41 54 45 20 56 49 52   .    CREATE VIR
31c0: 54 55 41 4c 20 54 41 42 4c 45 20 78 78 20 55 53  TUAL TABLE xx US
31d0: 49 4e 47 20 66 74 73 33 3b 0a 20 20 20 20 49 4e  ING fts3;.    IN
31e0: 53 45 52 54 20 49 4e 54 4f 20 78 78 20 56 41 4c  SERT INTO xx VAL
31f0: 55 45 53 28 27 6f 6e 65 20 74 77 6f 20 74 68 72  UES('one two thr
3200: 65 65 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 54  ee');.    INSERT
3210: 20 49 4e 54 4f 20 78 78 20 56 41 4c 55 45 53 28   INTO xx VALUES(
3220: 27 66 6f 75 72 20 66 69 76 65 20 73 69 78 27 29  'four five six')
3230: 3b 0a 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f  ;.    DELETE FRO
3240: 4d 20 78 78 20 57 48 45 52 45 20 64 6f 63 69 64  M xx WHERE docid
3250: 20 3d 20 31 3b 0a 20 20 7d 0a 20 20 65 78 65 63   = 1;.  }.  exec
3260: 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46  sql { SELECT * F
3270: 52 4f 4d 20 78 78 20 57 48 45 52 45 20 78 78 20  ROM xx WHERE xx 
3280: 4d 41 54 43 48 20 27 74 77 6f 27 20 7d 0a 7d 20  MATCH 'two' }.} 
3290: 7b 7d 0a 0a 0a 64 6f 5f 6d 61 6c 6c 6f 63 5f 74  {}...do_malloc_t
32a0: 65 73 74 20 66 74 73 33 63 6f 76 2d 31 32 20 2d  est fts3cov-12 -
32b0: 73 71 6c 70 72 65 70 20 7b 0a 20 20 43 52 45 41  sqlprep {.  CREA
32c0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
32d0: 20 74 31 32 20 55 53 49 4e 47 20 66 74 73 33 3b   t12 USING fts3;
32e0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
32f0: 31 32 20 56 41 4c 55 45 53 28 27 69 73 20 6f 6e  12 VALUES('is on
3300: 65 20 6f 66 20 74 68 65 20 74 77 6f 20 74 6f 67  e of the two tog
3310: 74 68 65 72 27 29 3b 0a 20 20 42 45 47 49 4e 3b  ther');.  BEGIN;
3320: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
3330: 20 74 31 32 20 56 41 4c 55 45 53 28 27 6f 6e 65   t12 VALUES('one
3340: 20 77 68 69 63 68 20 77 61 73 20 61 70 70 72 6f   which was appro
3350: 70 72 69 61 74 65 20 61 74 20 74 68 65 20 74 69  priate at the ti
3360: 6d 65 27 29 3b 0a 7d 20 2d 73 71 6c 62 6f 64 79  me');.} -sqlbody
3370: 20 7b 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52   {.  SELECT * FR
3380: 4f 4d 20 74 31 32 20 57 48 45 52 45 20 74 31 32  OM t12 WHERE t12
3390: 20 4d 41 54 43 48 20 27 6f 6e 65 27 0a 7d 0a 0a   MATCH 'one'.}..
33a0: 64 6f 5f 6d 61 6c 6c 6f 63 5f 74 65 73 74 20 66  do_malloc_test f
33b0: 74 73 33 63 6f 76 2d 31 33 20 2d 73 71 6c 70 72  ts3cov-13 -sqlpr
33c0: 65 70 20 7b 0a 20 20 50 52 41 47 4d 41 20 65 6e  ep {.  PRAGMA en
33d0: 63 6f 64 69 6e 67 20 3d 20 27 55 54 46 2d 31 36  coding = 'UTF-16
33e0: 27 3b 0a 20 20 43 52 45 41 54 45 20 56 49 52 54  ';.  CREATE VIRT
33f0: 55 41 4c 20 54 41 42 4c 45 20 74 31 33 20 55 53  UAL TABLE t13 US
3400: 49 4e 47 20 66 74 73 33 3b 0a 20 20 49 4e 53 45  ING fts3;.  INSE
3410: 52 54 20 49 4e 54 4f 20 74 31 33 20 56 41 4c 55  RT INTO t13 VALU
3420: 45 53 28 27 74 77 6f 20 73 63 61 6c 61 72 20 66  ES('two scalar f
3430: 75 6e 63 74 69 6f 6e 73 27 29 3b 0a 20 20 49 4e  unctions');.  IN
3440: 53 45 52 54 20 49 4e 54 4f 20 74 31 33 20 56 41  SERT INTO t13 VA
3450: 4c 55 45 53 28 27 73 63 61 6c 61 72 20 74 77 6f  LUES('scalar two
3460: 20 66 75 6e 63 74 69 6f 6e 73 27 29 3b 0a 20 20   functions');.  
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 66 75 6e 63 74 69 6f 6e  VALUES('function
3490: 73 20 73 63 61 6c 61 72 20 74 77 6f 27 29 3b 0a  s scalar two');.
34a0: 7d 20 2d 73 71 6c 62 6f 64 79 20 7b 0a 20 20 53  } -sqlbody {.  S
34b0: 45 4c 45 43 54 20 73 6e 69 70 70 65 74 28 74 31  ELECT snippet(t1
34c0: 33 2c 20 27 25 25 27 2c 20 27 25 25 27 2c 20 27  3, '%%', '%%', '
34d0: 23 27 29 20 46 52 4f 4d 20 74 31 33 20 57 48 45  #') FROM t13 WHE
34e0: 52 45 20 74 31 33 20 4d 41 54 43 48 20 27 74 77  RE t13 MATCH 'tw
34f0: 6f 27 3b 0a 20 20 53 45 4c 45 43 54 20 73 6e 69  o';.  SELECT sni
3500: 70 70 65 74 28 74 31 33 2c 20 27 25 25 27 2c 20  ppet(t13, '%%', 
3510: 27 25 25 27 29 20 46 52 4f 4d 20 74 31 33 20 57  '%%') FROM t13 W
3520: 48 45 52 45 20 74 31 33 20 4d 41 54 43 48 20 27  HERE t13 MATCH '
3530: 74 77 6f 27 3b 0a 20 20 53 45 4c 45 43 54 20 73  two';.  SELECT s
3540: 6e 69 70 70 65 74 28 74 31 33 2c 20 27 25 25 27  nippet(t13, '%%'
3550: 29 20 46 52 4f 4d 20 74 31 33 20 57 48 45 52 45  ) FROM t13 WHERE
3560: 20 74 31 33 20 4d 41 54 43 48 20 27 74 77 6f 27   t13 MATCH 'two'
3570: 3b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  ;.}..do_execsql_
3580: 74 65 73 74 20 31 34 2e 30 20 7b 0a 20 20 43 52  test 14.0 {.  CR
3590: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42  EATE VIRTUAL TAB
35a0: 4c 45 20 74 31 34 20 55 53 49 4e 47 20 66 74 73  LE t14 USING fts
35b0: 34 28 61 2c 20 62 29 3b 0a 20 20 49 4e 53 45 52  4(a, b);.  INSER
35c0: 54 20 49 4e 54 4f 20 74 31 34 20 56 41 4c 55 45  T INTO t14 VALUE
35d0: 53 28 27 6f 6e 65 20 74 77 6f 20 74 68 72 65 65  S('one two three
35e0: 27 2c 20 27 6f 6e 65 20 74 68 72 65 65 20 66 6f  ', 'one three fo
35f0: 75 72 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  ur');.  INSERT I
3600: 4e 54 4f 20 74 31 34 20 56 41 4c 55 45 53 28 27  NTO t14 VALUES('
3610: 61 20 62 20 63 27 2c 20 27 64 20 65 20 61 27 29  a b c', 'd e a')
3620: 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  ;.}.do_execsql_t
3630: 65 73 74 20 31 34 2e 31 20 7b 0a 20 20 53 45 4c  est 14.1 {.  SEL
3640: 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 74  ECT rowid FROM t
3650: 31 34 20 57 48 45 52 45 20 74 31 34 20 4d 41 54  14 WHERE t14 MAT
3660: 43 48 20 27 22 6f 6e 65 20 74 77 6f 20 74 68 72  CH '"one two thr
3670: 65 65 22 27 0a 7d 20 7b 31 7d 0a 64 6f 5f 65 78  ee"'.} {1}.do_ex
3680: 65 63 73 71 6c 5f 74 65 73 74 20 31 34 2e 32 20  ecsql_test 14.2 
3690: 7b 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64  {.  SELECT rowid
36a0: 20 46 52 4f 4d 20 74 31 34 20 57 48 45 52 45 20   FROM t14 WHERE 
36b0: 74 31 34 20 4d 41 54 43 48 20 27 22 6f 6e 65 20  t14 MATCH '"one 
36c0: 66 6f 75 72 22 27 0a 7d 20 7b 7d 0a 64 6f 5f 65  four"'.} {}.do_e
36d0: 78 65 63 73 71 6c 5f 74 65 73 74 20 31 34 2e 33  xecsql_test 14.3
36e0: 20 7b 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69   {.  SELECT rowi
36f0: 64 20 46 52 4f 4d 20 74 31 34 20 57 48 45 52 45  d FROM t14 WHERE
3700: 20 74 31 34 20 4d 41 54 43 48 20 27 22 65 20 61   t14 MATCH '"e a
3710: 22 27 0a 7d 20 7b 32 7d 0a 64 6f 5f 65 78 65 63  "'.} {2}.do_exec
3720: 73 71 6c 5f 74 65 73 74 20 31 34 2e 35 20 7b 0a  sql_test 14.5 {.
3730: 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46    SELECT rowid F
3740: 52 4f 4d 20 74 31 34 20 57 48 45 52 45 20 74 31  ROM t14 WHERE t1
3750: 34 20 4d 41 54 43 48 20 27 22 65 20 62 22 27 0a  4 MATCH '"e b"'.
3760: 7d 20 7b 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c  } {}.do_catchsql
3770: 5f 74 65 73 74 20 31 34 2e 36 20 7b 0a 20 20 53  _test 14.6 {.  S
3780: 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d  ELECT rowid FROM
3790: 20 74 31 34 20 57 48 45 52 45 20 72 6f 77 69 64   t14 WHERE rowid
37a0: 20 4d 41 54 43 48 20 27 6f 6e 65 27 0a 7d 20 7b   MATCH 'one'.} {
37b0: 31 20 7b 75 6e 61 62 6c 65 20 74 6f 20 75 73 65  1 {unable to use
37c0: 20 66 75 6e 63 74 69 6f 6e 20 4d 41 54 43 48 20   function MATCH 
37d0: 69 6e 20 74 68 65 20 72 65 71 75 65 73 74 65 64  in the requested
37e0: 20 63 6f 6e 74 65 78 74 7d 7d 0a 64 6f 5f 63 61   context}}.do_ca
37f0: 74 63 68 73 71 6c 5f 74 65 73 74 20 31 34 2e 37  tchsql_test 14.7
3800: 20 7b 0a 20 20 53 45 4c 45 43 54 20 72 6f 77 69   {.  SELECT rowi
3810: 64 20 46 52 4f 4d 20 74 31 34 20 57 48 45 52 45  d FROM t14 WHERE
3820: 20 64 6f 63 69 64 20 4d 41 54 43 48 20 27 6f 6e   docid MATCH 'on
3830: 65 27 0a 7d 20 7b 31 20 7b 75 6e 61 62 6c 65 20  e'.} {1 {unable 
3840: 74 6f 20 75 73 65 20 66 75 6e 63 74 69 6f 6e 20  to use function 
3850: 4d 41 54 43 48 20 69 6e 20 74 68 65 20 72 65 71  MATCH in the req
3860: 75 65 73 74 65 64 20 63 6f 6e 74 65 78 74 7d 7d  uested context}}
3870: 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  ..do_execsql_tes
3880: 74 20 31 35 2e 30 20 7b 0a 20 20 43 52 45 41 54  t 15.0 {.  CREAT
3890: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
38a0: 74 31 35 20 55 53 49 4e 47 20 66 74 73 34 28 61  t15 USING fts4(a
38b0: 2c 20 62 2c 20 63 29 3b 0a 20 20 49 4e 53 45 52  , b, c);.  INSER
38c0: 54 20 49 4e 54 4f 20 74 31 35 20 56 41 4c 55 45  T INTO t15 VALUE
38d0: 53 28 27 61 62 63 20 64 65 66 20 67 68 69 27 2c  S('abc def ghi',
38e0: 20 27 61 62 63 32 20 64 65 66 32 20 67 68 69 32   'abc2 def2 ghi2
38f0: 27 2c 20 27 61 62 63 33 20 64 65 66 33 20 67 68  ', 'abc3 def3 gh
3900: 69 33 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  i3');.  INSERT I
3910: 4e 54 4f 20 74 31 35 20 56 41 4c 55 45 53 28 27  NTO t15 VALUES('
3920: 61 62 63 32 20 64 65 66 32 20 67 68 69 32 27 2c  abc2 def2 ghi2',
3930: 20 27 61 62 63 32 20 64 65 66 32 20 67 68 69 32   'abc2 def2 ghi2
3940: 27 2c 20 27 61 62 63 20 64 65 66 33 20 67 68 69  ', 'abc def3 ghi
3950: 33 27 29 3b 0a 7d 0a 64 6f 5f 65 78 65 63 73 71  3');.}.do_execsq
3960: 6c 5f 74 65 73 74 20 31 35 2e 31 20 7b 0a 20 20  l_test 15.1 {.  
3970: 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f  SELECT rowid FRO
3980: 4d 20 74 31 35 20 57 48 45 52 45 20 74 31 35 20  M t15 WHERE t15 
3990: 4d 41 54 43 48 20 27 22 61 62 63 2a 20 64 65 66  MATCH '"abc* def
39a0: 32 22 27 0a 7d 20 7b 31 20 32 7d 0a 0a 23 20 54  2"'.} {1 2}..# T
39b0: 65 73 74 20 61 20 63 6f 72 72 75 70 74 69 6f 6e  est a corruption
39c0: 20 63 61 73 65 2e 0a 23 0a 64 6f 5f 65 78 65 63   case..#.do_exec
39d0: 73 71 6c 5f 74 65 73 74 20 31 36 2e 31 20 7b 0a  sql_test 16.1 {.
39e0: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
39f0: 20 54 41 42 4c 45 20 74 31 36 20 55 53 49 4e 47   TABLE t16 USING
3a00: 20 66 74 73 34 3b 0a 20 20 49 4e 53 45 52 54 20   fts4;.  INSERT 
3a10: 49 4e 54 4f 20 74 31 36 20 56 41 4c 55 45 53 28  INTO t16 VALUES(
3a20: 27 74 68 65 6f 72 65 74 69 63 61 6c 20 77 6f 72  'theoretical wor
3a30: 6b 20 74 6f 20 65 78 61 6d 69 6e 65 20 74 68 65  k to examine the
3a40: 20 72 65 6c 61 74 69 6f 6e 73 68 69 70 27 29 3b   relationship');
3a50: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
3a60: 31 36 20 56 41 4c 55 45 53 28 27 73 6f 6c 75 74  16 VALUES('solut
3a70: 69 6f 6e 20 6f 66 20 6f 75 72 20 70 72 6f 62 6c  ion of our probl
3a80: 65 6d 73 20 6f 6e 20 74 68 65 20 69 6e 76 69 73  ems on the invis
3a90: 69 62 6c 65 27 29 3b 0a 20 20 44 45 4c 45 54 45  ible');.  DELETE
3aa0: 20 46 52 4f 4d 20 74 31 36 5f 63 6f 6e 74 65 6e   FROM t16_conten
3ab0: 74 20 57 48 45 52 45 20 72 6f 77 69 64 20 3d 20  t WHERE rowid = 
3ac0: 32 3b 0a 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c  2;.}.do_catchsql
3ad0: 5f 74 65 73 74 20 31 36 2e 32 20 7b 0a 20 20 53  _test 16.2 {.  S
3ae0: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 36  ELECT * FROM t16
3af0: 20 57 48 45 52 45 20 74 31 36 20 4d 41 54 43 48   WHERE t16 MATCH
3b00: 20 27 69 6e 76 69 73 69 62 6c 65 27 0a 7d 20 7b   'invisible'.} {
3b10: 31 20 7b 64 61 74 61 62 61 73 65 20 64 69 73 6b  1 {database disk
3b20: 20 69 6d 61 67 65 20 69 73 20 6d 61 6c 66 6f 72   image is malfor
3b30: 6d 65 64 7d 7d 0a 0a 23 20 41 6e 64 20 61 6e 6f  med}}..# And ano
3b40: 74 68 65 72 20 63 6f 72 72 75 70 74 69 6f 6e 20  ther corruption 
3b50: 74 65 73 74 20 63 61 73 65 2e 0a 23 0a 64 6f 5f  test case..#.do_
3b60: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 37 2e  execsql_test 17.
3b70: 31 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52  1 {.  CREATE VIR
3b80: 54 55 41 4c 20 54 41 42 4c 45 20 74 31 37 20 55  TUAL TABLE t17 U
3b90: 53 49 4e 47 20 66 74 73 34 3b 0a 20 20 49 4e 53  SING fts4;.  INS
3ba0: 45 52 54 20 49 4e 54 4f 20 74 31 37 28 63 6f 6e  ERT INTO t17(con
3bb0: 74 65 6e 74 29 20 56 41 4c 55 45 53 28 27 6f 6e  tent) VALUES('on
3bc0: 65 20 6f 6e 65 20 6f 6e 65 27 29 3b 0a 20 20 55  e one one');.  U
3bd0: 50 44 41 54 45 20 74 31 37 5f 73 65 67 64 69 72  PDATE t17_segdir
3be0: 20 53 45 54 20 72 6f 6f 74 20 3d 20 58 27 30 30   SET root = X'00
3bf0: 30 33 36 46 36 45 36 35 46 46 46 46 46 46 46 46  036F6E65FFFFFFFF
3c00: 46 46 46 46 46 46 46 46 46 46 46 46 46 46 30 32  FFFFFFFFFFFFFF02
3c10: 30 33 30 33 30 30 27 0a 7d 20 7b 7d 0a 64 6f 5f  030300'.} {}.do_
3c20: 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20 31 37  catchsql_test 17
3c30: 2e 32 20 7b 0a 20 20 53 45 4c 45 43 54 20 2a 20  .2 {.  SELECT * 
3c40: 46 52 4f 4d 20 74 31 37 20 57 48 45 52 45 20 74  FROM t17 WHERE t
3c50: 31 37 20 4d 41 54 43 48 20 27 6f 6e 65 27 0a 7d  17 MATCH 'one'.}
3c60: 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20 64 69   {1 {database di
3c70: 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61 6c 66  sk image is malf
3c80: 6f 72 6d 65 64 7d 7d 0a 0a 0a 0a 0a 66 69 6e 69  ormed}}.....fini
3c90: 73 68 5f 74 65 73 74 0a                          sh_test.