/ Hex Artifact Content
Login

Artifact a112aba0b79e3adeaa485fed09484b32c654e97df58e454aa8489ac2cd57bf84:


0000: 23 20 32 30 31 36 20 46 65 62 72 75 61 72 79 20  # 2016 February 
0010: 34 0a 23 0a 23 20 54 68 65 20 61 75 74 68 6f 72  4.#.# The author
0020: 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 79 72   disclaims copyr
0030: 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 6f 75  ight to this sou
0040: 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 70 6c  rce code.  In pl
0050: 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67 61 6c  ace of.# a legal
0060: 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20 69 73   notice, here is
0070: 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23 0a 23   a blessing:.#.#
0080: 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f 20 67      May you do g
0090: 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76 69 6c  ood and not evil
00a0: 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 66  ..#    May you f
00b0: 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73 73 20  ind forgiveness 
00c0: 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61 6e 64  for yourself and
00d0: 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72 73 2e   forgive others.
00e0: 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 73 68  .#    May you sh
00f0: 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65 76 65  are freely, neve
0100: 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68  r taking more th
0110: 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23 0a 23  an 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 2a 0a 23 20 54 68 69 73 20 66  *******.# This f
0170: 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 72  ile implements r
0180: 65 67 72 65 73 73 69 6f 6e 20 74 65 73 74 73 20  egression tests 
0190: 66 6f 72 20 53 51 4c 69 74 65 20 6c 69 62 72 61  for SQLite libra
01a0: 72 79 2e 20 20 54 68 65 0a 23 20 66 6f 63 75 73  ry.  The.# focus
01b0: 20 6f 66 20 74 68 69 73 20 66 69 6c 65 20 69 73   of this file is
01c0: 20 74 65 73 74 69 6e 67 20 74 68 65 20 6f 70 65   testing the ope
01d0: 72 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 6c 69  ration of the li
01e0: 62 72 61 72 79 20 69 6e 0a 23 20 22 50 52 41 47  brary in.# "PRAG
01f0: 4d 41 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64 65 3d  MA journal_mode=
0200: 57 41 4c 22 20 6d 6f 64 65 2e 0a 23 0a 23 20 4d  WAL" mode..#.# M
0210: 6f 72 65 20 73 70 65 63 69 66 69 63 61 6c 6c 79  ore specifically
0220: 2c 20 69 74 20 74 65 73 74 73 20 22 6c 6f 63 6b  , it tests "lock
0230: 69 6e 67 20 70 72 6f 74 6f 63 6f 6c 22 20 65 72  ing protocol" er
0240: 72 6f 72 73 20 2d 20 65 72 72 6f 72 73 20 74 68  rors - errors th
0250: 61 74 0a 23 20 6d 61 79 20 62 65 20 63 61 75 73  at.# may be caus
0260: 65 64 20 69 66 20 6f 6e 65 20 6f 72 20 6d 6f 72  ed if one or mor
0270: 65 20 53 51 4c 69 74 65 20 63 6c 69 65 6e 74 73  e SQLite clients
0280: 20 64 6f 65 73 20 6e 6f 74 20 66 6f 6c 6c 6f 77   does not follow
0290: 20 74 68 65 20 65 78 70 65 63 74 65 64 0a 23 20   the expected.# 
02a0: 6c 6f 63 6b 69 6e 67 20 70 72 6f 74 6f 63 6f 6c  locking protocol
02b0: 20 77 68 65 6e 20 61 63 63 65 73 73 69 6e 67 20   when accessing 
02c0: 61 20 77 61 6c 2d 6d 6f 64 65 20 64 61 74 61 62  a wal-mode datab
02d0: 61 73 65 2e 20 54 68 65 73 65 20 74 65 73 74 73  ase. These tests
02e0: 20 74 61 6b 65 0a 23 20 71 75 69 74 65 20 61 20   take.# quite a 
02f0: 77 68 69 6c 65 20 74 6f 20 72 75 6e 2e 0a 23 0a  while to run..#.
0300: 0a 73 65 74 20 74 65 73 74 64 69 72 20 5b 66 69  .set testdir [fi
0310: 6c 65 20 64 69 72 6e 61 6d 65 20 24 61 72 67 76  le dirname $argv
0320: 30 5d 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64  0].source $testd
0330: 69 72 2f 74 65 73 74 65 72 2e 74 63 6c 0a 73 6f  ir/tester.tcl.so
0340: 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 6c 6f  urce $testdir/lo
0350: 63 6b 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c 0a 73 6f  ck_common.tcl.so
0360: 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 77 61  urce $testdir/wa
0370: 6c 5f 63 6f 6d 6d 6f 6e 2e 74 63 6c 0a 69 66 63  l_common.tcl.ifc
0380: 61 70 61 62 6c 65 20 21 77 61 6c 20 7b 66 69 6e  apable !wal {fin
0390: 69 73 68 5f 74 65 73 74 20 3b 20 72 65 74 75 72  ish_test ; retur
03a0: 6e 20 7d 0a 0a 73 65 74 20 74 65 73 74 70 72 65  n }..set testpre
03b0: 66 69 78 20 77 61 6c 70 72 6f 74 6f 63 6f 6c 0a  fix walprotocol.
03c0: 0a 23 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 2d 2d 2d 2d  ----------------
03f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 57 68  -----------.# Wh
0410: 65 6e 20 72 65 63 6f 76 65 72 69 6e 67 20 74 68  en recovering th
0420: 65 20 63 6f 6e 74 65 6e 74 73 20 6f 66 20 61 20  e contents of a 
0430: 57 41 4c 20 66 69 6c 65 2c 20 61 20 70 72 6f 63  WAL file, a proc
0440: 65 73 73 20 6f 62 74 61 69 6e 73 20 74 68 65 20  ess obtains the 
0450: 57 52 49 54 45 52 0a 23 20 6c 6f 63 6b 2c 20 74  WRITER.# lock, t
0460: 68 65 6e 20 6c 6f 63 6b 73 20 61 6c 6c 20 6f 74  hen locks all ot
0470: 68 65 72 20 62 79 74 65 73 20 62 65 66 6f 72 65  her bytes before
0480: 20 63 6f 6d 6d 65 6e 63 69 6e 67 20 72 65 63 6f   commencing reco
0490: 76 65 72 79 2e 20 49 66 20 69 74 20 66 61 69 6c  very. If it fail
04a0: 73 0a 23 20 74 6f 20 6c 6f 63 6b 20 61 6c 6c 20  s.# to lock all 
04b0: 6f 74 68 65 72 20 62 79 74 65 73 20 28 62 65 63  other bytes (bec
04c0: 61 75 73 65 20 73 6f 6d 65 20 6f 74 68 65 72 20  ause some other 
04d0: 70 72 6f 63 65 73 73 20 69 73 20 68 6f 6c 64 69  process is holdi
04e0: 6e 67 20 61 20 72 65 61 64 0a 23 20 6c 6f 63 6b  ng a read.# lock
04f0: 29 20 69 74 20 73 68 6f 75 6c 64 20 72 65 74 72  ) it should retr
0500: 79 20 75 70 20 74 6f 20 31 30 30 20 74 69 6d 65  y up to 100 time
0510: 73 2e 20 54 68 65 6e 20 72 65 74 75 72 6e 20 53  s. Then return S
0520: 51 4c 49 54 45 5f 50 52 4f 54 4f 43 4f 4c 20 74  QLITE_PROTOCOL t
0530: 6f 20 74 68 65 20 0a 23 20 63 61 6c 6c 65 72 2e  o the .# caller.
0540: 20 54 65 73 74 20 74 68 69 73 20 28 74 65 73 74   Test this (test
0550: 20 63 61 73 65 20 31 2e 33 29 2e 0a 23 0a 23 20   case 1.3)..#.# 
0560: 41 6c 73 6f 20 74 65 73 74 20 74 68 65 20 65 66  Also test the ef
0570: 66 65 63 74 20 6f 66 20 68 69 74 74 69 6e 67 20  fect of hitting 
0580: 61 6e 20 53 51 4c 49 54 45 5f 42 55 53 59 20 77  an SQLITE_BUSY w
0590: 68 69 6c 65 20 61 74 74 65 6d 70 74 69 6e 67 20  hile attempting 
05a0: 74 6f 20 6f 62 74 61 69 6e 0a 23 20 74 68 65 20  to obtain.# the 
05b0: 57 52 49 54 45 52 20 6c 6f 63 6b 20 28 73 68 6f  WRITER lock (sho
05c0: 75 6c 64 20 62 65 20 74 68 65 20 73 61 6d 65 29  uld be the same)
05d0: 2e 20 54 65 73 74 20 63 61 73 65 20 31 2e 34 2e  . Test case 1.4.
05e0: 0a 23 20 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74  .# .do_execsql_t
05f0: 65 73 74 20 31 2e 30 20 7b 0a 20 20 50 52 41 47  est 1.0 {.  PRAG
0600: 4d 41 20 6a 6f 75 72 6e 61 6c 5f 6d 6f 64 65 20  MA journal_mode 
0610: 3d 20 77 61 6c 3b 0a 20 20 43 52 45 41 54 45 20  = wal;.  CREATE 
0620: 54 41 42 4c 45 20 78 28 79 29 3b 0a 20 20 49 4e  TABLE x(y);.  IN
0630: 53 45 52 54 20 49 4e 54 4f 20 78 20 56 41 4c 55  SERT INTO x VALU
0640: 45 53 28 27 7a 27 29 3b 0a 7d 20 7b 77 61 6c 7d  ES('z');.} {wal}
0650: 0a 0a 70 72 6f 63 20 6c 6f 63 6b 5f 63 61 6c 6c  ..proc lock_call
0660: 62 61 63 6b 20 7b 6d 65 74 68 6f 64 20 66 69 6c  back {method fil
0670: 65 6e 61 6d 65 20 68 61 6e 64 6c 65 20 6c 6f 63  ename handle loc
0680: 6b 7d 20 7b 0a 20 20 6c 61 70 70 65 6e 64 20 3a  k} {.  lappend :
0690: 3a 6c 6f 63 6b 73 20 24 6c 6f 63 6b 0a 7d 0a 64  :locks $lock.}.d
06a0: 6f 5f 74 65 73 74 20 31 2e 31 20 7b 0a 20 20 74  o_test 1.1 {.  t
06b0: 65 73 74 76 66 73 20 54 0a 20 20 54 20 66 69 6c  estvfs T.  T fil
06c0: 74 65 72 20 78 53 68 6d 4c 6f 63 6b 20 0a 20 20  ter xShmLock .  
06d0: 54 20 73 63 72 69 70 74 20 6c 6f 63 6b 5f 63 61  T script lock_ca
06e0: 6c 6c 62 61 63 6b 0a 20 20 73 65 74 20 3a 3a 6c  llback.  set ::l
06f0: 6f 63 6b 73 20 5b 6c 69 73 74 5d 0a 20 20 73 71  ocks [list].  sq
0700: 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62  lite3 db test.db
0710: 20 2d 76 66 73 20 54 0a 20 20 65 78 65 63 73 71   -vfs T.  execsq
0720: 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f  l { SELECT * FRO
0730: 4d 20 78 20 7d 0a 20 20 6c 72 61 6e 67 65 20 24  M x }.  lrange $
0740: 3a 3a 6c 6f 63 6b 73 20 30 20 35 0a 7d 20 5b 6c  ::locks 0 5.} [l
0750: 69 73 74 20 7b 30 20 31 20 6c 6f 63 6b 20 65 78  ist {0 1 lock ex
0760: 63 6c 75 73 69 76 65 7d 20 7b 31 20 32 20 6c 6f  clusive} {1 2 lo
0770: 63 6b 20 65 78 63 6c 75 73 69 76 65 7d 20 7b 34  ck exclusive} {4
0780: 20 34 20 6c 6f 63 6b 20 65 78 63 6c 75 73 69 76   4 lock exclusiv
0790: 65 7d 20 5c 0a 20 20 20 20 20 20 20 20 7b 31 20  e} \.        {1 
07a0: 32 20 75 6e 6c 6f 63 6b 20 65 78 63 6c 75 73 69  2 unlock exclusi
07b0: 76 65 7d 20 7b 34 20 34 20 75 6e 6c 6f 63 6b 20  ve} {4 4 unlock 
07c0: 65 78 63 6c 75 73 69 76 65 7d 20 7b 30 20 31 20  exclusive} {0 1 
07d0: 75 6e 6c 6f 63 6b 20 65 78 63 6c 75 73 69 76 65  unlock exclusive
07e0: 7d 20 20 5c 0a 5d 0a 64 6f 5f 74 65 73 74 20 31  }  \.].do_test 1
07f0: 2e 32 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a  .2 {.  db close.
0800: 20 20 73 65 74 20 3a 3a 6c 6f 63 6b 73 20 5b 6c    set ::locks [l
0810: 69 73 74 5d 0a 20 20 73 71 6c 69 74 65 33 20 64  ist].  sqlite3 d
0820: 62 20 74 65 73 74 2e 64 62 20 2d 76 66 73 20 54  b test.db -vfs T
0830: 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c  .  execsql { SEL
0840: 45 43 54 20 2a 20 46 52 4f 4d 20 78 20 7d 0a 20  ECT * FROM x }. 
0850: 20 6c 72 61 6e 67 65 20 24 3a 3a 6c 6f 63 6b 73   lrange $::locks
0860: 20 30 20 35 0a 7d 20 5b 6c 69 73 74 20 7b 30 20   0 5.} [list {0 
0870: 31 20 6c 6f 63 6b 20 65 78 63 6c 75 73 69 76 65  1 lock exclusive
0880: 7d 20 7b 31 20 32 20 6c 6f 63 6b 20 65 78 63 6c  } {1 2 lock excl
0890: 75 73 69 76 65 7d 20 7b 34 20 34 20 6c 6f 63 6b  usive} {4 4 lock
08a0: 20 65 78 63 6c 75 73 69 76 65 7d 20 5c 0a 20 20   exclusive} \.  
08b0: 20 20 20 20 20 20 7b 31 20 32 20 75 6e 6c 6f 63        {1 2 unloc
08c0: 6b 20 65 78 63 6c 75 73 69 76 65 7d 20 7b 34 20  k exclusive} {4 
08d0: 34 20 75 6e 6c 6f 63 6b 20 65 78 63 6c 75 73 69  4 unlock exclusi
08e0: 76 65 7d 20 7b 30 20 31 20 75 6e 6c 6f 63 6b 20  ve} {0 1 unlock 
08f0: 65 78 63 6c 75 73 69 76 65 7d 20 20 5c 0a 5d 0a  exclusive}  \.].
0900: 70 72 6f 63 20 6c 6f 63 6b 5f 63 61 6c 6c 62 61  proc lock_callba
0910: 63 6b 20 7b 6d 65 74 68 6f 64 20 66 69 6c 65 6e  ck {method filen
0920: 61 6d 65 20 68 61 6e 64 6c 65 20 6c 6f 63 6b 7d  ame handle lock}
0930: 20 7b 0a 20 20 69 66 20 7b 24 6c 6f 63 6b 20 3d   {.  if {$lock =
0940: 3d 20 22 31 20 32 20 6c 6f 63 6b 20 65 78 63 6c  = "1 2 lock excl
0950: 75 73 69 76 65 22 7d 20 7b 20 72 65 74 75 72 6e  usive"} { return
0960: 20 53 51 4c 49 54 45 5f 42 55 53 59 20 7d 0a 20   SQLITE_BUSY }. 
0970: 20 72 65 74 75 72 6e 20 53 51 4c 49 54 45 5f 4f   return SQLITE_O
0980: 4b 0a 7d 0a 70 75 74 73 20 22 23 20 57 61 72 6e  K.}.puts "# Warn
0990: 69 6e 67 3a 20 54 68 69 73 20 6e 65 78 74 20 74  ing: This next t
09a0: 65 73 74 20 63 61 73 65 20 63 61 75 73 65 73 20  est case causes 
09b0: 53 51 4c 69 74 65 20 74 6f 20 63 61 6c 6c 20 78  SQLite to call x
09c0: 53 6c 65 65 70 28 31 29 20 31 30 30 20 74 69 6d  Sleep(1) 100 tim
09d0: 65 73 2e 22 0a 70 75 74 73 20 22 23 20 4e 6f 72  es.".puts "# Nor
09e0: 6d 61 6c 6c 79 20 74 68 69 73 20 65 71 75 61 74  mally this equat
09f0: 65 73 20 74 6f 20 61 20 64 65 6c 61 79 20 6f 66  es to a delay of
0a00: 20 72 6f 75 67 68 6c 79 20 31 30 20 73 65 63 6f   roughly 10 seco
0a10: 6e 64 73 2c 20 62 75 74 20 69 66 20 53 51 4c 69  nds, but if SQLi
0a20: 74 65 22 0a 70 75 74 73 20 22 23 20 69 73 20 62  te".puts "# is b
0a30: 75 69 6c 74 20 6f 6e 20 75 6e 69 78 20 77 69 74  uilt on unix wit
0a40: 68 6f 75 74 20 48 41 56 45 5f 55 53 4c 45 45 50  hout HAVE_USLEEP
0a50: 20 64 65 66 69 6e 65 64 2c 20 69 74 20 6d 61 79   defined, it may
0a60: 20 62 65 20 6d 75 63 68 20 6c 6f 6e 67 65 72 2e   be much longer.
0a70: 22 0a 64 6f 5f 74 65 73 74 20 31 2e 33 20 7b 0a  ".do_test 1.3 {.
0a80: 20 20 64 62 20 63 6c 6f 73 65 0a 20 20 73 65 74    db close.  set
0a90: 20 3a 3a 6c 6f 63 6b 73 20 5b 6c 69 73 74 5d 0a   ::locks [list].
0aa0: 20 20 73 71 6c 69 74 65 33 20 64 62 20 74 65 73    sqlite3 db tes
0ab0: 74 2e 64 62 20 2d 76 66 73 20 54 0a 20 20 63 61  t.db -vfs T.  ca
0ac0: 74 63 68 73 71 6c 20 7b 20 53 45 4c 45 43 54 20  tchsql { SELECT 
0ad0: 2a 20 46 52 4f 4d 20 78 20 7d 0a 7d 20 7b 31 20  * FROM x }.} {1 
0ae0: 7b 6c 6f 63 6b 69 6e 67 20 70 72 6f 74 6f 63 6f  {locking protoco
0af0: 6c 7d 7d 0a 0a 70 75 74 73 20 22 23 20 57 61 72  l}}..puts "# War
0b00: 6e 69 6e 67 3a 20 53 61 6d 65 20 61 67 61 69 6e  ning: Same again
0b10: 21 22 0a 70 72 6f 63 20 6c 6f 63 6b 5f 63 61 6c  !".proc lock_cal
0b20: 6c 62 61 63 6b 20 7b 6d 65 74 68 6f 64 20 66 69  lback {method fi
0b30: 6c 65 6e 61 6d 65 20 68 61 6e 64 6c 65 20 6c 6f  lename handle lo
0b40: 63 6b 7d 20 7b 0a 20 20 69 66 20 7b 24 6c 6f 63  ck} {.  if {$loc
0b50: 6b 20 3d 3d 20 22 30 20 31 20 6c 6f 63 6b 20 65  k == "0 1 lock e
0b60: 78 63 6c 75 73 69 76 65 22 7d 20 7b 20 72 65 74  xclusive"} { ret
0b70: 75 72 6e 20 53 51 4c 49 54 45 5f 42 55 53 59 20  urn SQLITE_BUSY 
0b80: 7d 0a 20 20 72 65 74 75 72 6e 20 53 51 4c 49 54  }.  return SQLIT
0b90: 45 5f 4f 4b 0a 7d 0a 64 6f 5f 74 65 73 74 20 31  E_OK.}.do_test 1
0ba0: 2e 34 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a  .4 {.  db close.
0bb0: 20 20 73 65 74 20 3a 3a 6c 6f 63 6b 73 20 5b 6c    set ::locks [l
0bc0: 69 73 74 5d 0a 20 20 73 71 6c 69 74 65 33 20 64  ist].  sqlite3 d
0bd0: 62 20 74 65 73 74 2e 64 62 20 2d 76 66 73 20 54  b test.db -vfs T
0be0: 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 20 53 45  .  catchsql { SE
0bf0: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 78 20 7d 0a  LECT * FROM x }.
0c00: 7d 20 7b 31 20 7b 6c 6f 63 6b 69 6e 67 20 70 72  } {1 {locking pr
0c10: 6f 74 6f 63 6f 6c 7d 7d 0a 0a 70 75 74 73 20 22  otocol}}..puts "
0c20: 23 20 57 61 72 6e 69 6e 67 3a 20 54 68 69 72 64  # Warning: Third
0c30: 20 74 69 6d 65 21 22 0a 70 72 6f 63 20 6c 6f 63   time!".proc loc
0c40: 6b 5f 63 61 6c 6c 62 61 63 6b 20 7b 6d 65 74 68  k_callback {meth
0c50: 6f 64 20 66 69 6c 65 6e 61 6d 65 20 68 61 6e 64  od filename hand
0c60: 6c 65 20 6c 6f 63 6b 7d 20 7b 0a 20 20 69 66 20  le lock} {.  if 
0c70: 7b 24 6c 6f 63 6b 20 3d 3d 20 22 34 20 34 20 6c  {$lock == "4 4 l
0c80: 6f 63 6b 20 65 78 63 6c 75 73 69 76 65 22 7d 20  ock exclusive"} 
0c90: 7b 20 72 65 74 75 72 6e 20 53 51 4c 49 54 45 5f  { return SQLITE_
0ca0: 42 55 53 59 20 7d 0a 20 20 72 65 74 75 72 6e 20  BUSY }.  return 
0cb0: 53 51 4c 49 54 45 5f 4f 4b 0a 7d 0a 64 6f 5f 74  SQLITE_OK.}.do_t
0cc0: 65 73 74 20 31 2e 35 20 7b 0a 20 20 64 62 20 63  est 1.5 {.  db c
0cd0: 6c 6f 73 65 0a 20 20 73 65 74 20 3a 3a 6c 6f 63  lose.  set ::loc
0ce0: 6b 73 20 5b 6c 69 73 74 5d 0a 20 20 73 71 6c 69  ks [list].  sqli
0cf0: 74 65 33 20 64 62 20 74 65 73 74 2e 64 62 20 2d  te3 db test.db -
0d00: 76 66 73 20 54 0a 20 20 63 61 74 63 68 73 71 6c  vfs T.  catchsql
0d10: 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d   { SELECT * FROM
0d20: 20 78 20 7d 0a 7d 20 7b 31 20 7b 6c 6f 63 6b 69   x }.} {1 {locki
0d30: 6e 67 20 70 72 6f 74 6f 63 6f 6c 7d 7d 0a 64 62  ng protocol}}.db
0d40: 20 63 6c 6f 73 65 0a 54 20 64 65 6c 65 74 65 0a   close.T delete.
0d50: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
0d60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0d90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 0a 64  -----------.# .d
0da0: 6f 5f 74 65 73 74 20 32 2e 31 20 7b 0a 20 20 66  o_test 2.1 {.  f
0db0: 6f 72 63 65 64 65 6c 65 74 65 20 74 65 73 74 2e  orcedelete test.
0dc0: 64 62 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e  db test.db-journ
0dd0: 61 6c 20 74 65 73 74 2e 64 62 20 77 61 6c 0a 20  al test.db wal. 
0de0: 20 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74   sqlite3 db test
0df0: 2e 64 62 0a 20 20 73 71 6c 69 74 65 33 20 64 62  .db.  sqlite3 db
0e00: 32 20 74 65 73 74 2e 64 62 0a 20 20 65 78 65 63  2 test.db.  exec
0e10: 73 71 6c 20 7b 0a 20 20 20 20 50 52 41 47 4d 41  sql {.    PRAGMA
0e20: 20 61 75 74 6f 5f 76 61 63 75 75 6d 20 3d 20 6f   auto_vacuum = o
0e30: 66 66 3b 0a 20 20 20 20 50 52 41 47 4d 41 20 6a  ff;.    PRAGMA j
0e40: 6f 75 72 6e 61 6c 5f 6d 6f 64 65 20 3d 20 57 41  ournal_mode = WA
0e50: 4c 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54 41  L;.    CREATE TA
0e60: 42 4c 45 20 62 28 63 29 3b 0a 20 20 20 20 49 4e  BLE b(c);.    IN
0e70: 53 45 52 54 20 49 4e 54 4f 20 62 20 56 41 4c 55  SERT INTO b VALU
0e80: 45 53 28 27 54 65 68 72 61 6e 27 29 3b 0a 20 20  ES('Tehran');.  
0e90: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 62 20    INSERT INTO b 
0ea0: 56 41 4c 55 45 53 28 27 51 6f 6d 27 29 3b 0a 20  VALUES('Qom');. 
0eb0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 62     INSERT INTO b
0ec0: 20 56 41 4c 55 45 53 28 27 4d 61 72 6b 61 7a 69   VALUES('Markazi
0ed0: 27 29 3b 0a 20 20 20 20 50 52 41 47 4d 41 20 77  ');.    PRAGMA w
0ee0: 61 6c 5f 63 68 65 63 6b 70 6f 69 6e 74 3b 0a 20  al_checkpoint;. 
0ef0: 20 7d 0a 7d 20 7b 77 61 6c 20 30 20 35 20 35 7d   }.} {wal 0 5 5}
0f00: 0a 64 6f 5f 74 65 73 74 20 32 2e 32 20 7b 0a 20  .do_test 2.2 {. 
0f10: 20 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43   execsql { SELEC
0f20: 54 20 2a 20 46 52 4f 4d 20 62 20 7d 0a 7d 20 7b  T * FROM b }.} {
0f30: 54 65 68 72 61 6e 20 51 6f 6d 20 4d 61 72 6b 61  Tehran Qom Marka
0f40: 7a 69 7d 0a 64 6f 5f 74 65 73 74 20 32 2e 33 20  zi}.do_test 2.3 
0f50: 7b 0a 20 20 64 62 20 65 76 61 6c 20 7b 20 53 45  {.  db eval { SE
0f60: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 62 20 7d 20  LECT * FROM b } 
0f70: 7b 0a 20 20 20 20 64 62 20 65 76 61 6c 20 7b 20  {.    db eval { 
0f80: 49 4e 53 45 52 54 20 49 4e 54 4f 20 62 20 56 41  INSERT INTO b VA
0f90: 4c 55 45 53 28 27 51 61 7a 76 69 6e 27 29 20 7d  LUES('Qazvin') }
0fa0: 0a 20 20 20 20 73 65 74 20 72 20 5b 64 62 32 20  .    set r [db2 
0fb0: 65 76 61 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20  eval { SELECT * 
0fc0: 46 52 4f 4d 20 62 20 7d 5d 0a 20 20 20 20 62 72  FROM b }].    br
0fd0: 65 61 6b 0a 20 20 7d 0a 20 20 73 65 74 20 72 0a  eak.  }.  set r.
0fe0: 7d 20 7b 54 65 68 72 61 6e 20 51 6f 6d 20 4d 61  } {Tehran Qom Ma
0ff0: 72 6b 61 7a 69 20 51 61 7a 76 69 6e 7d 0a 64 6f  rkazi Qazvin}.do
1000: 5f 74 65 73 74 20 32 2e 34 20 7b 0a 20 20 65 78  _test 2.4 {.  ex
1010: 65 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53 45  ecsql {.    INSE
1020: 52 54 20 49 4e 54 4f 20 62 20 56 41 4c 55 45 53  RT INTO b VALUES
1030: 28 27 47 69 6c 61 6e 27 29 3b 0a 20 20 20 20 49  ('Gilan');.    I
1040: 4e 53 45 52 54 20 49 4e 54 4f 20 62 20 56 41 4c  NSERT INTO b VAL
1050: 55 45 53 28 27 41 72 64 61 62 69 6c 27 29 3b 0a  UES('Ardabil');.
1060: 20 20 7d 0a 7d 20 7b 7d 0a 64 62 32 20 63 6c 6f    }.} {}.db2 clo
1070: 73 65 0a 0a 66 61 75 6c 74 73 69 6d 5f 73 61 76  se..faultsim_sav
1080: 65 5f 61 6e 64 5f 63 6c 6f 73 65 0a 74 65 73 74  e_and_close.test
1090: 76 66 73 20 54 20 2d 64 65 66 61 75 6c 74 20 31  vfs T -default 1
10a0: 0a 66 61 75 6c 74 73 69 6d 5f 72 65 73 74 6f 72  .faultsim_restor
10b0: 65 5f 61 6e 64 5f 72 65 6f 70 65 6e 0a 54 20 66  e_and_reopen.T f
10c0: 69 6c 74 65 72 20 78 53 68 6d 4c 6f 63 6b 0a 54  ilter xShmLock.T
10d0: 20 73 63 72 69 70 74 20 6c 6f 63 6b 5f 63 61 6c   script lock_cal
10e0: 6c 62 61 63 6b 0a 0a 70 72 6f 63 20 6c 6f 63 6b  lback..proc lock
10f0: 5f 63 61 6c 6c 62 61 63 6b 20 7b 6d 65 74 68 6f  _callback {metho
1100: 64 20 66 69 6c 65 20 68 61 6e 64 6c 65 20 73 70  d file handle sp
1110: 65 63 7d 20 7b 0a 20 20 69 66 20 7b 24 73 70 65  ec} {.  if {$spe
1120: 63 20 3d 3d 20 22 31 20 32 20 75 6e 6c 6f 63 6b  c == "1 2 unlock
1130: 20 65 78 63 6c 75 73 69 76 65 22 7d 20 7b 0a 20   exclusive"} {. 
1140: 20 20 20 54 20 66 69 6c 74 65 72 20 7b 7d 0a 20     T filter {}. 
1150: 20 20 20 73 65 74 20 3a 3a 72 20 5b 63 61 74 63     set ::r [catc
1160: 68 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20  hsql { SELECT * 
1170: 46 52 4f 4d 20 62 20 7d 20 64 62 32 5d 0a 20 20  FROM b } db2].  
1180: 7d 0a 7d 0a 73 71 6c 69 74 65 33 20 64 62 20 74  }.}.sqlite3 db t
1190: 65 73 74 2e 64 62 0a 73 71 6c 69 74 65 33 20 64  est.db.sqlite3 d
11a0: 62 32 20 74 65 73 74 2e 64 62 0a 70 75 74 73 20  b2 test.db.puts 
11b0: 22 23 20 57 61 72 6e 69 6e 67 3a 20 41 6e 6f 74  "# Warning: Anot
11c0: 68 65 72 20 73 6c 6f 77 20 74 65 73 74 21 22 0a  her slow test!".
11d0: 64 6f 5f 74 65 73 74 20 32 2e 35 20 7b 0a 20 20  do_test 2.5 {.  
11e0: 65 78 65 63 73 71 6c 20 7b 20 53 45 4c 45 43 54  execsql { SELECT
11f0: 20 2a 20 46 52 4f 4d 20 62 20 7d 0a 7d 20 7b 54   * FROM b }.} {T
1200: 65 68 72 61 6e 20 51 6f 6d 20 4d 61 72 6b 61 7a  ehran Qom Markaz
1210: 69 20 51 61 7a 76 69 6e 20 47 69 6c 61 6e 20 41  i Qazvin Gilan A
1220: 72 64 61 62 69 6c 7d 0a 64 6f 5f 74 65 73 74 20  rdabil}.do_test 
1230: 32 2e 36 20 7b 0a 20 20 73 65 74 20 3a 3a 72 0a  2.6 {.  set ::r.
1240: 7d 20 7b 31 20 7b 6c 6f 63 6b 69 6e 67 20 70 72  } {1 {locking pr
1250: 6f 74 6f 63 6f 6c 7d 7d 0a 0a 64 62 20 63 6c 6f  otocol}}..db clo
1260: 73 65 0a 64 62 32 20 63 6c 6f 73 65 0a 0a 66 61  se.db2 close..fa
1270: 75 6c 74 73 69 6d 5f 72 65 73 74 6f 72 65 5f 61  ultsim_restore_a
1280: 6e 64 5f 72 65 6f 70 65 6e 0a 73 71 6c 69 74 65  nd_reopen.sqlite
1290: 33 20 64 62 32 20 74 65 73 74 2e 64 62 0a 54 20  3 db2 test.db.T 
12a0: 66 69 6c 74 65 72 20 78 53 68 6d 4c 6f 63 6b 0a  filter xShmLock.
12b0: 54 20 73 63 72 69 70 74 20 6c 6f 63 6b 5f 63 61  T script lock_ca
12c0: 6c 6c 62 61 63 6b 0a 70 72 6f 63 20 6c 6f 63 6b  llback.proc lock
12d0: 5f 63 61 6c 6c 62 61 63 6b 20 7b 6d 65 74 68 6f  _callback {metho
12e0: 64 20 66 69 6c 65 20 68 61 6e 64 6c 65 20 73 70  d file handle sp
12f0: 65 63 7d 20 7b 0a 20 20 69 66 20 7b 24 73 70 65  ec} {.  if {$spe
1300: 63 20 3d 3d 20 22 31 20 32 20 75 6e 6c 6f 63 6b  c == "1 2 unlock
1310: 20 65 78 63 6c 75 73 69 76 65 22 7d 20 7b 0a 20   exclusive"} {. 
1320: 20 20 20 54 20 66 69 6c 74 65 72 20 7b 7d 0a 20     T filter {}. 
1330: 20 20 20 73 65 74 20 3a 3a 72 20 5b 63 61 74 63     set ::r [catc
1340: 68 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20  hsql { SELECT * 
1350: 46 52 4f 4d 20 62 20 7d 20 64 62 32 5d 0a 20 20  FROM b } db2].  
1360: 7d 0a 7d 0a 75 6e 73 65 74 20 3a 3a 72 0a 70 75  }.}.unset ::r.pu
1370: 74 73 20 22 23 20 57 61 72 6e 69 6e 67 3a 20 4c  ts "# Warning: L
1380: 61 73 74 20 6f 6e 65 21 22 0a 64 6f 5f 74 65 73  ast one!".do_tes
1390: 74 20 32 2e 37 20 7b 0a 20 20 65 78 65 63 73 71  t 2.7 {.  execsq
13a0: 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52 4f  l { SELECT * FRO
13b0: 4d 20 62 20 7d 0a 7d 20 7b 54 65 68 72 61 6e 20  M b }.} {Tehran 
13c0: 51 6f 6d 20 4d 61 72 6b 61 7a 69 20 51 61 7a 76  Qom Markazi Qazv
13d0: 69 6e 20 47 69 6c 61 6e 20 41 72 64 61 62 69 6c  in Gilan Ardabil
13e0: 7d 0a 64 6f 5f 74 65 73 74 20 32 2e 38 20 7b 0a  }.do_test 2.8 {.
13f0: 20 20 73 65 74 20 3a 3a 72 0a 7d 20 7b 31 20 7b    set ::r.} {1 {
1400: 6c 6f 63 6b 69 6e 67 20 70 72 6f 74 6f 63 6f 6c  locking protocol
1410: 7d 7d 0a 0a 64 62 20 63 6c 6f 73 65 0a 64 62 32  }}..db close.db2
1420: 20 63 6c 6f 73 65 0a 54 20 64 65 6c 65 74 65 0a   close.T delete.
1430: 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a           .finish_test.