/ Hex Artifact Content
Login

Artifact 1c1db5fcfe59401e7833146100f1d8de284a0a686fac31ddac9fb56c459f725b:


0000: 23 20 32 30 31 34 20 4a 75 6e 65 20 31 37 0a 23  # 2014 June 17.#
0010: 0a 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69  .# The author di
0020: 73 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68  sclaims copyrigh
0030: 74 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65  t to this source
0040: 20 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65   code.  In place
0050: 20 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f   of.# a legal no
0060: 74 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20  tice, here is a 
0070: 62 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20  blessing:.#.#   
0080: 20 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64   May you do good
0090: 20 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23   and not evil..#
00a0: 20 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64      May you find
00b0: 20 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72   forgiveness for
00c0: 20 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f   yourself and fo
00d0: 72 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20  rgive others..# 
00e0: 20 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65     May you share
00f0: 20 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74   freely, never t
0100: 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20  aking more than 
0110: 79 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a  you give..#.#***
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 2a 2a 2a 0a 23 0a 23 20 54 68 69 73 20  ******.#.# This 
0170: 66 69 6c 65 20 69 73 20 66 6f 63 75 73 65 64 20  file is focused 
0180: 6f 6e 20 4f 4f 4d 20 65 72 72 6f 72 73 2e 0a 23  on OOM errors..#
0190: 0a 0a 73 6f 75 72 63 65 20 5b 66 69 6c 65 20 6a  ..source [file j
01a0: 6f 69 6e 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d  oin [file dirnam
01b0: 65 20 5b 69 6e 66 6f 20 73 63 72 69 70 74 5d 5d  e [info script]]
01c0: 20 66 74 73 35 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c   fts5_common.tcl
01d0: 5d 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69  ].source $testdi
01e0: 72 2f 6d 61 6c 6c 6f 63 5f 63 6f 6d 6d 6f 6e 2e  r/malloc_common.
01f0: 74 63 6c 0a 73 65 74 20 74 65 73 74 70 72 65 66  tcl.set testpref
0200: 69 78 20 66 74 73 35 66 61 75 6c 74 34 0a 0a 23  ix fts5fault4..#
0210: 20 49 66 20 53 51 4c 49 54 45 5f 45 4e 41 42 4c   If SQLITE_ENABL
0220: 45 5f 46 54 53 33 20 69 73 20 64 65 66 69 6e 65  E_FTS3 is define
0230: 64 2c 20 6f 6d 69 74 20 74 68 69 73 20 66 69 6c  d, omit this fil
0240: 65 2e 0a 69 66 63 61 70 61 62 6c 65 20 21 66 74  e..ifcapable !ft
0250: 73 35 20 7b 0a 20 20 66 69 6e 69 73 68 5f 74 65  s5 {.  finish_te
0260: 73 74 0a 20 20 72 65 74 75 72 6e 0a 7d 0a 0a 23  st.  return.}..#
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 2d 2d 2d 2d  ----------------
02b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 41 6e 20 4f  ---------.# An O
02c0: 4f 4d 20 77 68 69 6c 65 20 64 72 6f 70 70 69 6e  OM while droppin
02d0: 67 20 61 6e 20 66 74 73 35 20 74 61 62 6c 65 2e  g an fts5 table.
02e0: 0a 23 0a 64 62 20 66 75 6e 63 20 72 6e 64 64 6f  .#.db func rnddo
02f0: 63 20 66 74 73 35 5f 72 6e 64 64 6f 63 20 0a 64  c fts5_rnddoc .d
0300: 6f 5f 74 65 73 74 20 31 2e 30 20 7b 0a 20 20 65  o_test 1.0 {.  e
0310: 78 65 63 73 71 6c 20 7b 20 43 52 45 41 54 45 20  xecsql { CREATE 
0320: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78 78  VIRTUAL TABLE xx
0330: 20 55 53 49 4e 47 20 66 74 73 35 28 78 29 20 7d   USING fts5(x) }
0340: 0a 7d 20 7b 7d 0a 66 61 75 6c 74 73 69 6d 5f 73  .} {}.faultsim_s
0350: 61 76 65 5f 61 6e 64 5f 63 6c 6f 73 65 0a 0a 64  ave_and_close..d
0360: 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 20  o_faultsim_test 
0370: 31 20 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d 2a 20  1 -faults oom-* 
0380: 2d 70 72 65 70 20 7b 0a 20 20 66 61 75 6c 74 73  -prep {.  faults
0390: 69 6d 5f 72 65 73 74 6f 72 65 5f 61 6e 64 5f 72  im_restore_and_r
03a0: 65 6f 70 65 6e 0a 20 20 65 78 65 63 73 71 6c 20  eopen.  execsql 
03b0: 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20  { SELECT * FROM 
03c0: 78 78 20 7d 0a 7d 20 2d 62 6f 64 79 20 7b 0a 20  xx }.} -body {. 
03d0: 20 65 78 65 63 73 71 6c 20 7b 20 44 52 4f 50 20   execsql { DROP 
03e0: 54 41 42 4c 45 20 78 78 20 7d 0a 7d 20 2d 74 65  TABLE xx }.} -te
03f0: 73 74 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f  st {.  faultsim_
0400: 74 65 73 74 5f 72 65 73 75 6c 74 20 5b 6c 69 73  test_result [lis
0410: 74 20 30 20 7b 7d 5d 0a 7d 0a 0a 23 2d 2d 2d 2d  t 0 {}].}..#----
0420: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0450: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0460: 2d 2d 2d 2d 2d 0a 23 20 41 6e 20 4f 4f 4d 20 77  -----.# An OOM w
0470: 68 69 6c 65 20 22 72 65 73 65 65 6b 69 6e 67 22  hile "reseeking"
0480: 20 61 6e 20 46 54 53 20 63 75 72 73 6f 72 2e 0a   an FTS cursor..
0490: 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73  #.do_execsql_tes
04a0: 74 20 33 2e 30 20 7b 0a 20 20 43 52 45 41 54 45  t 3.0 {.  CREATE
04b0: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 6a   VIRTUAL TABLE j
04c0: 6a 20 55 53 49 4e 47 20 66 74 73 35 28 6a 29 3b  j USING fts5(j);
04d0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 6a  .  INSERT INTO j
04e0: 6a 28 72 6f 77 69 64 2c 20 6a 29 20 56 41 4c 55  j(rowid, j) VALU
04f0: 45 53 28 31 30 31 2c 20 27 6d 20 74 20 77 20 74  ES(101, 'm t w t
0500: 20 66 20 73 20 73 27 29 3b 0a 20 20 49 4e 53 45   f s s');.  INSE
0510: 52 54 20 49 4e 54 4f 20 6a 6a 28 72 6f 77 69 64  RT INTO jj(rowid
0520: 2c 20 6a 29 20 56 41 4c 55 45 53 28 32 30 32 2c  , j) VALUES(202,
0530: 20 27 74 20 77 20 74 20 66 20 73 27 29 3b 0a 20   't w t f s');. 
0540: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 6a 6a 28   INSERT INTO jj(
0550: 72 6f 77 69 64 2c 20 6a 29 20 56 41 4c 55 45 53  rowid, j) VALUES
0560: 28 33 30 33 2c 20 27 77 20 74 20 66 27 29 3b 0a  (303, 'w t f');.
0570: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 6a 6a    INSERT INTO jj
0580: 28 72 6f 77 69 64 2c 20 6a 29 20 56 41 4c 55 45  (rowid, j) VALUE
0590: 53 28 34 30 34 2c 20 27 74 27 29 3b 0a 7d 0a 66  S(404, 't');.}.f
05a0: 61 75 6c 74 73 69 6d 5f 73 61 76 65 5f 61 6e 64  aultsim_save_and
05b0: 5f 63 6c 6f 73 65 0a 0a 64 6f 5f 66 61 75 6c 74  _close..do_fault
05c0: 73 69 6d 5f 74 65 73 74 20 33 20 2d 66 61 75 6c  sim_test 3 -faul
05d0: 74 73 20 6f 6f 6d 2d 2a 20 2d 70 72 65 70 20 7b  ts oom-* -prep {
05e0: 0a 20 20 66 61 75 6c 74 73 69 6d 5f 72 65 73 74  .  faultsim_rest
05f0: 6f 72 65 5f 61 6e 64 5f 72 65 6f 70 65 6e 0a 20  ore_and_reopen. 
0600: 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43   execsql { SELEC
0610: 54 20 2a 20 46 52 4f 4d 20 6a 6a 20 7d 0a 7d 20  T * FROM jj }.} 
0620: 2d 62 6f 64 79 20 7b 0a 20 20 73 65 74 20 72 65  -body {.  set re
0630: 73 20 5b 6c 69 73 74 5d 0a 20 20 64 62 20 65 76  s [list].  db ev
0640: 61 6c 20 7b 20 53 45 4c 45 43 54 20 72 6f 77 69  al { SELECT rowi
0650: 64 20 46 52 4f 4d 20 6a 6a 20 57 48 45 52 45 20  d FROM jj WHERE 
0660: 6a 6a 20 4d 41 54 43 48 20 27 74 27 20 7d 20 7b  jj MATCH 't' } {
0670: 0a 20 20 20 20 6c 61 70 70 65 6e 64 20 72 65 73  .    lappend res
0680: 20 24 72 6f 77 69 64 0a 20 20 20 20 69 66 20 7b   $rowid.    if {
0690: 24 72 6f 77 69 64 3d 3d 33 30 33 7d 20 7b 0a 20  $rowid==303} {. 
06a0: 20 20 20 20 20 65 78 65 63 73 71 6c 20 7b 20 44       execsql { D
06b0: 45 4c 45 54 45 20 46 52 4f 4d 20 6a 6a 20 57 48  ELETE FROM jj WH
06c0: 45 52 45 20 72 6f 77 69 64 3d 34 30 34 20 7d 0a  ERE rowid=404 }.
06d0: 20 20 20 20 7d 0a 20 20 7d 0a 20 20 73 65 74 20      }.  }.  set 
06e0: 72 65 73 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20  res.} -test {.  
06f0: 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65  faultsim_test_re
0700: 73 75 6c 74 20 5b 6c 69 73 74 20 30 20 7b 31 30  sult [list 0 {10
0710: 31 20 32 30 32 20 33 30 33 7d 5d 0a 7d 0a 0a 23  1 202 303}].}..#
0720: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0730: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0740: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0750: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0760: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 41 6e 20 4f  ---------.# An O
0770: 4f 4d 20 77 69 74 68 69 6e 20 61 20 73 70 65 63  OM within a spec
0780: 69 61 6c 20 22 2a 72 65 61 64 73 22 20 71 75 65  ial "*reads" que
0790: 72 79 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64  ry..#.reset_db.d
07a0: 62 20 66 75 6e 63 20 72 6e 64 64 6f 63 20 66 74  b func rnddoc ft
07b0: 73 35 5f 72 6e 64 64 6f 63 0a 64 6f 5f 65 78 65  s5_rnddoc.do_exe
07c0: 63 73 71 6c 5f 74 65 73 74 20 34 2e 30 20 7b 0a  csql_test 4.0 {.
07d0: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
07e0: 20 54 41 42 4c 45 20 78 31 20 55 53 49 4e 47 20   TABLE x1 USING 
07f0: 66 74 73 35 28 78 29 3b 0a 20 20 49 4e 53 45 52  fts5(x);.  INSER
0800: 54 20 49 4e 54 4f 20 78 31 28 78 31 2c 20 72 61  T INTO x1(x1, ra
0810: 6e 6b 29 20 56 41 4c 55 45 53 28 27 70 67 73 7a  nk) VALUES('pgsz
0820: 27 2c 20 33 32 29 3b 0a 0a 20 20 57 49 54 48 20  ', 32);..  WITH 
0830: 69 69 28 69 29 20 41 53 20 28 20 53 45 4c 45 43  ii(i) AS ( SELEC
0840: 54 20 31 20 55 4e 49 4f 4e 20 41 4c 4c 20 53 45  T 1 UNION ALL SE
0850: 4c 45 43 54 20 69 2b 31 20 46 52 4f 4d 20 69 69  LECT i+1 FROM ii
0860: 20 57 48 45 52 45 20 69 3c 31 30 20 29 0a 20 20   WHERE i<10 ).  
0870: 49 4e 53 45 52 54 20 49 4e 54 4f 20 78 31 20 53  INSERT INTO x1 S
0880: 45 4c 45 43 54 20 72 6e 64 64 6f 63 28 35 29 20  ELECT rnddoc(5) 
0890: 46 52 4f 4d 20 69 69 3b 0a 7d 0a 0a 73 65 74 20  FROM ii;.}..set 
08a0: 3a 3a 72 65 73 20 5b 64 62 20 65 76 61 6c 20 7b  ::res [db eval {
08b0: 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 78 31  SELECT rowid, x1
08c0: 20 46 52 4f 4d 20 78 31 20 57 48 45 52 45 20 78   FROM x1 WHERE x
08d0: 31 20 4d 41 54 43 48 20 27 2a 72 65 61 64 73 27  1 MATCH '*reads'
08e0: 7d 5d 0a 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f  }]..do_faultsim_
08f0: 74 65 73 74 20 34 20 2d 66 61 75 6c 74 73 20 6f  test 4 -faults o
0900: 6f 6d 2d 2a 20 2d 62 6f 64 79 20 7b 0a 20 20 64  om-* -body {.  d
0910: 62 20 65 76 61 6c 20 7b 53 45 4c 45 43 54 20 72  b eval {SELECT r
0920: 6f 77 69 64 2c 20 78 2c 20 78 31 20 46 52 4f 4d  owid, x, x1 FROM
0930: 20 78 31 20 57 48 45 52 45 20 78 31 20 4d 41 54   x1 WHERE x1 MAT
0940: 43 48 20 27 2a 72 65 61 64 73 27 7d 0a 7d 20 2d  CH '*reads'}.} -
0950: 74 65 73 74 20 7b 0a 20 20 66 61 75 6c 74 73 69  test {.  faultsi
0960: 6d 5f 74 65 73 74 5f 72 65 73 75 6c 74 20 7b 30  m_test_result {0
0970: 20 7b 30 20 7b 7d 20 33 7d 7d 0a 7d 0a 0a 23 2d   {0 {} 3}}.}..#-
0980: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0990: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09c0: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 41 6e 20 4f 4f  --------.# An OO
09d0: 4d 20 77 69 74 68 69 6e 20 61 20 71 75 65 72 79  M within a query
09e0: 20 74 68 61 74 20 75 73 65 73 20 61 20 63 75 73   that uses a cus
09f0: 74 6f 6d 20 72 61 6e 6b 20 66 75 6e 63 74 69 6f  tom rank functio
0a00: 6e 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f  n..#.reset_db.do
0a10: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 35 2e  _execsql_test 5.
0a20: 30 20 7b 0a 20 20 50 52 41 47 4d 41 20 65 6e 63  0 {.  PRAGMA enc
0a30: 6f 64 69 6e 67 3d 27 75 74 66 31 36 27 3b 0a 20  oding='utf16';. 
0a40: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
0a50: 54 41 42 4c 45 20 78 32 20 55 53 49 4e 47 20 66  TABLE x2 USING f
0a60: 74 73 35 28 78 29 3b 0a 20 20 49 4e 53 45 52 54  ts5(x);.  INSERT
0a70: 20 49 4e 54 4f 20 78 32 28 72 6f 77 69 64 2c 20   INTO x2(rowid, 
0a80: 78 29 20 56 41 4c 55 45 53 28 31 30 2c 20 27 61  x) VALUES(10, 'a
0a90: 20 62 20 63 27 29 3b 20 2d 2d 20 33 0a 20 20 49   b c'); -- 3.  I
0aa0: 4e 53 45 52 54 20 49 4e 54 4f 20 78 32 28 72 6f  NSERT INTO x2(ro
0ab0: 77 69 64 2c 20 78 29 20 56 41 4c 55 45 53 28 32  wid, x) VALUES(2
0ac0: 30 2c 20 27 61 20 62 20 63 27 29 3b 20 2d 2d 20  0, 'a b c'); -- 
0ad0: 36 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  6.  INSERT INTO 
0ae0: 78 32 28 72 6f 77 69 64 2c 20 78 29 20 56 41 4c  x2(rowid, x) VAL
0af0: 55 45 53 28 33 30 2c 20 27 61 20 62 20 63 27 29  UES(30, 'a b c')
0b00: 3b 20 2d 2d 20 32 0a 20 20 49 4e 53 45 52 54 20  ; -- 2.  INSERT 
0b10: 49 4e 54 4f 20 78 32 28 72 6f 77 69 64 2c 20 78  INTO x2(rowid, x
0b20: 29 20 56 41 4c 55 45 53 28 34 30 2c 20 27 61 20  ) VALUES(40, 'a 
0b30: 62 20 63 27 29 3b 20 2d 2d 20 35 0a 20 20 49 4e  b c'); -- 5.  IN
0b40: 53 45 52 54 20 49 4e 54 4f 20 78 32 28 72 6f 77  SERT INTO x2(row
0b50: 69 64 2c 20 78 29 20 56 41 4c 55 45 53 28 35 30  id, x) VALUES(50
0b60: 2c 20 27 61 20 62 20 63 27 29 3b 20 2d 2d 20 31  , 'a b c'); -- 1
0b70: 0a 7d 0a 0a 70 72 6f 63 20 72 6f 77 69 64 6d 6f  .}..proc rowidmo
0b80: 64 20 7b 63 6d 64 20 6d 6f 64 7d 20 7b 20 0a 20  d {cmd mod} { . 
0b90: 20 73 65 74 20 72 6f 77 20 5b 24 63 6d 64 20 78   set row [$cmd x
0ba0: 52 6f 77 69 64 5d 0a 20 20 65 78 70 72 20 7b 24  Rowid].  expr {$
0bb0: 72 6f 77 20 25 20 24 6d 6f 64 7d 0a 7d 0a 73 71  row % $mod}.}.sq
0bc0: 6c 69 74 65 33 5f 66 74 73 35 5f 63 72 65 61 74  lite3_fts5_creat
0bd0: 65 5f 66 75 6e 63 74 69 6f 6e 20 64 62 20 72 6f  e_function db ro
0be0: 77 69 64 6d 6f 64 20 72 6f 77 69 64 6d 6f 64 0a  widmod rowidmod.
0bf0: 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65 73  .do_faultsim_tes
0c00: 74 20 35 2e 31 20 2d 66 61 75 6c 74 73 20 6f 6f  t 5.1 -faults oo
0c10: 6d 2d 2a 20 2d 62 6f 64 79 20 7b 0a 20 20 64 62  m-* -body {.  db
0c20: 20 65 76 61 6c 20 7b 0a 20 20 20 20 53 45 4c 45   eval {.    SELE
0c30: 43 54 20 72 6f 77 69 64 20 7c 7c 20 27 2d 27 20  CT rowid || '-' 
0c40: 7c 7c 20 72 61 6e 6b 20 46 52 4f 4d 20 78 32 20  || rank FROM x2 
0c50: 57 48 45 52 45 20 78 32 20 4d 41 54 43 48 20 27  WHERE x2 MATCH '
0c60: 62 27 20 41 4e 44 20 0a 20 20 20 20 72 61 6e 6b  b' AND .    rank
0c70: 20 4d 41 54 43 48 20 22 72 6f 77 69 64 6d 6f 64   MATCH "rowidmod
0c80: 28 27 37 27 29 22 20 4f 52 44 45 52 20 42 59 20  ('7')" ORDER BY 
0c90: 72 61 6e 6b 0a 20 20 7d 0a 7d 20 2d 74 65 73 74  rank.  }.} -test
0ca0: 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65   {.  faultsim_te
0cb0: 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b 35 30  st_result {0 {50
0cc0: 2d 31 20 33 30 2d 32 20 31 30 2d 33 20 34 30 2d  -1 30-2 10-3 40-
0cd0: 35 20 32 30 2d 36 7d 7d 0a 7d 0a 0a 70 72 6f 63  5 20-6}}.}..proc
0ce0: 20 72 6f 77 69 64 70 72 65 66 69 78 20 7b 63 6d   rowidprefix {cm
0cf0: 64 20 70 72 65 66 69 78 7d 20 7b 20 0a 20 20 73  d prefix} { .  s
0d00: 65 74 20 72 6f 77 20 5b 24 63 6d 64 20 78 52 6f  et row [$cmd xRo
0d10: 77 69 64 5d 0a 20 20 73 65 74 20 7b 7d 20 22 24  wid].  set {} "$
0d20: 7b 72 6f 77 7d 2d 24 7b 70 72 65 66 69 78 7d 22  {row}-${prefix}"
0d30: 0a 7d 0a 73 71 6c 69 74 65 33 5f 66 74 73 35 5f  .}.sqlite3_fts5_
0d40: 63 72 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e 20  create_function 
0d50: 64 62 20 72 6f 77 69 64 70 72 65 66 69 78 20 72  db rowidprefix r
0d60: 6f 77 69 64 70 72 65 66 69 78 0a 0a 73 65 74 20  owidprefix..set 
0d70: 73 74 72 20 5b 73 74 72 69 6e 67 20 72 65 70 65  str [string repe
0d80: 61 74 20 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d  at abcdefghijklm
0d90: 6e 6f 70 71 72 73 74 75 76 77 78 79 7a 20 31 30  nopqrstuvwxyz 10
0da0: 5d 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65  ].do_faultsim_te
0db0: 73 74 20 35 2e 32 20 2d 66 61 75 6c 74 73 20 6f  st 5.2 -faults o
0dc0: 6f 6d 2d 2a 20 2d 62 6f 64 79 20 7b 0a 20 20 64  om-* -body {.  d
0dd0: 62 20 65 76 61 6c 20 22 0a 20 20 20 20 53 45 4c  b eval ".    SEL
0de0: 45 43 54 20 72 61 6e 6b 2c 20 78 20 46 52 4f 4d  ECT rank, x FROM
0df0: 20 78 32 20 57 48 45 52 45 20 78 32 20 4d 41 54   x2 WHERE x2 MAT
0e00: 43 48 20 27 62 27 20 41 4e 44 20 0a 20 20 20 20  CH 'b' AND .    
0e10: 72 61 6e 6b 20 4d 41 54 43 48 20 27 72 6f 77 69  rank MATCH 'rowi
0e20: 64 70 72 65 66 69 78 28 27 27 24 3a 3a 73 74 72  dprefix(''$::str
0e30: 27 27 29 27 0a 20 20 20 20 4c 49 4d 49 54 20 31  '')'.    LIMIT 1
0e40: 0a 20 20 22 0a 7d 20 2d 74 65 73 74 20 7b 0a 20  .  ".} -test {. 
0e50: 20 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72   faultsim_test_r
0e60: 65 73 75 6c 74 20 22 30 20 7b 31 30 2d 24 3a 3a  esult "0 {10-$::
0e70: 73 74 72 20 7b 61 20 62 20 63 7d 7d 22 0a 7d 0a  str {a b c}}".}.
0e80: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
0e90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ea0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0eb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ec0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 4f  ------------.# O
0ed0: 4f 4d 20 65 72 72 6f 72 73 20 77 69 74 68 69 6e  OM errors within
0ee0: 20 61 75 78 69 6c 69 61 72 79 20 66 75 6e 63 74   auxiliary funct
0ef0: 69 6f 6e 73 2e 0a 23 0a 72 65 73 65 74 5f 64 62  ions..#.reset_db
0f00: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
0f10: 20 36 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20   6.0 {.  CREATE 
0f20: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 78 33  VIRTUAL TABLE x3
0f30: 20 55 53 49 4e 47 20 66 74 73 35 28 78 78 78 29   USING fts5(xxx)
0f40: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
0f50: 78 33 20 56 41 4c 55 45 53 28 27 61 20 62 20 63  x3 VALUES('a b c
0f60: 20 64 20 63 20 62 20 61 27 29 3b 0a 20 20 49 4e   d c b a');.  IN
0f70: 53 45 52 54 20 49 4e 54 4f 20 78 33 20 56 41 4c  SERT INTO x3 VAL
0f80: 55 45 53 28 27 61 20 61 20 61 20 61 20 61 20 61  UES('a a a a a a
0f90: 20 61 27 29 3b 0a 20 20 49 4e 53 45 52 54 20 49   a');.  INSERT I
0fa0: 4e 54 4f 20 78 33 20 56 41 4c 55 45 53 28 27 61  NTO x3 VALUES('a
0fb0: 20 61 20 61 20 61 20 61 20 61 20 61 27 29 3b 0a   a a a a a a');.
0fc0: 7d 0a 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74  }..do_faultsim_t
0fd0: 65 73 74 20 36 2e 31 20 2d 66 61 75 6c 74 73 20  est 6.1 -faults 
0fe0: 6f 6f 6d 2d 74 2a 20 2d 62 6f 64 79 20 7b 0a 20  oom-t* -body {. 
0ff0: 20 64 62 20 65 76 61 6c 20 7b 20 53 45 4c 45 43   db eval { SELEC
1000: 54 20 68 69 67 68 6c 69 67 68 74 28 78 33 2c 20  T highlight(x3, 
1010: 30 2c 20 27 2a 27 2c 20 27 2a 27 29 20 46 52 4f  0, '*', '*') FRO
1020: 4d 20 78 33 20 57 48 45 52 45 20 78 33 20 4d 41  M x3 WHERE x3 MA
1030: 54 43 48 20 27 63 27 20 7d 0a 7d 20 2d 74 65 73  TCH 'c' }.} -tes
1040: 74 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74  t {.  faultsim_t
1050: 65 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b 7b  est_result {0 {{
1060: 61 20 62 20 2a 63 2a 20 64 20 2a 63 2a 20 62 20  a b *c* d *c* b 
1070: 61 7d 7d 7d 0a 7d 0a 0a 70 72 6f 63 20 66 69 72  a}}}.}..proc fir
1080: 73 74 69 6e 73 74 20 7b 63 6d 64 7d 20 7b 20 0a  stinst {cmd} { .
1090: 20 20 66 6f 72 65 61 63 68 20 7b 70 20 63 20 6f    foreach {p c o
10a0: 7d 20 5b 24 63 6d 64 20 78 49 6e 73 74 20 30 5d  } [$cmd xInst 0]
10b0: 20 7b 7d 0a 20 20 65 78 70 72 20 24 63 2a 31 30   {}.  expr $c*10
10c0: 30 20 2b 20 24 6f 0a 7d 0a 73 71 6c 69 74 65 33  0 + $o.}.sqlite3
10d0: 5f 66 74 73 35 5f 63 72 65 61 74 65 5f 66 75 6e  _fts5_create_fun
10e0: 63 74 69 6f 6e 20 64 62 20 66 69 72 73 74 69 6e  ction db firstin
10f0: 73 74 20 66 69 72 73 74 69 6e 73 74 0a 0a 64 6f  st firstinst..do
1100: 5f 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 20 36  _faultsim_test 6
1110: 2e 32 20 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d 74  .2 -faults oom-t
1120: 2a 20 2d 62 6f 64 79 20 7b 0a 20 20 64 62 20 65  * -body {.  db e
1130: 76 61 6c 20 7b 20 53 45 4c 45 43 54 20 66 69 72  val { SELECT fir
1140: 73 74 69 6e 73 74 28 78 33 29 20 46 52 4f 4d 20  stinst(x3) FROM 
1150: 78 33 20 57 48 45 52 45 20 78 33 20 4d 41 54 43  x3 WHERE x3 MATC
1160: 48 20 27 63 27 20 7d 0a 7d 20 2d 74 65 73 74 20  H 'c' }.} -test 
1170: 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65 73  {.  faultsim_tes
1180: 74 5f 72 65 73 75 6c 74 20 7b 30 20 32 7d 20 7b  t_result {0 2} {
1190: 31 20 53 51 4c 49 54 45 5f 4e 4f 4d 45 4d 7d 0a  1 SQLITE_NOMEM}.
11a0: 7d 0a 0a 70 72 6f 63 20 70 72 65 76 69 63 20 7b  }..proc previc {
11b0: 63 6d 64 7d 20 7b 0a 20 20 73 65 74 20 72 65 73  cmd} {.  set res
11c0: 20 5b 24 63 6d 64 20 78 47 65 74 41 75 78 64 61   [$cmd xGetAuxda
11d0: 74 61 49 6e 74 20 30 5d 0a 20 20 24 63 6d 64 20  taInt 0].  $cmd 
11e0: 78 53 65 74 41 75 78 64 61 74 61 49 6e 74 20 5b  xSetAuxdataInt [
11f0: 24 63 6d 64 20 78 49 6e 73 74 43 6f 75 6e 74 5d  $cmd xInstCount]
1200: 0a 20 20 72 65 74 75 72 6e 20 24 72 65 73 0a 7d  .  return $res.}
1210: 0a 73 71 6c 69 74 65 33 5f 66 74 73 35 5f 63 72  .sqlite3_fts5_cr
1220: 65 61 74 65 5f 66 75 6e 63 74 69 6f 6e 20 64 62  eate_function db
1230: 20 70 72 65 76 69 63 20 20 70 72 65 76 69 63 0a   previc  previc.
1240: 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65 73  .do_faultsim_tes
1250: 74 20 36 2e 32 20 2d 66 61 75 6c 74 73 20 6f 6f  t 6.2 -faults oo
1260: 6d 2d 74 2a 20 2d 62 6f 64 79 20 7b 0a 20 20 64  m-t* -body {.  d
1270: 62 20 65 76 61 6c 20 7b 20 53 45 4c 45 43 54 20  b eval { SELECT 
1280: 70 72 65 76 69 63 28 78 33 29 20 46 52 4f 4d 20  previc(x3) FROM 
1290: 78 33 20 57 48 45 52 45 20 78 33 20 4d 41 54 43  x3 WHERE x3 MATC
12a0: 48 20 27 61 27 20 7d 0a 7d 20 2d 74 65 73 74 20  H 'a' }.} -test 
12b0: 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65 73  {.  faultsim_tes
12c0: 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b 30 20 32  t_result {0 {0 2
12d0: 20 37 7d 7d 20 7b 31 20 53 51 4c 49 54 45 5f 4e   7}} {1 SQLITE_N
12e0: 4f 4d 45 4d 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  OMEM}.}..#------
12f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1300: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1310: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1320: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1330: 2d 2d 2d 0a 23 20 4f 4f 4d 20 65 72 72 6f 72 20  ---.# OOM error 
1340: 77 68 65 6e 20 71 75 65 72 79 69 6e 67 20 66 6f  when querying fo
1350: 72 20 61 20 70 68 72 61 73 65 20 77 69 74 68 20  r a phrase with 
1360: 6d 61 6e 79 20 74 6f 6b 65 6e 73 2e 0a 23 0a 72  many tokens..#.r
1370: 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73  eset_db.do_execs
1380: 71 6c 5f 74 65 73 74 20 37 2e 30 20 7b 0a 20 20  ql_test 7.0 {.  
1390: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
13a0: 41 42 4c 45 20 74 74 20 55 53 49 4e 47 20 66 74  ABLE tt USING ft
13b0: 73 35 28 78 2c 20 79 29 3b 0a 20 20 49 4e 53 45  s5(x, y);.  INSE
13c0: 52 54 20 49 4e 54 4f 20 74 74 20 56 41 4c 55 45  RT INTO tt VALUE
13d0: 53 28 27 66 20 62 20 67 20 62 20 63 20 62 27 2c  S('f b g b c b',
13e0: 20 27 66 20 61 20 64 20 63 20 63 20 62 27 29 3b   'f a d c c b');
13f0: 20 20 2d 2d 20 31 0a 20 20 49 4e 53 45 52 54 20    -- 1.  INSERT 
1400: 49 4e 54 4f 20 74 74 20 56 41 4c 55 45 53 28 27  INTO tt VALUES('
1410: 64 20 61 20 65 20 66 20 65 20 64 27 2c 20 27 66  d a e f e d', 'f
1420: 20 62 20 62 20 64 20 65 20 65 27 29 3b 20 20 2d   b b d e e');  -
1430: 2d 20 32 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  - 2.  INSERT INT
1440: 4f 20 74 74 20 56 41 4c 55 45 53 28 27 66 20 62  O tt VALUES('f b
1450: 20 67 20 61 20 64 20 63 27 2c 20 27 65 20 66 20   g a d c', 'e f 
1460: 63 20 66 20 61 20 64 27 29 3b 20 20 2d 2d 20 33  c f a d');  -- 3
1470: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74  .  INSERT INTO t
1480: 74 20 56 41 4c 55 45 53 28 27 66 20 66 20 63 20  t VALUES('f f c 
1490: 64 20 67 20 66 27 2c 20 27 66 20 61 20 65 20 62  d g f', 'f a e b
14a0: 20 67 20 62 27 29 3b 20 20 2d 2d 20 34 0a 20 20   g b');  -- 4.  
14b0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 20 56  INSERT INTO tt V
14c0: 41 4c 55 45 53 28 27 61 20 67 20 62 20 64 20 61  ALUES('a g b d a
14d0: 20 67 27 2c 20 27 65 20 67 20 61 20 65 20 61 20   g', 'e g a e a 
14e0: 63 27 29 3b 20 20 2d 2d 20 35 0a 20 20 49 4e 53  c');  -- 5.  INS
14f0: 45 52 54 20 49 4e 54 4f 20 74 74 20 56 41 4c 55  ERT INTO tt VALU
1500: 45 53 28 27 63 20 64 20 62 20 64 20 65 20 66 27  ES('c d b d e f'
1510: 2c 20 27 66 20 67 20 65 20 67 20 65 20 65 27 29  , 'f g e g e e')
1520: 3b 20 20 2d 2d 20 36 0a 20 20 49 4e 53 45 52 54  ;  -- 6.  INSERT
1530: 20 49 4e 54 4f 20 74 74 20 56 41 4c 55 45 53 28   INTO tt VALUES(
1540: 27 65 20 67 20 66 20 66 20 62 20 63 27 2c 20 27  'e g f f b c', '
1550: 66 20 63 20 65 20 66 20 67 20 66 27 29 3b 20 20  f c e f g f');  
1560: 2d 2d 20 37 0a 20 20 49 4e 53 45 52 54 20 49 4e  -- 7.  INSERT IN
1570: 54 4f 20 74 74 20 56 41 4c 55 45 53 28 27 65 20  TO tt VALUES('e 
1580: 67 20 63 20 66 20 63 20 65 27 2c 20 27 66 20 65  g c f c e', 'f e
1590: 20 65 20 61 20 66 20 67 27 29 3b 20 20 2d 2d 20   e a f g');  -- 
15a0: 38 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  8.  INSERT INTO 
15b0: 74 74 20 56 41 4c 55 45 53 28 27 65 20 61 20 65  tt VALUES('e a e
15c0: 20 62 20 65 20 65 27 2c 20 27 64 20 63 20 63 20   b e e', 'd c c 
15d0: 66 20 66 20 66 27 29 3b 20 20 2d 2d 20 39 0a 20  f f f');  -- 9. 
15e0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 20   INSERT INTO tt 
15f0: 56 41 4c 55 45 53 28 27 66 20 61 20 67 20 67 20  VALUES('f a g g 
1600: 63 20 63 27 2c 20 27 65 20 67 20 64 20 67 20 63  c c', 'e g d g c
1610: 20 65 27 29 3b 20 20 2d 2d 20 31 30 0a 20 20 49   e');  -- 10.  I
1620: 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 20 56 41  NSERT INTO tt VA
1630: 4c 55 45 53 28 27 63 20 64 20 62 20 61 20 65 20  LUES('c d b a e 
1640: 66 27 2c 20 27 66 20 67 20 65 20 68 20 65 20 65  f', 'f g e h e e
1650: 27 29 3b 20 20 2d 2d 20 31 31 0a 0a 20 20 43 52  ');  -- 11..  CR
1660: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42  EATE VIRTUAL TAB
1670: 4c 45 20 74 74 32 20 55 53 49 4e 47 20 66 74 73  LE tt2 USING fts
1680: 35 28 6f 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  5(o);.  INSERT I
1690: 4e 54 4f 20 74 74 32 28 72 6f 77 69 64 2c 20 6f  NTO tt2(rowid, o
16a0: 29 20 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20  ) SELECT rowid, 
16b0: 78 7c 7c 27 20 27 7c 7c 79 20 46 52 4f 4d 20 74  x||' '||y FROM t
16c0: 74 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  t;.  INSERT INTO
16d0: 20 74 74 32 28 72 6f 77 69 64 2c 20 6f 29 20 56   tt2(rowid, o) V
16e0: 41 4c 55 45 53 28 31 32 2c 20 27 61 20 62 20 63  ALUES(12, 'a b c
16f0: 20 64 20 65 20 66 20 67 20 68 20 69 20 6a 20 6b   d e f g h i j k
1700: 20 6c 27 29 3b 0a 7d 0a 0a 64 6f 5f 66 61 75 6c   l');.}..do_faul
1710: 74 73 69 6d 5f 74 65 73 74 20 37 2e 32 20 2d 66  tsim_test 7.2 -f
1720: 61 75 6c 74 73 20 6f 6f 6d 2d 2a 20 2d 62 6f 64  aults oom-* -bod
1730: 79 20 7b 0a 20 20 64 62 20 65 76 61 6c 20 7b 20  y {.  db eval { 
1740: 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f  SELECT rowid FRO
1750: 4d 20 74 74 20 57 48 45 52 45 20 74 74 20 4d 41  M tt WHERE tt MA
1760: 54 43 48 20 27 66 2b 67 2b 65 2b 67 2b 65 2b 65  TCH 'f+g+e+g+e+e
1770: 27 20 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20  ' }.} -test {.  
1780: 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65  faultsim_test_re
1790: 73 75 6c 74 20 7b 30 20 36 7d 20 7b 31 20 53 51  sult {0 6} {1 SQ
17a0: 4c 49 54 45 5f 4e 4f 4d 45 4d 7d 0a 7d 0a 0a 64  LITE_NOMEM}.}..d
17b0: 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 20  o_faultsim_test 
17c0: 37 2e 33 20 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d  7.3 -faults oom-
17d0: 2a 20 2d 62 6f 64 79 20 7b 0a 20 20 64 62 20 65  * -body {.  db e
17e0: 76 61 6c 20 7b 20 53 45 4c 45 43 54 20 72 6f 77  val { SELECT row
17f0: 69 64 20 46 52 4f 4d 20 74 74 20 57 48 45 52 45  id FROM tt WHERE
1800: 20 74 74 20 4d 41 54 43 48 20 27 4e 45 41 52 28   tt MATCH 'NEAR(
1810: 61 20 62 20 63 20 64 20 65 20 66 29 27 20 7d 0a  a b c d e f)' }.
1820: 7d 20 2d 74 65 73 74 20 7b 0a 20 20 66 61 75 6c  } -test {.  faul
1830: 74 73 69 6d 5f 74 65 73 74 5f 72 65 73 75 6c 74  tsim_test_result
1840: 20 7b 30 20 31 31 7d 20 7b 31 20 53 51 4c 49 54   {0 11} {1 SQLIT
1850: 45 5f 4e 4f 4d 45 4d 7d 0a 7d 0a 0a 64 6f 5f 66  E_NOMEM}.}..do_f
1860: 61 75 6c 74 73 69 6d 5f 74 65 73 74 20 37 2e 34  aultsim_test 7.4
1870: 20 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d 74 2a 20   -faults oom-t* 
1880: 2d 62 6f 64 79 20 7b 0a 20 20 64 62 20 65 76 61  -body {.  db eva
1890: 6c 20 7b 20 53 45 4c 45 43 54 20 72 6f 77 69 64  l { SELECT rowid
18a0: 20 46 52 4f 4d 20 74 74 32 20 57 48 45 52 45 20   FROM tt2 WHERE 
18b0: 74 74 32 20 4d 41 54 43 48 20 27 22 67 20 63 20  tt2 MATCH '"g c 
18c0: 66 20 63 20 65 20 66 20 65 20 65 20 61 20 66 22  f c e f e e a f"
18d0: 27 20 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20  ' }.} -test {.  
18e0: 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65  faultsim_test_re
18f0: 73 75 6c 74 20 7b 30 20 38 7d 20 7b 31 20 53 51  sult {0 8} {1 SQ
1900: 4c 49 54 45 5f 4e 4f 4d 45 4d 7d 0a 7d 0a 0a 64  LITE_NOMEM}.}..d
1910: 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 20  o_faultsim_test 
1920: 37 2e 35 20 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d  7.5 -faults oom-
1930: 2a 20 2d 62 6f 64 79 20 7b 0a 20 20 64 62 20 65  * -body {.  db e
1940: 76 61 6c 20 7b 53 45 4c 45 43 54 20 72 6f 77 69  val {SELECT rowi
1950: 64 20 46 52 4f 4d 20 74 74 32 20 57 48 45 52 45  d FROM tt2 WHERE
1960: 20 74 74 32 20 4d 41 54 43 48 20 27 4e 45 41 52   tt2 MATCH 'NEAR
1970: 28 61 20 62 20 63 20 64 20 65 20 66 20 67 20 68  (a b c d e f g h
1980: 20 69 20 6a 20 6b 29 27 7d 0a 7d 20 2d 74 65 73   i j k)'}.} -tes
1990: 74 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74  t {.  faultsim_t
19a0: 65 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 31 32  est_result {0 12
19b0: 7d 20 7b 31 20 53 51 4c 49 54 45 5f 4e 4f 4d 45  } {1 SQLITE_NOME
19c0: 4d 7d 0a 7d 0a 0a 64 6f 5f 66 61 75 6c 74 73 69  M}.}..do_faultsi
19d0: 6d 5f 74 65 73 74 20 37 2e 36 20 2d 66 61 75 6c  m_test 7.6 -faul
19e0: 74 73 20 6f 6f 6d 2d 2a 20 2d 62 6f 64 79 20 7b  ts oom-* -body {
19f0: 0a 20 20 64 62 20 65 76 61 6c 20 7b 53 45 4c 45  .  db eval {SELE
1a00: 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 74 74  CT rowid FROM tt
1a10: 20 57 48 45 52 45 20 74 74 20 4d 41 54 43 48 20   WHERE tt MATCH 
1a20: 27 79 3a 20 22 63 20 63 22 27 7d 0a 7d 20 2d 74  'y: "c c"'}.} -t
1a30: 65 73 74 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d  est {.  faultsim
1a40: 5f 74 65 73 74 5f 72 65 73 75 6c 74 20 7b 30 20  _test_result {0 
1a50: 7b 31 20 39 7d 7d 20 7b 31 20 53 51 4c 49 54 45  {1 9}} {1 SQLITE
1a60: 5f 4e 4f 4d 45 4d 7d 0a 7d 0a 0a 23 2d 2d 2d 2d  _NOMEM}.}..#----
1a70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1a80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1a90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1aa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1ab0: 2d 2d 2d 2d 2d 0a 23 0a 72 65 73 65 74 5f 64 62  -----.#.reset_db
1ac0: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
1ad0: 20 38 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20   8.0 {.  CREATE 
1ae0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 74  VIRTUAL TABLE tt
1af0: 20 55 53 49 4e 47 20 66 74 73 35 28 78 29 3b 0a   USING fts5(x);.
1b00: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74    INSERT INTO tt
1b10: 28 74 74 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45  (tt, rank) VALUE
1b20: 53 28 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a 20  S('pgsz', 32);. 
1b30: 20 42 45 47 49 4e 3b 0a 20 20 20 20 49 4e 53 45   BEGIN;.    INSE
1b40: 52 54 20 49 4e 54 4f 20 74 74 28 72 6f 77 69 64  RT INTO tt(rowid
1b50: 2c 20 78 29 20 56 41 4c 55 45 53 28 31 2c 20 27  , x) VALUES(1, '
1b60: 61 20 62 20 63 20 64 20 78 20 78 27 29 3b 0a 20  a b c d x x');. 
1b70: 20 20 20 57 49 54 48 20 69 69 28 69 29 20 41 53     WITH ii(i) AS
1b80: 20 28 53 45 4c 45 43 54 20 32 20 55 4e 49 4f 4e   (SELECT 2 UNION
1b90: 20 41 4c 4c 20 53 45 4c 45 43 54 20 69 2b 31 20   ALL SELECT i+1 
1ba0: 46 52 4f 4d 20 69 69 20 57 48 45 52 45 20 69 3c  FROM ii WHERE i<
1bb0: 39 39 29 0a 20 20 20 20 20 20 49 4e 53 45 52 54  99).      INSERT
1bc0: 20 49 4e 54 4f 20 74 74 28 72 6f 77 69 64 2c 20   INTO tt(rowid, 
1bd0: 78 29 20 53 45 4c 45 43 54 20 69 2c 20 27 61 20  x) SELECT i, 'a 
1be0: 62 20 63 20 78 20 78 20 64 27 20 46 52 4f 4d 20  b c x x d' FROM 
1bf0: 69 69 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  ii;.    INSERT I
1c00: 4e 54 4f 20 74 74 28 72 6f 77 69 64 2c 20 78 29  NTO tt(rowid, x)
1c10: 20 56 41 4c 55 45 53 28 31 30 30 2c 20 27 61 20   VALUES(100, 'a 
1c20: 62 20 63 20 64 20 78 20 78 27 29 3b 0a 20 20 43  b c d x x');.  C
1c30: 4f 4d 4d 49 54 3b 0a 7d 0a 0a 64 6f 5f 66 61 75  OMMIT;.}..do_fau
1c40: 6c 74 73 69 6d 5f 74 65 73 74 20 38 2e 31 20 2d  ltsim_test 8.1 -
1c50: 66 61 75 6c 74 73 20 6f 6f 6d 2d 74 2a 20 2d 62  faults oom-t* -b
1c60: 6f 64 79 20 7b 0a 20 20 64 62 20 65 76 61 6c 20  ody {.  db eval 
1c70: 7b 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46  { SELECT rowid F
1c80: 52 4f 4d 20 74 74 20 57 48 45 52 45 20 74 74 20  ROM tt WHERE tt 
1c90: 4d 41 54 43 48 20 27 4e 45 41 52 28 61 20 62 20  MATCH 'NEAR(a b 
1ca0: 63 20 64 2c 20 32 29 27 20 7d 0a 7d 20 2d 74 65  c d, 2)' }.} -te
1cb0: 73 74 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f  st {.  faultsim_
1cc0: 74 65 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b  test_result {0 {
1cd0: 31 20 31 30 30 7d 7d 20 7b 31 20 53 51 4c 49 54  1 100}} {1 SQLIT
1ce0: 45 5f 4e 4f 4d 45 4d 7d 0a 7d 0a 0a 64 6f 5f 66  E_NOMEM}.}..do_f
1cf0: 61 75 6c 74 73 69 6d 5f 74 65 73 74 20 38 2e 32  aultsim_test 8.2
1d00: 20 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d 74 2a 20   -faults oom-t* 
1d10: 2d 62 6f 64 79 20 7b 0a 20 20 64 62 20 65 76 61  -body {.  db eva
1d20: 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f 75 6e 74  l { SELECT count
1d30: 28 2a 29 20 46 52 4f 4d 20 74 74 20 57 48 45 52  (*) FROM tt WHER
1d40: 45 20 74 74 20 4d 41 54 43 48 20 27 61 20 4f 52  E tt MATCH 'a OR
1d50: 20 64 27 20 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a   d' }.} -test {.
1d60: 20 20 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f    faultsim_test_
1d70: 72 65 73 75 6c 74 20 7b 30 20 31 30 30 7d 20 7b  result {0 100} {
1d80: 31 20 53 51 4c 49 54 45 5f 4e 4f 4d 45 4d 7d 0a  1 SQLITE_NOMEM}.
1d90: 7d 0a 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }...#-----------
1da0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1db0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1dc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1dd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
1de0: 20 46 61 75 6c 74 20 69 6e 20 4e 4f 54 20 71 75   Fault in NOT qu
1df0: 65 72 79 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a  ery..#.reset_db.
1e00: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
1e10: 39 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56  9.0 {.  CREATE V
1e20: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 74 20  IRTUAL TABLE tt 
1e30: 55 53 49 4e 47 20 66 74 73 35 28 78 29 3b 0a 20  USING fts5(x);. 
1e40: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 74 28   INSERT INTO tt(
1e50: 74 74 2c 20 72 61 6e 6b 29 20 56 41 4c 55 45 53  tt, rank) VALUES
1e60: 28 27 70 67 73 7a 27 2c 20 33 32 29 3b 0a 20 20  ('pgsz', 32);.  
1e70: 42 45 47 49 4e 3b 0a 20 20 20 20 57 49 54 48 20  BEGIN;.    WITH 
1e80: 69 69 28 69 29 20 41 53 20 28 53 45 4c 45 43 54  ii(i) AS (SELECT
1e90: 20 31 20 55 4e 49 4f 4e 20 41 4c 4c 20 53 45 4c   1 UNION ALL SEL
1ea0: 45 43 54 20 69 2b 31 20 46 52 4f 4d 20 69 69 20  ECT i+1 FROM ii 
1eb0: 57 48 45 52 45 20 69 3c 32 30 30 29 0a 20 20 20  WHERE i<200).   
1ec0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
1ed0: 74 28 72 6f 77 69 64 2c 20 78 29 20 0a 20 20 20  t(rowid, x) .   
1ee0: 20 20 20 53 45 4c 45 43 54 20 69 2c 20 43 41 53     SELECT i, CAS
1ef0: 45 20 57 48 45 4e 20 28 69 25 35 30 29 3d 3d 30  E WHEN (i%50)==0
1f00: 20 54 48 45 4e 20 27 61 20 61 20 61 20 61 20 61   THEN 'a a a a a
1f10: 20 61 27 20 45 4c 53 45 20 27 61 20 78 20 61 20   a' ELSE 'a x a 
1f20: 78 20 61 20 78 27 20 45 4e 44 20 0a 20 20 20 20  x a x' END .    
1f30: 20 20 46 52 4f 4d 20 69 69 3b 0a 20 20 43 4f 4d    FROM ii;.  COM
1f40: 4d 49 54 3b 0a 7d 0a 0a 64 6f 5f 66 61 75 6c 74  MIT;.}..do_fault
1f50: 73 69 6d 5f 74 65 73 74 20 39 2e 31 20 2d 66 61  sim_test 9.1 -fa
1f60: 75 6c 74 73 20 6f 6f 6d 2d 2a 20 2d 62 6f 64 79  ults oom-* -body
1f70: 20 7b 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 53   {.  db eval { S
1f80: 45 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d  ELECT rowid FROM
1f90: 20 74 74 20 57 48 45 52 45 20 74 74 20 4d 41 54   tt WHERE tt MAT
1fa0: 43 48 20 27 61 20 4e 4f 54 20 78 27 20 7d 0a 7d  CH 'a NOT x' }.}
1fb0: 20 2d 74 65 73 74 20 7b 0a 20 20 66 61 75 6c 74   -test {.  fault
1fc0: 73 69 6d 5f 74 65 73 74 5f 72 65 73 75 6c 74 20  sim_test_result 
1fd0: 7b 30 20 7b 35 30 20 31 30 30 20 31 35 30 20 32  {0 {50 100 150 2
1fe0: 30 30 7d 7d 20 7b 31 20 53 51 4c 49 54 45 5f 4e  00}} {1 SQLITE_N
1ff0: 4f 4d 45 4d 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  OMEM}.}..#------
2000: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2020: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2030: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2040: 2d 2d 2d 0a 23 20 4f 4f 4d 20 69 6e 20 66 74 73  ---.# OOM in fts
2050: 35 5f 65 78 70 72 28 29 20 53 51 4c 20 66 75 6e  5_expr() SQL fun
2060: 63 74 69 6f 6e 2e 0a 23 0a 64 6f 5f 66 61 75 6c  ction..#.do_faul
2070: 74 73 69 6d 5f 74 65 73 74 20 31 30 2e 31 20 2d  tsim_test 10.1 -
2080: 66 61 75 6c 74 73 20 6f 6f 6d 2d 74 2a 20 2d 62  faults oom-t* -b
2090: 6f 64 79 20 7b 0a 20 20 64 62 20 6f 6e 65 20 7b  ody {.  db one {
20a0: 20 53 45 4c 45 43 54 20 66 74 73 35 5f 65 78 70   SELECT fts5_exp
20b0: 72 28 27 61 20 41 4e 44 20 62 20 4e 45 41 52 28  r('a AND b NEAR(
20c0: 61 20 62 29 27 29 20 7d 0a 7d 20 2d 74 65 73 74  a b)') }.} -test
20d0: 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65   {.  faultsim_te
20e0: 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b 22 61  st_result {0 {"a
20f0: 22 20 41 4e 44 20 22 62 22 20 41 4e 44 20 4e 45  " AND "b" AND NE
2100: 41 52 28 22 61 22 20 22 62 22 2c 20 31 30 29 7d  AR("a" "b", 10)}
2110: 7d 20 0a 7d 0a 0a 64 6f 5f 66 61 75 6c 74 73 69  } .}..do_faultsi
2120: 6d 5f 74 65 73 74 20 31 30 2e 32 20 2d 66 61 75  m_test 10.2 -fau
2130: 6c 74 73 20 6f 6f 6d 2d 74 2a 20 2d 62 6f 64 79  lts oom-t* -body
2140: 20 7b 0a 20 20 64 62 20 6f 6e 65 20 7b 20 53 45   {.  db one { SE
2150: 4c 45 43 54 20 66 74 73 35 5f 65 78 70 72 5f 74  LECT fts5_expr_t
2160: 63 6c 28 27 78 3a 22 61 20 62 20 63 22 20 41 4e  cl('x:"a b c" AN
2170: 44 20 62 20 4e 45 41 52 28 61 20 62 29 27 2c 20  D b NEAR(a b)', 
2180: 27 6e 73 27 2c 20 27 78 27 29 20 7d 0a 7d 20 2d  'ns', 'x') }.} -
2190: 74 65 73 74 20 7b 0a 20 20 73 65 74 20 72 65 73  test {.  set res
21a0: 20 7b 41 4e 44 20 5b 6e 73 20 2d 63 6f 6c 20 30   {AND [ns -col 0
21b0: 20 2d 2d 20 7b 61 20 62 20 63 7d 5d 20 5b 6e 73   -- {a b c}] [ns
21c0: 20 2d 2d 20 7b 62 7d 5d 20 5b 6e 73 20 2d 6e 65   -- {b}] [ns -ne
21d0: 61 72 20 31 30 20 2d 2d 20 7b 61 7d 20 7b 62 7d  ar 10 -- {a} {b}
21e0: 5d 7d 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65  ]}.  faultsim_te
21f0: 73 74 5f 72 65 73 75 6c 74 20 5b 6c 69 73 74 20  st_result [list 
2200: 30 20 24 72 65 73 5d 0a 7d 0a 0a 64 6f 5f 66 61  0 $res].}..do_fa
2210: 75 6c 74 73 69 6d 5f 74 65 73 74 20 31 30 2e 33  ultsim_test 10.3
2220: 20 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d 74 2a 20   -faults oom-t* 
2230: 2d 62 6f 64 79 20 7b 0a 20 20 64 62 20 6f 6e 65  -body {.  db one
2240: 20 7b 20 53 45 4c 45 43 54 20 66 74 73 35 5f 65   { SELECT fts5_e
2250: 78 70 72 28 27 78 3a 61 27 2c 20 27 78 27 29 20  xpr('x:a', 'x') 
2260: 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20 66 61  }.} -test {.  fa
2270: 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65 73 75  ultsim_test_resu
2280: 6c 74 20 7b 30 20 7b 78 20 3a 20 22 61 22 7d 7d  lt {0 {x : "a"}}
2290: 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .}..#-----------
22a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
22b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
22c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
22d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
22e0: 20 4f 4f 4d 20 77 68 69 6c 65 20 63 6f 6e 66 69   OOM while confi
22f0: 67 75 72 69 6e 67 20 27 72 61 6e 6b 27 20 6f 70  guring 'rank' op
2300: 74 69 6f 6e 2e 0a 23 0a 72 65 73 65 74 5f 64 62  tion..#.reset_db
2310: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74  .do_execsql_test
2320: 20 31 31 2e 30 20 7b 0a 20 20 43 52 45 41 54 45   11.0 {.  CREATE
2330: 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 66   VIRTUAL TABLE f
2340: 74 20 55 53 49 4e 47 20 66 74 73 35 28 78 29 3b  t USING fts5(x);
2350: 0a 7d 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74  .}.do_faultsim_t
2360: 65 73 74 20 31 31 2e 31 20 2d 66 61 75 6c 74 73  est 11.1 -faults
2370: 20 6f 6f 6d 2d 74 2a 20 2d 62 6f 64 79 20 7b 0a   oom-t* -body {.
2380: 20 20 64 62 20 65 76 61 6c 20 7b 20 49 4e 53 45    db eval { INSE
2390: 52 54 20 49 4e 54 4f 20 66 74 28 66 74 2c 20 72  RT INTO ft(ft, r
23a0: 61 6e 6b 29 20 56 41 4c 55 45 53 28 27 72 61 6e  ank) VALUES('ran
23b0: 6b 27 2c 20 27 62 6d 32 35 28 31 30 2e 30 2c 20  k', 'bm25(10.0, 
23c0: 35 2e 30 29 27 29 20 7d 0a 7d 20 2d 74 65 73 74  5.0)') }.} -test
23d0: 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65   {.  faultsim_te
23e0: 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b 7d 7d  st_result {0 {}}
23f0: 20 7b 31 20 7b 64 69 73 6b 20 49 2f 4f 20 65 72   {1 {disk I/O er
2400: 72 6f 72 7d 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  ror}}.}..#------
2410: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2420: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2430: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2440: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2450: 2d 2d 2d 0a 23 20 4f 4f 4d 20 77 68 69 6c 65 20  ---.# OOM while 
2460: 63 72 65 61 74 69 6e 67 20 61 6e 20 66 74 73 35  creating an fts5
2470: 76 6f 63 61 62 20 74 61 62 6c 65 2e 0a 23 0a 72  vocab table..#.r
2480: 65 73 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73  eset_db.do_execs
2490: 71 6c 5f 74 65 73 74 20 31 32 2e 30 20 7b 0a 20  ql_test 12.0 {. 
24a0: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
24b0: 54 41 42 4c 45 20 66 74 20 55 53 49 4e 47 20 66  TABLE ft USING f
24c0: 74 73 35 28 78 29 3b 0a 7d 0a 66 61 75 6c 74 73  ts5(x);.}.faults
24d0: 69 6d 5f 73 61 76 65 5f 61 6e 64 5f 63 6c 6f 73  im_save_and_clos
24e0: 65 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65  e.do_faultsim_te
24f0: 73 74 20 31 32 2e 31 20 2d 66 61 75 6c 74 73 20  st 12.1 -faults 
2500: 6f 6f 6d 2d 74 2a 20 2d 70 72 65 70 20 7b 0a 20  oom-t* -prep {. 
2510: 20 66 61 75 6c 74 73 69 6d 5f 72 65 73 74 6f 72   faultsim_restor
2520: 65 5f 61 6e 64 5f 72 65 6f 70 65 6e 0a 20 20 64  e_and_reopen.  d
2530: 62 20 65 76 61 6c 20 7b 20 53 45 4c 45 43 54 20  b eval { SELECT 
2540: 2a 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61  * FROM sqlite_ma
2550: 73 74 65 72 20 7d 0a 7d 20 2d 62 6f 64 79 20 7b  ster }.} -body {
2560: 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 43 52 45  .  db eval { CRE
2570: 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c  ATE VIRTUAL TABL
2580: 45 20 76 76 20 55 53 49 4e 47 20 66 74 73 35 76  E vv USING fts5v
2590: 6f 63 61 62 28 66 74 2c 20 27 72 6f 77 27 29 20  ocab(ft, 'row') 
25a0: 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20 66 61  }.} -test {.  fa
25b0: 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65 73 75  ultsim_test_resu
25c0: 6c 74 20 7b 30 20 7b 7d 7d 20 0a 7d 0a 0a 23 2d  lt {0 {}} .}..#-
25d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
25e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
25f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2610: 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 4f 4f 4d 20 77  --------.# OOM w
2620: 68 69 6c 65 20 71 75 65 72 79 69 6e 67 20 61 6e  hile querying an
2630: 20 66 74 73 35 76 6f 63 61 62 20 74 61 62 6c 65   fts5vocab table
2640: 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64 6f 5f  ..#.reset_db.do_
2650: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31 33 2e  execsql_test 13.
2660: 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49 52  0 {.  CREATE VIR
2670: 54 55 41 4c 20 54 41 42 4c 45 20 66 74 20 55 53  TUAL TABLE ft US
2680: 49 4e 47 20 66 74 73 35 28 78 29 3b 0a 20 20 49  ING fts5(x);.  I
2690: 4e 53 45 52 54 20 49 4e 54 4f 20 66 74 20 56 41  NSERT INTO ft VA
26a0: 4c 55 45 53 28 27 61 20 62 27 29 3b 0a 20 20 43  LUES('a b');.  C
26b0: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
26c0: 42 4c 45 20 76 76 20 55 53 49 4e 47 20 66 74 73  BLE vv USING fts
26d0: 35 76 6f 63 61 62 28 66 74 2c 20 27 72 6f 77 27  5vocab(ft, 'row'
26e0: 29 3b 0a 7d 0a 66 61 75 6c 74 73 69 6d 5f 73 61  );.}.faultsim_sa
26f0: 76 65 5f 61 6e 64 5f 63 6c 6f 73 65 0a 64 6f 5f  ve_and_close.do_
2700: 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 20 31 33  faultsim_test 13
2710: 2e 31 20 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d 74  .1 -faults oom-t
2720: 2a 20 2d 70 72 65 70 20 7b 0a 20 20 66 61 75 6c  * -prep {.  faul
2730: 74 73 69 6d 5f 72 65 73 74 6f 72 65 5f 61 6e 64  tsim_restore_and
2740: 5f 72 65 6f 70 65 6e 0a 20 20 64 62 20 65 76 61  _reopen.  db eva
2750: 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f  l { SELECT * FRO
2760: 4d 20 76 76 20 7d 0a 7d 20 2d 62 6f 64 79 20 7b  M vv }.} -body {
2770: 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 53 45 4c  .  db eval { SEL
2780: 45 43 54 20 2a 20 46 52 4f 4d 20 76 76 20 7d 0a  ECT * FROM vv }.
2790: 7d 20 2d 74 65 73 74 20 7b 0a 20 20 66 61 75 6c  } -test {.  faul
27a0: 74 73 69 6d 5f 74 65 73 74 5f 72 65 73 75 6c 74  tsim_test_result
27b0: 20 7b 30 20 7b 61 20 31 20 31 20 62 20 31 20 31   {0 {a 1 1 b 1 1
27c0: 7d 7d 20 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  }} .}..#--------
27d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
27e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
27f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2800: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2810: 2d 0a 23 20 4f 4f 4d 20 69 6e 20 6d 75 6c 74 69  -.# OOM in multi
2820: 2d 63 6f 6c 75 6d 6e 20 74 6f 6b 65 6e 20 71 75  -column token qu
2830: 65 72 79 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a  ery..#.reset_db.
2840: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
2850: 31 33 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20  13.0 {.  CREATE 
2860: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 66 74  VIRTUAL TABLE ft
2870: 20 55 53 49 4e 47 20 66 74 73 35 28 78 2c 20 79   USING fts5(x, y
2880: 2c 20 7a 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  , z);.  INSERT I
2890: 4e 54 4f 20 66 74 28 66 74 2c 20 72 61 6e 6b 29  NTO ft(ft, rank)
28a0: 20 56 41 4c 55 45 53 28 27 70 67 73 7a 27 2c 20   VALUES('pgsz', 
28b0: 33 32 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e  32);.  INSERT IN
28c0: 54 4f 20 66 74 20 56 41 4c 55 45 53 28 0a 20 20  TO ft VALUES(.  
28d0: 20 20 20 20 27 78 20 78 20 78 20 78 20 78 20 78      'x x x x x x
28e0: 20 78 20 78 20 78 20 78 20 78 20 78 20 78 20 78   x x x x x x x x
28f0: 20 78 20 78 27 2c 0a 20 20 20 20 20 20 27 79 20   x x',.      'y 
2900: 79 20 79 20 79 20 79 20 79 20 79 20 79 20 79 20  y y y y y y y y 
2910: 79 20 79 20 79 20 79 20 79 20 79 20 79 27 2c 0a  y y y y y y y',.
2920: 20 20 20 20 20 20 27 7a 20 7a 20 7a 20 7a 20 7a        'z z z z z
2930: 20 7a 20 7a 20 7a 20 78 20 78 20 78 20 78 20 78   z z z x x x x x
2940: 20 78 20 78 20 78 27 0a 20 20 29 3b 0a 20 20 49   x x x'.  );.  I
2950: 4e 53 45 52 54 20 49 4e 54 4f 20 66 74 20 53 45  NSERT INTO ft SE
2960: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 66 74 3b 0a  LECT * FROM ft;.
2970: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 66 74    INSERT INTO ft
2980: 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 66   SELECT * FROM f
2990: 74 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  t;.  INSERT INTO
29a0: 20 66 74 20 53 45 4c 45 43 54 20 2a 20 46 52 4f   ft SELECT * FRO
29b0: 4d 20 66 74 3b 0a 20 20 49 4e 53 45 52 54 20 49  M ft;.  INSERT I
29c0: 4e 54 4f 20 66 74 20 53 45 4c 45 43 54 20 2a 20  NTO ft SELECT * 
29d0: 46 52 4f 4d 20 66 74 3b 0a 7d 0a 66 61 75 6c 74  FROM ft;.}.fault
29e0: 73 69 6d 5f 73 61 76 65 5f 61 6e 64 5f 63 6c 6f  sim_save_and_clo
29f0: 73 65 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74  se.do_faultsim_t
2a00: 65 73 74 20 31 33 2e 31 20 2d 66 61 75 6c 74 73  est 13.1 -faults
2a10: 20 6f 6f 6d 2d 74 2a 20 2d 70 72 65 70 20 7b 0a   oom-t* -prep {.
2a20: 20 20 66 61 75 6c 74 73 69 6d 5f 72 65 73 74 6f    faultsim_resto
2a30: 72 65 5f 61 6e 64 5f 72 65 6f 70 65 6e 0a 20 20  re_and_reopen.  
2a40: 64 62 20 65 76 61 6c 20 7b 20 53 45 4c 45 43 54  db eval { SELECT
2a50: 20 2a 20 46 52 4f 4d 20 66 74 20 7d 0a 7d 20 2d   * FROM ft }.} -
2a60: 62 6f 64 79 20 7b 0a 20 20 64 62 20 65 76 61 6c  body {.  db eval
2a70: 20 7b 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20   { SELECT rowid 
2a80: 46 52 4f 4d 20 66 74 20 57 48 45 52 45 20 66 74  FROM ft WHERE ft
2a90: 20 4d 41 54 43 48 20 27 7b 78 20 7a 7d 3a 20 78   MATCH '{x z}: x
2aa0: 27 20 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20  ' }.} -test {.  
2ab0: 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65  faultsim_test_re
2ac0: 73 75 6c 74 20 7b 30 20 7b 31 20 32 20 33 20 34  sult {0 {1 2 3 4
2ad0: 20 35 20 36 20 37 20 38 20 39 20 31 30 20 31 31   5 6 7 8 9 10 11
2ae0: 20 31 32 20 31 33 20 31 34 20 31 35 20 31 36 7d   12 13 14 15 16}
2af0: 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }.}..#----------
2b00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
2b40: 23 20 4f 4f 4d 20 69 6e 20 61 6e 20 22 41 4c 54  # OOM in an "ALT
2b50: 45 52 20 54 41 42 4c 45 20 52 45 4e 41 4d 45 20  ER TABLE RENAME 
2b60: 54 4f 22 0a 23 0a 72 65 73 65 74 5f 64 62 0a 64  TO".#.reset_db.d
2b70: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 31  o_execsql_test 1
2b80: 34 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56  4.0 {.  CREATE V
2b90: 49 52 54 55 41 4c 20 54 41 42 4c 45 20 22 74 62  IRTUAL TABLE "tb
2ba0: 6c 20 6f 6e 65 22 20 55 53 49 4e 47 20 66 74 73  l one" USING fts
2bb0: 35 28 78 2c 20 79 2c 20 7a 29 3b 0a 7d 0a 66 61  5(x, y, z);.}.fa
2bc0: 75 6c 74 73 69 6d 5f 73 61 76 65 5f 61 6e 64 5f  ultsim_save_and_
2bd0: 63 6c 6f 73 65 0a 64 6f 5f 66 61 75 6c 74 73 69  close.do_faultsi
2be0: 6d 5f 74 65 73 74 20 31 34 2e 31 20 2d 66 61 75  m_test 14.1 -fau
2bf0: 6c 74 73 20 6f 6f 6d 2d 74 2a 20 2d 70 72 65 70  lts oom-t* -prep
2c00: 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 72 65   {.  faultsim_re
2c10: 73 74 6f 72 65 5f 61 6e 64 5f 72 65 6f 70 65 6e  store_and_reopen
2c20: 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 53 45 4c  .  db eval { SEL
2c30: 45 43 54 20 2a 20 46 52 4f 4d 20 22 74 62 6c 20  ECT * FROM "tbl 
2c40: 6f 6e 65 22 20 7d 0a 7d 20 2d 62 6f 64 79 20 7b  one" }.} -body {
2c50: 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 41 4c 54  .  db eval { ALT
2c60: 45 52 20 54 41 42 4c 45 20 22 74 62 6c 20 6f 6e  ER TABLE "tbl on
2c70: 65 22 20 52 45 4e 41 4d 45 20 54 4f 20 22 74 62  e" RENAME TO "tb
2c80: 6c 20 74 77 6f 22 20 7d 0a 7d 20 2d 74 65 73 74  l two" }.} -test
2c90: 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65   {.  faultsim_te
2ca0: 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b 7d 7d  st_result {0 {}}
2cb0: 0a 7d 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a  .}..finish_test.