/ Hex Artifact Content
Login

Artifact a67af9620a510ce19f96ba69f3848228b7c62a73:


0000: 23 20 32 30 30 36 20 53 65 70 74 65 6d 62 65 72  # 2006 September
0010: 20 34 0a 23 0a 23 20 54 68 65 20 61 75 74 68 6f   4.#.# 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 0a 23 0a 23 20 24 49 64 3a 20 6d 69  ary..#.# $Id: mi
01b0: 73 63 37 2e 74 65 73 74 2c 76 20 31 2e 31 35 20  sc7.test,v 1.15 
01c0: 32 30 30 37 2f 30 38 2f 32 32 20 32 30 3a 31 38  2007/08/22 20:18
01d0: 3a 32 32 20 64 72 68 20 45 78 70 20 24 0a 0a 73  :22 drh Exp $..s
01e0: 65 74 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65  et testdir [file
01f0: 20 64 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d   dirname $argv0]
0200: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72  .source $testdir
0210: 2f 74 65 73 74 65 72 2e 74 63 6c 0a 0a 23 64 6f  /tester.tcl..#do
0220: 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 20 7b 0a  _test misc7-1 {.
0230: 23 20 20 63 5f 6d 69 73 75 73 65 5f 74 65 73 74  #  c_misuse_test
0240: 0a 23 7d 20 7b 7d 0a 0a 64 6f 5f 74 65 73 74 20  .#} {}..do_test 
0250: 6d 69 73 63 37 2d 32 20 7b 0a 20 20 63 5f 72 65  misc7-2 {.  c_re
0260: 61 6c 6c 6f 63 5f 74 65 73 74 0a 7d 20 7b 7d 0a  alloc_test.} {}.
0270: 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 33  .do_test misc7-3
0280: 20 7b 0a 20 20 63 5f 63 6f 6c 6c 61 74 69 6f 6e   {.  c_collation
0290: 5f 74 65 73 74 0a 7d 20 7b 7d 0a 0a 23 20 54 72  _test.} {}..# Tr
02a0: 79 20 74 6f 20 6f 70 65 6e 20 61 20 64 69 72 65  y to open a dire
02b0: 63 74 6f 72 79 3a 0a 23 0a 64 6f 5f 74 65 73 74  ctory:.#.do_test
02c0: 20 6d 69 73 63 37 2d 34 20 7b 0a 20 20 66 69 6c   misc7-4 {.  fil
02d0: 65 20 64 65 6c 65 74 65 20 6d 79 64 69 72 0a 20  e delete mydir. 
02e0: 20 66 69 6c 65 20 6d 6b 64 69 72 20 6d 79 64 69   file mkdir mydi
02f0: 72 0a 20 20 73 65 74 20 72 63 20 5b 63 61 74 63  r.  set rc [catc
0300: 68 20 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 20  h {.    sqlite3 
0310: 64 62 32 20 2e 2f 6d 79 64 69 72 0a 20 20 7d 20  db2 ./mydir.  } 
0320: 6d 73 67 5d 0a 20 20 6c 69 73 74 20 24 72 63 20  msg].  list $rc 
0330: 24 6d 73 67 0a 7d 20 7b 31 20 7b 75 6e 61 62 6c  $msg.} {1 {unabl
0340: 65 20 74 6f 20 6f 70 65 6e 20 64 61 74 61 62 61  e to open databa
0350: 73 65 20 66 69 6c 65 7d 7d 0a 0a 23 20 54 72 79  se file}}..# Try
0360: 20 74 6f 20 6f 70 65 6e 20 61 20 66 69 6c 65 20   to open a file 
0370: 77 69 74 68 20 61 20 64 69 72 65 63 74 6f 72 79  with a directory
0380: 20 77 68 65 72 65 20 69 74 27 73 20 6a 6f 75 72   where it's jour
0390: 6e 61 6c 20 66 69 6c 65 20 73 68 6f 75 6c 64 20  nal file should 
03a0: 62 65 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 6d 69  be..#.do_test mi
03b0: 73 63 37 2d 35 20 7b 0a 20 20 66 69 6c 65 20 64  sc7-5 {.  file d
03c0: 65 6c 65 74 65 20 6d 79 64 69 72 0a 20 20 66 69  elete mydir.  fi
03d0: 6c 65 20 6d 6b 64 69 72 20 6d 79 64 69 72 2d 6a  le mkdir mydir-j
03e0: 6f 75 72 6e 61 6c 0a 20 20 73 71 6c 69 74 65 33  ournal.  sqlite3
03f0: 20 64 62 32 20 2e 2f 6d 79 64 69 72 0a 20 20 63   db2 ./mydir.  c
0400: 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52  atchsql {.    CR
0410: 45 41 54 45 20 54 41 42 4c 45 20 61 62 63 28 61  EATE TABLE abc(a
0420: 2c 20 62 2c 20 63 29 3b 0a 20 20 7d 20 64 62 32  , b, c);.  } db2
0430: 0a 7d 20 7b 31 20 7b 75 6e 61 62 6c 65 20 74 6f  .} {1 {unable to
0440: 20 6f 70 65 6e 20 64 61 74 61 62 61 73 65 20 66   open database f
0450: 69 6c 65 7d 7d 0a 64 62 32 20 63 6c 6f 73 65 0a  ile}}.db2 close.
0460: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
0470: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0480: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0490: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
04a0: 2d 2d 2d 2d 2d 2d 0a 23 20 54 68 65 20 66 6f 6c  ------.# The fol
04b0: 6c 6f 77 69 6e 67 20 74 65 73 74 73 2c 20 6d 69  lowing tests, mi
04c0: 73 63 37 2d 36 2e 2a 20 74 65 73 74 20 74 68 65  sc7-6.* test the
04d0: 20 6c 69 62 72 61 72 69 65 73 20 62 65 68 61 76   libraries behav
04e0: 69 6f 75 72 20 77 68 65 6e 0a 23 20 69 74 20 63  iour when.# it c
04f0: 61 6e 6e 6f 74 20 6f 70 65 6e 20 61 20 66 69 6c  annot open a fil
0500: 65 2e 20 54 6f 20 66 6f 72 63 65 20 74 68 69 73  e. To force this
0510: 20 63 6f 6e 64 69 74 69 6f 6e 2c 20 77 65 20 75   condition, we u
0520: 73 65 20 75 70 20 61 6c 6c 20 74 68 65 0a 23 20  se up all the.# 
0530: 66 69 6c 65 2d 64 65 73 63 72 69 70 74 6f 72 73  file-descriptors
0540: 20 62 65 66 6f 72 65 20 72 75 6e 6e 69 6e 67 20   before running 
0550: 73 71 6c 69 74 65 2e 20 54 68 69 73 20 70 72 6f  sqlite. This pro
0560: 62 61 62 6c 79 20 6f 6e 6c 79 20 77 6f 72 6b 73  bably only works
0570: 0a 23 20 6f 6e 20 75 6e 69 78 2e 0a 23 0a 0a 70  .# on unix..#..p
0580: 72 6f 63 20 75 73 65 5f 75 70 5f 66 69 6c 65 73  roc use_up_files
0590: 20 7b 7d 20 7b 0a 20 20 73 65 74 20 72 65 74 20   {} {.  set ret 
05a0: 5b 6c 69 73 74 5d 0a 20 20 63 61 74 63 68 20 7b  [list].  catch {
05b0: 0a 20 20 20 20 77 68 69 6c 65 20 31 20 7b 20 6c  .    while 1 { l
05c0: 61 70 70 65 6e 64 20 72 65 74 20 5b 6f 70 65 6e  append ret [open
05d0: 20 74 65 73 74 2e 64 62 5d 20 7d 0a 20 20 7d 0a   test.db] }.  }.
05e0: 20 20 72 65 74 75 72 6e 20 24 72 65 74 0a 7d 0a    return $ret.}.
05f0: 0a 70 72 6f 63 20 64 6f 5f 66 69 6c 65 6f 70 65  .proc do_fileope
0600: 6e 5f 74 65 73 74 20 7b 70 72 65 66 69 78 20 73  n_test {prefix s
0610: 71 6c 7d 20 7b 0a 20 20 73 65 74 20 66 64 5f 6c  ql} {.  set fd_l
0620: 69 73 74 20 5b 75 73 65 5f 75 70 5f 66 69 6c 65  ist [use_up_file
0630: 73 5d 0a 20 20 73 65 74 20 3a 3a 67 6f 20 31 0a  s].  set ::go 1.
0640: 20 20 73 65 74 20 3a 3a 6e 20 31 0a 20 20 73 65    set ::n 1.  se
0650: 74 20 3a 3a 73 71 6c 20 24 73 71 6c 0a 20 20 77  t ::sql $sql.  w
0660: 68 69 6c 65 20 7b 24 3a 3a 67 6f 7d 20 7b 0a 20  hile {$::go} {. 
0670: 20 20 20 63 61 74 63 68 20 7b 64 62 20 63 6c 6f     catch {db clo
0680: 73 65 7d 0a 20 20 20 20 64 6f 5f 74 65 73 74 20  se}.    do_test 
0690: 24 7b 70 72 65 66 69 78 7d 2e 24 7b 3a 3a 6e 7d  ${prefix}.${::n}
06a0: 20 7b 0a 20 20 20 20 20 20 73 65 74 20 72 63 20   {.      set rc 
06b0: 5b 63 61 74 63 68 20 7b 0a 20 20 20 20 20 20 20  [catch {.       
06c0: 20 73 71 6c 69 74 65 20 64 62 20 74 65 73 74 2e   sqlite db test.
06d0: 64 62 0a 20 20 20 20 20 20 20 20 64 62 20 65 76  db.        db ev
06e0: 61 6c 20 24 3a 3a 73 71 6c 0a 20 20 20 20 20 20  al $::sql.      
06f0: 7d 20 6d 73 67 5d 0a 20 20 20 20 20 20 69 66 20  } msg].      if 
0700: 7b 24 72 63 20 3d 3d 20 30 7d 20 7b 73 65 74 20  {$rc == 0} {set 
0710: 3a 3a 67 6f 20 30 7d 0a 20 20 0a 20 20 20 20 20  ::go 0}.  .     
0720: 20 65 78 70 72 20 7b 24 72 63 20 3d 3d 20 30 20   expr {$rc == 0 
0730: 7c 7c 20 28 24 72 63 20 3d 3d 20 31 20 26 26 20  || ($rc == 1 && 
0740: 5b 73 74 72 69 6e 67 20 66 69 72 73 74 20 75 6e  [string first un
0750: 61 62 6c 65 20 24 6d 73 67 5d 3d 3d 30 29 7d 0a  able $msg]==0)}.
0760: 20 20 20 20 7d 20 31 0a 20 20 0a 20 20 20 20 63      } 1.  .    c
0770: 6c 6f 73 65 20 5b 6c 69 6e 64 65 78 20 24 66 64  lose [lindex $fd
0780: 5f 6c 69 73 74 20 30 5d 0a 20 20 20 20 73 65 74  _list 0].    set
0790: 20 66 64 5f 6c 69 73 74 20 5b 6c 72 61 6e 67 65   fd_list [lrange
07a0: 20 24 66 64 5f 6c 69 73 74 20 31 20 65 6e 64 5d   $fd_list 1 end]
07b0: 0a 20 20 20 20 69 6e 63 72 20 3a 3a 6e 0a 20 20  .    incr ::n.  
07c0: 7d 0a 20 20 66 6f 72 65 61 63 68 20 66 64 20 24  }.  foreach fd $
07d0: 66 64 5f 6c 69 73 74 20 7b 0a 20 20 20 20 63 6c  fd_list {.    cl
07e0: 6f 73 65 20 24 66 64 0a 20 20 7d 0a 20 20 64 62  ose $fd.  }.  db
07f0: 20 63 6c 6f 73 65 0a 7d 0a 0a 65 78 65 63 73 71   close.}..execsq
0800: 6c 20 7b 20 43 52 45 41 54 45 20 54 41 42 4c 45  l { CREATE TABLE
0810: 20 61 62 63 28 61 20 50 52 49 4d 41 52 59 20 4b   abc(a PRIMARY K
0820: 45 59 2c 20 62 2c 20 63 29 3b 20 7d 0a 64 62 20  EY, b, c); }.db 
0830: 63 6c 6f 73 65 0a 0a 69 66 20 7b 24 74 63 6c 5f  close..if {$tcl_
0840: 70 6c 61 74 66 6f 72 6d 28 70 6c 61 74 66 6f 72  platform(platfor
0850: 6d 29 21 3d 22 77 69 6e 64 6f 77 73 22 7d 20 7b  m)!="windows"} {
0860: 0a 20 20 64 6f 5f 66 69 6c 65 6f 70 65 6e 5f 74  .  do_fileopen_t
0870: 65 73 74 20 6d 69 73 63 37 2d 36 2e 31 20 7b 0a  est misc7-6.1 {.
0880: 20 20 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 49      BEGIN;.    I
0890: 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 56  NSERT INTO abc V
08a0: 41 4c 55 45 53 28 31 2c 20 32 2c 20 33 29 3b 0a  ALUES(1, 2, 3);.
08b0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
08c0: 61 62 63 20 56 41 4c 55 45 53 28 32 2c 20 33 2c  abc VALUES(2, 3,
08d0: 20 34 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20   4);.    INSERT 
08e0: 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20  INTO abc SELECT 
08f0: 61 2b 32 2c 20 62 2c 20 63 20 46 52 4f 4d 20 61  a+2, b, c FROM a
0900: 62 63 3b 0a 20 20 20 20 43 4f 4d 4d 49 54 3b 0a  bc;.    COMMIT;.
0910: 20 20 7d 0a 20 20 0a 20 20 64 6f 5f 66 69 6c 65    }.  .  do_file
0920: 6f 70 65 6e 5f 74 65 73 74 20 6d 69 73 63 37 2d  open_test misc7-
0930: 36 2e 32 20 7b 0a 20 20 20 20 50 52 41 47 4d 41  6.2 {.    PRAGMA
0940: 20 74 65 6d 70 2e 63 61 63 68 65 5f 73 69 7a 65   temp.cache_size
0950: 20 3d 20 31 30 30 30 3b 0a 20 20 7d 0a 7d 0a 0a   = 1000;.  }.}..
0960: 23 0a 23 20 45 6e 64 20 6f 66 20 74 65 73 74 73  #.# End of tests
0970: 20 66 6f 72 20 6f 75 74 2d 6f 66 2d 66 69 6c 65   for out-of-file
0980: 2d 64 65 73 63 72 69 70 74 6f 72 73 20 63 6f 6e  -descriptors con
0990: 64 69 74 69 6f 6e 2e 0a 23 2d 2d 2d 2d 2d 2d 2d  dition..#-------
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 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 0a 73  -------------..s
09e0: 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64  qlite3 db test.d
09f0: 62 0a 65 78 65 63 73 71 6c 20 7b 0a 20 20 44 45  b.execsql {.  DE
0a00: 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 3b 0a 20  LETE FROM abc;. 
0a10: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63   INSERT INTO abc
0a20: 20 56 41 4c 55 45 53 28 31 2c 20 32 2c 20 33 29   VALUES(1, 2, 3)
0a30: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
0a40: 61 62 63 20 56 41 4c 55 45 53 28 32 2c 20 33 2c  abc VALUES(2, 3,
0a50: 20 34 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e   4);.  INSERT IN
0a60: 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 61 2b  TO abc SELECT a+
0a70: 32 2c 20 62 2c 20 63 20 46 52 4f 4d 20 61 62 63  2, b, c FROM abc
0a80: 3b 0a 7d 0a 20 20 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  ;.}.  ..#-------
0a90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0aa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ab0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0ac0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
0ad0: 54 65 73 74 20 74 68 61 74 20 74 68 65 20 73 71  Test that the sq
0ae0: 6c 69 74 65 33 5f 62 75 73 79 5f 74 69 6d 65 6f  lite3_busy_timeo
0af0: 75 74 20 63 61 6c 6c 20 73 65 65 6d 73 20 74 6f  ut call seems to
0b00: 20 64 65 6c 61 79 20 61 70 70 72 6f 78 69 6d 61   delay approxima
0b10: 74 65 6c 79 0a 23 20 74 68 65 20 72 69 67 68 74  tely.# the right
0b20: 20 61 6d 6f 75 6e 74 20 6f 66 20 74 69 6d 65 2e   amount of time.
0b30: 0a 23 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 37  .#.do_test misc7
0b40: 2d 37 2e 30 20 7b 0a 20 20 73 71 6c 69 74 65 33  -7.0 {.  sqlite3
0b50: 20 64 62 32 20 74 65 73 74 2e 64 62 0a 20 20 73   db2 test.db.  s
0b60: 71 6c 69 74 65 33 5f 62 75 73 79 5f 74 69 6d 65  qlite3_busy_time
0b70: 6f 75 74 20 5b 73 71 6c 69 74 65 33 5f 63 6f 6e  out [sqlite3_con
0b80: 6e 65 63 74 69 6f 6e 5f 70 6f 69 6e 74 65 72 20  nection_pointer 
0b90: 64 62 5d 20 32 30 30 30 0a 20 20 65 78 65 63 73  db] 2000.  execs
0ba0: 71 6c 20 7b 0a 20 20 20 20 42 45 47 49 4e 20 45  ql {.    BEGIN E
0bb0: 58 43 4c 55 53 49 56 45 3b 0a 20 20 7d 20 64 62  XCLUSIVE;.  } db
0bc0: 32 0a 0a 20 20 23 20 4e 6f 77 20 64 62 32 20 68  2..  # Now db2 h
0bd0: 61 73 20 61 6e 20 65 78 63 6c 75 73 69 76 65 20  as an exclusive 
0be0: 6c 6f 63 6b 20 6f 6e 20 74 68 65 20 64 61 74 61  lock on the data
0bf0: 62 61 73 65 20 66 69 6c 65 2c 20 61 6e 64 20 64  base file, and d
0c00: 62 20 68 61 73 0a 20 20 23 20 61 20 62 75 73 79  b has.  # a busy
0c10: 2d 74 69 6d 65 6f 75 74 20 6f 66 20 32 30 30 30  -timeout of 2000
0c20: 20 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 2e 20 53   milliseconds. S
0c30: 6f 20 63 68 65 63 6b 20 74 68 61 74 20 74 72 79  o check that try
0c40: 69 6e 67 20 74 6f 0a 20 20 23 20 61 63 63 65 73  ing to.  # acces
0c50: 73 20 74 68 65 20 64 61 74 61 62 61 73 65 20 75  s the database u
0c60: 73 69 6e 67 20 63 6f 6e 6e 65 63 74 69 6f 6e 20  sing connection 
0c70: 64 62 20 64 65 6c 61 79 73 20 66 6f 72 20 61 74  db delays for at
0c80: 20 6c 65 61 73 74 20 31 35 30 30 20 6d 73 2e 0a   least 1500 ms..
0c90: 20 20 23 0a 20 20 73 65 74 20 74 6d 20 5b 74 69    #.  set tm [ti
0ca0: 6d 65 20 7b 0a 20 20 20 20 73 65 74 20 72 65 73  me {.    set res
0cb0: 75 6c 74 20 5b 63 61 74 63 68 73 71 6c 20 7b 0a  ult [catchsql {.
0cc0: 20 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 2a          SELECT *
0cd0: 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73   FROM sqlite_mas
0ce0: 74 65 72 3b 0a 20 20 20 20 20 20 7d 20 64 62 5d  ter;.      } db]
0cf0: 0a 20 20 7d 5d 0a 20 20 73 65 74 20 64 65 6c 61  .  }].  set dela
0d00: 79 20 5b 6c 69 6e 64 65 78 20 24 74 6d 20 30 5d  y [lindex $tm 0]
0d10: 20 20 3b 23 20 49 6e 20 6d 69 63 72 6f 73 65 63    ;# In microsec
0d20: 6f 6e 64 73 0a 20 20 6c 61 70 70 65 6e 64 20 72  onds.  lappend r
0d30: 65 73 75 6c 74 20 5b 65 78 70 72 20 7b 24 64 65  esult [expr {$de
0d40: 6c 61 79 3e 31 35 30 30 30 30 30 20 26 26 20 24  lay>1500000 && $
0d50: 64 65 6c 61 79 3c 34 30 30 30 30 30 30 7d 5d 0a  delay<4000000}].
0d60: 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20 69  } {1 {database i
0d70: 73 20 6c 6f 63 6b 65 64 7d 20 31 7d 0a 64 62 32  s locked} 1}.db2
0d80: 20 63 6c 6f 73 65 0a 0a 23 2d 2d 2d 2d 2d 2d 2d   close..#-------
0d90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0da0: 2d 2d 2d 2d 2d 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 0a 23 20  -------------.# 
0dd0: 54 65 73 74 20 74 68 61 74 20 6e 6f 74 68 69 6e  Test that nothin
0de0: 67 20 67 6f 65 73 20 68 6f 72 72 69 62 6c 79 20  g goes horribly 
0df0: 77 72 6f 6e 67 20 77 68 65 6e 20 61 74 74 61 63  wrong when attac
0e00: 68 69 6e 67 20 61 20 64 61 74 61 62 61 73 65 0a  hing a database.
0e10: 23 20 61 66 74 65 72 20 74 68 65 20 6f 6d 69 74  # after the omit
0e20: 5f 72 65 61 64 6c 6f 63 6b 20 70 72 61 67 6d 61  _readlock pragma
0e30: 20 68 61 73 20 62 65 65 6e 20 65 78 65 72 63 69   has been exerci
0e40: 73 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 6d  sed..#.do_test m
0e50: 69 73 63 37 2d 37 2e 31 20 7b 0a 20 20 66 69 6c  isc7-7.1 {.  fil
0e60: 65 20 64 65 6c 65 74 65 20 2d 66 6f 72 63 65 20  e delete -force 
0e70: 74 65 73 74 32 2e 64 62 0a 20 20 66 69 6c 65 20  test2.db.  file 
0e80: 64 65 6c 65 74 65 20 2d 66 6f 72 63 65 20 74 65  delete -force te
0e90: 73 74 32 2e 64 62 2d 6a 6f 75 72 6e 61 6c 0a 20  st2.db-journal. 
0ea0: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 50   execsql {.    P
0eb0: 52 41 47 4d 41 20 6f 6d 69 74 5f 72 65 61 64 6c  RAGMA omit_readl
0ec0: 6f 63 6b 20 3d 20 31 3b 0a 20 20 20 20 41 54 54  ock = 1;.    ATT
0ed0: 41 43 48 20 27 74 65 73 74 32 2e 64 62 27 20 41  ACH 'test2.db' A
0ee0: 53 20 61 75 78 3b 0a 20 20 20 20 43 52 45 41 54  S aux;.    CREAT
0ef0: 45 20 54 41 42 4c 45 20 61 75 78 2e 68 65 6c 6c  E TABLE aux.hell
0f00: 6f 28 77 6f 72 6c 64 29 3b 0a 20 20 20 20 53 45  o(world);.    SE
0f10: 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f 4d 20 61  LECT name FROM a
0f20: 75 78 2e 73 71 6c 69 74 65 5f 6d 61 73 74 65 72  ux.sqlite_master
0f30: 3b 0a 20 20 7d 0a 7d 20 7b 68 65 6c 6c 6f 7d 0a  ;.  }.} {hello}.
0f40: 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 37 2e  do_test misc7-7.
0f50: 32 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  2 {.  execsql {.
0f60: 20 20 20 20 44 45 54 41 43 48 20 61 75 78 3b 0a      DETACH aux;.
0f70: 20 20 7d 0a 7d 20 7b 7d 0a 0a 23 20 54 65 73 74    }.} {}..# Test
0f80: 20 74 68 65 20 55 54 46 2d 31 36 20 76 65 72 73   the UTF-16 vers
0f90: 69 6f 6e 20 6f 66 20 74 68 65 20 22 6f 75 74 20  ion of the "out 
0fa0: 6f 66 20 6d 65 6d 6f 72 79 22 20 6d 65 73 73 61  of memory" messa
0fb0: 67 65 20 28 75 73 65 64 20 77 68 65 6e 0a 23 20  ge (used when.# 
0fc0: 6d 61 6c 6c 6f 63 20 66 61 69 6c 73 20 64 75 72  malloc fails dur
0fd0: 69 6e 67 20 73 71 6c 69 74 65 33 5f 6f 70 65 6e  ing sqlite3_open
0fe0: 28 29 20 29 2e 0a 23 0a 69 66 63 61 70 61 62 6c  () )..#.ifcapabl
0ff0: 65 20 75 74 66 31 36 20 7b 0a 20 20 64 6f 5f 74  e utf16 {.  do_t
1000: 65 73 74 20 6d 69 73 63 37 2d 38 20 7b 0a 20 20  est misc7-8 {.  
1010: 20 20 65 6e 63 6f 64 69 6e 67 20 63 6f 6e 76 65    encoding conve
1020: 72 74 66 72 6f 6d 20 75 6e 69 63 6f 64 65 20 5b  rtfrom unicode [
1030: 73 71 6c 69 74 65 33 5f 65 72 72 6d 73 67 31 36  sqlite3_errmsg16
1040: 20 30 78 30 30 30 30 30 30 30 30 5d 0a 20 20 7d   0x00000000].  }
1050: 20 7b 6f 75 74 20 6f 66 20 6d 65 6d 6f 72 79 7d   {out of memory}
1060: 0a 7d 0a 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63  .}..do_test misc
1070: 37 2d 39 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  7-9 {.  execsql 
1080: 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 2a 20 0a  {.    SELECT * .
1090: 20 20 20 20 46 52 4f 4d 20 28 53 45 4c 45 43 54      FROM (SELECT
10a0: 20 6e 61 6d 65 2b 31 20 41 53 20 6f 6e 65 20 46   name+1 AS one F
10b0: 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65  ROM sqlite_maste
10c0: 72 20 4c 49 4d 49 54 20 31 20 4f 46 46 53 45 54  r LIMIT 1 OFFSET
10d0: 20 31 29 20 0a 20 20 20 20 57 48 45 52 45 20 6f   1) .    WHERE o
10e0: 6e 65 20 4c 49 4b 45 20 27 68 65 6c 6c 6f 25 27  ne LIKE 'hello%'
10f0: 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 23 2d 2d 2d  ;.  }.} {}..#---
1100: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1110: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1120: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1130: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1140: 2d 0a 23 20 49 6d 70 72 6f 76 65 20 63 6f 76 65  -.# Improve cove
1150: 72 61 67 65 20 66 6f 72 20 76 74 61 62 20 63 6f  rage for vtab co
1160: 64 65 2e 0a 23 0a 69 66 63 61 70 61 62 6c 65 20  de..#.ifcapable 
1170: 76 74 61 62 20 7b 0a 20 20 23 20 52 75 6e 20 73  vtab {.  # Run s
1180: 6f 6d 65 20 64 65 62 75 67 20 63 6f 64 65 20 74  ome debug code t
1190: 6f 20 69 6d 70 72 6f 76 65 20 72 65 70 6f 72 74  o improve report
11a0: 65 64 20 63 6f 76 65 72 61 67 65 0a 20 20 23 0a  ed coverage.  #.
11b0: 0a 20 20 23 20 73 65 74 20 73 71 6c 69 74 65 5f  .  # set sqlite_
11c0: 77 68 65 72 65 5f 74 72 61 63 65 20 31 0a 20 20  where_trace 1.  
11d0: 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 30  do_test misc7-10
11e0: 20 7b 0a 20 20 20 20 72 65 67 69 73 74 65 72 5f   {.    register_
11f0: 65 63 68 6f 5f 6d 6f 64 75 6c 65 20 5b 73 71 6c  echo_module [sql
1200: 69 74 65 33 5f 63 6f 6e 6e 65 63 74 69 6f 6e 5f  ite3_connection_
1210: 70 6f 69 6e 74 65 72 20 64 62 5d 0a 20 20 20 20  pointer db].    
1220: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20 20  execsql {.      
1230: 43 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54  CREATE VIRTUAL T
1240: 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20 65 63  ABLE t1 USING ec
1250: 68 6f 28 61 62 63 29 3b 0a 20 20 20 20 20 20 53  ho(abc);.      S
1260: 45 4c 45 43 54 20 61 20 46 52 4f 4d 20 74 31 20  ELECT a FROM t1 
1270: 57 48 45 52 45 20 61 20 3d 20 31 20 4f 52 44 45  WHERE a = 1 ORDE
1280: 52 20 42 59 20 62 3b 0a 20 20 20 20 7d 0a 20 20  R BY b;.    }.  
1290: 7d 20 7b 31 7d 0a 20 20 73 65 74 20 73 71 6c 69  } {1}.  set sqli
12a0: 74 65 5f 77 68 65 72 65 5f 74 72 61 63 65 20 30  te_where_trace 0
12b0: 0a 0a 20 20 23 20 53 70 65 63 69 66 79 20 61 6e  ..  # Specify an
12c0: 20 4f 52 44 45 52 20 42 59 20 63 6c 61 75 73 65   ORDER BY clause
12d0: 20 74 68 61 74 20 63 61 6e 6e 6f 74 20 62 65 20   that cannot be 
12e0: 69 6e 64 65 78 65 64 2e 0a 20 20 64 6f 5f 74 65  indexed..  do_te
12f0: 73 74 20 6d 69 73 63 37 2d 31 31 20 7b 0a 20 20  st misc7-11 {.  
1300: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
1310: 20 20 53 45 4c 45 43 54 20 74 31 2e 61 2c 20 74    SELECT t1.a, t
1320: 32 2e 61 20 46 52 4f 4d 20 74 31 2c 20 74 31 20  2.a FROM t1, t1 
1330: 41 53 20 74 32 20 4f 52 44 45 52 20 42 59 20 32  AS t2 ORDER BY 2
1340: 20 4c 49 4d 49 54 20 31 3b 0a 20 20 20 20 7d 0a   LIMIT 1;.    }.
1350: 20 20 7d 20 7b 31 20 31 7d 0a 0a 20 20 23 20 54    } {1 1}..  # T
1360: 68 65 20 77 68 6f 6c 65 20 70 6f 69 6e 74 20 6f  he whole point o
1370: 66 20 74 68 69 73 20 69 73 20 74 6f 20 74 65 73  f this is to tes
1380: 74 20 61 6e 20 65 72 72 6f 72 20 63 6f 64 65 20  t an error code 
1390: 6f 74 68 65 72 20 74 68 61 6e 0a 20 20 23 20 53  other than.  # S
13a0: 51 4c 49 54 45 5f 4e 4f 4d 45 4d 20 66 72 6f 6d  QLITE_NOMEM from
13b0: 20 74 68 65 20 76 74 61 62 20 78 42 65 73 74 49   the vtab xBestI
13c0: 6e 64 65 78 20 63 61 6c 6c 62 61 63 6b 2e 0a 20  ndex callback.. 
13d0: 20 23 0a 20 20 64 6f 5f 69 6f 65 72 72 5f 74 65   #.  do_ioerr_te
13e0: 73 74 20 6d 69 73 63 37 2d 31 32 20 2d 74 63 6c  st misc7-12 -tcl
13f0: 70 72 65 70 20 7b 0a 20 20 20 20 73 71 6c 69 74  prep {.    sqlit
1400: 65 33 20 64 62 32 20 74 65 73 74 2e 64 62 0a 20  e3 db2 test.db. 
1410: 20 20 20 72 65 67 69 73 74 65 72 5f 65 63 68 6f     register_echo
1420: 5f 6d 6f 64 75 6c 65 20 5b 73 71 6c 69 74 65 33  _module [sqlite3
1430: 5f 63 6f 6e 6e 65 63 74 69 6f 6e 5f 70 6f 69 6e  _connection_poin
1440: 74 65 72 20 64 62 32 5d 0a 20 20 20 20 64 62 32  ter db2].    db2
1450: 20 65 76 61 6c 20 7b 0a 20 20 20 20 20 20 43 52   eval {.      CR
1460: 45 41 54 45 20 54 41 42 4c 45 20 61 62 63 28 61  EATE TABLE abc(a
1470: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 2c   PRIMARY KEY, b,
1480: 20 63 29 3b 0a 20 20 20 20 20 20 49 4e 53 45 52   c);.      INSER
1490: 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55 45  T INTO abc VALUE
14a0: 53 28 31 2c 20 32 2c 20 33 29 3b 0a 20 20 20 20  S(1, 2, 3);.    
14b0: 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41 4c    CREATE VIRTUAL
14c0: 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47 20   TABLE t1 USING 
14d0: 65 63 68 6f 28 61 62 63 29 3b 0a 20 20 20 20 7d  echo(abc);.    }
14e0: 0a 20 20 20 20 64 62 32 20 63 6c 6f 73 65 0a 20  .    db2 close. 
14f0: 20 7d 20 2d 74 63 6c 62 6f 64 79 20 7b 0a 20 20   } -tclbody {.  
1500: 20 20 72 65 67 69 73 74 65 72 5f 65 63 68 6f 5f    register_echo_
1510: 6d 6f 64 75 6c 65 20 5b 73 71 6c 69 74 65 33 5f  module [sqlite3_
1520: 63 6f 6e 6e 65 63 74 69 6f 6e 5f 70 6f 69 6e 74  connection_point
1530: 65 72 20 64 62 5d 0a 20 20 20 20 65 78 65 63 73  er db].    execs
1540: 71 6c 20 7b 53 45 4c 45 43 54 20 2a 20 46 52 4f  ql {SELECT * FRO
1550: 4d 20 74 31 20 57 48 45 52 45 20 61 20 3d 20 31  M t1 WHERE a = 1
1560: 3b 7d 0a 20 20 7d 20 0a 0a 20 20 23 20 54 68 65  ;}.  } ..  # The
1570: 20 63 61 73 65 20 77 68 65 72 65 20 74 68 65 20   case where the 
1580: 76 69 72 74 75 61 6c 20 74 61 62 6c 65 20 6d 6f  virtual table mo
1590: 64 75 6c 65 20 72 65 74 75 72 6e 73 20 61 20 76  dule returns a v
15a0: 65 72 79 20 6c 61 72 67 65 20 6e 75 6d 62 65 72  ery large number
15b0: 0a 20 20 23 20 61 73 20 74 68 65 20 63 6f 73 74  .  # as the cost
15c0: 20 6f 66 20 61 20 73 63 61 6e 20 28 67 72 65 61   of a scan (grea
15d0: 74 65 72 20 74 68 61 6e 20 53 51 4c 49 54 45 5f  ter than SQLITE_
15e0: 42 49 47 5f 44 4f 55 42 4c 45 20 69 6e 20 74 68  BIG_DOUBLE in th
15f0: 65 20 63 6f 64 65 29 2e 0a 20 20 23 0a 20 20 64  e code)..  #.  d
1600: 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 33 20  o_test misc7-13 
1610: 7b 0a 20 20 20 20 73 71 6c 69 74 65 33 20 64 62  {.    sqlite3 db
1620: 20 74 65 73 74 2e 64 62 0a 20 20 20 20 72 65 67   test.db.    reg
1630: 69 73 74 65 72 5f 65 63 68 6f 5f 6d 6f 64 75 6c  ister_echo_modul
1640: 65 20 5b 73 71 6c 69 74 65 33 5f 63 6f 6e 6e 65  e [sqlite3_conne
1650: 63 74 69 6f 6e 5f 70 6f 69 6e 74 65 72 20 64 62  ction_pointer db
1660: 5d 0a 20 20 20 20 73 65 74 20 3a 3a 65 63 68 6f  ].    set ::echo
1670: 5f 6d 6f 64 75 6c 65 5f 63 6f 73 74 20 32 2e 30  _module_cost 2.0
1680: 65 2b 39 39 0a 20 20 20 20 65 78 65 63 73 71 6c  e+99.    execsql
1690: 20 7b 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20   {SELECT * FROM 
16a0: 74 31 20 57 48 45 52 45 20 61 20 3d 20 31 3b 7d  t1 WHERE a = 1;}
16b0: 0a 20 20 7d 20 7b 31 20 32 20 33 7d 0a 20 20 75  .  } {1 2 3}.  u
16c0: 6e 73 65 74 20 3a 3a 65 63 68 6f 5f 6d 6f 64 75  nset ::echo_modu
16d0: 6c 65 5f 63 6f 73 74 0a 7d 0a 0a 64 62 20 63 6c  le_cost.}..db cl
16e0: 6f 73 65 0a 66 69 6c 65 20 64 65 6c 65 74 65 20  ose.file delete 
16f0: 2d 66 6f 72 63 65 20 74 65 73 74 2e 64 62 0a 66  -force test.db.f
1700: 69 6c 65 20 64 65 6c 65 74 65 20 2d 66 6f 72 63  ile delete -forc
1710: 65 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61  e test.db-journa
1720: 6c 0a 73 71 6c 69 74 65 33 20 64 62 20 74 65 73  l.sqlite3 db tes
1730: 74 2e 64 62 0a 0a 69 66 63 61 70 61 62 6c 65 20  t.db..ifcapable 
1740: 65 78 70 6c 61 69 6e 20 7b 0a 20 20 64 6f 5f 74  explain {.  do_t
1750: 65 73 74 20 6d 69 73 63 37 2d 31 34 20 7b 0a 20  est misc7-14 {. 
1760: 20 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20     execsql {.   
1770: 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20     CREATE TABLE 
1780: 61 62 63 28 61 20 50 52 49 4d 41 52 59 20 4b 45  abc(a PRIMARY KE
1790: 59 2c 20 62 2c 20 63 29 3b 0a 20 20 20 20 7d 0a  Y, b, c);.    }.
17a0: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20      execsql {.  
17b0: 20 20 20 20 45 58 50 4c 41 49 4e 20 51 55 45 52      EXPLAIN QUER
17c0: 59 20 50 4c 41 4e 20 53 45 4c 45 43 54 20 2a 20  Y PLAN SELECT * 
17d0: 46 52 4f 4d 20 61 62 63 20 41 53 20 74 32 20 57  FROM abc AS t2 W
17e0: 48 45 52 45 20 72 6f 77 69 64 20 3d 20 31 3b 0a  HERE rowid = 1;.
17f0: 20 20 20 20 7d 0a 20 20 7d 20 7b 30 20 30 20 7b      }.  } {0 0 {
1800: 54 41 42 4c 45 20 61 62 63 20 41 53 20 74 32 20  TABLE abc AS t2 
1810: 55 53 49 4e 47 20 50 52 49 4d 41 52 59 20 4b 45  USING PRIMARY KE
1820: 59 7d 7d 0a 20 20 64 6f 5f 74 65 73 74 20 6d 69  Y}}.  do_test mi
1830: 73 63 37 2d 31 35 20 7b 0a 20 20 20 20 65 78 65  sc7-15 {.    exe
1840: 63 73 71 6c 20 7b 0a 20 20 20 20 20 20 45 58 50  csql {.      EXP
1850: 4c 41 49 4e 20 51 55 45 52 59 20 50 4c 41 4e 20  LAIN QUERY PLAN 
1860: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 62  SELECT * FROM ab
1870: 63 20 41 53 20 74 32 20 57 48 45 52 45 20 61 20  c AS t2 WHERE a 
1880: 3d 20 31 3b 0a 20 20 20 20 7d 0a 20 20 7d 20 7b  = 1;.    }.  } {
1890: 30 20 30 20 7b 54 41 42 4c 45 20 61 62 63 20 41  0 0 {TABLE abc A
18a0: 53 20 74 32 20 57 49 54 48 20 49 4e 44 45 58 20  S t2 WITH INDEX 
18b0: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78  sqlite_autoindex
18c0: 5f 61 62 63 5f 31 7d 7d 0a 7d 0a 0a 64 62 20 63  _abc_1}}.}..db c
18d0: 6c 6f 73 65 0a 66 69 6c 65 20 64 65 6c 65 74 65  lose.file delete
18e0: 20 2d 66 6f 72 63 65 20 74 65 73 74 2e 64 62 0a   -force test.db.
18f0: 66 69 6c 65 20 64 65 6c 65 74 65 20 2d 66 6f 72  file delete -for
1900: 63 65 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e  ce test.db-journ
1910: 61 6c 0a 73 71 6c 69 74 65 33 20 64 62 20 74 65  al.sqlite3 db te
1920: 73 74 2e 64 62 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d  st.db..#--------
1930: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1940: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1950: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1960: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54  ------------.# T
1970: 68 69 73 20 69 73 20 61 6c 6c 20 74 6f 20 66 6f  his is all to fo
1980: 72 63 65 20 74 68 65 20 70 61 67 65 72 5f 72 65  rce the pager_re
1990: 6d 6f 76 65 5f 66 72 6f 6d 5f 73 74 6d 74 5f 6c  move_from_stmt_l
19a0: 69 73 74 28 29 20 66 75 6e 63 74 69 6f 6e 0a 23  ist() function.#
19b0: 20 28 69 6e 73 69 64 65 20 70 61 67 65 72 2e 63   (inside pager.c
19c0: 29 20 74 6f 20 72 65 6d 6f 76 65 20 61 20 70 61  ) to remove a pa
19d0: 67 65 72 20 66 72 6f 6d 20 74 68 65 20 6d 69 64  ger from the mid
19e0: 64 6c 65 20 6f 66 20 74 68 65 0a 23 20 73 74 61  dle of the.# sta
19f0: 74 65 6d 65 6e 74 2d 6c 69 73 74 2e 0a 23 0a 64  tement-list..#.d
1a00: 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 35 2e  o_test misc7-15.
1a10: 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  1 {.  execsql {.
1a20: 20 20 20 20 50 52 41 47 4d 41 20 63 61 63 68 65      PRAGMA cache
1a30: 5f 73 69 7a 65 20 3d 20 31 30 3b 0a 20 20 20 20  _size = 10;.    
1a40: 42 45 47 49 4e 3b 0a 20 20 20 20 43 52 45 41 54  BEGIN;.    CREAT
1a50: 45 20 54 41 42 4c 45 20 61 62 63 28 61 20 50 52  E TABLE abc(a PR
1a60: 49 4d 41 52 59 20 4b 45 59 2c 20 62 2c 20 63 29  IMARY KEY, b, c)
1a70: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
1a80: 4f 20 61 62 63 20 0a 20 20 20 20 56 41 4c 55 45  O abc .    VALUE
1a90: 53 28 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30  S(randstr(100,10
1aa0: 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c  0), randstr(100,
1ab0: 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30  100), randstr(10
1ac0: 30 2c 31 30 30 29 29 3b 0a 20 20 20 20 49 4e 53  0,100));.    INS
1ad0: 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c  ERT INTO abc SEL
1ae0: 45 43 54 20 0a 20 20 20 20 20 20 20 20 20 20 20  ECT .           
1af0: 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30   randstr(100,100
1b00: 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31  ), randstr(100,1
1b10: 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30  00), randstr(100
1b20: 2c 31 30 30 29 20 46 52 4f 4d 20 61 62 63 3b 0a  ,100) FROM abc;.
1b30: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
1b40: 61 62 63 20 53 45 4c 45 43 54 20 0a 20 20 20 20  abc SELECT .    
1b50: 20 20 20 20 20 20 20 20 72 61 6e 64 73 74 72 28          randstr(
1b60: 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64 73 74  100,100), randst
1b70: 72 28 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64  r(100,100), rand
1b80: 73 74 72 28 31 30 30 2c 31 30 30 29 20 46 52 4f  str(100,100) FRO
1b90: 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e 53 45 52  M abc;.    INSER
1ba0: 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43  T INTO abc SELEC
1bb0: 54 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 72  T .            r
1bc0: 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29 2c  andstr(100,100),
1bd0: 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30   randstr(100,100
1be0: 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31  ), randstr(100,1
1bf0: 30 30 29 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20  00) FROM abc;.  
1c00: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62    INSERT INTO ab
1c10: 63 20 53 45 4c 45 43 54 20 0a 20 20 20 20 20 20  c SELECT .      
1c20: 20 20 20 20 20 20 72 61 6e 64 73 74 72 28 31 30        randstr(10
1c30: 30 2c 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28  0,100), randstr(
1c40: 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64 73 74  100,100), randst
1c50: 72 28 31 30 30 2c 31 30 30 29 20 46 52 4f 4d 20  r(100,100) FROM 
1c60: 61 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20  abc;.    INSERT 
1c70: 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20  INTO abc SELECT 
1c80: 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 61 6e  .            ran
1c90: 64 73 74 72 28 31 30 30 2c 31 30 30 29 2c 20 72  dstr(100,100), r
1ca0: 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29 2c  andstr(100,100),
1cb0: 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30   randstr(100,100
1cc0: 29 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20  ) FROM abc;.    
1cd0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20  INSERT INTO abc 
1ce0: 53 45 4c 45 43 54 20 0a 20 20 20 20 20 20 20 20  SELECT .        
1cf0: 20 20 20 20 72 61 6e 64 73 74 72 28 31 30 30 2c      randstr(100,
1d00: 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30  100), randstr(10
1d10: 30 2c 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28  0,100), randstr(
1d20: 31 30 30 2c 31 30 30 29 20 46 52 4f 4d 20 61 62  100,100) FROM ab
1d30: 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  c;.    INSERT IN
1d40: 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 0a 20  TO abc SELECT . 
1d50: 20 20 20 20 20 20 20 20 20 20 20 72 61 6e 64 73             rands
1d60: 74 72 28 31 30 30 2c 31 30 30 29 2c 20 72 61 6e  tr(100,100), ran
1d70: 64 73 74 72 28 31 30 30 2c 31 30 30 29 2c 20 72  dstr(100,100), r
1d80: 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29 20  andstr(100,100) 
1d90: 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e  FROM abc;.    IN
1da0: 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45  SERT INTO abc SE
1db0: 4c 45 43 54 20 0a 20 20 20 20 20 20 20 20 20 20  LECT .          
1dc0: 20 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30    randstr(100,10
1dd0: 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c  0), randstr(100,
1de0: 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30  100), randstr(10
1df0: 30 2c 31 30 30 29 20 46 52 4f 4d 20 61 62 63 3b  0,100) FROM abc;
1e00: 0a 20 20 20 20 43 4f 4d 4d 49 54 3b 0a 20 20 7d  .    COMMIT;.  }
1e10: 0a 20 20 65 78 70 72 20 7b 5b 66 69 6c 65 20 73  .  expr {[file s
1e20: 69 7a 65 20 74 65 73 74 2e 64 62 5d 3e 31 30 32  ize test.db]>102
1e30: 34 30 7d 0a 7d 20 7b 31 7d 0a 64 6f 5f 74 65 73  40}.} {1}.do_tes
1e40: 74 20 6d 69 73 63 37 2d 31 35 2e 32 20 7b 0a 20  t misc7-15.2 {. 
1e50: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 44   execsql {.    D
1e60: 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63 20 57  ELETE FROM abc W
1e70: 48 45 52 45 20 72 6f 77 69 64 20 3e 20 31 32 3b  HERE rowid > 12;
1e80: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
1e90: 20 61 62 63 20 53 45 4c 45 43 54 20 0a 20 20 20   abc SELECT .   
1ea0: 20 20 20 20 20 20 20 20 20 72 61 6e 64 73 74 72           randstr
1eb0: 28 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64 73  (100,100), rands
1ec0: 74 72 28 31 30 30 2c 31 30 30 29 2c 20 72 61 6e  tr(100,100), ran
1ed0: 64 73 74 72 28 31 30 30 2c 31 30 30 29 20 46 52  dstr(100,100) FR
1ee0: 4f 4d 20 61 62 63 3b 0a 20 20 7d 0a 7d 20 7b 7d  OM abc;.  }.} {}
1ef0: 0a 0a 64 62 20 63 6c 6f 73 65 0a 66 69 6c 65 20  ..db close.file 
1f00: 64 65 6c 65 74 65 20 2d 66 6f 72 63 65 20 74 65  delete -force te
1f10: 73 74 2e 64 62 0a 66 69 6c 65 20 64 65 6c 65 74  st.db.file delet
1f20: 65 20 2d 66 6f 72 63 65 20 74 65 73 74 2e 64 62  e -force test.db
1f30: 2d 6a 6f 75 72 6e 61 6c 0a 73 71 6c 69 74 65 33  -journal.sqlite3
1f40: 20 64 62 20 74 65 73 74 2e 64 62 0a 0a 64 6f 5f   db test.db..do_
1f50: 69 6f 65 72 72 5f 74 65 73 74 20 6d 69 73 63 37  ioerr_test misc7
1f60: 2d 31 36 20 2d 73 71 6c 70 72 65 70 20 7b 0a 20  -16 -sqlprep {. 
1f70: 20 20 50 52 41 47 4d 41 20 63 61 63 68 65 5f 73    PRAGMA cache_s
1f80: 69 7a 65 20 3d 20 31 30 3b 0a 20 20 20 50 52 41  ize = 10;.   PRA
1f90: 47 4d 41 20 64 65 66 61 75 6c 74 5f 63 61 63 68  GMA default_cach
1fa0: 65 5f 73 69 7a 65 20 3d 20 31 30 3b 0a 20 20 20  e_size = 10;.   
1fb0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 33 28  CREATE TABLE t3(
1fc0: 61 2c 20 62 2c 20 55 4e 49 51 55 45 28 61 2c 20  a, b, UNIQUE(a, 
1fd0: 62 29 29 3b 0a 20 20 20 49 4e 53 45 52 54 20 49  b));.   INSERT I
1fe0: 4e 54 4f 20 74 33 20 56 41 4c 55 45 53 28 20 72  NTO t3 VALUES( r
1ff0: 61 6e 64 73 74 72 28 31 30 30 2c 20 31 30 30 29  andstr(100, 100)
2000: 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c 20 31  , randstr(100, 1
2010: 30 30 29 20 29 3b 0a 20 20 20 49 4e 53 45 52 54  00) );.   INSERT
2020: 20 49 4e 54 4f 20 74 33 20 53 45 4c 45 43 54 20   INTO t3 SELECT 
2030: 72 61 6e 64 73 74 72 28 31 30 30 2c 20 31 30 30  randstr(100, 100
2040: 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c 20  ), randstr(100, 
2050: 31 30 30 29 20 46 52 4f 4d 20 74 33 3b 0a 20 20  100) FROM t3;.  
2060: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 33 20   INSERT INTO t3 
2070: 53 45 4c 45 43 54 20 72 61 6e 64 73 74 72 28 31  SELECT randstr(1
2080: 30 30 2c 20 31 30 30 29 2c 20 72 61 6e 64 73 74  00, 100), randst
2090: 72 28 31 30 30 2c 20 31 30 30 29 20 46 52 4f 4d  r(100, 100) FROM
20a0: 20 74 33 3b 0a 20 20 20 49 4e 53 45 52 54 20 49   t3;.   INSERT I
20b0: 4e 54 4f 20 74 33 20 53 45 4c 45 43 54 20 72 61  NTO t3 SELECT ra
20c0: 6e 64 73 74 72 28 31 30 30 2c 20 31 30 30 29 2c  ndstr(100, 100),
20d0: 20 72 61 6e 64 73 74 72 28 31 30 30 2c 20 31 30   randstr(100, 10
20e0: 30 29 20 46 52 4f 4d 20 74 33 3b 0a 20 20 20 49  0) FROM t3;.   I
20f0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 33 20 53 45  NSERT INTO t3 SE
2100: 4c 45 43 54 20 72 61 6e 64 73 74 72 28 31 30 30  LECT randstr(100
2110: 2c 20 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28  , 100), randstr(
2120: 31 30 30 2c 20 31 30 30 29 20 46 52 4f 4d 20 74  100, 100) FROM t
2130: 33 3b 0a 20 20 20 49 4e 53 45 52 54 20 49 4e 54  3;.   INSERT INT
2140: 4f 20 74 33 20 53 45 4c 45 43 54 20 72 61 6e 64  O t3 SELECT rand
2150: 73 74 72 28 31 30 30 2c 20 31 30 30 29 2c 20 72  str(100, 100), r
2160: 61 6e 64 73 74 72 28 31 30 30 2c 20 31 30 30 29  andstr(100, 100)
2170: 20 46 52 4f 4d 20 74 33 3b 0a 20 20 20 55 50 44   FROM t3;.   UPD
2180: 41 54 45 20 74 33 20 0a 20 20 20 53 45 54 20 62  ATE t3 .   SET b
2190: 20 3d 20 27 68 65 6c 6c 6f 20 77 6f 72 6c 64 27   = 'hello world'
21a0: 0a 20 20 20 57 48 45 52 45 20 72 6f 77 69 64 20  .   WHERE rowid 
21b0: 3e 3d 20 28 53 45 4c 45 43 54 20 6d 61 78 28 72  >= (SELECT max(r
21c0: 6f 77 69 64 29 2d 31 20 46 52 4f 4d 20 74 33 29  owid)-1 FROM t3)
21d0: 3b 0a 7d 20 2d 74 63 6c 62 6f 64 79 20 7b 0a 20  ;.} -tclbody {. 
21e0: 20 73 65 74 20 72 63 20 5b 63 61 74 63 68 20 7b   set rc [catch {
21f0: 64 62 20 65 76 61 6c 20 7b 0a 20 20 20 20 42 45  db eval {.    BE
2200: 47 49 4e 3b 0a 20 20 20 20 20 20 50 52 41 47 4d  GIN;.      PRAGM
2210: 41 20 63 61 63 68 65 5f 73 69 7a 65 20 3d 20 31  A cache_size = 1
2220: 30 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20  0;.      INSERT 
2230: 49 4e 54 4f 20 74 33 20 56 41 4c 55 45 53 28 20  INTO t3 VALUES( 
2240: 72 61 6e 64 73 74 72 28 31 30 30 2c 20 31 30 30  randstr(100, 100
2250: 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c 20  ), randstr(100, 
2260: 31 30 30 29 20 29 3b 0a 20 20 20 20 20 20 55 50  100) );.      UP
2270: 44 41 54 45 20 74 33 20 53 45 54 20 61 20 3d 20  DATE t3 SET a = 
2280: 62 3b 0a 20 20 20 20 43 4f 4d 4d 49 54 3b 0a 20  b;.    COMMIT;. 
2290: 20 7d 7d 20 6d 73 67 5d 0a 0a 20 20 69 66 20 7b   }} msg]..  if {
22a0: 21 24 72 63 20 7c 7c 20 28 24 72 63 20 26 26 20  !$rc || ($rc && 
22b0: 5b 73 74 72 69 6e 67 20 66 69 72 73 74 20 22 63  [string first "c
22c0: 6f 6c 75 6d 6e 73 22 20 24 6d 73 67 5d 3d 3d 30  olumns" $msg]==0
22d0: 29 7d 20 7b 0a 20 20 20 20 73 65 74 20 6d 73 67  )} {.    set msg
22e0: 0a 20 20 7d 20 65 6c 73 65 20 7b 0a 20 20 20 20  .  } else {.    
22f0: 65 72 72 6f 72 20 24 6d 73 67 0a 20 20 7d 0a 7d  error $msg.  }.}
2300: 0a 0a 73 71 6c 69 74 65 33 20 64 62 20 74 65 73  ..sqlite3 db tes
2310: 74 2e 64 62 0a 0a 64 6f 5f 74 65 73 74 20 6d 69  t.db..do_test mi
2320: 73 63 37 2d 31 36 2e 58 20 7b 0a 20 20 65 78 65  sc7-16.X {.  exe
2330: 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43  csql {.    SELEC
2340: 54 20 63 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20  T count(*) FROM 
2350: 74 33 3b 0a 20 20 7d 0a 7d 20 7b 33 32 7d 0a 0a  t3;.  }.} {32}..
2360: 73 65 74 20 73 71 6c 69 74 65 5f 70 61 67 65 72  set sqlite_pager
2370: 5f 6e 5f 73 6f 72 74 5f 62 75 63 6b 65 74 20 34  _n_sort_bucket 4
2380: 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 31  .do_test misc7-1
2390: 37 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  7 {.  execsql {.
23a0: 20 20 20 20 50 52 41 47 4d 41 20 69 6e 74 65 67      PRAGMA integ
23b0: 72 69 74 79 5f 63 68 65 63 6b 3b 0a 20 20 20 20  rity_check;.    
23c0: 56 41 43 55 55 4d 3b 0a 20 20 20 20 50 52 41 47  VACUUM;.    PRAG
23d0: 4d 41 20 69 6e 74 65 67 72 69 74 79 5f 63 68 65  MA integrity_che
23e0: 63 6b 3b 0a 20 20 7d 0a 7d 20 7b 6f 6b 20 6f 6b  ck;.  }.} {ok ok
23f0: 7d 0a 73 65 74 20 73 71 6c 69 74 65 5f 70 61 67  }.set sqlite_pag
2400: 65 72 5f 6e 5f 73 6f 72 74 5f 62 75 63 6b 65 74  er_n_sort_bucket
2410: 20 30 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   0..#-----------
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 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65  -----------.# Te
2460: 73 74 20 74 68 65 20 73 69 74 75 61 74 69 6f 6e  st the situation
2470: 20 77 68 65 72 65 20 61 20 68 6f 74 2d 6a 6f 75   where a hot-jou
2480: 72 6e 61 6c 20 69 73 20 64 69 73 63 6f 76 65 72  rnal is discover
2490: 65 64 20 62 75 74 20 77 72 69 74 65 2d 61 63 63  ed but write-acc
24a0: 65 73 73 0a 23 20 74 6f 20 69 74 20 69 73 20 64  ess.# to it is d
24b0: 65 6e 69 65 64 2e 20 54 68 69 73 20 73 68 6f 75  enied. This shou
24c0: 6c 64 20 72 65 74 75 72 6e 20 53 51 4c 49 54 45  ld return SQLITE
24d0: 5f 42 55 53 59 2e 0a 23 0a 23 20 54 68 65 73 65  _BUSY..#.# These
24e0: 20 74 65 73 74 73 20 64 6f 20 6e 6f 74 20 77 6f   tests do not wo
24f0: 72 6b 20 6f 6e 20 77 69 6e 64 6f 77 73 20 64 75  rk on windows du
2500: 65 20 74 6f 20 72 65 73 74 72 69 63 74 69 6f 6e  e to restriction
2510: 73 20 69 6e 20 74 68 65 0a 23 20 77 69 6e 64 6f  s in the.# windo
2520: 77 73 20 66 69 6c 65 20 73 79 73 74 65 6d 2e 0a  ws file system..
2530: 23 0a 69 66 20 7b 24 74 63 6c 5f 70 6c 61 74 66  #.if {$tcl_platf
2540: 6f 72 6d 28 70 6c 61 74 66 6f 72 6d 29 21 3d 22  orm(platform)!="
2550: 77 69 6e 64 6f 77 73 22 7d 20 7b 0a 64 6f 5f 74  windows"} {.do_t
2560: 65 73 74 20 6d 69 73 63 37 2d 31 37 2e 31 20 7b  est misc7-17.1 {
2570: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
2580: 20 42 45 47 49 4e 3b 0a 20 20 20 20 44 45 4c 45   BEGIN;.    DELE
2590: 54 45 20 46 52 4f 4d 20 74 33 20 57 48 45 52 45  TE FROM t3 WHERE
25a0: 20 28 6f 69 64 25 33 29 3d 3d 30 3b 0a 20 20 7d   (oid%3)==0;.  }
25b0: 0a 20 20 63 6f 70 79 5f 66 69 6c 65 20 74 65 73  .  copy_file tes
25c0: 74 2e 64 62 20 62 61 6b 2e 64 62 0a 20 20 63 6f  t.db bak.db.  co
25d0: 70 79 5f 66 69 6c 65 20 74 65 73 74 2e 64 62 2d  py_file test.db-
25e0: 6a 6f 75 72 6e 61 6c 20 62 61 6b 2e 64 62 2d 6a  journal bak.db-j
25f0: 6f 75 72 6e 61 6c 0a 20 20 65 78 65 63 73 71 6c  ournal.  execsql
2600: 20 7b 0a 20 20 20 20 43 4f 4d 4d 49 54 3b 0a 20   {.    COMMIT;. 
2610: 20 7d 0a 0a 20 20 64 62 20 63 6c 6f 73 65 0a 20   }..  db close. 
2620: 20 63 6f 70 79 5f 66 69 6c 65 20 62 61 6b 2e 64   copy_file bak.d
2630: 62 20 74 65 73 74 2e 64 62 0a 20 20 63 6f 70 79  b test.db.  copy
2640: 5f 66 69 6c 65 20 62 61 6b 2e 64 62 2d 6a 6f 75  _file bak.db-jou
2650: 72 6e 61 6c 20 74 65 73 74 2e 64 62 2d 6a 6f 75  rnal test.db-jou
2660: 72 6e 61 6c 0a 20 20 73 71 6c 69 74 65 33 20 64  rnal.  sqlite3 d
2670: 62 20 74 65 73 74 2e 64 62 0a 0a 20 20 63 61 74  b test.db..  cat
2680: 63 68 20 7b 66 69 6c 65 20 61 74 74 72 69 62 75  ch {file attribu
2690: 74 65 73 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72  tes test.db-jour
26a0: 6e 61 6c 20 2d 70 65 72 6d 69 73 73 69 6f 6e 73  nal -permissions
26b0: 20 72 2d 2d 2d 2d 2d 2d 2d 2d 7d 0a 20 20 63 61   r--------}.  ca
26c0: 74 63 68 20 7b 66 69 6c 65 20 61 74 74 72 69 62  tch {file attrib
26d0: 75 74 65 73 20 74 65 73 74 2e 64 62 2d 6a 6f 75  utes test.db-jou
26e0: 72 6e 61 6c 20 2d 72 65 61 64 6f 6e 6c 79 20 31  rnal -readonly 1
26f0: 7d 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20  }.  catchsql {. 
2700: 20 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28     SELECT count(
2710: 2a 29 20 46 52 4f 4d 20 74 33 3b 0a 20 20 7d 0a  *) FROM t3;.  }.
2720: 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20 69  } {1 {database i
2730: 73 20 6c 6f 63 6b 65 64 7d 7d 0a 64 6f 5f 74 65  s locked}}.do_te
2740: 73 74 20 6d 69 73 63 37 2d 31 37 2e 32 20 7b 0a  st misc7-17.2 {.
2750: 20 20 63 61 74 63 68 20 7b 66 69 6c 65 20 61 74    catch {file at
2760: 74 72 69 62 75 74 65 73 20 74 65 73 74 2e 64 62  tributes test.db
2770: 2d 6a 6f 75 72 6e 61 6c 20 2d 70 65 72 6d 69 73  -journal -permis
2780: 73 69 6f 6e 73 20 72 77 2d 2d 2d 2d 2d 2d 2d 7d  sions rw-------}
2790: 0a 20 20 63 61 74 63 68 20 7b 66 69 6c 65 20 61  .  catch {file a
27a0: 74 74 72 69 62 75 74 65 73 20 74 65 73 74 2e 64  ttributes test.d
27b0: 62 2d 6a 6f 75 72 6e 61 6c 20 2d 72 65 61 64 6f  b-journal -reado
27c0: 6e 6c 79 20 30 7d 0a 20 20 63 61 74 63 68 73 71  nly 0}.  catchsq
27d0: 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 63  l {.    SELECT c
27e0: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74 33 3b  ount(*) FROM t3;
27f0: 0a 20 20 7d 0a 7d 20 7b 30 20 33 32 7d 0a 0a 73  .  }.} {0 32}..s
2800: 65 74 20 3a 3a 70 65 6e 64 69 6e 67 5f 62 79 74  et ::pending_byt
2810: 65 5f 70 61 67 65 20 5b 65 78 70 72 20 28 24 3a  e_page [expr ($:
2820: 3a 73 71 6c 69 74 65 5f 70 65 6e 64 69 6e 67 5f  :sqlite_pending_
2830: 62 79 74 65 20 2f 20 31 30 32 34 29 20 2b 20 31  byte / 1024) + 1
2840: 5d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d  ].do_test misc7-
2850: 31 37 2e 33 20 7b 0a 20 20 64 62 20 65 76 61 6c  17.3 {.  db eval
2860: 20 7b 0a 20 20 20 20 70 72 61 67 6d 61 20 77 72   {.    pragma wr
2870: 69 74 61 62 6c 65 5f 73 63 68 65 6d 61 20 3d 20  itable_schema = 
2880: 74 72 75 65 3b 0a 20 20 20 20 55 50 44 41 54 45  true;.    UPDATE
2890: 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 0a   sqlite_master .
28a0: 20 20 20 20 20 20 53 45 54 20 72 6f 6f 74 70 61        SET rootpa
28b0: 67 65 20 3d 20 24 70 65 6e 64 69 6e 67 5f 62 79  ge = $pending_by
28c0: 74 65 5f 70 61 67 65 0a 20 20 20 20 20 20 57 48  te_page.      WH
28d0: 45 52 45 20 74 79 70 65 20 3d 20 27 74 61 62 6c  ERE type = 'tabl
28e0: 65 27 20 41 4e 44 20 6e 61 6d 65 20 3d 20 27 74  e' AND name = 't
28f0: 33 27 3b 0a 20 20 7d 0a 20 20 65 78 65 63 73 71  3';.  }.  execsq
2900: 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 72  l {.    SELECT r
2910: 6f 6f 74 70 61 67 65 20 46 52 4f 4d 20 73 71 6c  ootpage FROM sql
2920: 69 74 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45  ite_master WHERE
2930: 20 74 79 70 65 20 3d 20 27 74 61 62 6c 65 27 20   type = 'table' 
2940: 41 4e 44 20 6e 61 6d 65 20 3d 20 27 74 33 27 3b  AND name = 't3';
2950: 0a 20 20 7d 0a 7d 20 24 3a 3a 70 65 6e 64 69 6e  .  }.} $::pendin
2960: 67 5f 62 79 74 65 5f 70 61 67 65 0a 0a 64 6f 5f  g_byte_page..do_
2970: 74 65 73 74 20 6d 69 73 63 37 2d 31 37 2e 34 20  test misc7-17.4 
2980: 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a 20 20 73  {.  db close.  s
2990: 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64  qlite3 db test.d
29a0: 62 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20  b.  catchsql {. 
29b0: 20 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28     SELECT count(
29c0: 2a 29 20 46 52 4f 4d 20 74 33 3b 0a 20 20 7d 20  *) FROM t3;.  } 
29d0: 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73 65 20  .} {1 {database 
29e0: 64 69 73 6b 20 69 6d 61 67 65 20 69 73 20 6d 61  disk image is ma
29f0: 6c 66 6f 72 6d 65 64 7d 7d 0a 7d 0a 0a 23 20 54  lformed}}.}..# T
2a00: 69 63 6b 65 74 20 23 32 34 37 30 0a 23 0a 64 6f  icket #2470.#.do
2a10: 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 38 2e 31  _test misc7-18.1
2a20: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20   {.  execsql {. 
2a30: 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20     CREATE TABLE 
2a40: 74 61 62 6c 65 5f 31 20 28 63 6f 6c 5f 31 30 29  table_1 (col_10)
2a50: 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54 41 42  ;.    CREATE TAB
2a60: 4c 45 20 74 61 62 6c 65 5f 32 20 28 0a 20 20 20  LE table_2 (.   
2a70: 20 20 20 63 6f 6c 5f 31 2c 20 63 6f 6c 5f 32 2c     col_1, col_2,
2a80: 20 63 6f 6c 5f 33 2c 20 63 6f 6c 5f 34 2c 20 63   col_3, col_4, c
2a90: 6f 6c 5f 35 2c 0a 20 20 20 20 20 20 63 6f 6c 5f  ol_5,.      col_
2aa0: 36 2c 20 63 6f 6c 5f 37 2c 20 63 6f 6c 5f 38 2c  6, col_7, col_8,
2ab0: 20 63 6f 6c 5f 39 2c 20 63 6f 6c 5f 31 30 0a 20   col_9, col_10. 
2ac0: 20 20 20 29 3b 0a 20 20 20 20 53 45 4c 45 43 54     );.    SELECT
2ad0: 20 63 6f 6c 5f 31 30 0a 20 20 20 20 46 52 4f 4d   col_10.    FROM
2ae0: 0a 20 20 20 20 20 20 28 53 45 4c 45 43 54 20 74  .      (SELECT t
2af0: 61 62 6c 65 5f 31 2e 63 6f 6c 5f 31 30 20 41 53  able_1.col_10 AS
2b00: 20 63 6f 6c 5f 31 30 20 46 52 4f 4d 20 74 61 62   col_10 FROM tab
2b10: 6c 65 5f 31 29 2c 0a 20 20 20 20 20 20 28 53 45  le_1),.      (SE
2b20: 4c 45 43 54 20 74 61 62 6c 65 5f 31 2e 63 6f 6c  LECT table_1.col
2b30: 5f 31 30 2c 20 74 61 62 6c 65 5f 32 2e 63 6f 6c  _10, table_2.col
2b40: 5f 39 20 41 53 20 71 63 6f 6c 5f 39 0a 20 20 20  _9 AS qcol_9.   
2b50: 20 20 20 20 20 20 46 52 4f 4d 20 74 61 62 6c 65        FROM table
2b60: 5f 31 2c 20 74 61 62 6c 65 5f 32 0a 20 20 20 20  _1, table_2.    
2b70: 20 20 20 20 47 52 4f 55 50 20 42 59 20 74 61 62      GROUP BY tab
2b80: 6c 65 5f 31 2e 63 6f 6c 5f 31 30 2c 20 71 63 6f  le_1.col_10, qco
2b90: 6c 5f 39 29 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a  l_9);.  }.} {}..
2ba0: 64 62 20 63 6c 6f 73 65 0a 66 69 6c 65 20 64 65  db close.file de
2bb0: 6c 65 74 65 20 2d 66 6f 72 63 65 20 74 65 73 74  lete -force test
2bc0: 2e 64 62 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74  .db..finish_test
2bd0: 0a                                               .