/ Hex Artifact Content
Login

Artifact c0faffda13d045a96dfc541347886bb1a3d6f3205857fc98e683edfab766ea88:


0000: 23 20 32 30 31 38 20 44 65 63 65 6d 62 65 72 20  # 2018 December 
0010: 32 33 0a 23 0a 23 20 54 68 65 20 61 75 74 68 6f  23.#.# The autho
0020: 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 79  r disclaims copy
0030: 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 6f  right to this so
0040: 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 70  urce code.  In p
0050: 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67 61  lace of.# a lega
0060: 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20 69  l notice, here i
0070: 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23 0a  s a blessing:.#.
0080: 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f 20  #    May you do 
0090: 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76 69  good and not evi
00a0: 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20  l..#    May you 
00b0: 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73 73  find forgiveness
00c0: 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61 6e   for yourself an
00d0: 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72 73  d forgive others
00e0: 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 73  ..#    May you s
00f0: 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65 76  hare freely, nev
0100: 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20 74  er taking more t
0110: 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23 0a  han you give..#.
0120: 23 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 2a 2a 0a 23 20 54 68 69 73 20  ********.# This 
0170: 66 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20  file implements 
0180: 72 65 67 72 65 73 73 69 6f 6e 20 74 65 73 74 73  regression tests
0190: 20 66 6f 72 20 53 51 4c 69 74 65 20 6c 69 62 72   for SQLite libr
01a0: 61 72 79 2e 20 20 54 68 65 0a 23 20 66 6f 63 75  ary.  The.# focu
01b0: 73 20 6f 66 20 74 68 69 73 20 66 69 6c 65 20 69  s of this file i
01c0: 73 20 74 65 73 74 69 6e 67 20 74 68 65 20 6f 70  s testing the op
01d0: 65 72 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 6c  eration of the l
01e0: 69 62 72 61 72 79 20 69 6e 0a 23 20 22 50 52 41  ibrary in.# "PRA
01f0: 47 4d 41 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64 65  GMA journal_mode
0200: 3d 57 41 4c 22 20 6d 6f 64 65 2e 0a 23 0a 0a 73  =WAL" mode..#..s
0210: 65 74 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65  et testdir [file
0220: 20 64 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d   dirname $argv0]
0230: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72  .source $testdir
0240: 2f 74 65 73 74 65 72 2e 74 63 6c 0a 73 6f 75 72  /tester.tcl.sour
0250: 63 65 20 24 74 65 73 74 64 69 72 2f 6c 6f 63 6b  ce $testdir/lock
0260: 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c 0a 73 6f 75 72  _common.tcl.sour
0270: 63 65 20 24 74 65 73 74 64 69 72 2f 6d 61 6c 6c  ce $testdir/mall
0280: 6f 63 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c 0a 73 6f  oc_common.tcl.so
0290: 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 77 61  urce $testdir/wa
02a0: 6c 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c 0a 73 65 74  l_common.tcl.set
02b0: 20 74 65 73 74 70 72 65 66 69 78 20 77 61 6c 76   testprefix walv
02c0: 66 73 0a 0a 69 66 63 61 70 61 62 6c 65 20 21 77  fs..ifcapable !w
02d0: 61 6c 20 7b 66 69 6e 69 73 68 5f 74 65 73 74 20  al {finish_test 
02e0: 3b 20 72 65 74 75 72 6e 20 7d 0a 0a 64 62 20 63  ; return }..db c
02f0: 6c 6f 73 65 0a 74 65 73 74 76 66 73 20 74 76 66  lose.testvfs tvf
0300: 73 20 0a 74 76 66 73 20 73 63 72 69 70 74 20 78  s .tvfs script x
0310: 53 79 6e 63 0a 74 76 66 73 20 66 69 6c 74 65 72  Sync.tvfs filter
0320: 20 78 53 79 6e 63 0a 73 65 74 20 3a 3a 73 79 6e   xSync.set ::syn
0330: 63 5f 63 6f 75 6e 74 20 30 0a 70 72 6f 63 20 78  c_count 0.proc x
0340: 53 79 6e 63 20 7b 6d 65 74 68 6f 64 20 66 69 6c  Sync {method fil
0350: 65 20 61 72 67 73 7d 20 7b 0a 20 20 69 66 20 7b  e args} {.  if {
0360: 5b 66 69 6c 65 20 74 61 69 6c 20 24 66 69 6c 65  [file tail $file
0370: 5d 3d 3d 22 74 65 73 74 2e 64 62 2d 77 61 6c 22  ]=="test.db-wal"
0380: 7d 20 7b 0a 20 20 20 20 69 6e 63 72 20 3a 3a 73  } {.    incr ::s
0390: 79 6e 63 5f 63 6f 75 6e 74 0a 20 20 7d 0a 7d 0a  ync_count.  }.}.
03a0: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
03b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54  ------------.# T
03f0: 65 73 74 20 74 68 61 74 20 69 66 20 49 4f 43 41  est that if IOCA
0400: 50 5f 53 45 51 55 45 4e 54 49 41 4c 20 69 73 20  P_SEQUENTIAL is 
0410: 73 65 74 2c 20 74 68 65 20 77 61 6c 2d 68 65 61  set, the wal-hea
0420: 64 65 72 20 69 73 20 6e 6f 74 20 73 79 6e 63 65  der is not synce
0430: 64 20 74 6f 0a 23 20 64 69 73 6b 20 69 6d 6d 65  d to.# disk imme
0440: 64 69 61 74 65 6c 79 20 61 66 74 65 72 20 69 74  diately after it
0450: 20 69 73 20 77 72 69 74 74 65 6e 2e 0a 23 0a 73   is written..#.s
0460: 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64  qlite3 db test.d
0470: 62 20 2d 76 66 73 20 74 76 66 73 0a 64 6f 5f 65  b -vfs tvfs.do_e
0480: 78 65 63 73 71 6c 5f 74 65 73 74 20 31 2e 30 20  xecsql_test 1.0 
0490: 7b 0a 20 20 50 52 41 47 4d 41 20 61 75 74 6f 5f  {.  PRAGMA auto_
04a0: 76 61 63 75 75 6d 20 3d 20 30 3b 0a 20 20 50 52  vacuum = 0;.  PR
04b0: 41 47 4d 41 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64  AGMA journal_mod
04c0: 65 20 3d 20 77 61 6c 3b 0a 20 20 50 52 41 47 4d  e = wal;.  PRAGM
04d0: 41 20 73 79 6e 63 68 72 6f 6e 6f 75 73 20 3d 20  A synchronous = 
04e0: 6e 6f 72 6d 61 6c 3b 0a 20 20 43 52 45 41 54 45  normal;.  CREATE
04f0: 20 54 41 42 4c 45 20 74 31 28 61 2c 20 62 2c 20   TABLE t1(a, b, 
0500: 63 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54  c);.  INSERT INT
0510: 4f 20 74 31 20 56 41 4c 55 45 53 28 31 2c 20 32  O t1 VALUES(1, 2
0520: 2c 20 33 29 3b 0a 20 20 49 4e 53 45 52 54 20 49  , 3);.  INSERT I
0530: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 34 2c  NTO t1 VALUES(4,
0540: 20 35 2c 20 36 29 3b 0a 20 20 49 4e 53 45 52 54   5, 6);.  INSERT
0550: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
0560: 37 2c 20 38 2c 20 39 29 3b 0a 20 20 50 52 41 47  7, 8, 9);.  PRAG
0570: 4d 41 20 77 61 6c 5f 63 68 65 63 6b 70 6f 69 6e  MA wal_checkpoin
0580: 74 3b 0a 7d 20 7b 77 61 6c 20 30 20 35 20 35 7d  t;.} {wal 0 5 5}
0590: 0a 0a 73 65 74 20 3a 3a 73 79 6e 63 5f 63 6f 75  ..set ::sync_cou
05a0: 6e 74 20 30 0a 64 6f 5f 74 65 73 74 20 31 2e 31  nt 0.do_test 1.1
05b0: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 49   {.  execsql { I
05c0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41  NSERT INTO t1 VA
05d0: 4c 55 45 53 28 31 30 2c 20 31 31 2c 20 31 32 29  LUES(10, 11, 12)
05e0: 20 7d 0a 20 20 73 65 74 20 3a 3a 73 79 6e 63 5f   }.  set ::sync_
05f0: 63 6f 75 6e 74 0a 7d 20 31 0a 0a 64 62 20 63 6c  count.} 1..db cl
0600: 6f 73 65 0a 74 76 66 73 20 64 65 76 63 68 61 72  ose.tvfs devchar
0610: 20 73 65 71 75 65 6e 74 69 61 6c 0a 73 71 6c 69   sequential.sqli
0620: 74 65 33 20 64 62 20 74 65 73 74 2e 64 62 20 2d  te3 db test.db -
0630: 76 66 73 20 74 76 66 73 0a 64 6f 5f 65 78 65 63  vfs tvfs.do_exec
0640: 73 71 6c 5f 74 65 73 74 20 31 2e 32 20 7b 0a 20  sql_test 1.2 {. 
0650: 20 50 52 41 47 4d 41 20 73 79 6e 63 68 72 6f 6e   PRAGMA synchron
0660: 6f 75 73 20 3d 20 6e 6f 72 6d 61 6c 3b 0a 20 20  ous = normal;.  
0670: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56  INSERT INTO t1 V
0680: 41 4c 55 45 53 28 31 33 2c 20 31 34 2c 20 31 35  ALUES(13, 14, 15
0690: 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  );.  INSERT INTO
06a0: 20 74 31 20 56 41 4c 55 45 53 28 31 36 2c 20 31   t1 VALUES(16, 1
06b0: 37 2c 20 31 38 29 3b 0a 20 20 50 52 41 47 4d 41  7, 18);.  PRAGMA
06c0: 20 77 61 6c 5f 63 68 65 63 6b 70 6f 69 6e 74 3b   wal_checkpoint;
06d0: 0a 7d 20 7b 30 20 34 20 34 7d 0a 0a 73 65 74 20  .} {0 4 4}..set 
06e0: 3a 3a 73 79 6e 63 5f 63 6f 75 6e 74 20 30 0a 64  ::sync_count 0.d
06f0: 6f 5f 74 65 73 74 20 31 2e 33 20 7b 0a 20 20 65  o_test 1.3 {.  e
0700: 78 65 63 73 71 6c 20 7b 20 49 4e 53 45 52 54 20  xecsql { INSERT 
0710: 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 31  INTO t1 VALUES(1
0720: 30 2c 20 31 31 2c 20 31 32 29 20 7d 0a 20 20 73  0, 11, 12) }.  s
0730: 65 74 20 3a 3a 73 79 6e 63 5f 63 6f 75 6e 74 0a  et ::sync_count.
0740: 7d 20 30 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  } 0..#----------
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 2d 2d 2d 2d 2d 2d 2d  ----------------
0770: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0780: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
0790: 23 20 54 65 73 74 20 74 68 61 74 20 22 50 52 41  # Test that "PRA
07a0: 47 4d 41 20 6a 6f 75 72 6e 61 6c 5f 73 69 7a 65  GMA journal_size
07b0: 5f 6c 69 6d 69 74 22 20 77 6f 72 6b 73 20 69 6e  _limit" works in
07c0: 20 77 61 6c 20 6d 6f 64 65 2e 0a 23 0a 72 65 73   wal mode..#.res
07d0: 65 74 5f 64 62 0a 64 6f 5f 65 78 65 63 73 71 6c  et_db.do_execsql
07e0: 5f 74 65 73 74 20 32 2e 30 20 7b 0a 20 20 50 52  _test 2.0 {.  PR
07f0: 41 47 4d 41 20 6a 6f 75 72 6e 61 6c 5f 73 69 7a  AGMA journal_siz
0800: 65 5f 6c 69 6d 69 74 20 3d 20 31 30 30 30 30 3b  e_limit = 10000;
0810: 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20  .  CREATE TABLE 
0820: 74 31 28 78 29 3b 0a 20 20 50 52 41 47 4d 41 20  t1(x);.  PRAGMA 
0830: 6a 6f 75 72 6e 61 6c 5f 6d 6f 64 65 20 3d 20 77  journal_mode = w
0840: 61 6c 3b 0a 20 20 57 49 54 48 20 73 28 69 29 20  al;.  WITH s(i) 
0850: 41 53 20 28 0a 20 20 20 20 53 45 4c 45 43 54 20  AS (.    SELECT 
0860: 31 20 55 4e 49 4f 4e 20 41 4c 4c 20 53 45 4c 45  1 UNION ALL SELE
0870: 43 54 20 69 2b 31 20 46 52 4f 4d 20 73 20 4c 49  CT i+1 FROM s LI
0880: 4d 49 54 20 32 30 0a 20 20 29 0a 20 20 49 4e 53  MIT 20.  ).  INS
0890: 45 52 54 20 49 4e 54 4f 20 74 31 20 53 45 4c 45  ERT INTO t1 SELE
08a0: 43 54 20 72 61 6e 64 6f 6d 62 6c 6f 62 28 37 35  CT randomblob(75
08b0: 30 29 20 46 52 4f 4d 20 73 3b 0a 7d 20 7b 31 30  0) FROM s;.} {10
08c0: 30 30 30 20 77 61 6c 7d 0a 64 6f 5f 74 65 73 74  000 wal}.do_test
08d0: 20 32 2e 31 20 7b 0a 20 20 65 78 70 72 20 5b 66   2.1 {.  expr [f
08e0: 69 6c 65 20 73 69 7a 65 20 74 65 73 74 2e 64 62  ile size test.db
08f0: 2d 77 61 6c 5d 3e 31 32 30 30 30 0a 7d 20 7b 31  -wal]>12000.} {1
0900: 7d 0a 64 6f 5f 74 65 73 74 20 32 2e 32 20 7b 0a  }.do_test 2.2 {.
0910: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
0920: 50 52 41 47 4d 41 20 77 61 6c 5f 63 68 65 63 6b  PRAGMA wal_check
0930: 70 6f 69 6e 74 3b 0a 20 20 20 20 49 4e 53 45 52  point;.    INSER
0940: 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53  T INTO t1 VALUES
0950: 28 72 61 6e 64 6f 6d 62 6c 6f 62 28 37 35 30 29  (randomblob(750)
0960: 29 3b 0a 20 20 7d 0a 20 20 66 69 6c 65 20 73 69  );.  }.  file si
0970: 7a 65 20 74 65 73 74 2e 64 62 2d 77 61 6c 0a 7d  ze test.db-wal.}
0980: 20 7b 31 30 30 30 30 7d 0a 64 6f 5f 74 65 73 74   {10000}.do_test
0990: 20 32 2e 33 20 7b 0a 20 20 65 78 65 63 73 71 6c   2.3 {.  execsql
09a0: 20 7b 0a 20 20 20 20 50 52 41 47 4d 41 20 6a 6f   {.    PRAGMA jo
09b0: 75 72 6e 61 6c 5f 73 69 7a 65 5f 6c 69 6d 69 74  urnal_size_limit
09c0: 20 3d 20 38 30 30 30 3b 0a 20 20 20 20 50 52 41   = 8000;.    PRA
09d0: 47 4d 41 20 77 61 6c 5f 63 68 65 63 6b 70 6f 69  GMA wal_checkpoi
09e0: 6e 74 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  nt;.    INSERT I
09f0: 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 72 61  NTO t1 VALUES(ra
0a00: 6e 64 6f 6d 62 6c 6f 62 28 37 35 30 29 29 3b 0a  ndomblob(750));.
0a10: 20 20 7d 0a 20 20 66 69 6c 65 20 73 69 7a 65 20    }.  file size 
0a20: 74 65 73 74 2e 64 62 2d 77 61 6c 0a 7d 20 7b 38  test.db-wal.} {8
0a30: 30 30 30 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  000}..#---------
0a40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0a80: 0a 23 20 54 65 73 74 20 74 68 61 74 20 61 20 63  .# Test that a c
0a90: 68 65 63 6b 70 6f 69 6e 74 20 6d 61 79 20 62 65  heckpoint may be
0aa0: 20 69 6e 74 65 72 72 75 70 74 65 64 20 75 73 69   interrupted usi
0ab0: 6e 67 20 73 71 6c 69 74 65 33 5f 69 6e 74 65 72  ng sqlite3_inter
0ac0: 72 75 70 74 28 29 2e 0a 23 20 41 6e 64 20 74 68  rupt()..# And th
0ad0: 61 74 20 74 68 65 20 65 72 72 6f 72 20 63 6f 64  at the error cod
0ae0: 65 20 69 73 20 53 51 4c 49 54 45 5f 4e 4f 4d 45  e is SQLITE_NOME
0af0: 4d 2c 20 6e 6f 74 20 53 51 4c 49 54 45 5f 49 4e  M, not SQLITE_IN
0b00: 54 45 52 52 55 50 54 2c 20 69 66 0a 23 20 61 6e  TERRUPT, if.# an
0b10: 20 4f 4f 4d 20 65 72 72 6f 72 20 6f 63 63 75 72   OOM error occur
0b20: 73 20 6a 75 73 74 20 62 65 66 6f 72 65 20 74 68  s just before th
0b30: 65 20 73 71 6c 69 74 65 33 5f 69 6e 74 65 72 72  e sqlite3_interr
0b40: 75 70 74 28 29 20 63 61 6c 6c 2e 0a 23 0a 72 65  upt() call..#.re
0b50: 73 65 74 5f 64 62 0a 64 62 20 63 6c 6f 73 65 0a  set_db.db close.
0b60: 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e  sqlite3 db test.
0b70: 64 62 20 2d 76 66 73 20 74 76 66 73 0a 74 76 66  db -vfs tvfs.tvf
0b80: 73 20 66 69 6c 74 65 72 20 7b 7d 0a 0a 64 6f 5f  s filter {}..do_
0b90: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 33 2e 30  execsql_test 3.0
0ba0: 20 7b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c   {.  CREATE TABL
0bb0: 45 20 74 31 28 78 29 3b 0a 20 20 50 52 41 47 4d  E t1(x);.  PRAGM
0bc0: 41 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64 65 20 3d  A journal_mode =
0bd0: 20 77 61 6c 3b 0a 20 20 57 49 54 48 20 73 28 69   wal;.  WITH s(i
0be0: 29 20 41 53 20 28 0a 20 20 20 20 53 45 4c 45 43  ) AS (.    SELEC
0bf0: 54 20 31 20 55 4e 49 4f 4e 20 41 4c 4c 20 53 45  T 1 UNION ALL SE
0c00: 4c 45 43 54 20 69 2b 31 20 46 52 4f 4d 20 73 20  LECT i+1 FROM s 
0c10: 4c 49 4d 49 54 20 32 30 0a 20 20 29 0a 20 20 49  LIMIT 20.  ).  I
0c20: 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 53 45  NSERT INTO t1 SE
0c30: 4c 45 43 54 20 72 61 6e 64 6f 6d 62 6c 6f 62 28  LECT randomblob(
0c40: 37 35 30 29 20 46 52 4f 4d 20 73 3b 0a 7d 20 7b  750) FROM s;.} {
0c50: 77 61 6c 7d 0a 0a 74 76 66 73 20 66 69 6c 74 65  wal}..tvfs filte
0c60: 72 20 78 57 72 69 74 65 0a 74 76 66 73 20 73 63  r xWrite.tvfs sc
0c70: 72 69 70 74 20 78 57 72 69 74 65 0a 73 65 74 20  ript xWrite.set 
0c80: 3a 3a 63 6e 74 20 32 0a 70 72 6f 63 20 78 57 72  ::cnt 2.proc xWr
0c90: 69 74 65 20 7b 6d 65 74 68 6f 64 20 66 69 6c 65  ite {method file
0ca0: 20 61 72 67 73 7d 20 7b 0a 20 20 69 66 20 7b 5b   args} {.  if {[
0cb0: 66 69 6c 65 20 74 61 69 6c 20 24 66 69 6c 65 5d  file tail $file]
0cc0: 3d 3d 22 74 65 73 74 2e 64 62 22 7d 20 7b 0a 20  =="test.db"} {. 
0cd0: 20 20 20 69 6e 63 72 20 3a 3a 63 6e 74 20 2d 31     incr ::cnt -1
0ce0: 0a 20 20 20 20 69 66 20 7b 24 3a 3a 63 6e 74 3d  .    if {$::cnt=
0cf0: 3d 30 7d 20 7b 0a 20 20 20 20 20 20 73 71 6c 69  =0} {.      sqli
0d00: 74 65 33 5f 69 6e 74 65 72 72 75 70 74 20 64 62  te3_interrupt db
0d10: 0a 20 20 20 20 7d 0a 20 20 7d 0a 20 20 72 65 74  .    }.  }.  ret
0d20: 75 72 6e 20 53 51 4c 49 54 45 5f 4f 4b 0a 7d 0a  urn SQLITE_OK.}.
0d30: 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73  .do_catchsql_tes
0d40: 74 20 33 2e 31 20 7b 0a 20 20 50 52 41 47 4d 41  t 3.1 {.  PRAGMA
0d50: 20 77 61 6c 5f 63 68 65 63 6b 70 6f 69 6e 74 0a   wal_checkpoint.
0d60: 7d 20 7b 31 20 69 6e 74 65 72 72 75 70 74 65 64  } {1 interrupted
0d70: 7d 0a 0a 73 65 74 20 3a 3a 63 6e 74 20 32 0a 70  }..set ::cnt 2.p
0d80: 72 6f 63 20 78 57 72 69 74 65 20 7b 6d 65 74 68  roc xWrite {meth
0d90: 6f 64 20 66 69 6c 65 20 61 72 67 73 7d 20 7b 0a  od file args} {.
0da0: 20 20 69 66 20 7b 5b 66 69 6c 65 20 74 61 69 6c    if {[file tail
0db0: 20 24 66 69 6c 65 5d 3d 3d 22 74 65 73 74 2e 64   $file]=="test.d
0dc0: 62 22 7d 20 7b 0a 20 20 20 20 69 6e 63 72 20 3a  b"} {.    incr :
0dd0: 3a 63 6e 74 20 2d 31 0a 20 20 20 20 69 66 20 7b  :cnt -1.    if {
0de0: 24 3a 3a 63 6e 74 3d 3d 30 7d 20 7b 0a 20 20 20  $::cnt==0} {.   
0df0: 20 20 20 73 71 6c 69 74 65 33 5f 6d 65 6d 64 65     sqlite3_memde
0e00: 62 75 67 5f 66 61 69 6c 20 35 20 2d 72 65 70 65  bug_fail 5 -repe
0e10: 61 74 20 30 0a 20 20 20 20 20 20 63 61 74 63 68  at 0.      catch
0e20: 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 27 61 20  sql { SELECT 'a 
0e30: 62 69 67 20 6c 6f 6e 67 20 73 74 72 69 6e 67 21  big long string!
0e40: 27 20 7d 0a 20 20 20 20 20 20 73 71 6c 69 74 65  ' }.      sqlite
0e50: 33 5f 69 6e 74 65 72 72 75 70 74 20 64 62 0a 20  3_interrupt db. 
0e60: 20 20 20 7d 0a 20 20 7d 0a 20 20 72 65 74 75 72     }.  }.  retur
0e70: 6e 20 53 51 4c 49 54 45 5f 4f 4b 0a 7d 0a 0a 64  n SQLITE_OK.}..d
0e80: 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20  o_catchsql_test 
0e90: 33 2e 32 20 7b 0a 20 20 50 52 41 47 4d 41 20 77  3.2 {.  PRAGMA w
0ea0: 61 6c 5f 63 68 65 63 6b 70 6f 69 6e 74 0a 7d 20  al_checkpoint.} 
0eb0: 7b 31 20 7b 6f 75 74 20 6f 66 20 6d 65 6d 6f 72  {1 {out of memor
0ec0: 79 7d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  y}}..#----------
0ed0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ee0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ef0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0f00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
0f10: 23 0a 72 65 73 65 74 5f 64 62 0a 64 62 20 63 6c  #.reset_db.db cl
0f20: 6f 73 65 0a 64 6f 5f 74 65 73 74 20 34 2e 30 20  ose.do_test 4.0 
0f30: 7b 0a 20 20 73 71 6c 69 74 65 33 20 64 62 20 74  {.  sqlite3 db t
0f40: 65 73 74 2e 64 62 20 2d 76 66 73 20 74 76 66 73  est.db -vfs tvfs
0f50: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
0f60: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31   CREATE TABLE t1
0f70: 28 78 29 3b 0a 20 20 20 20 50 52 41 47 4d 41 20  (x);.    PRAGMA 
0f80: 6a 6f 75 72 6e 61 6c 5f 6d 6f 64 65 20 3d 20 77  journal_mode = w
0f90: 61 6c 3b 0a 20 20 20 20 57 49 54 48 20 73 28 69  al;.    WITH s(i
0fa0: 29 20 41 53 20 28 0a 20 20 20 20 20 20 20 20 53  ) AS (.        S
0fb0: 45 4c 45 43 54 20 31 20 55 4e 49 4f 4e 20 41 4c  ELECT 1 UNION AL
0fc0: 4c 20 53 45 4c 45 43 54 20 69 2b 31 20 46 52 4f  L SELECT i+1 FRO
0fd0: 4d 20 73 20 4c 49 4d 49 54 20 32 30 0a 20 20 20  M s LIMIT 20.   
0fe0: 20 29 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e   ).    INSERT IN
0ff0: 54 4f 20 74 31 20 53 45 4c 45 43 54 20 72 61 6e  TO t1 SELECT ran
1000: 64 6f 6d 62 6c 6f 62 28 37 35 30 29 20 46 52 4f  domblob(750) FRO
1010: 4d 20 73 3b 0a 20 20 7d 20 64 62 0a 7d 20 7b 77  M s;.  } db.} {w
1020: 61 6c 7d 0a 64 62 20 63 6c 6f 73 65 0a 0a 74 76  al}.db close..tv
1030: 66 73 20 66 69 6c 74 65 72 20 78 53 68 6d 4d 61  fs filter xShmMa
1040: 70 0a 74 76 66 73 20 73 63 72 69 70 74 20 78 53  p.tvfs script xS
1050: 68 6d 4d 61 70 0a 70 72 6f 63 20 78 53 68 6d 4d  hmMap.proc xShmM
1060: 61 70 20 7b 6d 65 74 68 6f 64 20 66 69 6c 65 20  ap {method file 
1070: 61 72 67 73 7d 20 7b 20 0a 20 20 72 65 74 75 72  args} { .  retur
1080: 6e 20 53 51 4c 49 54 45 5f 52 45 41 44 4f 4e 4c  n SQLITE_READONL
1090: 59 20 0a 7d 0a 73 71 6c 69 74 65 33 20 64 62 20  Y .}.sqlite3 db 
10a0: 74 65 73 74 2e 64 62 20 2d 76 66 73 20 74 76 66  test.db -vfs tvf
10b0: 73 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65  s.do_catchsql_te
10c0: 73 74 20 34 2e 31 20 7b 0a 20 20 53 45 4c 45 43  st 4.1 {.  SELEC
10d0: 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20  T count(*) FROM 
10e0: 74 31 0a 7d 20 7b 31 20 7b 61 74 74 65 6d 70 74  t1.} {1 {attempt
10f0: 20 74 6f 20 77 72 69 74 65 20 61 20 72 65 61 64   to write a read
1100: 6f 6e 6c 79 20 64 61 74 61 62 61 73 65 7d 7d 0a  only database}}.
1110: 0a 73 65 74 20 3a 3a 63 6e 74 20 35 0a 74 76 66  .set ::cnt 5.tvf
1120: 73 20 66 69 6c 74 65 72 20 7b 78 53 68 6d 4d 61  s filter {xShmMa
1130: 70 20 78 53 68 6d 4c 6f 63 6b 7d 0a 70 72 6f 63  p xShmLock}.proc
1140: 20 78 53 68 6d 4d 61 70 20 7b 6d 65 74 68 6f 64   xShmMap {method
1150: 20 66 69 6c 65 20 6e 61 6d 65 20 61 72 67 73 7d   file name args}
1160: 20 7b 20 0a 20 20 73 77 69 74 63 68 20 2d 2d 20   { .  switch -- 
1170: 24 6d 65 74 68 6f 64 20 7b 0a 20 20 20 20 78 53  $method {.    xS
1180: 68 6d 4d 61 70 20 7b 20 20 72 65 74 75 72 6e 20  hmMap {  return 
1190: 53 51 4c 49 54 45 5f 52 45 41 44 4f 4e 4c 59 20  SQLITE_READONLY 
11a0: 7d 0a 20 20 20 20 78 53 68 6d 4c 6f 63 6b 20 7b  }.    xShmLock {
11b0: 0a 20 20 20 20 20 20 69 66 20 7b 24 61 72 67 73  .      if {$args
11c0: 20 3d 3d 20 22 7b 30 20 31 20 6c 6f 63 6b 20 73   == "{0 1 lock s
11d0: 68 61 72 65 64 7d 22 7d 20 7b 0a 20 20 20 20 20  hared}"} {.     
11e0: 20 20 20 69 6e 63 72 20 3a 3a 63 6e 74 20 2d 31     incr ::cnt -1
11f0: 0a 20 20 20 20 20 20 20 20 69 66 20 7b 24 3a 3a  .        if {$::
1200: 63 6e 74 3e 30 7d 20 7b 20 72 65 74 75 72 6e 20  cnt>0} { return 
1210: 53 51 4c 49 54 45 5f 42 55 53 59 20 7d 0a 20 20  SQLITE_BUSY }.  
1220: 20 20 20 20 7d 0a 20 20 20 20 7d 0a 20 20 7d 0a      }.    }.  }.
1230: 20 20 72 65 74 75 72 6e 20 53 51 4c 49 54 45 5f    return SQLITE_
1240: 4f 4b 0a 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c  OK.}.do_catchsql
1250: 5f 74 65 73 74 20 34 2e 32 20 7b 0a 20 20 53 45  _test 4.2 {.  SE
1260: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
1270: 4f 4d 20 74 31 0a 7d 20 7b 31 20 7b 61 74 74 65  OM t1.} {1 {atte
1280: 6d 70 74 20 74 6f 20 77 72 69 74 65 20 61 20 72  mpt to write a r
1290: 65 61 64 6f 6e 6c 79 20 64 61 74 61 62 61 73 65  eadonly database
12a0: 7d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  }}..#-----------
12b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
12c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
12d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
12e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
12f0: 0a 72 65 73 65 74 5f 64 62 0a 64 62 20 63 6c 6f  .reset_db.db clo
1300: 73 65 20 0a 73 71 6c 69 74 65 33 20 64 62 20 74  se .sqlite3 db t
1310: 65 73 74 2e 64 62 20 2d 76 66 73 20 74 76 66 73  est.db -vfs tvfs
1320: 0a 74 76 66 73 20 66 69 6c 74 65 72 20 7b 7d 0a  .tvfs filter {}.
1330: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
1340: 35 2e 30 20 7b 0a 20 20 50 52 41 47 4d 41 20 61  5.0 {.  PRAGMA a
1350: 75 74 6f 5f 76 61 63 75 75 6d 20 3d 20 30 3b 0a  uto_vacuum = 0;.
1360: 20 20 50 52 41 47 4d 41 20 70 61 67 65 5f 73 69    PRAGMA page_si
1370: 7a 65 20 3d 20 31 30 32 34 3b 0a 20 20 43 52 45  ze = 1024;.  CRE
1380: 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 29 3b  ATE TABLE t1(x);
1390: 0a 20 20 50 52 41 47 4d 41 20 6a 6f 75 72 6e 61  .  PRAGMA journa
13a0: 6c 5f 6d 6f 64 65 20 3d 20 77 61 6c 3b 0a 20 20  l_mode = wal;.  
13b0: 57 49 54 48 20 73 28 69 29 20 41 53 20 28 0a 20  WITH s(i) AS (. 
13c0: 20 20 20 20 20 53 45 4c 45 43 54 20 31 20 55 4e       SELECT 1 UN
13d0: 49 4f 4e 20 41 4c 4c 20 53 45 4c 45 43 54 20 69  ION ALL SELECT i
13e0: 2b 31 20 46 52 4f 4d 20 73 20 4c 49 4d 49 54 20  +1 FROM s LIMIT 
13f0: 32 30 0a 20 20 29 0a 20 20 49 4e 53 45 52 54 20  20.  ).  INSERT 
1400: 49 4e 54 4f 20 74 31 20 53 45 4c 45 43 54 20 72  INTO t1 SELECT r
1410: 61 6e 64 6f 6d 62 6c 6f 62 28 37 35 30 29 20 46  andomblob(750) F
1420: 52 4f 4d 20 73 3b 0a 7d 20 7b 77 61 6c 7d 0a 0a  ROM s;.} {wal}..
1430: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
1440: 35 2e 31 20 7b 0a 20 20 53 45 4c 45 43 54 20 63  5.1 {.  SELECT c
1450: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74 31 0a  ount(*) FROM t1.
1460: 7d 20 7b 32 30 7d 0a 0a 64 6f 5f 74 65 73 74 20  } {20}..do_test 
1470: 35 2e 32 20 7b 0a 20 20 76 66 73 5f 73 65 74 5f  5.2 {.  vfs_set_
1480: 72 65 61 64 6d 61 72 6b 20 64 62 20 6d 61 69 6e  readmark db main
1490: 20 31 20 31 30 30 0a 20 20 76 66 73 5f 73 65 74   1 100.  vfs_set
14a0: 5f 72 65 61 64 6d 61 72 6b 20 64 62 20 6d 61 69  _readmark db mai
14b0: 6e 20 32 20 31 30 30 0a 20 20 76 66 73 5f 73 65  n 2 100.  vfs_se
14c0: 74 5f 72 65 61 64 6d 61 72 6b 20 64 62 20 6d 61  t_readmark db ma
14d0: 69 6e 20 33 20 31 30 30 0a 20 20 76 66 73 5f 73  in 3 100.  vfs_s
14e0: 65 74 5f 72 65 61 64 6d 61 72 6b 20 64 62 20 6d  et_readmark db m
14f0: 61 69 6e 20 34 20 31 30 30 0a 7d 20 7b 31 30 30  ain 4 100.} {100
1500: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  }..do_execsql_te
1510: 73 74 20 35 2e 33 20 7b 0a 20 20 53 45 4c 45 43  st 5.3 {.  SELEC
1520: 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20  T count(*) FROM 
1530: 74 31 0a 7d 20 7b 32 30 7d 0a 0a 64 6f 5f 74 65  t1.} {20}..do_te
1540: 73 74 20 35 2e 33 20 7b 0a 20 20 6c 69 73 74 20  st 5.3 {.  list 
1550: 5b 76 66 73 5f 73 65 74 5f 72 65 61 64 6d 61 72  [vfs_set_readmar
1560: 6b 20 64 62 20 6d 61 69 6e 20 31 5d 20 5c 0a 20  k db main 1] \. 
1570: 20 20 20 20 20 20 5b 76 66 73 5f 73 65 74 5f 72        [vfs_set_r
1580: 65 61 64 6d 61 72 6b 20 64 62 20 6d 61 69 6e 20  eadmark db main 
1590: 32 5d 20 5c 0a 20 20 20 20 20 20 20 5b 76 66 73  2] \.       [vfs
15a0: 5f 73 65 74 5f 72 65 61 64 6d 61 72 6b 20 64 62  _set_readmark db
15b0: 20 6d 61 69 6e 20 33 5d 20 5c 0a 20 20 20 20 20   main 3] \.     
15c0: 20 20 5b 76 66 73 5f 73 65 74 5f 72 65 61 64 6d    [vfs_set_readm
15d0: 61 72 6b 20 64 62 20 6d 61 69 6e 20 34 5d 20 0a  ark db main 4] .
15e0: 7d 20 7b 32 34 20 31 30 30 20 31 30 30 20 31 30  } {24 100 100 10
15f0: 30 7d 0a 0a 74 76 66 73 20 73 63 72 69 70 74 20  0}..tvfs script 
1600: 78 53 68 6d 4c 6f 63 6b 0a 74 76 66 73 20 66 69  xShmLock.tvfs fi
1610: 6c 74 65 72 20 78 53 68 6d 4c 6f 63 6b 0a 73 65  lter xShmLock.se
1620: 74 20 3a 3a 63 6e 74 20 32 30 0a 70 72 6f 63 20  t ::cnt 20.proc 
1630: 78 53 68 6d 4c 6f 63 6b 20 7b 61 72 67 73 7d 20  xShmLock {args} 
1640: 7b 0a 20 20 69 6e 63 72 20 3a 3a 63 6e 74 20 2d  {.  incr ::cnt -
1650: 31 0a 20 20 69 66 20 7b 24 3a 3a 63 6e 74 3e 30  1.  if {$::cnt>0
1660: 7d 20 7b 20 72 65 74 75 72 6e 20 53 51 4c 49 54  } { return SQLIT
1670: 45 5f 42 55 53 59 20 7d 0a 20 20 72 65 74 75 72  E_BUSY }.  retur
1680: 6e 20 53 51 4c 49 54 45 5f 4f 4b 0a 7d 0a 0a 64  n SQLITE_OK.}..d
1690: 6f 5f 74 65 73 74 20 35 2e 34 20 7b 0a 20 20 76  o_test 5.4 {.  v
16a0: 66 73 5f 73 65 74 5f 72 65 61 64 6d 61 72 6b 20  fs_set_readmark 
16b0: 64 62 20 6d 61 69 6e 20 31 20 31 30 30 0a 20 20  db main 1 100.  
16c0: 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54  execsql { SELECT
16d0: 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74   count(*) FROM t
16e0: 31 20 7d 0a 7d 20 7b 32 30 7d 0a 0a 76 66 73 5f  1 }.} {20}..vfs_
16f0: 73 65 74 5f 72 65 61 64 6d 61 72 6b 20 64 62 20  set_readmark db 
1700: 6d 61 69 6e 20 31 20 31 30 30 0a 76 66 73 5f 73  main 1 100.vfs_s
1710: 65 74 5f 72 65 61 64 6d 61 72 6b 20 64 62 20 6d  et_readmark db m
1720: 61 69 6e 20 32 20 31 30 30 0a 76 66 73 5f 73 65  ain 2 100.vfs_se
1730: 74 5f 72 65 61 64 6d 61 72 6b 20 64 62 20 6d 61  t_readmark db ma
1740: 69 6e 20 33 20 31 30 30 0a 76 66 73 5f 73 65 74  in 3 100.vfs_set
1750: 5f 72 65 61 64 6d 61 72 6b 20 64 62 20 6d 61 69  _readmark db mai
1760: 6e 20 34 20 31 30 30 0a 0a 74 76 66 73 20 73 63  n 4 100..tvfs sc
1770: 72 69 70 74 20 78 53 68 6d 4d 61 70 4c 6f 63 6b  ript xShmMapLock
1780: 0a 74 76 66 73 20 66 69 6c 74 65 72 20 7b 78 53  .tvfs filter {xS
1790: 68 6d 4c 6f 63 6b 20 78 53 68 6d 4d 61 70 7d 0a  hmLock xShmMap}.
17a0: 70 72 6f 63 20 78 53 68 6d 4d 61 70 4c 6f 63 6b  proc xShmMapLock
17b0: 20 7b 6d 65 74 68 6f 64 20 61 72 67 73 7d 20 7b   {method args} {
17c0: 0a 20 20 69 66 20 7b 24 6d 65 74 68 6f 64 3d 3d  .  if {$method==
17d0: 22 78 53 68 6d 4d 61 70 22 7d 20 7b 0a 20 20 20  "xShmMap"} {.   
17e0: 20 72 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f   return "SQLITE_
17f0: 52 45 41 44 4f 4e 4c 59 22 0a 20 20 7d 0a 20 20  READONLY".  }.  
1800: 72 65 74 75 72 6e 20 53 51 4c 49 54 45 5f 42 55  return SQLITE_BU
1810: 53 59 0a 7d 0a 0a 73 71 6c 69 74 65 33 20 64 62  SY.}..sqlite3 db
1820: 32 20 74 65 73 74 2e 64 62 20 2d 76 66 73 20 74  2 test.db -vfs t
1830: 76 66 73 0a 62 72 65 61 6b 70 6f 69 6e 74 0a 64  vfs.breakpoint.d
1840: 6f 5f 74 65 73 74 20 35 2e 35 20 7b 0a 20 20 6c  o_test 5.5 {.  l
1850: 69 73 74 20 5b 63 61 74 63 68 20 7b 20 65 78 65  ist [catch { exe
1860: 63 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f  csql { SELECT co
1870: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74 31 20 7d  unt(*) FROM t1 }
1880: 20 64 62 32 20 7d 20 6d 73 67 5d 20 24 6d 73 67   db2 } msg] $msg
1890: 0a 7d 20 7b 31 20 7b 61 74 74 65 6d 70 74 20 74  .} {1 {attempt t
18a0: 6f 20 77 72 69 74 65 20 61 20 72 65 61 64 6f 6e  o write a readon
18b0: 6c 79 20 64 61 74 61 62 61 73 65 7d 7d 0a 0a 74  ly database}}..t
18c0: 76 66 73 20 66 69 6c 74 65 72 20 7b 7d 0a 76 66  vfs filter {}.vf
18d0: 73 5f 73 65 74 5f 72 65 61 64 6d 61 72 6b 20 64  s_set_readmark d
18e0: 62 20 6d 61 69 6e 20 31 20 31 0a 0a 64 6f 5f 74  b main 1 1..do_t
18f0: 65 73 74 20 35 2e 36 20 7b 0a 20 20 6c 69 73 74  est 5.6 {.  list
1900: 20 5b 63 61 74 63 68 20 7b 20 65 78 65 63 73 71   [catch { execsq
1910: 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f 75 6e 74  l { SELECT count
1920: 28 2a 29 20 46 52 4f 4d 20 74 31 20 7d 20 64 62  (*) FROM t1 } db
1930: 32 20 7d 20 6d 73 67 5d 20 24 6d 73 67 0a 7d 20  2 } msg] $msg.} 
1940: 7b 30 20 32 30 7d 0a 64 62 32 20 63 6c 6f 73 65  {0 20}.db2 close
1950: 0a 64 62 20 63 6c 6f 73 65 0a 0a 23 2d 2d 2d 2d  .db close..#----
1960: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1970: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1980: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1990: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
19a0: 2d 2d 2d 2d 2d 0a 23 20 43 61 75 73 65 20 61 6e  -----.# Cause an
19b0: 20 53 51 4c 49 54 45 5f 50 52 4f 54 4f 43 4f 4c   SQLITE_PROTOCOL
19c0: 20 77 68 69 6c 65 20 61 74 74 65 6d 70 74 69 6e   while attemptin
19d0: 67 20 74 6f 20 72 65 73 74 61 72 74 20 74 68 65  g to restart the
19e0: 20 77 61 6c 20 66 69 6c 65 2e 0a 23 0a 72 65 73   wal file..#.res
19f0: 65 74 5f 64 62 0a 74 76 66 73 20 66 69 6c 74 65  et_db.tvfs filte
1a00: 72 20 7b 7d 0a 64 62 20 63 6c 6f 73 65 0a 73 71  r {}.db close.sq
1a10: 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62  lite3 db test.db
1a20: 20 2d 76 66 73 20 74 76 66 73 0a 64 6f 5f 65 78   -vfs tvfs.do_ex
1a30: 65 63 73 71 6c 5f 74 65 73 74 20 36 2e 30 20 7b  ecsql_test 6.0 {
1a40: 0a 20 20 50 52 41 47 4d 41 20 61 75 74 6f 5f 76  .  PRAGMA auto_v
1a50: 61 63 75 75 6d 20 3d 20 30 3b 0a 20 20 50 52 41  acuum = 0;.  PRA
1a60: 47 4d 41 20 70 61 67 65 5f 73 69 7a 65 20 3d 20  GMA page_size = 
1a70: 31 30 32 34 3b 0a 20 20 43 52 45 41 54 45 20 54  1024;.  CREATE T
1a80: 41 42 4c 45 20 74 31 28 78 29 3b 0a 20 20 50 52  ABLE t1(x);.  PR
1a90: 41 47 4d 41 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64  AGMA journal_mod
1aa0: 65 20 3d 20 77 61 6c 3b 0a 20 20 57 49 54 48 20  e = wal;.  WITH 
1ab0: 73 28 69 29 20 41 53 20 28 0a 20 20 20 20 20 20  s(i) AS (.      
1ac0: 53 45 4c 45 43 54 20 31 20 55 4e 49 4f 4e 20 41  SELECT 1 UNION A
1ad0: 4c 4c 20 53 45 4c 45 43 54 20 69 2b 31 20 46 52  LL SELECT i+1 FR
1ae0: 4f 4d 20 73 20 4c 49 4d 49 54 20 32 30 0a 20 20  OM s LIMIT 20.  
1af0: 29 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ).  INSERT INTO 
1b00: 74 31 20 53 45 4c 45 43 54 20 72 61 6e 64 6f 6d  t1 SELECT random
1b10: 62 6c 6f 62 28 37 35 30 29 20 46 52 4f 4d 20 73  blob(750) FROM s
1b20: 3b 0a 7d 20 7b 77 61 6c 7d 0a 0a 64 6f 5f 74 65  ;.} {wal}..do_te
1b30: 73 74 20 36 2e 31 20 7b 0a 20 20 65 78 65 63 73  st 6.1 {.  execs
1b40: 71 6c 20 7b 20 50 52 41 47 4d 41 20 77 61 6c 5f  ql { PRAGMA wal_
1b50: 63 68 65 63 6b 70 6f 69 6e 74 20 7d 20 0a 20 20  checkpoint } .  
1b60: 73 65 74 20 7b 7d 20 7b 7d 0a 7d 20 7b 7d 0a 0a  set {} {}.} {}..
1b70: 74 76 66 73 20 66 69 6c 74 65 72 20 78 53 68 6d  tvfs filter xShm
1b80: 4c 6f 63 6b 0a 74 76 66 73 20 73 63 72 69 70 74  Lock.tvfs script
1b90: 20 78 53 68 6d 4c 6f 63 6b 0a 73 65 74 20 3a 3a   xShmLock.set ::
1ba0: 66 6c 61 67 20 30 0a 70 72 6f 63 20 78 53 68 6d  flag 0.proc xShm
1bb0: 4c 6f 63 6b 20 7b 6d 65 74 68 6f 64 20 66 69 6c  Lock {method fil
1bc0: 65 20 68 61 6e 64 6c 65 20 73 70 65 63 7d 20 7b  e handle spec} {
1bd0: 0a 20 20 69 66 20 7b 24 3a 3a 66 6c 61 67 20 26  .  if {$::flag &
1be0: 26 20 5b 6c 72 61 6e 67 65 20 24 73 70 65 63 20  & [lrange $spec 
1bf0: 32 20 65 6e 64 5d 3d 3d 22 6c 6f 63 6b 20 73 68  2 end]=="lock sh
1c00: 61 72 65 64 22 7d 20 7b 0a 20 20 20 20 72 65 74  ared"} {.    ret
1c10: 75 72 6e 20 53 51 4c 49 54 45 5f 42 55 53 59 0a  urn SQLITE_BUSY.
1c20: 20 20 7d 0a 20 20 69 66 20 7b 24 73 70 65 63 3d    }.  if {$spec=
1c30: 3d 22 33 20 31 20 75 6e 6c 6f 63 6b 20 73 68 61  ="3 1 unlock sha
1c40: 72 65 64 22 7d 20 7b 0a 20 20 20 20 73 65 74 20  red"} {.    set 
1c50: 3a 3a 66 6c 61 67 20 31 0a 20 20 7d 0a 20 20 72  ::flag 1.  }.  r
1c60: 65 74 75 72 6e 20 53 51 4c 49 54 45 5f 4f 4b 0a  eturn SQLITE_OK.
1c70: 7d 0a 0a 70 75 74 73 20 22 23 20 57 41 52 4e 49  }..puts "# WARNI
1c80: 4e 47 3a 20 54 68 69 73 20 6e 65 78 74 20 74 65  NG: This next te
1c90: 73 74 20 74 61 6b 65 73 20 61 72 6f 75 6e 64 20  st takes around 
1ca0: 31 32 20 73 65 63 6f 6e 64 73 22 0a 64 6f 5f 63  12 seconds".do_c
1cb0: 61 74 63 68 73 71 6c 5f 74 65 73 74 20 36 2e 32  atchsql_test 6.2
1cc0: 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f   {.  INSERT INTO
1cd0: 20 74 31 20 56 41 4c 55 45 53 28 31 29 3b 0a 7d   t1 VALUES(1);.}
1ce0: 20 7b 31 20 7b 6c 6f 63 6b 69 6e 67 20 70 72 6f   {1 {locking pro
1cf0: 74 6f 63 6f 6c 7d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  tocol}}..#------
1d00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1d40: 2d 2d 2d 0a 23 20 43 68 65 63 6b 20 74 68 61 74  ---.# Check that
1d50: 20 61 20 63 68 65 63 6b 70 6f 69 6e 74 20 66 61   a checkpoint fa
1d60: 69 6c 73 20 69 66 20 69 74 20 63 61 6e 6e 6f 74  ils if it cannot
1d70: 20 67 65 74 20 74 68 65 20 43 48 45 43 4b 50 4f   get the CHECKPO
1d80: 49 4e 54 45 52 20 6c 6f 63 6b 0a 23 0a 72 65 73  INTER lock.#.res
1d90: 65 74 5f 64 62 0a 74 76 66 73 20 66 69 6c 74 65  et_db.tvfs filte
1da0: 72 20 7b 7d 0a 64 62 20 63 6c 6f 73 65 0a 73 71  r {}.db close.sq
1db0: 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62  lite3 db test.db
1dc0: 20 2d 76 66 73 20 74 76 66 73 0a 64 6f 5f 65 78   -vfs tvfs.do_ex
1dd0: 65 63 73 71 6c 5f 74 65 73 74 20 37 2e 30 20 7b  ecsql_test 7.0 {
1de0: 0a 20 20 50 52 41 47 4d 41 20 61 75 74 6f 5f 76  .  PRAGMA auto_v
1df0: 61 63 75 75 6d 20 3d 20 30 3b 0a 20 20 50 52 41  acuum = 0;.  PRA
1e00: 47 4d 41 20 70 61 67 65 5f 73 69 7a 65 20 3d 20  GMA page_size = 
1e10: 31 30 32 34 3b 0a 20 20 43 52 45 41 54 45 20 54  1024;.  CREATE T
1e20: 41 42 4c 45 20 74 31 28 78 29 3b 0a 20 20 50 52  ABLE t1(x);.  PR
1e30: 41 47 4d 41 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64  AGMA journal_mod
1e40: 65 20 3d 20 77 61 6c 3b 0a 20 20 57 49 54 48 20  e = wal;.  WITH 
1e50: 73 28 69 29 20 41 53 20 28 0a 20 20 20 20 20 20  s(i) AS (.      
1e60: 53 45 4c 45 43 54 20 31 20 55 4e 49 4f 4e 20 41  SELECT 1 UNION A
1e70: 4c 4c 20 53 45 4c 45 43 54 20 69 2b 31 20 46 52  LL SELECT i+1 FR
1e80: 4f 4d 20 73 20 4c 49 4d 49 54 20 32 30 0a 20 20  OM s LIMIT 20.  
1e90: 29 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ).  INSERT INTO 
1ea0: 74 31 20 53 45 4c 45 43 54 20 72 61 6e 64 6f 6d  t1 SELECT random
1eb0: 62 6c 6f 62 28 37 35 30 29 20 46 52 4f 4d 20 73  blob(750) FROM s
1ec0: 3b 0a 7d 20 7b 77 61 6c 7d 0a 0a 74 76 66 73 20  ;.} {wal}..tvfs 
1ed0: 73 63 72 69 70 74 20 78 53 68 6d 4c 6f 63 6b 0a  script xShmLock.
1ee0: 74 76 66 73 20 66 69 6c 74 65 72 20 78 53 68 6d  tvfs filter xShm
1ef0: 4c 6f 63 6b 0a 70 72 6f 63 20 78 53 68 6d 4c 6f  Lock.proc xShmLo
1f00: 63 6b 20 7b 6d 65 74 68 6f 64 20 66 69 6c 65 20  ck {method file 
1f10: 68 61 6e 64 6c 65 20 73 70 65 63 7d 20 7b 0a 20  handle spec} {. 
1f20: 20 69 66 20 7b 24 73 70 65 63 3d 3d 22 31 20 31   if {$spec=="1 1
1f30: 20 6c 6f 63 6b 20 65 78 63 6c 75 73 69 76 65 22   lock exclusive"
1f40: 7d 20 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 53  } {.    return S
1f50: 51 4c 49 54 45 5f 42 55 53 59 0a 20 20 7d 0a 20  QLITE_BUSY.  }. 
1f60: 20 72 65 74 75 72 6e 20 53 51 4c 49 54 45 5f 4f   return SQLITE_O
1f70: 4b 0a 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  K.}..do_execsql_
1f80: 74 65 73 74 20 37 2e 31 20 7b 0a 20 20 50 52 41  test 7.1 {.  PRA
1f90: 47 4d 41 20 77 61 6c 5f 63 68 65 63 6b 70 6f 69  GMA wal_checkpoi
1fa0: 6e 74 0a 7d 20 7b 31 20 2d 31 20 2d 31 7d 0a 0a  nt.} {1 -1 -1}..
1fb0: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
1fc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1fd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1fe0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1ff0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 43 68 65  ----------.# Che
2000: 63 6b 20 74 68 61 74 20 74 68 65 20 70 61 67 65  ck that the page
2010: 20 63 61 63 68 65 20 69 73 20 63 6f 72 72 65 63   cache is correc
2020: 74 6c 79 20 66 6c 75 73 68 65 64 20 69 66 20 61  tly flushed if a
2030: 20 63 68 65 63 6b 70 6f 69 6e 74 65 72 20 75 73   checkpointer us
2040: 69 6e 67 0a 23 20 61 20 76 65 72 73 69 6f 6e 20  ing.# a version 
2050: 32 20 56 46 53 20 6d 61 6b 65 73 20 61 20 63 68  2 VFS makes a ch
2060: 65 63 6b 70 6f 69 6e 74 20 77 69 74 68 20 61 6e  eckpoint with an
2070: 20 6f 75 74 2d 6f 66 2d 64 61 74 65 20 63 61 63   out-of-date cac
2080: 68 65 2e 0a 23 0a 72 65 73 65 74 5f 64 62 0a 74  he..#.reset_db.t
2090: 65 73 74 76 66 73 20 74 76 66 73 32 20 2d 69 76  estvfs tvfs2 -iv
20a0: 65 72 73 69 6f 6e 20 32 0a 64 62 20 63 6c 6f 73  ersion 2.db clos
20b0: 65 0a 73 71 6c 69 74 65 33 20 64 62 20 74 65 73  e.sqlite3 db tes
20c0: 74 2e 64 62 20 2d 76 66 73 20 74 76 66 73 32 0a  t.db -vfs tvfs2.
20d0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20  do_execsql_test 
20e0: 38 2e 30 20 7b 0a 20 20 50 52 41 47 4d 41 20 61  8.0 {.  PRAGMA a
20f0: 75 74 6f 5f 76 61 63 75 75 6d 20 3d 20 30 3b 0a  uto_vacuum = 0;.
2100: 20 20 50 52 41 47 4d 41 20 70 61 67 65 5f 73 69    PRAGMA page_si
2110: 7a 65 20 3d 20 31 30 32 34 3b 0a 20 20 43 52 45  ze = 1024;.  CRE
2120: 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 29 3b  ATE TABLE t1(x);
2130: 0a 20 20 50 52 41 47 4d 41 20 6a 6f 75 72 6e 61  .  PRAGMA journa
2140: 6c 5f 6d 6f 64 65 20 3d 20 77 61 6c 3b 0a 20 20  l_mode = wal;.  
2150: 57 49 54 48 20 73 28 69 29 20 41 53 20 28 20 53  WITH s(i) AS ( S
2160: 45 4c 45 43 54 20 31 20 55 4e 49 4f 4e 20 41 4c  ELECT 1 UNION AL
2170: 4c 20 53 45 4c 45 43 54 20 69 2b 31 20 46 52 4f  L SELECT i+1 FRO
2180: 4d 20 73 20 4c 49 4d 49 54 20 32 30 20 29 0a 20  M s LIMIT 20 ). 
2190: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
21a0: 53 45 4c 45 43 54 20 72 61 6e 64 6f 6d 62 6c 6f  SELECT randomblo
21b0: 62 28 37 35 29 20 46 52 4f 4d 20 73 3b 0a 7d 20  b(75) FROM s;.} 
21c0: 7b 77 61 6c 7d 0a 0a 64 6f 5f 65 78 65 63 73 71  {wal}..do_execsq
21d0: 6c 5f 74 65 73 74 20 38 2e 31 20 7b 20 53 45 4c  l_test 8.1 { SEL
21e0: 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f  ECT count(*) FRO
21f0: 4d 20 74 31 20 7d 20 7b 32 30 7d 0a 0a 64 6f 5f  M t1 } {20}..do_
2200: 74 65 73 74 20 38 2e 32 20 7b 0a 20 20 73 71 6c  test 8.2 {.  sql
2210: 69 74 65 33 20 64 62 32 20 74 65 73 74 2e 64 62  ite3 db2 test.db
2220: 20 2d 76 66 73 20 74 76 66 73 32 0a 20 20 65 78   -vfs tvfs2.  ex
2230: 65 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53 45  ecsql {.    INSE
2240: 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45  RT INTO t1 VALUE
2250: 53 28 72 61 6e 64 6f 6d 62 6c 6f 62 28 37 35 29  S(randomblob(75)
2260: 29 3b 0a 20 20 7d 20 64 62 32 0a 20 20 64 62 32  );.  } db2.  db2
2270: 20 63 6c 6f 73 65 0a 7d 20 7b 7d 0a 0a 64 6f 5f   close.} {}..do_
2280: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 38 2e 33  execsql_test 8.3
2290: 20 7b 20 0a 20 20 50 52 41 47 4d 41 20 77 61 6c   { .  PRAGMA wal
22a0: 5f 63 68 65 63 6b 70 6f 69 6e 74 3b 0a 20 20 53  _checkpoint;.  S
22b0: 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46  ELECT count(*) F
22c0: 52 4f 4d 20 74 31 20 0a 7d 20 7b 30 20 35 20 35  ROM t1 .} {0 5 5
22d0: 20 32 31 7d 0a 74 76 66 73 32 20 64 65 6c 65 74   21}.tvfs2 delet
22e0: 65 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  e..#------------
22f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2300: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2310: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2320: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 72 65  -------------.re
2330: 73 65 74 5f 64 62 0a 64 62 20 63 6c 6f 73 65 0a  set_db.db close.
2340: 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e  sqlite3 db test.
2350: 64 62 20 2d 76 66 73 20 74 76 66 73 0a 64 6f 5f  db -vfs tvfs.do_
2360: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 39 2e 30  execsql_test 9.0
2370: 20 7b 0a 20 20 50 52 41 47 4d 41 20 61 75 74 6f   {.  PRAGMA auto
2380: 5f 76 61 63 75 75 6d 20 3d 20 30 3b 0a 20 20 50  _vacuum = 0;.  P
2390: 52 41 47 4d 41 20 70 61 67 65 5f 73 69 7a 65 20  RAGMA page_size 
23a0: 3d 20 31 30 32 34 3b 0a 20 20 43 52 45 41 54 45  = 1024;.  CREATE
23b0: 20 54 41 42 4c 45 20 74 31 28 78 29 3b 0a 20 20   TABLE t1(x);.  
23c0: 50 52 41 47 4d 41 20 6a 6f 75 72 6e 61 6c 5f 6d  PRAGMA journal_m
23d0: 6f 64 65 20 3d 20 77 61 6c 3b 0a 20 20 57 49 54  ode = wal;.  WIT
23e0: 48 20 73 28 69 29 20 41 53 20 28 20 53 45 4c 45  H s(i) AS ( SELE
23f0: 43 54 20 31 20 55 4e 49 4f 4e 20 41 4c 4c 20 53  CT 1 UNION ALL S
2400: 45 4c 45 43 54 20 69 2b 31 20 46 52 4f 4d 20 73  ELECT i+1 FROM s
2410: 20 4c 49 4d 49 54 20 32 30 20 29 0a 20 20 49 4e   LIMIT 20 ).  IN
2420: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 53 45 4c  SERT INTO t1 SEL
2430: 45 43 54 20 72 61 6e 64 6f 6d 62 6c 6f 62 28 37  ECT randomblob(7
2440: 35 29 20 46 52 4f 4d 20 73 3b 0a 7d 20 7b 77 61  5) FROM s;.} {wa
2450: 6c 7d 0a 0a 73 71 6c 69 74 65 33 20 64 62 32 20  l}..sqlite3 db2 
2460: 74 65 73 74 2e 64 62 20 2d 76 66 73 20 74 76 66  test.db -vfs tvf
2470: 73 0a 74 76 66 73 20 66 69 6c 74 65 72 20 7b 78  s.tvfs filter {x
2480: 53 68 6d 4d 61 70 20 78 53 68 6d 4c 6f 63 6b 7d  ShmMap xShmLock}
2490: 0a 74 76 66 73 20 73 63 72 69 70 74 20 78 53 68  .tvfs script xSh
24a0: 6d 4d 61 70 0a 70 72 6f 63 20 78 53 68 6d 4d 61  mMap.proc xShmMa
24b0: 70 20 7b 6d 65 74 68 6f 64 20 66 69 6c 65 20 68  p {method file h
24c0: 61 6e 64 6c 65 20 61 72 67 73 7d 20 7b 0a 20 20  andle args} {.  
24d0: 73 77 69 74 63 68 20 2d 2d 20 24 6d 65 74 68 6f  switch -- $metho
24e0: 64 20 7b 0a 20 20 20 20 78 53 68 6d 4d 61 70 20  d {.    xShmMap 
24f0: 7b 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 22  {.      return "
2500: 53 51 4c 49 54 45 5f 52 45 41 44 4f 4e 4c 59 5f  SQLITE_READONLY_
2510: 43 41 4e 54 49 4e 49 54 22 0a 20 20 20 20 7d 0a  CANTINIT".    }.
2520: 20 20 20 20 78 53 68 6d 4c 6f 63 6b 20 7b 0a 20      xShmLock {. 
2530: 20 20 20 20 20 69 66 20 7b 24 61 72 67 73 3d 3d       if {$args==
2540: 22 7b 33 20 31 20 6c 6f 63 6b 20 73 68 61 72 65  "{3 1 lock share
2550: 64 7d 22 7d 20 7b 0a 20 20 20 20 20 20 20 20 72  d}"} {.        r
2560: 65 74 75 72 6e 20 22 53 51 4c 49 54 45 5f 49 4f  eturn "SQLITE_IO
2570: 45 52 52 22 0a 20 20 20 20 20 20 7d 0a 20 20 20  ERR".      }.   
2580: 20 7d 0a 20 20 7d 0a 7d 0a 0a 64 6f 5f 74 65 73   }.  }.}..do_tes
2590: 74 20 39 2e 31 20 7b 0a 20 20 63 61 74 63 68 73  t 9.1 {.  catchs
25a0: 71 6c 20 7b 20 53 45 4c 45 43 54 20 63 6f 75 6e  ql { SELECT coun
25b0: 74 28 2a 29 20 46 52 4f 4d 20 74 31 20 7d 20 64  t(*) FROM t1 } d
25c0: 62 32 0a 7d 20 7b 31 20 7b 64 69 73 6b 20 49 2f  b2.} {1 {disk I/
25d0: 4f 20 65 72 72 6f 72 7d 7d 0a 0a 64 62 20 63 6c  O error}}..db cl
25e0: 6f 73 65 0a 64 62 32 20 63 6c 6f 73 65 0a 74 76  ose.db2 close.tv
25f0: 66 73 20 64 65 6c 65 74 65 0a 66 69 6e 69 73 68  fs delete.finish
2600: 5f 74 65 73 74 0a 0a                             _test..