/ Hex Artifact Content
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Artifact 69c8fdbef830cd0d450908d4504d5bb86609e255af99c421c20a0756251fe344:


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 32 0a 0a 23  ix fts5fault2..#
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 35 20 69 73 20 6e 6f 74 20 64 65  E_FTS5 is not de
0230: 66 69 6e 65 64 2c 20 6f 6d 69 74 20 74 68 69 73  fined, omit this
0240: 20 66 69 6c 65 2e 0a 69 66 63 61 70 61 62 6c 65   file..ifcapable
0250: 20 21 66 74 73 35 20 7b 0a 20 20 66 69 6e 69 73   !fts5 {.  finis
0260: 68 5f 74 65 73 74 0a 20 20 72 65 74 75 72 6e 0a  h_test.  return.
0270: 7d 0a 0a 73 65 74 20 64 6f 63 20 5b 73 74 72 69  }..set doc [stri
0280: 6e 67 20 74 72 69 6d 20 5b 73 74 72 69 6e 67 20  ng trim [string 
0290: 72 65 70 65 61 74 20 22 78 20 79 20 7a 20 22 20  repeat "x y z " 
02a0: 32 30 30 5d 5d 0a 64 6f 5f 65 78 65 63 73 71 6c  200]].do_execsql
02b0: 5f 74 65 73 74 20 31 2e 30 20 7b 0a 20 20 43 52  _test 1.0 {.  CR
02c0: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 61 20  EATE TABLE t1(a 
02d0: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20  INTEGER PRIMARY 
02e0: 4b 45 59 2c 20 78 29 3b 0a 20 20 43 52 45 41 54  KEY, x);.  CREAT
02f0: 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20  E VIRTUAL TABLE 
0300: 78 31 20 55 53 49 4e 47 20 66 74 73 35 28 78 2c  x1 USING fts5(x,
0310: 20 63 6f 6e 74 65 6e 74 3d 27 74 31 27 2c 20 63   content='t1', c
0320: 6f 6e 74 65 6e 74 5f 72 6f 77 69 64 3d 27 61 27  ontent_rowid='a'
0330: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
0340: 20 78 31 28 78 31 2c 20 72 61 6e 6b 29 20 56 41   x1(x1, rank) VA
0350: 4c 55 45 53 28 27 70 67 73 7a 27 2c 20 33 32 29  LUES('pgsz', 32)
0360: 3b 0a 20 20 57 49 54 48 20 69 6e 70 75 74 28 61  ;.  WITH input(a
0370: 2c 62 29 20 41 53 20 28 0a 20 20 20 20 53 45 4c  ,b) AS (.    SEL
0380: 45 43 54 20 31 2c 20 24 64 6f 63 20 55 4e 49 4f  ECT 1, $doc UNIO
0390: 4e 20 41 4c 4c 0a 20 20 20 20 53 45 4c 45 43 54  N ALL.    SELECT
03a0: 20 61 2b 31 2c 20 28 24 64 6f 63 20 7c 7c 20 43   a+1, ($doc || C
03b0: 41 53 45 20 57 48 45 4e 20 28 61 2b 31 29 25 31  ASE WHEN (a+1)%1
03c0: 30 30 20 54 48 45 4e 20 27 27 20 45 4c 53 45 20  00 THEN '' ELSE 
03d0: 27 20 78 79 7a 27 20 45 4e 44 29 20 0a 20 20 20  ' xyz' END) .   
03e0: 20 46 52 4f 4d 20 69 6e 70 75 74 20 57 48 45 52   FROM input WHER
03f0: 45 20 61 20 3c 20 31 30 30 30 0a 20 20 29 0a 20  E a < 1000.  ). 
0400: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
0410: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 69 6e  SELECT * FROM in
0420: 70 75 74 3b 0a 0a 20 20 49 4e 53 45 52 54 20 49  put;..  INSERT I
0430: 4e 54 4f 20 78 31 28 78 31 29 20 56 41 4c 55 45  NTO x1(x1) VALUE
0440: 53 28 27 72 65 62 75 69 6c 64 27 29 3b 0a 7d 0a  S('rebuild');.}.
0450: 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65 73  .do_faultsim_tes
0460: 74 20 31 2e 31 20 2d 66 61 75 6c 74 73 20 6f 6f  t 1.1 -faults oo
0470: 6d 2d 2a 20 2d 70 72 65 70 20 7b 0a 7d 20 2d 62  m-* -prep {.} -b
0480: 6f 64 79 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  ody {.  execsql 
0490: 7b 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46  { SELECT rowid F
04a0: 52 4f 4d 20 78 31 20 57 48 45 52 45 20 78 31 20  ROM x1 WHERE x1 
04b0: 4d 41 54 43 48 20 27 7a 20 41 4e 44 20 78 79 7a  MATCH 'z AND xyz
04c0: 27 20 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20  ' }.} -test {.  
04d0: 66 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65  faultsim_test_re
04e0: 73 75 6c 74 20 7b 30 20 7b 31 30 30 20 32 30 30  sult {0 {100 200
04f0: 20 33 30 30 20 34 30 30 20 35 30 30 20 36 30 30   300 400 500 600
0500: 20 37 30 30 20 38 30 30 20 39 30 30 20 31 30 30   700 800 900 100
0510: 30 7d 7d 0a 7d 0a 0a 64 6f 5f 66 61 75 6c 74 73  0}}.}..do_faults
0520: 69 6d 5f 74 65 73 74 20 31 2e 32 20 2d 66 61 75  im_test 1.2 -fau
0530: 6c 74 73 20 6f 6f 6d 2d 2a 20 2d 70 72 65 70 20  lts oom-* -prep 
0540: 7b 0a 7d 20 2d 62 6f 64 79 20 7b 0a 20 20 65 78  {.} -body {.  ex
0550: 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 72  ecsql { SELECT r
0560: 6f 77 69 64 20 46 52 4f 4d 20 78 31 20 57 48 45  owid FROM x1 WHE
0570: 52 45 20 78 31 20 4d 41 54 43 48 20 27 7a 20 2b  RE x1 MATCH 'z +
0580: 20 78 79 7a 27 20 4f 52 44 45 52 20 42 59 20 31   xyz' ORDER BY 1
0590: 20 44 45 53 43 7d 0a 7d 20 2d 74 65 73 74 20 7b   DESC}.} -test {
05a0: 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65 73 74  .  faultsim_test
05b0: 5f 72 65 73 75 6c 74 20 7b 30 20 7b 31 30 30 30  _result {0 {1000
05c0: 20 39 30 30 20 38 30 30 20 37 30 30 20 36 30 30   900 800 700 600
05d0: 20 35 30 30 20 34 30 30 20 33 30 30 20 32 30 30   500 400 300 200
05e0: 20 31 30 30 7d 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d   100}}.}..#-----
05f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0600: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0610: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0620: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0630: 2d 2d 2d 2d 0a 23 20 4f 4f 4d 20 77 69 74 68 69  ----.# OOM withi
0640: 6e 20 61 20 71 75 65 72 79 20 74 68 61 74 20 61  n a query that a
0650: 63 63 65 73 73 65 73 20 74 68 65 20 69 6e 2d 6d  ccesses the in-m
0660: 65 6d 6f 72 79 20 68 61 73 68 20 74 61 62 6c 65  emory hash table
0670: 2e 20 0a 23 0a 72 65 73 65 74 5f 64 62 20 0a 64  . .#.reset_db .d
0680: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 32  o_execsql_test 2
0690: 2e 30 20 7b 0a 20 20 43 52 45 41 54 45 20 56 49  .0 {.  CREATE VI
06a0: 52 54 55 41 4c 20 54 41 42 4c 45 20 22 61 20 62  RTUAL TABLE "a b
06b0: 20 63 22 20 55 53 49 4e 47 20 66 74 73 35 28 61   c" USING fts5(a
06c0: 2c 20 62 2c 20 63 29 3b 0a 20 20 49 4e 53 45 52  , b, c);.  INSER
06d0: 54 20 49 4e 54 4f 20 22 61 20 62 20 63 22 20 56  T INTO "a b c" V
06e0: 41 4c 55 45 53 28 27 6f 6e 65 20 74 77 6f 27 2c  ALUES('one two',
06f0: 20 27 78 20 78 20 78 27 2c 20 27 74 68 72 65 65   'x x x', 'three
0700: 20 66 6f 75 72 27 29 3b 0a 20 20 49 4e 53 45 52   four');.  INSER
0710: 54 20 49 4e 54 4f 20 22 61 20 62 20 63 22 20 56  T INTO "a b c" V
0720: 41 4c 55 45 53 28 27 6e 69 6e 65 20 74 65 6e 27  ALUES('nine ten'
0730: 2c 20 27 79 20 79 20 79 27 2c 20 27 74 77 6f 20  , 'y y y', 'two 
0740: 74 77 6f 27 29 3b 0a 7d 0a 0a 64 6f 5f 66 61 75  two');.}..do_fau
0750: 6c 74 73 69 6d 5f 74 65 73 74 20 32 2e 31 20 2d  ltsim_test 2.1 -
0760: 66 61 75 6c 74 73 20 6f 6f 6d 2d 74 72 61 6e 73  faults oom-trans
0770: 2a 20 2d 70 72 65 70 20 7b 0a 20 20 65 78 65 63  * -prep {.  exec
0780: 73 71 6c 20 7b 0a 20 20 20 20 42 45 47 49 4e 3b  sql {.    BEGIN;
0790: 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e  .      INSERT IN
07a0: 54 4f 20 22 61 20 62 20 63 22 20 56 41 4c 55 45  TO "a b c" VALUE
07b0: 53 28 27 6f 6e 65 20 6f 6e 65 27 2c 20 27 7a 20  S('one one', 'z 
07c0: 7a 20 7a 27 2c 20 27 6e 69 6e 65 20 74 65 6e 27  z z', 'nine ten'
07d0: 29 3b 0a 20 20 7d 0a 7d 20 2d 62 6f 64 79 20 7b  );.  }.} -body {
07e0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c  .  execsql { SEL
07f0: 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 22  ECT rowid FROM "
0800: 61 20 62 20 63 22 20 57 48 45 52 45 20 22 61 20  a b c" WHERE "a 
0810: 62 20 63 22 20 4d 41 54 43 48 20 27 6f 6e 65 27  b c" MATCH 'one'
0820: 20 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20 66   }.} -test {.  f
0830: 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65 73  aultsim_test_res
0840: 75 6c 74 20 7b 30 20 7b 31 20 33 7d 7d 0a 20 20  ult {0 {1 3}}.  
0850: 63 61 74 63 68 73 71 6c 20 7b 20 52 4f 4c 4c 42  catchsql { ROLLB
0860: 41 43 4b 20 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  ACK }.}..#------
0870: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0880: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0890: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
08a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
08b0: 2d 2d 2d 0a 23 20 4f 4f 4d 20 77 69 74 68 69 6e  ---.# OOM within
08c0: 20 61 6e 20 27 6f 70 74 69 6d 69 7a 65 27 20 6f   an 'optimize' o
08d0: 70 65 72 61 74 69 6f 6e 20 74 68 61 74 20 77 72  peration that wr
08e0: 69 74 65 73 20 6d 75 6c 74 69 70 6c 65 20 70 61  ites multiple pa
08f0: 67 65 73 20 74 6f 20 64 69 73 6b 2e 0a 23 0a 72  ges to disk..#.r
0900: 65 73 65 74 5f 64 62 20 0a 64 6f 5f 65 78 65 63  eset_db .do_exec
0910: 73 71 6c 5f 74 65 73 74 20 33 2e 30 20 7b 0a 20  sql_test 3.0 {. 
0920: 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20   CREATE VIRTUAL 
0930: 54 41 42 4c 45 20 7a 7a 7a 20 55 53 49 4e 47 20  TABLE zzz USING 
0940: 66 74 73 35 28 7a 29 3b 0a 20 20 49 4e 53 45 52  fts5(z);.  INSER
0950: 54 20 49 4e 54 4f 20 7a 7a 7a 28 7a 7a 7a 2c 20  T INTO zzz(zzz, 
0960: 72 61 6e 6b 29 20 56 41 4c 55 45 53 28 27 70 67  rank) VALUES('pg
0970: 73 7a 27 2c 20 33 32 29 3b 0a 20 20 49 4e 53 45  sz', 32);.  INSE
0980: 52 54 20 49 4e 54 4f 20 7a 7a 7a 20 56 41 4c 55  RT INTO zzz VALU
0990: 45 53 28 27 61 20 62 20 63 20 64 27 29 3b 0a 20  ES('a b c d');. 
09a0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 7a 7a 7a   INSERT INTO zzz
09b0: 20 53 45 4c 45 43 54 20 27 63 20 64 20 65 20 66   SELECT 'c d e f
09c0: 27 20 46 52 4f 4d 20 7a 7a 7a 3b 0a 20 20 49 4e  ' FROM zzz;.  IN
09d0: 53 45 52 54 20 49 4e 54 4f 20 7a 7a 7a 20 53 45  SERT INTO zzz SE
09e0: 4c 45 43 54 20 27 65 20 66 20 67 20 68 27 20 46  LECT 'e f g h' F
09f0: 52 4f 4d 20 7a 7a 7a 3b 0a 20 20 49 4e 53 45 52  ROM zzz;.  INSER
0a00: 54 20 49 4e 54 4f 20 7a 7a 7a 20 53 45 4c 45 43  T INTO zzz SELEC
0a10: 54 20 27 69 20 6a 20 6b 20 6c 27 20 46 52 4f 4d  T 'i j k l' FROM
0a20: 20 7a 7a 7a 3b 0a 20 20 49 4e 53 45 52 54 20 49   zzz;.  INSERT I
0a30: 4e 54 4f 20 7a 7a 7a 20 53 45 4c 45 43 54 20 27  NTO zzz SELECT '
0a40: 6c 20 6b 20 6d 20 6e 27 20 46 52 4f 4d 20 7a 7a  l k m n' FROM zz
0a50: 7a 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  z;.  INSERT INTO
0a60: 20 7a 7a 7a 20 53 45 4c 45 43 54 20 27 6f 20 70   zzz SELECT 'o p
0a70: 20 71 20 72 27 20 46 52 4f 4d 20 7a 7a 7a 3b 0a   q r' FROM zzz;.
0a80: 7d 0a 66 61 75 6c 74 73 69 6d 5f 73 61 76 65 5f  }.faultsim_save_
0a90: 61 6e 64 5f 63 6c 6f 73 65 0a 0a 64 6f 5f 66 61  and_close..do_fa
0aa0: 75 6c 74 73 69 6d 5f 74 65 73 74 20 33 2e 31 20  ultsim_test 3.1 
0ab0: 2d 66 61 75 6c 74 73 20 6f 6f 6d 2d 74 72 61 6e  -faults oom-tran
0ac0: 73 2a 20 2d 70 72 65 70 20 7b 0a 20 20 66 61 75  s* -prep {.  fau
0ad0: 6c 74 73 69 6d 5f 72 65 73 74 6f 72 65 5f 61 6e  ltsim_restore_an
0ae0: 64 5f 72 65 6f 70 65 6e 0a 20 20 65 78 65 63 73  d_reopen.  execs
0af0: 71 6c 20 7b 20 53 45 4c 45 43 54 20 72 6f 77 69  ql { SELECT rowi
0b00: 64 20 46 52 4f 4d 20 7a 7a 7a 20 7d 0a 7d 20 2d  d FROM zzz }.} -
0b10: 62 6f 64 79 20 7b 0a 20 20 65 78 65 63 73 71 6c  body {.  execsql
0b20: 20 7b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 7a   { INSERT INTO z
0b30: 7a 7a 28 7a 7a 7a 29 20 56 41 4c 55 45 53 28 27  zz(zzz) VALUES('
0b40: 6f 70 74 69 6d 69 7a 65 27 29 20 7d 0a 7d 20 2d  optimize') }.} -
0b50: 74 65 73 74 20 7b 0a 20 20 66 61 75 6c 74 73 69  test {.  faultsi
0b60: 6d 5f 74 65 73 74 5f 72 65 73 75 6c 74 20 7b 30  m_test_result {0
0b70: 20 7b 7d 7d 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d   {}}.}..#-------
0b80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0b90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ba0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0bb0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0bc0: 2d 2d 0a 23 20 4f 4f 4d 20 77 69 74 68 69 6e 20  --.# OOM within 
0bd0: 61 6e 20 27 69 6e 74 65 67 72 69 74 79 2d 63 68  an 'integrity-ch
0be0: 65 63 6b 27 20 6f 70 65 72 61 74 69 6f 6e 2e 0a  eck' operation..
0bf0: 23 0a 72 65 73 65 74 5f 64 62 20 0a 64 62 20 66  #.reset_db .db f
0c00: 75 6e 63 20 72 6e 64 64 6f 63 20 66 74 73 35 5f  unc rnddoc fts5_
0c10: 72 6e 64 64 6f 63 0a 64 6f 5f 65 78 65 63 73 71  rnddoc.do_execsq
0c20: 6c 5f 74 65 73 74 20 34 2e 30 20 7b 0a 20 20 43  l_test 4.0 {.  C
0c30: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41  REATE VIRTUAL TA
0c40: 42 4c 45 20 7a 7a 7a 20 55 53 49 4e 47 20 66 74  BLE zzz USING ft
0c50: 73 35 28 7a 29 3b 0a 20 20 49 4e 53 45 52 54 20  s5(z);.  INSERT 
0c60: 49 4e 54 4f 20 7a 7a 7a 28 7a 7a 7a 2c 20 72 61  INTO zzz(zzz, ra
0c70: 6e 6b 29 20 56 41 4c 55 45 53 28 27 70 67 73 7a  nk) VALUES('pgsz
0c80: 27 2c 20 33 32 29 3b 0a 20 20 57 49 54 48 20 69  ', 32);.  WITH i
0c90: 69 28 69 29 20 41 53 20 28 53 45 4c 45 43 54 20  i(i) AS (SELECT 
0ca0: 31 20 55 4e 49 4f 4e 20 53 45 4c 45 43 54 20 69  1 UNION SELECT i
0cb0: 2b 31 20 46 52 4f 4d 20 69 69 20 57 48 45 52 45  +1 FROM ii WHERE
0cc0: 20 69 3c 31 30 29 0a 20 20 49 4e 53 45 52 54 20   i<10).  INSERT 
0cd0: 49 4e 54 4f 20 7a 7a 7a 20 53 45 4c 45 43 54 20  INTO zzz SELECT 
0ce0: 72 6e 64 64 6f 63 28 31 30 29 20 7c 7c 20 27 20  rnddoc(10) || ' 
0cf0: 78 63 63 63 27 20 46 52 4f 4d 20 69 69 3b 0a 7d  xccc' FROM ii;.}
0d00: 0a 0a 64 6f 5f 66 61 75 6c 74 73 69 6d 5f 74 65  ..do_faultsim_te
0d10: 73 74 20 34 2e 31 20 2d 66 61 75 6c 74 73 20 6f  st 4.1 -faults o
0d20: 6f 6d 2d 74 72 61 6e 73 2a 20 2d 70 72 65 70 20  om-trans* -prep 
0d30: 7b 0a 7d 20 2d 62 6f 64 79 20 7b 0a 20 20 65 78  {.} -body {.  ex
0d40: 65 63 73 71 6c 20 7b 20 49 4e 53 45 52 54 20 49  ecsql { INSERT I
0d50: 4e 54 4f 20 7a 7a 7a 28 7a 7a 7a 29 20 56 41 4c  NTO zzz(zzz) VAL
0d60: 55 45 53 28 27 69 6e 74 65 67 72 69 74 79 2d 63  UES('integrity-c
0d70: 68 65 63 6b 27 29 20 7d 0a 7d 20 2d 74 65 73 74  heck') }.} -test
0d80: 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 74 65   {.  faultsim_te
0d90: 73 74 5f 72 65 73 75 6c 74 20 7b 30 20 7b 7d 7d  st_result {0 {}}
0da0: 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .}..#-----------
0db0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0dc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0dd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0de0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
0df0: 20 4f 4f 4d 20 77 68 69 6c 65 20 70 61 72 73 69   OOM while parsi
0e00: 6e 67 20 61 20 74 6f 6b 65 6e 69 7a 65 3d 6f 70  ng a tokenize=op
0e10: 74 69 6f 6e 0a 23 0a 72 65 73 65 74 5f 64 62 0a  tion.#.reset_db.
0e20: 66 61 75 6c 74 73 69 6d 5f 73 61 76 65 5f 61 6e  faultsim_save_an
0e30: 64 5f 63 6c 6f 73 65 0a 64 6f 5f 66 61 75 6c 74  d_close.do_fault
0e40: 73 69 6d 5f 74 65 73 74 20 35 2e 30 20 2d 66 61  sim_test 5.0 -fa
0e50: 75 6c 74 73 20 6f 6f 6d 2d 2a 20 2d 70 72 65 70  ults oom-* -prep
0e60: 20 7b 0a 20 20 66 61 75 6c 74 73 69 6d 5f 72 65   {.  faultsim_re
0e70: 73 74 6f 72 65 5f 61 6e 64 5f 72 65 6f 70 65 6e  store_and_reopen
0e80: 0a 7d 20 2d 62 6f 64 79 20 7b 0a 20 20 65 78 65  .} -body {.  exe
0e90: 63 73 71 6c 20 7b 20 0a 20 20 20 20 43 52 45 41  csql { .    CREA
0ea0: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45  TE VIRTUAL TABLE
0eb0: 20 75 69 6f 20 55 53 49 4e 47 20 66 74 73 35 28   uio USING fts5(
0ec0: 61 2c 20 62 2c 20 0a 20 20 20 20 20 20 74 6f 6b  a, b, .      tok
0ed0: 65 6e 69 7a 65 3d 22 70 6f 72 74 65 72 20 27 61  enize="porter 'a
0ee0: 73 63 69 69 27 22 2c 0a 20 20 20 20 20 20 63 6f  scii'",.      co
0ef0: 6e 74 65 6e 74 3d 22 61 6e 6f 74 68 65 72 20 74  ntent="another t
0f00: 61 62 6c 65 22 2c 0a 20 20 20 20 20 20 63 6f 6e  able",.      con
0f10: 74 65 6e 74 5f 72 6f 77 69 64 3d 22 73 6f 6d 65  tent_rowid="some
0f20: 63 6f 6c 75 6d 6e 22 0a 20 20 20 20 29 3b 0a 20  column".    );. 
0f30: 20 7d 0a 7d 20 2d 74 65 73 74 20 7b 0a 20 20 66   }.} -test {.  f
0f40: 61 75 6c 74 73 69 6d 5f 74 65 73 74 5f 72 65 73  aultsim_test_res
0f50: 75 6c 74 20 7b 30 20 7b 7d 7d 0a 7d 0a 0a 66 69  ult {0 {}}.}..fi
0f60: 6e 69 73 68 5f 74 65 73 74 0a                    nish_test.