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

Artifact edbbe77d48c7d70a60f8c33e2c7d182ca25f0181:


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 32 35 20  sc7.test,v 1.25 
01c0: 32 30 30 38 2f 31 30 2f 33 30 20 31 35 3a 30 33  2008/10/30 15:03
01d0: 3a 31 36 20 64 72 68 20 45 78 70 20 24 0a 0a 73  :16 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 64 6f 5f  /tester.tcl..do_
0220: 74 65 73 74 20 6d 69 73 63 37 2d 31 2d 6d 69 73  test misc7-1-mis
0230: 75 73 65 20 7b 0a 20 20 63 5f 6d 69 73 75 73 65  use {.  c_misuse
0240: 5f 74 65 73 74 0a 7d 20 7b 7d 0a 0a 64 6f 5f 74  _test.} {}..do_t
0250: 65 73 74 20 6d 69 73 63 37 2d 32 20 7b 0a 20 20  est misc7-2 {.  
0260: 63 5f 72 65 61 6c 6c 6f 63 5f 74 65 73 74 0a 7d  c_realloc_test.}
0270: 20 7b 7d 0a 0a 64 6f 5f 74 65 73 74 20 6d 69 73   {}..do_test mis
0280: 63 37 2d 33 20 7b 0a 20 20 63 5f 63 6f 6c 6c 61  c7-3 {.  c_colla
0290: 74 69 6f 6e 5f 74 65 73 74 0a 7d 20 7b 7d 0a 0a  tion_test.} {}..
02a0: 23 20 54 72 79 20 74 6f 20 6f 70 65 6e 20 61 20  # Try to open a 
02b0: 64 69 72 65 63 74 6f 72 79 3a 0a 23 0a 64 6f 5f  directory:.#.do_
02c0: 74 65 73 74 20 6d 69 73 63 37 2d 34 20 7b 0a 20  test misc7-4 {. 
02d0: 20 66 69 6c 65 20 64 65 6c 65 74 65 20 6d 79 64   file delete myd
02e0: 69 72 0a 20 20 66 69 6c 65 20 6d 6b 64 69 72 20  ir.  file mkdir 
02f0: 6d 79 64 69 72 0a 20 20 73 65 74 20 72 63 20 5b  mydir.  set rc [
0300: 63 61 74 63 68 20 7b 0a 20 20 20 20 73 71 6c 69  catch {.    sqli
0310: 74 65 33 20 64 62 32 20 2e 2f 6d 79 64 69 72 0a  te3 db2 ./mydir.
0320: 20 20 7d 20 6d 73 67 5d 0a 20 20 6c 69 73 74 20    } msg].  list 
0330: 24 72 63 20 24 6d 73 67 0a 7d 20 7b 31 20 7b 75  $rc $msg.} {1 {u
0340: 6e 61 62 6c 65 20 74 6f 20 6f 70 65 6e 20 64 61  nable to open da
0350: 74 61 62 61 73 65 20 66 69 6c 65 7d 7d 0a 0a 23  tabase file}}..#
0360: 20 54 72 79 20 74 6f 20 6f 70 65 6e 20 61 20 66   Try to open a f
0370: 69 6c 65 20 77 69 74 68 20 61 20 64 69 72 65 63  ile with a direc
0380: 74 6f 72 79 20 77 68 65 72 65 20 69 74 73 20 6a  tory where its j
0390: 6f 75 72 6e 61 6c 20 66 69 6c 65 20 73 68 6f 75  ournal file shou
03a0: 6c 64 20 62 65 2e 0a 23 0a 64 6f 5f 74 65 73 74  ld be..#.do_test
03b0: 20 6d 69 73 63 37 2d 35 20 7b 0a 20 20 66 69 6c   misc7-5 {.  fil
03c0: 65 20 64 65 6c 65 74 65 20 6d 79 64 69 72 0a 20  e delete mydir. 
03d0: 20 66 69 6c 65 20 6d 6b 64 69 72 20 6d 79 64 69   file mkdir mydi
03e0: 72 2d 6a 6f 75 72 6e 61 6c 0a 20 20 73 71 6c 69  r-journal.  sqli
03f0: 74 65 33 20 64 62 32 20 2e 2f 6d 79 64 69 72 0a  te3 db2 ./mydir.
0400: 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20 20 20    catchsql {.   
0410: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 61 62   CREATE TABLE ab
0420: 63 28 61 2c 20 62 2c 20 63 29 3b 0a 20 20 7d 20  c(a, b, c);.  } 
0430: 64 62 32 0a 7d 20 7b 31 20 7b 75 6e 61 62 6c 65  db2.} {1 {unable
0440: 20 74 6f 20 6f 70 65 6e 20 64 61 74 61 62 61 73   to open databas
0450: 65 20 66 69 6c 65 7d 7d 0a 64 62 32 20 63 6c 6f  e file}}.db2 clo
0460: 73 65 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  se..#-----------
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 2d 2d 2d 0a 23 20 54 68 65 20  ---------.# The 
04b0: 66 6f 6c 6c 6f 77 69 6e 67 20 74 65 73 74 73 2c  following tests,
04c0: 20 6d 69 73 63 37 2d 36 2e 2a 20 74 65 73 74 20   misc7-6.* test 
04d0: 74 68 65 20 6c 69 62 72 61 72 69 65 73 20 62 65  the libraries be
04e0: 68 61 76 69 6f 75 72 20 77 68 65 6e 0a 23 20 69  haviour when.# i
04f0: 74 20 63 61 6e 6e 6f 74 20 6f 70 65 6e 20 61 20  t cannot open a 
0500: 66 69 6c 65 2e 20 54 6f 20 66 6f 72 63 65 20 74  file. To force t
0510: 68 69 73 20 63 6f 6e 64 69 74 69 6f 6e 2c 20 77  his condition, w
0520: 65 20 75 73 65 20 75 70 20 61 6c 6c 20 74 68 65  e use up all the
0530: 0a 23 20 66 69 6c 65 2d 64 65 73 63 72 69 70 74  .# file-descript
0540: 6f 72 73 20 62 65 66 6f 72 65 20 72 75 6e 6e 69  ors before runni
0550: 6e 67 20 73 71 6c 69 74 65 2e 20 54 68 69 73 20  ng sqlite. This 
0560: 70 72 6f 62 61 62 6c 79 20 6f 6e 6c 79 20 77 6f  probably only wo
0570: 72 6b 73 0a 23 20 6f 6e 20 75 6e 69 78 2e 0a 23  rks.# on unix..#
0580: 0a 0a 70 72 6f 63 20 75 73 65 5f 75 70 5f 66 69  ..proc use_up_fi
0590: 6c 65 73 20 7b 7d 20 7b 0a 20 20 73 65 74 20 72  les {} {.  set r
05a0: 65 74 20 5b 6c 69 73 74 5d 0a 20 20 63 61 74 63  et [list].  catc
05b0: 68 20 7b 0a 20 20 20 20 77 68 69 6c 65 20 31 20  h {.    while 1 
05c0: 7b 20 6c 61 70 70 65 6e 64 20 72 65 74 20 5b 6f  { lappend ret [o
05d0: 70 65 6e 20 74 65 73 74 2e 64 62 5d 20 7d 0a 20  pen test.db] }. 
05e0: 20 7d 0a 20 20 72 65 74 75 72 6e 20 24 72 65 74   }.  return $ret
05f0: 0a 7d 0a 0a 70 72 6f 63 20 64 6f 5f 66 69 6c 65  .}..proc do_file
0600: 6f 70 65 6e 5f 74 65 73 74 20 7b 70 72 65 66 69  open_test {prefi
0610: 78 20 73 71 6c 7d 20 7b 0a 20 20 73 65 74 20 66  x sql} {.  set f
0620: 64 5f 6c 69 73 74 20 5b 75 73 65 5f 75 70 5f 66  d_list [use_up_f
0630: 69 6c 65 73 5d 0a 20 20 73 65 74 20 3a 3a 67 6f  iles].  set ::go
0640: 20 31 0a 20 20 73 65 74 20 3a 3a 6e 20 31 0a 20   1.  set ::n 1. 
0650: 20 73 65 74 20 3a 3a 73 71 6c 20 24 73 71 6c 0a   set ::sql $sql.
0660: 20 20 77 68 69 6c 65 20 7b 24 3a 3a 67 6f 7d 20    while {$::go} 
0670: 7b 0a 20 20 20 20 63 61 74 63 68 20 7b 64 62 20  {.    catch {db 
0680: 63 6c 6f 73 65 7d 0a 20 20 20 20 64 6f 5f 74 65  close}.    do_te
0690: 73 74 20 24 7b 70 72 65 66 69 78 7d 2e 24 7b 3a  st ${prefix}.${:
06a0: 3a 6e 7d 20 7b 0a 20 20 20 20 20 20 73 65 74 20  :n} {.      set 
06b0: 72 63 20 5b 63 61 74 63 68 20 7b 0a 20 20 20 20  rc [catch {.    
06c0: 20 20 20 20 73 71 6c 69 74 65 20 64 62 20 74 65      sqlite db te
06d0: 73 74 2e 64 62 0a 20 20 20 20 20 20 20 20 64 62  st.db.        db
06e0: 20 65 76 61 6c 20 24 3a 3a 73 71 6c 0a 20 20 20   eval $::sql.   
06f0: 20 20 20 7d 20 6d 73 67 5d 0a 20 20 20 20 20 20     } msg].      
0700: 69 66 20 7b 24 72 63 20 3d 3d 20 30 7d 20 7b 73  if {$rc == 0} {s
0710: 65 74 20 3a 3a 67 6f 20 30 7d 0a 20 20 0a 20 20  et ::go 0}.  .  
0720: 20 20 20 20 65 78 70 72 20 7b 24 72 63 20 3d 3d      expr {$rc ==
0730: 20 30 20 7c 7c 20 28 24 72 63 20 3d 3d 20 31 20   0 || ($rc == 1 
0740: 26 26 20 5b 73 74 72 69 6e 67 20 66 69 72 73 74  && [string first
0750: 20 75 6e 61 62 6c 65 20 24 6d 73 67 5d 3d 3d 30   unable $msg]==0
0760: 29 7d 0a 20 20 20 20 7d 20 31 0a 20 20 0a 20 20  )}.    } 1.  .  
0770: 20 20 63 6c 6f 73 65 20 5b 6c 69 6e 64 65 78 20    close [lindex 
0780: 24 66 64 5f 6c 69 73 74 20 30 5d 0a 20 20 20 20  $fd_list 0].    
0790: 73 65 74 20 66 64 5f 6c 69 73 74 20 5b 6c 72 61  set fd_list [lra
07a0: 6e 67 65 20 24 66 64 5f 6c 69 73 74 20 31 20 65  nge $fd_list 1 e
07b0: 6e 64 5d 0a 20 20 20 20 69 6e 63 72 20 3a 3a 6e  nd].    incr ::n
07c0: 0a 20 20 7d 0a 20 20 66 6f 72 65 61 63 68 20 66  .  }.  foreach f
07d0: 64 20 24 66 64 5f 6c 69 73 74 20 7b 0a 20 20 20  d $fd_list {.   
07e0: 20 63 6c 6f 73 65 20 24 66 64 0a 20 20 7d 0a 20   close $fd.  }. 
07f0: 20 64 62 20 63 6c 6f 73 65 0a 7d 0a 0a 65 78 65   db close.}..exe
0800: 63 73 71 6c 20 7b 20 43 52 45 41 54 45 20 54 41  csql { CREATE TA
0810: 42 4c 45 20 61 62 63 28 61 20 50 52 49 4d 41 52  BLE abc(a PRIMAR
0820: 59 20 4b 45 59 2c 20 62 2c 20 63 29 3b 20 7d 0a  Y KEY, b, c); }.
0830: 64 62 20 63 6c 6f 73 65 0a 0a 69 66 20 7b 24 74  db close..if {$t
0840: 63 6c 5f 70 6c 61 74 66 6f 72 6d 28 70 6c 61 74  cl_platform(plat
0850: 66 6f 72 6d 29 21 3d 22 77 69 6e 64 6f 77 73 22  form)!="windows"
0860: 7d 20 7b 0a 20 20 64 6f 5f 66 69 6c 65 6f 70 65  } {.  do_fileope
0870: 6e 5f 74 65 73 74 20 6d 69 73 63 37 2d 36 2e 31  n_test misc7-6.1
0880: 20 7b 0a 20 20 20 20 42 45 47 49 4e 3b 0a 20 20   {.    BEGIN;.  
0890: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62    INSERT INTO ab
08a0: 63 20 56 41 4c 55 45 53 28 31 2c 20 32 2c 20 33  c VALUES(1, 2, 3
08b0: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
08c0: 54 4f 20 61 62 63 20 56 41 4c 55 45 53 28 32 2c  TO abc VALUES(2,
08d0: 20 33 2c 20 34 29 3b 0a 20 20 20 20 49 4e 53 45   3, 4);.    INSE
08e0: 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45  RT INTO abc SELE
08f0: 43 54 20 61 2b 32 2c 20 62 2c 20 63 20 46 52 4f  CT a+2, b, c FRO
0900: 4d 20 61 62 63 3b 0a 20 20 20 20 43 4f 4d 4d 49  M abc;.    COMMI
0910: 54 3b 0a 20 20 7d 0a 20 20 0a 20 20 64 6f 5f 66  T;.  }.  .  do_f
0920: 69 6c 65 6f 70 65 6e 5f 74 65 73 74 20 6d 69 73  ileopen_test mis
0930: 63 37 2d 36 2e 32 20 7b 0a 20 20 20 20 50 52 41  c7-6.2 {.    PRA
0940: 47 4d 41 20 74 65 6d 70 2e 63 61 63 68 65 5f 73  GMA temp.cache_s
0950: 69 7a 65 20 3d 20 31 30 30 30 3b 0a 20 20 7d 0a  ize = 1000;.  }.
0960: 7d 0a 0a 23 0a 23 20 45 6e 64 20 6f 66 20 74 65  }..#.# End of te
0970: 73 74 73 20 66 6f 72 20 6f 75 74 2d 6f 66 2d 66  sts for out-of-f
0980: 69 6c 65 2d 64 65 73 63 72 69 70 74 6f 72 73 20  ile-descriptors 
0990: 63 6f 6e 64 69 74 69 6f 6e 2e 0a 23 2d 2d 2d 2d  condition..#----
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 2d 2d 2d  ----------------
09e0: 0a 0a 73 71 6c 69 74 65 33 20 64 62 20 74 65 73  ..sqlite3 db tes
09f0: 74 2e 64 62 0a 65 78 65 63 73 71 6c 20 7b 0a 20  t.db.execsql {. 
0a00: 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 61 62 63   DELETE FROM abc
0a10: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20  ;.  INSERT INTO 
0a20: 61 62 63 20 56 41 4c 55 45 53 28 31 2c 20 32 2c  abc VALUES(1, 2,
0a30: 20 33 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e   3);.  INSERT IN
0a40: 54 4f 20 61 62 63 20 56 41 4c 55 45 53 28 32 2c  TO abc VALUES(2,
0a50: 20 33 2c 20 34 29 3b 0a 20 20 49 4e 53 45 52 54   3, 4);.  INSERT
0a60: 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54   INTO abc SELECT
0a70: 20 61 2b 32 2c 20 62 2c 20 63 20 46 52 4f 4d 20   a+2, b, c FROM 
0a80: 61 62 63 3b 0a 7d 0a 20 20 0a 0a 23 2d 2d 2d 2d  abc;.}.  ..#----
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 2d 2d 2d  ----------------
0ad0: 0a 23 20 54 65 73 74 20 74 68 61 74 20 74 68 65  .# Test that the
0ae0: 20 73 71 6c 69 74 65 33 5f 62 75 73 79 5f 74 69   sqlite3_busy_ti
0af0: 6d 65 6f 75 74 20 63 61 6c 6c 20 73 65 65 6d 73  meout call seems
0b00: 20 74 6f 20 64 65 6c 61 79 20 61 70 70 72 6f 78   to delay approx
0b10: 69 6d 61 74 65 6c 79 0a 23 20 74 68 65 20 72 69  imately.# the ri
0b20: 67 68 74 20 61 6d 6f 75 6e 74 20 6f 66 20 74 69  ght amount of ti
0b30: 6d 65 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 6d 69  me..#.do_test mi
0b40: 73 63 37 2d 37 2e 30 20 7b 0a 20 20 73 71 6c 69  sc7-7.0 {.  sqli
0b50: 74 65 33 20 64 62 32 20 74 65 73 74 2e 64 62 0a  te3 db2 test.db.
0b60: 20 20 73 71 6c 69 74 65 33 5f 62 75 73 79 5f 74    sqlite3_busy_t
0b70: 69 6d 65 6f 75 74 20 5b 73 71 6c 69 74 65 33 5f  imeout [sqlite3_
0b80: 63 6f 6e 6e 65 63 74 69 6f 6e 5f 70 6f 69 6e 74  connection_point
0b90: 65 72 20 64 62 5d 20 32 30 30 30 0a 20 20 65 78  er db] 2000.  ex
0ba0: 65 63 73 71 6c 20 7b 0a 20 20 20 20 42 45 47 49  ecsql {.    BEGI
0bb0: 4e 20 45 58 43 4c 55 53 49 56 45 3b 0a 20 20 7d  N EXCLUSIVE;.  }
0bc0: 20 64 62 32 0a 0a 20 20 23 20 4e 6f 77 20 64 62   db2..  # Now db
0bd0: 32 20 68 61 73 20 61 6e 20 65 78 63 6c 75 73 69  2 has an exclusi
0be0: 76 65 20 6c 6f 63 6b 20 6f 6e 20 74 68 65 20 64  ve lock on the d
0bf0: 61 74 61 62 61 73 65 20 66 69 6c 65 2c 20 61 6e  atabase file, an
0c00: 64 20 64 62 20 68 61 73 0a 20 20 23 20 61 20 62  d db has.  # a b
0c10: 75 73 79 2d 74 69 6d 65 6f 75 74 20 6f 66 20 32  usy-timeout of 2
0c20: 30 30 30 20 6d 69 6c 6c 69 73 65 63 6f 6e 64 73  000 milliseconds
0c30: 2e 20 53 6f 20 63 68 65 63 6b 20 74 68 61 74 20  . So check that 
0c40: 74 72 79 69 6e 67 20 74 6f 0a 20 20 23 20 61 63  trying to.  # ac
0c50: 63 65 73 73 20 74 68 65 20 64 61 74 61 62 61 73  cess the databas
0c60: 65 20 75 73 69 6e 67 20 63 6f 6e 6e 65 63 74 69  e using connecti
0c70: 6f 6e 20 64 62 20 64 65 6c 61 79 73 20 66 6f 72  on db delays for
0c80: 20 61 74 20 6c 65 61 73 74 20 31 35 30 30 20 6d   at least 1500 m
0c90: 73 2e 0a 20 20 23 0a 20 20 73 65 74 20 74 6d 20  s..  #.  set tm 
0ca0: 5b 74 69 6d 65 20 7b 0a 20 20 20 20 73 65 74 20  [time {.    set 
0cb0: 72 65 73 75 6c 74 20 5b 63 61 74 63 68 73 71 6c  result [catchsql
0cc0: 20 7b 0a 20 20 20 20 20 20 20 20 53 45 4c 45 43   {.        SELEC
0cd0: 54 20 2a 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f  T * FROM sqlite_
0ce0: 6d 61 73 74 65 72 3b 0a 20 20 20 20 20 20 7d 20  master;.      } 
0cf0: 64 62 5d 0a 20 20 7d 5d 0a 20 20 73 65 74 20 64  db].  }].  set d
0d00: 65 6c 61 79 20 5b 6c 69 6e 64 65 78 20 24 74 6d  elay [lindex $tm
0d10: 20 30 5d 20 20 3b 23 20 49 6e 20 6d 69 63 72 6f   0]  ;# In micro
0d20: 73 65 63 6f 6e 64 73 0a 20 20 6c 61 70 70 65 6e  seconds.  lappen
0d30: 64 20 72 65 73 75 6c 74 20 5b 65 78 70 72 20 7b  d result [expr {
0d40: 24 64 65 6c 61 79 3e 31 35 30 30 30 30 30 20 26  $delay>1500000 &
0d50: 26 20 24 64 65 6c 61 79 3c 34 30 30 30 30 30 30  & $delay<4000000
0d60: 7d 5d 0a 7d 20 7b 31 20 7b 64 61 74 61 62 61 73  }].} {1 {databas
0d70: 65 20 69 73 20 6c 6f 63 6b 65 64 7d 20 31 7d 0a  e is locked} 1}.
0d80: 64 62 32 20 63 6c 6f 73 65 0a 0a 23 2d 2d 2d 2d  db2 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 2d 2d 2d  ----------------
0dd0: 0a 23 20 54 65 73 74 20 74 68 61 74 20 6e 6f 74  .# Test that not
0de0: 68 69 6e 67 20 67 6f 65 73 20 68 6f 72 72 69 62  hing goes horrib
0df0: 6c 79 20 77 72 6f 6e 67 20 77 68 65 6e 20 61 74  ly wrong when at
0e00: 74 61 63 68 69 6e 67 20 61 20 64 61 74 61 62 61  taching a databa
0e10: 73 65 0a 23 20 61 66 74 65 72 20 74 68 65 20 6f  se.# after the o
0e20: 6d 69 74 5f 72 65 61 64 6c 6f 63 6b 20 70 72 61  mit_readlock pra
0e30: 67 6d 61 20 68 61 73 20 62 65 65 6e 20 65 78 65  gma has been exe
0e40: 72 63 69 73 65 64 2e 0a 23 0a 64 6f 5f 74 65 73  rcised..#.do_tes
0e50: 74 20 6d 69 73 63 37 2d 37 2e 31 20 7b 0a 20 20  t misc7-7.1 {.  
0e60: 66 69 6c 65 20 64 65 6c 65 74 65 20 2d 66 6f 72  file delete -for
0e70: 63 65 20 74 65 73 74 32 2e 64 62 0a 20 20 66 69  ce test2.db.  fi
0e80: 6c 65 20 64 65 6c 65 74 65 20 2d 66 6f 72 63 65  le delete -force
0e90: 20 74 65 73 74 32 2e 64 62 2d 6a 6f 75 72 6e 61   test2.db-journa
0ea0: 6c 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20  l.  execsql {.  
0eb0: 20 20 50 52 41 47 4d 41 20 6f 6d 69 74 5f 72 65    PRAGMA omit_re
0ec0: 61 64 6c 6f 63 6b 20 3d 20 31 3b 0a 20 20 20 20  adlock = 1;.    
0ed0: 41 54 54 41 43 48 20 27 74 65 73 74 32 2e 64 62  ATTACH 'test2.db
0ee0: 27 20 41 53 20 61 75 78 3b 0a 20 20 20 20 43 52  ' AS aux;.    CR
0ef0: 45 41 54 45 20 54 41 42 4c 45 20 61 75 78 2e 68  EATE TABLE aux.h
0f00: 65 6c 6c 6f 28 77 6f 72 6c 64 29 3b 0a 20 20 20  ello(world);.   
0f10: 20 53 45 4c 45 43 54 20 6e 61 6d 65 20 46 52 4f   SELECT name FRO
0f20: 4d 20 61 75 78 2e 73 71 6c 69 74 65 5f 6d 61 73  M aux.sqlite_mas
0f30: 74 65 72 3b 0a 20 20 7d 0a 7d 20 7b 68 65 6c 6c  ter;.  }.} {hell
0f40: 6f 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 37  o}.do_test misc7
0f50: 2d 37 2e 32 20 7b 0a 20 20 65 78 65 63 73 71 6c  -7.2 {.  execsql
0f60: 20 7b 0a 20 20 20 20 44 45 54 41 43 48 20 61 75   {.    DETACH au
0f70: 78 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 23 20 54  x;.  }.} {}..# T
0f80: 65 73 74 20 74 68 65 20 55 54 46 2d 31 36 20 76  est the UTF-16 v
0f90: 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 22 6f  ersion of the "o
0fa0: 75 74 20 6f 66 20 6d 65 6d 6f 72 79 22 20 6d 65  ut of memory" me
0fb0: 73 73 61 67 65 20 28 75 73 65 64 20 77 68 65 6e  ssage (used when
0fc0: 0a 23 20 6d 61 6c 6c 6f 63 20 66 61 69 6c 73 20  .# malloc fails 
0fd0: 64 75 72 69 6e 67 20 73 71 6c 69 74 65 33 5f 6f  during sqlite3_o
0fe0: 70 65 6e 28 29 20 29 2e 0a 23 0a 69 66 63 61 70  pen() )..#.ifcap
0ff0: 61 62 6c 65 20 75 74 66 31 36 20 7b 0a 20 20 64  able utf16 {.  d
1000: 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 38 20 7b  o_test misc7-8 {
1010: 0a 20 20 20 20 65 6e 63 6f 64 69 6e 67 20 63 6f  .    encoding co
1020: 6e 76 65 72 74 66 72 6f 6d 20 75 6e 69 63 6f 64  nvertfrom unicod
1030: 65 20 5b 73 71 6c 69 74 65 33 5f 65 72 72 6d 73  e [sqlite3_errms
1040: 67 31 36 20 30 78 30 30 30 30 30 30 30 30 5d 0a  g16 0x00000000].
1050: 20 20 7d 20 7b 6f 75 74 20 6f 66 20 6d 65 6d 6f    } {out of memo
1060: 72 79 7d 0a 7d 0a 0a 64 6f 5f 74 65 73 74 20 6d  ry}.}..do_test m
1070: 69 73 63 37 2d 39 20 7b 0a 20 20 65 78 65 63 73  isc7-9 {.  execs
1080: 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20  ql {.    SELECT 
1090: 2a 20 0a 20 20 20 20 46 52 4f 4d 20 28 53 45 4c  * .    FROM (SEL
10a0: 45 43 54 20 6e 61 6d 65 2b 31 20 41 53 20 6f 6e  ECT name+1 AS on
10b0: 65 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61  e FROM sqlite_ma
10c0: 73 74 65 72 20 4c 49 4d 49 54 20 31 20 4f 46 46  ster LIMIT 1 OFF
10d0: 53 45 54 20 31 29 20 0a 20 20 20 20 57 48 45 52  SET 1) .    WHER
10e0: 45 20 6f 6e 65 20 4c 49 4b 45 20 27 68 65 6c 6c  E one LIKE 'hell
10f0: 6f 25 27 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 23  o%';.  }.} {}..#
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 2d 2d 2d 0a 23 20 49 6d 70 72 6f 76 65 20 63  ----.# Improve c
1150: 6f 76 65 72 61 67 65 20 66 6f 72 20 76 74 61 62  overage for vtab
1160: 20 63 6f 64 65 2e 0a 23 0a 69 66 63 61 70 61 62   code..#.ifcapab
1170: 6c 65 20 76 74 61 62 20 7b 0a 20 20 23 20 52 75  le vtab {.  # Ru
1180: 6e 20 73 6f 6d 65 20 64 65 62 75 67 20 63 6f 64  n some debug cod
1190: 65 20 74 6f 20 69 6d 70 72 6f 76 65 20 72 65 70  e to improve rep
11a0: 6f 72 74 65 64 20 63 6f 76 65 72 61 67 65 0a 20  orted coverage. 
11b0: 20 23 0a 0a 20 20 23 20 73 65 74 20 73 71 6c 69   #..  # set sqli
11c0: 74 65 5f 77 68 65 72 65 5f 74 72 61 63 65 20 31  te_where_trace 1
11d0: 0a 20 20 64 6f 5f 74 65 73 74 20 6d 69 73 63 37  .  do_test misc7
11e0: 2d 31 30 20 7b 0a 20 20 20 20 72 65 67 69 73 74  -10 {.    regist
11f0: 65 72 5f 65 63 68 6f 5f 6d 6f 64 75 6c 65 20 5b  er_echo_module [
1200: 73 71 6c 69 74 65 33 5f 63 6f 6e 6e 65 63 74 69  sqlite3_connecti
1210: 6f 6e 5f 70 6f 69 6e 74 65 72 20 64 62 5d 0a 20  on_pointer db]. 
1220: 20 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20     execsql {.   
1230: 20 20 20 43 52 45 41 54 45 20 56 49 52 54 55 41     CREATE VIRTUA
1240: 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49 4e 47  L TABLE t1 USING
1250: 20 65 63 68 6f 28 61 62 63 29 3b 0a 20 20 20 20   echo(abc);.    
1260: 20 20 53 45 4c 45 43 54 20 61 20 46 52 4f 4d 20    SELECT a FROM 
1270: 74 31 20 57 48 45 52 45 20 61 20 3d 20 31 20 4f  t1 WHERE a = 1 O
1280: 52 44 45 52 20 42 59 20 62 3b 0a 20 20 20 20 7d  RDER BY b;.    }
1290: 0a 20 20 7d 20 7b 31 7d 0a 20 20 73 65 74 20 73  .  } {1}.  set s
12a0: 71 6c 69 74 65 5f 77 68 65 72 65 5f 74 72 61 63  qlite_where_trac
12b0: 65 20 30 0a 0a 20 20 23 20 53 70 65 63 69 66 79  e 0..  # Specify
12c0: 20 61 6e 20 4f 52 44 45 52 20 42 59 20 63 6c 61   an ORDER BY cla
12d0: 75 73 65 20 74 68 61 74 20 63 61 6e 6e 6f 74 20  use that cannot 
12e0: 62 65 20 69 6e 64 65 78 65 64 2e 0a 20 20 64 6f  be indexed..  do
12f0: 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 31 20 7b  _test misc7-11 {
1300: 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b 0a 20  .    execsql {. 
1310: 20 20 20 20 20 53 45 4c 45 43 54 20 74 31 2e 61       SELECT t1.a
1320: 2c 20 74 32 2e 61 20 46 52 4f 4d 20 74 31 2c 20  , t2.a FROM t1, 
1330: 74 31 20 41 53 20 74 32 20 4f 52 44 45 52 20 42  t1 AS t2 ORDER B
1340: 59 20 32 20 4c 49 4d 49 54 20 31 3b 0a 20 20 20  Y 2 LIMIT 1;.   
1350: 20 7d 0a 20 20 7d 20 7b 31 20 31 7d 0a 0a 20 20   }.  } {1 1}..  
1360: 23 20 54 68 65 20 77 68 6f 6c 65 20 70 6f 69 6e  # The whole poin
1370: 74 20 6f 66 20 74 68 69 73 20 69 73 20 74 6f 20  t of this is to 
1380: 74 65 73 74 20 61 6e 20 65 72 72 6f 72 20 63 6f  test an error co
1390: 64 65 20 6f 74 68 65 72 20 74 68 61 6e 0a 20 20  de other than.  
13a0: 23 20 53 51 4c 49 54 45 5f 4e 4f 4d 45 4d 20 66  # SQLITE_NOMEM f
13b0: 72 6f 6d 20 74 68 65 20 76 74 61 62 20 78 42 65  rom the vtab xBe
13c0: 73 74 49 6e 64 65 78 20 63 61 6c 6c 62 61 63 6b  stIndex callback
13d0: 2e 0a 20 20 23 0a 20 20 64 6f 5f 69 6f 65 72 72  ..  #.  do_ioerr
13e0: 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 32 20 2d  _test misc7-12 -
13f0: 74 63 6c 70 72 65 70 20 7b 0a 20 20 20 20 73 71  tclprep {.    sq
1400: 6c 69 74 65 33 20 64 62 32 20 74 65 73 74 2e 64  lite3 db2 test.d
1410: 62 0a 20 20 20 20 72 65 67 69 73 74 65 72 5f 65  b.    register_e
1420: 63 68 6f 5f 6d 6f 64 75 6c 65 20 5b 73 71 6c 69  cho_module [sqli
1430: 74 65 33 5f 63 6f 6e 6e 65 63 74 69 6f 6e 5f 70  te3_connection_p
1440: 6f 69 6e 74 65 72 20 64 62 32 5d 0a 20 20 20 20  ointer db2].    
1450: 64 62 32 20 65 76 61 6c 20 7b 0a 20 20 20 20 20  db2 eval {.     
1460: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 61 62   CREATE TABLE ab
1470: 63 28 61 20 50 52 49 4d 41 52 59 20 4b 45 59 2c  c(a PRIMARY KEY,
1480: 20 62 2c 20 63 29 3b 0a 20 20 20 20 20 20 49 4e   b, c);.      IN
1490: 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41  SERT INTO abc VA
14a0: 4c 55 45 53 28 31 2c 20 32 2c 20 33 29 3b 0a 20  LUES(1, 2, 3);. 
14b0: 20 20 20 20 20 43 52 45 41 54 45 20 56 49 52 54       CREATE VIRT
14c0: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49  UAL TABLE t1 USI
14d0: 4e 47 20 65 63 68 6f 28 61 62 63 29 3b 0a 20 20  NG echo(abc);.  
14e0: 20 20 7d 0a 20 20 20 20 64 62 32 20 63 6c 6f 73    }.    db2 clos
14f0: 65 0a 20 20 7d 20 2d 74 63 6c 62 6f 64 79 20 7b  e.  } -tclbody {
1500: 0a 20 20 20 20 72 65 67 69 73 74 65 72 5f 65 63  .    register_ec
1510: 68 6f 5f 6d 6f 64 75 6c 65 20 5b 73 71 6c 69 74  ho_module [sqlit
1520: 65 33 5f 63 6f 6e 6e 65 63 74 69 6f 6e 5f 70 6f  e3_connection_po
1530: 69 6e 74 65 72 20 64 62 5d 0a 20 20 20 20 65 78  inter db].    ex
1540: 65 63 73 71 6c 20 7b 53 45 4c 45 43 54 20 2a 20  ecsql {SELECT * 
1550: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 61 20  FROM t1 WHERE a 
1560: 3d 20 31 3b 7d 0a 20 20 7d 20 0a 0a 20 20 23 20  = 1;}.  } ..  # 
1570: 54 68 65 20 63 61 73 65 20 77 68 65 72 65 20 74  The case where t
1580: 68 65 20 76 69 72 74 75 61 6c 20 74 61 62 6c 65  he virtual table
1590: 20 6d 6f 64 75 6c 65 20 72 65 74 75 72 6e 73 20   module returns 
15a0: 61 20 76 65 72 79 20 6c 61 72 67 65 20 6e 75 6d  a very large num
15b0: 62 65 72 0a 20 20 23 20 61 73 20 74 68 65 20 63  ber.  # as the c
15c0: 6f 73 74 20 6f 66 20 61 20 73 63 61 6e 20 28 67  ost of a scan (g
15d0: 72 65 61 74 65 72 20 74 68 61 6e 20 53 51 4c 49  reater than SQLI
15e0: 54 45 5f 42 49 47 5f 44 4f 55 42 4c 45 20 69 6e  TE_BIG_DOUBLE in
15f0: 20 74 68 65 20 63 6f 64 65 29 2e 0a 20 20 23 0a   the code)..  #.
1600: 20 20 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d    do_test misc7-
1610: 31 33 20 7b 0a 20 20 20 20 73 71 6c 69 74 65 33  13 {.    sqlite3
1620: 20 64 62 20 74 65 73 74 2e 64 62 0a 20 20 20 20   db test.db.    
1630: 72 65 67 69 73 74 65 72 5f 65 63 68 6f 5f 6d 6f  register_echo_mo
1640: 64 75 6c 65 20 5b 73 71 6c 69 74 65 33 5f 63 6f  dule [sqlite3_co
1650: 6e 6e 65 63 74 69 6f 6e 5f 70 6f 69 6e 74 65 72  nnection_pointer
1660: 20 64 62 5d 0a 20 20 20 20 73 65 74 20 3a 3a 65   db].    set ::e
1670: 63 68 6f 5f 6d 6f 64 75 6c 65 5f 63 6f 73 74 20  cho_module_cost 
1680: 32 2e 30 65 2b 39 39 0a 20 20 20 20 65 78 65 63  2.0e+99.    exec
1690: 73 71 6c 20 7b 53 45 4c 45 43 54 20 2a 20 46 52  sql {SELECT * FR
16a0: 4f 4d 20 74 31 20 57 48 45 52 45 20 61 20 3d 20  OM t1 WHERE a = 
16b0: 31 3b 7d 0a 20 20 7d 20 7b 31 20 32 20 33 7d 0a  1;}.  } {1 2 3}.
16c0: 20 20 75 6e 73 65 74 20 3a 3a 65 63 68 6f 5f 6d    unset ::echo_m
16d0: 6f 64 75 6c 65 5f 63 6f 73 74 0a 7d 0a 0a 64 62  odule_cost.}..db
16e0: 20 63 6c 6f 73 65 0a 66 69 6c 65 20 64 65 6c 65   close.file dele
16f0: 74 65 20 2d 66 6f 72 63 65 20 74 65 73 74 2e 64  te -force test.d
1700: 62 0a 66 69 6c 65 20 64 65 6c 65 74 65 20 2d 66  b.file delete -f
1710: 6f 72 63 65 20 74 65 73 74 2e 64 62 2d 6a 6f 75  orce test.db-jou
1720: 72 6e 61 6c 0a 73 71 6c 69 74 65 33 20 64 62 20  rnal.sqlite3 db 
1730: 74 65 73 74 2e 64 62 0a 0a 69 66 63 61 70 61 62  test.db..ifcapab
1740: 6c 65 20 65 78 70 6c 61 69 6e 20 7b 0a 20 20 64  le explain {.  d
1750: 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 34 2e  o_test misc7-14.
1760: 31 20 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20  1 {.    execsql 
1770: 7b 0a 20 20 20 20 20 20 43 52 45 41 54 45 20 54  {.      CREATE T
1780: 41 42 4c 45 20 61 62 63 28 61 20 50 52 49 4d 41  ABLE abc(a PRIMA
1790: 52 59 20 4b 45 59 2c 20 62 2c 20 63 29 3b 0a 20  RY KEY, b, c);. 
17a0: 20 20 20 7d 0a 20 20 20 20 65 78 65 63 73 71 6c     }.    execsql
17b0: 20 7b 0a 20 20 20 20 20 20 45 58 50 4c 41 49 4e   {.      EXPLAIN
17c0: 20 51 55 45 52 59 20 50 4c 41 4e 20 53 45 4c 45   QUERY PLAN SELE
17d0: 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 20 41 53  CT * FROM abc AS
17e0: 20 74 32 20 57 48 45 52 45 20 72 6f 77 69 64 20   t2 WHERE rowid 
17f0: 3d 20 31 3b 0a 20 20 20 20 7d 0a 20 20 7d 20 7b  = 1;.    }.  } {
1800: 30 20 30 20 7b 54 41 42 4c 45 20 61 62 63 20 41  0 0 {TABLE abc A
1810: 53 20 74 32 20 55 53 49 4e 47 20 50 52 49 4d 41  S t2 USING PRIMA
1820: 52 59 20 4b 45 59 7d 7d 0a 20 20 64 6f 5f 74 65  RY KEY}}.  do_te
1830: 73 74 20 6d 69 73 63 37 2d 31 34 2e 32 20 7b 0a  st misc7-14.2 {.
1840: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20      execsql {.  
1850: 20 20 20 20 45 58 50 4c 41 49 4e 20 51 55 45 52      EXPLAIN QUER
1860: 59 20 50 4c 41 4e 20 53 45 4c 45 43 54 20 2a 20  Y PLAN SELECT * 
1870: 46 52 4f 4d 20 61 62 63 20 41 53 20 74 32 20 57  FROM abc AS t2 W
1880: 48 45 52 45 20 61 20 3d 20 31 3b 0a 20 20 20 20  HERE a = 1;.    
1890: 7d 0a 20 20 7d 20 7b 30 20 30 20 7b 54 41 42 4c  }.  } {0 0 {TABL
18a0: 45 20 61 62 63 20 41 53 20 74 32 20 57 49 54 48  E abc AS t2 WITH
18b0: 20 49 4e 44 45 58 20 73 71 6c 69 74 65 5f 61 75   INDEX sqlite_au
18c0: 74 6f 69 6e 64 65 78 5f 61 62 63 5f 31 7d 7d 0a  toindex_abc_1}}.
18d0: 20 20 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d    do_test misc7-
18e0: 31 34 2e 33 20 7b 0a 20 20 20 20 65 78 65 63 73  14.3 {.    execs
18f0: 71 6c 20 7b 0a 20 20 20 20 20 20 45 58 50 4c 41  ql {.      EXPLA
1900: 49 4e 20 51 55 45 52 59 20 50 4c 41 4e 20 53 45  IN QUERY PLAN SE
1910: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 61 62 63 20  LECT * FROM abc 
1920: 41 53 20 74 32 20 4f 52 44 45 52 20 42 59 20 61  AS t2 ORDER BY a
1930: 3b 0a 20 20 20 20 7d 0a 20 20 7d 20 7b 30 20 30  ;.    }.  } {0 0
1940: 20 7b 54 41 42 4c 45 20 61 62 63 20 41 53 20 74   {TABLE abc AS t
1950: 32 20 57 49 54 48 20 49 4e 44 45 58 20 73 71 6c  2 WITH INDEX sql
1960: 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 5f 61 62  ite_autoindex_ab
1970: 63 5f 31 20 4f 52 44 45 52 20 42 59 7d 7d 0a 7d  c_1 ORDER BY}}.}
1980: 0a 0a 64 62 20 63 6c 6f 73 65 0a 66 69 6c 65 20  ..db close.file 
1990: 64 65 6c 65 74 65 20 2d 66 6f 72 63 65 20 74 65  delete -force te
19a0: 73 74 2e 64 62 0a 66 69 6c 65 20 64 65 6c 65 74  st.db.file delet
19b0: 65 20 2d 66 6f 72 63 65 20 74 65 73 74 2e 64 62  e -force test.db
19c0: 2d 6a 6f 75 72 6e 61 6c 0a 73 71 6c 69 74 65 33  -journal.sqlite3
19d0: 20 64 62 20 74 65 73 74 2e 64 62 0a 0a 23 2d 2d   db test.db..#--
19e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
19f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1a00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1a10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1a20: 2d 2d 0a 23 20 54 68 69 73 20 69 73 20 61 6c 6c  --.# This is all
1a30: 20 74 6f 20 66 6f 72 63 65 20 74 68 65 20 70 61   to force the pa
1a40: 67 65 72 5f 72 65 6d 6f 76 65 5f 66 72 6f 6d 5f  ger_remove_from_
1a50: 73 74 6d 74 5f 6c 69 73 74 28 29 20 66 75 6e 63  stmt_list() func
1a60: 74 69 6f 6e 0a 23 20 28 69 6e 73 69 64 65 20 70  tion.# (inside p
1a70: 61 67 65 72 2e 63 29 20 74 6f 20 72 65 6d 6f 76  ager.c) to remov
1a80: 65 20 61 20 70 61 67 65 72 20 66 72 6f 6d 20 74  e a pager from t
1a90: 68 65 20 6d 69 64 64 6c 65 20 6f 66 20 74 68 65  he middle of the
1aa0: 0a 23 20 73 74 61 74 65 6d 65 6e 74 2d 6c 69 73  .# statement-lis
1ab0: 74 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 6d 69 73  t..#.do_test mis
1ac0: 63 37 2d 31 35 2e 31 20 7b 0a 20 20 65 78 65 63  c7-15.1 {.  exec
1ad0: 73 71 6c 20 7b 0a 20 20 20 20 50 52 41 47 4d 41  sql {.    PRAGMA
1ae0: 20 63 61 63 68 65 5f 73 69 7a 65 20 3d 20 31 30   cache_size = 10
1af0: 3b 0a 20 20 20 20 42 45 47 49 4e 3b 0a 20 20 20  ;.    BEGIN;.   
1b00: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 61 62   CREATE TABLE ab
1b10: 63 28 61 20 50 52 49 4d 41 52 59 20 4b 45 59 2c  c(a PRIMARY KEY,
1b20: 20 62 2c 20 63 29 3b 0a 20 20 20 20 49 4e 53 45   b, c);.    INSE
1b30: 52 54 20 49 4e 54 4f 20 61 62 63 20 0a 20 20 20  RT INTO abc .   
1b40: 20 56 41 4c 55 45 53 28 72 61 6e 64 73 74 72 28   VALUES(randstr(
1b50: 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64 73 74  100,100), randst
1b60: 72 28 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64  r(100,100), rand
1b70: 73 74 72 28 31 30 30 2c 31 30 30 29 29 3b 0a 20  str(100,100));. 
1b80: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61     INSERT INTO a
1b90: 62 63 20 53 45 4c 45 43 54 20 0a 20 20 20 20 20  bc SELECT .     
1ba0: 20 20 20 20 20 20 20 72 61 6e 64 73 74 72 28 31         randstr(1
1bb0: 30 30 2c 31 30 30 29 2c 20 72 61 6e 64 73 74 72  00,100), randstr
1bc0: 28 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64 73  (100,100), rands
1bd0: 74 72 28 31 30 30 2c 31 30 30 29 20 46 52 4f 4d  tr(100,100) FROM
1be0: 20 61 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54   abc;.    INSERT
1bf0: 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54   INTO abc SELECT
1c00: 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 72 61   .            ra
1c10: 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29 2c 20  ndstr(100,100), 
1c20: 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29  randstr(100,100)
1c30: 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30  , randstr(100,10
1c40: 30 29 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20  0) FROM abc;.   
1c50: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63   INSERT INTO abc
1c60: 20 53 45 4c 45 43 54 20 0a 20 20 20 20 20 20 20   SELECT .       
1c70: 20 20 20 20 20 72 61 6e 64 73 74 72 28 31 30 30       randstr(100
1c80: 2c 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31  ,100), randstr(1
1c90: 30 30 2c 31 30 30 29 2c 20 72 61 6e 64 73 74 72  00,100), randstr
1ca0: 28 31 30 30 2c 31 30 30 29 20 46 52 4f 4d 20 61  (100,100) FROM a
1cb0: 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  bc;.    INSERT I
1cc0: 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 0a  NTO abc SELECT .
1cd0: 20 20 20 20 20 20 20 20 20 20 20 20 72 61 6e 64              rand
1ce0: 73 74 72 28 31 30 30 2c 31 30 30 29 2c 20 72 61  str(100,100), ra
1cf0: 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29 2c 20  ndstr(100,100), 
1d00: 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29  randstr(100,100)
1d10: 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49   FROM abc;.    I
1d20: 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53  NSERT INTO abc S
1d30: 45 4c 45 43 54 20 0a 20 20 20 20 20 20 20 20 20  ELECT .         
1d40: 20 20 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31     randstr(100,1
1d50: 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30  00), randstr(100
1d60: 2c 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31  ,100), randstr(1
1d70: 30 30 2c 31 30 30 29 20 46 52 4f 4d 20 61 62 63  00,100) FROM abc
1d80: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
1d90: 4f 20 61 62 63 20 53 45 4c 45 43 54 20 0a 20 20  O abc SELECT .  
1da0: 20 20 20 20 20 20 20 20 20 20 72 61 6e 64 73 74            randst
1db0: 72 28 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64  r(100,100), rand
1dc0: 73 74 72 28 31 30 30 2c 31 30 30 29 2c 20 72 61  str(100,100), ra
1dd0: 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29 20 46  ndstr(100,100) F
1de0: 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e 53  ROM abc;.    INS
1df0: 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c  ERT INTO abc SEL
1e00: 45 43 54 20 0a 20 20 20 20 20 20 20 20 20 20 20  ECT .           
1e10: 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30   randstr(100,100
1e20: 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31  ), randstr(100,1
1e30: 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30  00), randstr(100
1e40: 2c 31 30 30 29 20 46 52 4f 4d 20 61 62 63 3b 0a  ,100) FROM abc;.
1e50: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
1e60: 61 62 63 20 53 45 4c 45 43 54 20 0a 20 20 20 20  abc SELECT .    
1e70: 20 20 20 20 20 20 20 20 72 61 6e 64 73 74 72 28          randstr(
1e80: 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64 73 74  100,100), randst
1e90: 72 28 31 30 30 2c 31 30 30 29 2c 20 72 61 6e 64  r(100,100), rand
1ea0: 73 74 72 28 31 30 30 2c 31 30 30 29 20 46 52 4f  str(100,100) FRO
1eb0: 4d 20 61 62 63 3b 0a 20 20 20 20 43 4f 4d 4d 49  M abc;.    COMMI
1ec0: 54 3b 0a 20 20 7d 0a 20 20 65 78 70 72 20 7b 5b  T;.  }.  expr {[
1ed0: 66 69 6c 65 20 73 69 7a 65 20 74 65 73 74 2e 64  file size test.d
1ee0: 62 5d 3e 31 30 32 34 30 7d 0a 7d 20 7b 31 7d 0a  b]>10240}.} {1}.
1ef0: 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 35  do_test misc7-15
1f00: 2e 32 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .2 {.  execsql {
1f10: 0a 20 20 20 20 44 45 4c 45 54 45 20 46 52 4f 4d  .    DELETE FROM
1f20: 20 61 62 63 20 57 48 45 52 45 20 72 6f 77 69 64   abc WHERE rowid
1f30: 20 3e 20 31 32 3b 0a 20 20 20 20 49 4e 53 45 52   > 12;.    INSER
1f40: 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43  T INTO abc SELEC
1f50: 54 20 0a 20 20 20 20 20 20 20 20 20 20 20 20 72  T .            r
1f60: 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30 29 2c  andstr(100,100),
1f70: 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31 30 30   randstr(100,100
1f80: 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30 2c 31  ), randstr(100,1
1f90: 30 30 29 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20  00) FROM abc;.  
1fa0: 7d 0a 7d 20 7b 7d 0a 0a 64 62 20 63 6c 6f 73 65  }.} {}..db close
1fb0: 0a 66 69 6c 65 20 64 65 6c 65 74 65 20 2d 66 6f  .file delete -fo
1fc0: 72 63 65 20 74 65 73 74 2e 64 62 0a 66 69 6c 65  rce test.db.file
1fd0: 20 64 65 6c 65 74 65 20 2d 66 6f 72 63 65 20 74   delete -force t
1fe0: 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c 0a 73  est.db-journal.s
1ff0: 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64  qlite3 db test.d
2000: 62 0a 0a 64 6f 5f 69 6f 65 72 72 5f 74 65 73 74  b..do_ioerr_test
2010: 20 6d 69 73 63 37 2d 31 36 20 2d 73 71 6c 70 72   misc7-16 -sqlpr
2020: 65 70 20 7b 0a 20 20 20 50 52 41 47 4d 41 20 63  ep {.   PRAGMA c
2030: 61 63 68 65 5f 73 69 7a 65 20 3d 20 31 30 3b 0a  ache_size = 10;.
2040: 20 20 20 50 52 41 47 4d 41 20 64 65 66 61 75 6c     PRAGMA defaul
2050: 74 5f 63 61 63 68 65 5f 73 69 7a 65 20 3d 20 31  t_cache_size = 1
2060: 30 3b 0a 20 20 20 43 52 45 41 54 45 20 54 41 42  0;.   CREATE TAB
2070: 4c 45 20 74 33 28 61 2c 20 62 2c 20 55 4e 49 51  LE t3(a, b, UNIQ
2080: 55 45 28 61 2c 20 62 29 29 3b 0a 20 20 20 49 4e  UE(a, b));.   IN
2090: 53 45 52 54 20 49 4e 54 4f 20 74 33 20 56 41 4c  SERT INTO t3 VAL
20a0: 55 45 53 28 20 72 61 6e 64 73 74 72 28 31 30 30  UES( randstr(100
20b0: 2c 20 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28  , 100), randstr(
20c0: 31 30 30 2c 20 31 30 30 29 20 29 3b 0a 20 20 20  100, 100) );.   
20d0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 33 20 53  INSERT INTO t3 S
20e0: 45 4c 45 43 54 20 72 61 6e 64 73 74 72 28 31 30  ELECT randstr(10
20f0: 30 2c 20 31 30 30 29 2c 20 72 61 6e 64 73 74 72  0, 100), randstr
2100: 28 31 30 30 2c 20 31 30 30 29 20 46 52 4f 4d 20  (100, 100) FROM 
2110: 74 33 3b 0a 20 20 20 49 4e 53 45 52 54 20 49 4e  t3;.   INSERT IN
2120: 54 4f 20 74 33 20 53 45 4c 45 43 54 20 72 61 6e  TO t3 SELECT ran
2130: 64 73 74 72 28 31 30 30 2c 20 31 30 30 29 2c 20  dstr(100, 100), 
2140: 72 61 6e 64 73 74 72 28 31 30 30 2c 20 31 30 30  randstr(100, 100
2150: 29 20 46 52 4f 4d 20 74 33 3b 0a 20 20 20 49 4e  ) FROM t3;.   IN
2160: 53 45 52 54 20 49 4e 54 4f 20 74 33 20 53 45 4c  SERT INTO t3 SEL
2170: 45 43 54 20 72 61 6e 64 73 74 72 28 31 30 30 2c  ECT randstr(100,
2180: 20 31 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31   100), randstr(1
2190: 30 30 2c 20 31 30 30 29 20 46 52 4f 4d 20 74 33  00, 100) FROM t3
21a0: 3b 0a 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  ;.   INSERT INTO
21b0: 20 74 33 20 53 45 4c 45 43 54 20 72 61 6e 64 73   t3 SELECT rands
21c0: 74 72 28 31 30 30 2c 20 31 30 30 29 2c 20 72 61  tr(100, 100), ra
21d0: 6e 64 73 74 72 28 31 30 30 2c 20 31 30 30 29 20  ndstr(100, 100) 
21e0: 46 52 4f 4d 20 74 33 3b 0a 20 20 20 49 4e 53 45  FROM t3;.   INSE
21f0: 52 54 20 49 4e 54 4f 20 74 33 20 53 45 4c 45 43  RT INTO t3 SELEC
2200: 54 20 72 61 6e 64 73 74 72 28 31 30 30 2c 20 31  T randstr(100, 1
2210: 30 30 29 2c 20 72 61 6e 64 73 74 72 28 31 30 30  00), randstr(100
2220: 2c 20 31 30 30 29 20 46 52 4f 4d 20 74 33 3b 0a  , 100) FROM t3;.
2230: 20 20 20 55 50 44 41 54 45 20 74 33 20 0a 20 20     UPDATE t3 .  
2240: 20 53 45 54 20 62 20 3d 20 27 68 65 6c 6c 6f 20   SET b = 'hello 
2250: 77 6f 72 6c 64 27 0a 20 20 20 57 48 45 52 45 20  world'.   WHERE 
2260: 72 6f 77 69 64 20 3e 3d 20 28 53 45 4c 45 43 54  rowid >= (SELECT
2270: 20 6d 61 78 28 72 6f 77 69 64 29 2d 31 20 46 52   max(rowid)-1 FR
2280: 4f 4d 20 74 33 29 3b 0a 7d 20 2d 74 63 6c 62 6f  OM t3);.} -tclbo
2290: 64 79 20 7b 0a 20 20 73 65 74 20 72 63 20 5b 63  dy {.  set rc [c
22a0: 61 74 63 68 20 7b 64 62 20 65 76 61 6c 20 7b 0a  atch {db eval {.
22b0: 20 20 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 20      BEGIN;.     
22c0: 20 50 52 41 47 4d 41 20 63 61 63 68 65 5f 73 69   PRAGMA cache_si
22d0: 7a 65 20 3d 20 31 30 3b 0a 20 20 20 20 20 20 49  ze = 10;.      I
22e0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 33 20 56 41  NSERT INTO t3 VA
22f0: 4c 55 45 53 28 20 72 61 6e 64 73 74 72 28 31 30  LUES( randstr(10
2300: 30 2c 20 31 30 30 29 2c 20 72 61 6e 64 73 74 72  0, 100), randstr
2310: 28 31 30 30 2c 20 31 30 30 29 20 29 3b 0a 20 20  (100, 100) );.  
2320: 20 20 20 20 55 50 44 41 54 45 20 74 33 20 53 45      UPDATE t3 SE
2330: 54 20 61 20 3d 20 62 3b 0a 20 20 20 20 43 4f 4d  T a = b;.    COM
2340: 4d 49 54 3b 0a 20 20 7d 7d 20 6d 73 67 5d 0a 0a  MIT;.  }} msg]..
2350: 20 20 69 66 20 7b 21 24 72 63 20 7c 7c 20 28 24    if {!$rc || ($
2360: 72 63 20 26 26 20 5b 73 74 72 69 6e 67 20 66 69  rc && [string fi
2370: 72 73 74 20 22 63 6f 6c 75 6d 6e 73 22 20 24 6d  rst "columns" $m
2380: 73 67 5d 3d 3d 30 29 7d 20 7b 0a 20 20 20 20 73  sg]==0)} {.    s
2390: 65 74 20 6d 73 67 0a 20 20 7d 20 65 6c 73 65 20  et msg.  } else 
23a0: 7b 0a 20 20 20 20 65 72 72 6f 72 20 24 6d 73 67  {.    error $msg
23b0: 0a 20 20 7d 0a 7d 0a 0a 73 71 6c 69 74 65 33 20  .  }.}..sqlite3 
23c0: 64 62 20 74 65 73 74 2e 64 62 0a 0a 64 6f 5f 74  db test.db..do_t
23d0: 65 73 74 20 6d 69 73 63 37 2d 31 36 2e 58 20 7b  est misc7-16.X {
23e0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
23f0: 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29   SELECT count(*)
2400: 20 46 52 4f 4d 20 74 33 3b 0a 20 20 7d 0a 7d 20   FROM t3;.  }.} 
2410: 7b 33 32 7d 0a 0a 73 65 74 20 73 71 6c 69 74 65  {32}..set sqlite
2420: 5f 70 61 67 65 72 5f 6e 5f 73 6f 72 74 5f 62 75  _pager_n_sort_bu
2430: 63 6b 65 74 20 34 0a 64 6f 5f 74 65 73 74 20 6d  cket 4.do_test m
2440: 69 73 63 37 2d 31 37 20 7b 0a 20 20 65 78 65 63  isc7-17 {.  exec
2450: 73 71 6c 20 7b 0a 20 20 20 20 50 52 41 47 4d 41  sql {.    PRAGMA
2460: 20 69 6e 74 65 67 72 69 74 79 5f 63 68 65 63 6b   integrity_check
2470: 3b 0a 20 20 20 20 56 41 43 55 55 4d 3b 0a 20 20  ;.    VACUUM;.  
2480: 20 20 50 52 41 47 4d 41 20 69 6e 74 65 67 72 69    PRAGMA integri
2490: 74 79 5f 63 68 65 63 6b 3b 0a 20 20 7d 0a 7d 20  ty_check;.  }.} 
24a0: 7b 6f 6b 20 6f 6b 7d 0a 73 65 74 20 73 71 6c 69  {ok ok}.set sqli
24b0: 74 65 5f 70 61 67 65 72 5f 6e 5f 73 6f 72 74 5f  te_pager_n_sort_
24c0: 62 75 63 6b 65 74 20 30 0a 0a 23 2d 2d 2d 2d 2d  bucket 0..#-----
24d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
24e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
24f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2500: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2510: 2d 0a 23 20 54 65 73 74 20 74 68 65 20 73 69 74  -.# Test the sit
2520: 75 61 74 69 6f 6e 20 77 68 65 72 65 20 61 20 68  uation where a h
2530: 6f 74 2d 6a 6f 75 72 6e 61 6c 20 69 73 20 64 69  ot-journal is di
2540: 73 63 6f 76 65 72 65 64 20 62 75 74 20 77 72 69  scovered but wri
2550: 74 65 2d 61 63 63 65 73 73 0a 23 20 74 6f 20 69  te-access.# to i
2560: 74 20 69 73 20 64 65 6e 69 65 64 2e 20 54 68 69  t is denied. Thi
2570: 73 20 73 68 6f 75 6c 64 20 72 65 74 75 72 6e 20  s should return 
2580: 53 51 4c 49 54 45 5f 42 55 53 59 2e 0a 23 0a 23  SQLITE_BUSY..#.#
2590: 20 54 68 65 73 65 20 74 65 73 74 73 20 64 6f 20   These tests do 
25a0: 6e 6f 74 20 77 6f 72 6b 20 6f 6e 20 77 69 6e 64  not work on wind
25b0: 6f 77 73 20 64 75 65 20 74 6f 20 72 65 73 74 72  ows due to restr
25c0: 69 63 74 69 6f 6e 73 20 69 6e 20 74 68 65 0a 23  ictions in the.#
25d0: 20 77 69 6e 64 6f 77 73 20 66 69 6c 65 20 73 79   windows file sy
25e0: 73 74 65 6d 2e 0a 23 0a 69 66 20 7b 24 74 63 6c  stem..#.if {$tcl
25f0: 5f 70 6c 61 74 66 6f 72 6d 28 70 6c 61 74 66 6f  _platform(platfo
2600: 72 6d 29 21 3d 22 77 69 6e 64 6f 77 73 22 20 26  rm)!="windows" &
2610: 26 20 24 74 63 6c 5f 70 6c 61 74 66 6f 72 6d 28  & $tcl_platform(
2620: 70 6c 61 74 66 6f 72 6d 29 21 3d 22 6f 73 32 22  platform)!="os2"
2630: 7d 20 7b 0a 0a 20 20 23 20 53 6f 6d 65 20 6e 65  } {..  # Some ne
2640: 74 77 6f 72 6b 20 66 69 6c 65 73 79 73 74 65 6d  twork filesystem
2650: 73 20 28 65 78 3a 20 41 46 50 29 20 64 6f 20 6e  s (ex: AFP) do n
2660: 6f 74 20 73 75 70 70 6f 72 74 20 73 65 74 74 69  ot support setti
2670: 6e 67 20 72 65 61 64 2d 6f 6e 6c 79 0a 20 20 23  ng read-only.  #
2680: 20 70 65 72 6d 69 73 73 69 6f 6e 73 2e 20 20 4f   permissions.  O
2690: 6e 6c 79 20 72 75 6e 20 74 68 65 73 65 20 74 65  nly run these te
26a0: 73 74 73 20 69 66 20 66 75 6c 6c 20 75 6e 69 78  sts if full unix
26b0: 20 70 65 72 6d 69 73 73 69 6f 6e 20 73 65 74 74   permission sett
26c0: 69 6e 67 0a 20 20 23 20 63 61 70 61 62 69 6c 69  ing.  # capabili
26d0: 74 69 65 73 20 61 72 65 20 73 75 70 70 6f 72 74  ties are support
26e0: 65 64 2e 0a 20 20 23 0a 20 20 66 69 6c 65 20 61  ed..  #.  file a
26f0: 74 74 72 69 62 75 74 65 73 20 74 65 73 74 2e 64  ttributes test.d
2700: 62 20 2d 70 65 72 6d 69 73 73 69 6f 6e 73 20 72  b -permissions r
2710: 77 2d 72 2d 2d 72 2d 2d 0a 20 20 69 66 20 7b 5b  w-r--r--.  if {[
2720: 66 69 6c 65 20 61 74 74 72 69 62 75 74 65 73 20  file attributes 
2730: 74 65 73 74 2e 64 62 20 2d 70 65 72 6d 69 73 73  test.db -permiss
2740: 69 6f 6e 73 5d 3d 3d 30 36 34 34 7d 20 7b 0a 0a  ions]==0644} {..
2750: 20 20 20 20 64 6f 5f 74 65 73 74 20 6d 69 73 63      do_test misc
2760: 37 2d 31 37 2e 31 20 7b 0a 20 20 20 20 20 20 65  7-17.1 {.      e
2770: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 20 20 20  xecsql {.       
2780: 20 42 45 47 49 4e 3b 0a 20 20 20 20 20 20 20 20   BEGIN;.        
2790: 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 33 20 57  DELETE FROM t3 W
27a0: 48 45 52 45 20 28 6f 69 64 25 33 29 3d 3d 30 3b  HERE (oid%3)==0;
27b0: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 63  .      }.      c
27c0: 6f 70 79 5f 66 69 6c 65 20 74 65 73 74 2e 64 62  opy_file test.db
27d0: 20 62 61 6b 2e 64 62 0a 20 20 20 20 20 20 63 6f   bak.db.      co
27e0: 70 79 5f 66 69 6c 65 20 74 65 73 74 2e 64 62 2d  py_file test.db-
27f0: 6a 6f 75 72 6e 61 6c 20 62 61 6b 2e 64 62 2d 6a  journal bak.db-j
2800: 6f 75 72 6e 61 6c 0a 20 20 20 20 20 20 65 78 65  ournal.      exe
2810: 63 73 71 6c 20 7b 0a 20 20 20 20 20 20 20 20 43  csql {.        C
2820: 4f 4d 4d 49 54 3b 0a 20 20 20 20 20 20 7d 0a 20  OMMIT;.      }. 
2830: 20 20 20 0a 20 20 20 20 20 20 64 62 20 63 6c 6f     .      db clo
2840: 73 65 0a 20 20 20 20 20 20 63 6f 70 79 5f 66 69  se.      copy_fi
2850: 6c 65 20 62 61 6b 2e 64 62 20 74 65 73 74 2e 64  le bak.db test.d
2860: 62 0a 20 20 20 20 20 20 63 6f 70 79 5f 66 69 6c  b.      copy_fil
2870: 65 20 62 61 6b 2e 64 62 2d 6a 6f 75 72 6e 61 6c  e bak.db-journal
2880: 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c   test.db-journal
2890: 0a 20 20 20 20 20 20 73 71 6c 69 74 65 33 20 64  .      sqlite3 d
28a0: 62 20 74 65 73 74 2e 64 62 0a 20 20 20 20 0a 20  b test.db.    . 
28b0: 20 20 20 20 20 63 61 74 63 68 20 7b 66 69 6c 65       catch {file
28c0: 20 61 74 74 72 69 62 75 74 65 73 20 74 65 73 74   attributes test
28d0: 2e 64 62 2d 6a 6f 75 72 6e 61 6c 20 2d 70 65 72  .db-journal -per
28e0: 6d 69 73 73 69 6f 6e 73 20 72 2d 2d 2d 2d 2d 2d  missions r------
28f0: 2d 2d 7d 0a 20 20 20 20 20 20 63 61 74 63 68 20  --}.      catch 
2900: 7b 66 69 6c 65 20 61 74 74 72 69 62 75 74 65 73  {file attributes
2910: 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c   test.db-journal
2920: 20 2d 72 65 61 64 6f 6e 6c 79 20 31 7d 0a 20 20   -readonly 1}.  
2930: 20 20 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20      catchsql {. 
2940: 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 63 6f         SELECT co
2950: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 74 33 3b 0a  unt(*) FROM t3;.
2960: 20 20 20 20 20 20 7d 0a 20 20 20 20 7d 20 7b 31        }.    } {1
2970: 20 7b 75 6e 61 62 6c 65 20 74 6f 20 6f 70 65 6e   {unable to open
2980: 20 64 61 74 61 62 61 73 65 20 66 69 6c 65 7d 7d   database file}}
2990: 0a 20 20 20 20 64 6f 5f 74 65 73 74 20 6d 69 73  .    do_test mis
29a0: 63 37 2d 31 37 2e 32 20 7b 0a 20 20 20 20 20 20  c7-17.2 {.      
29b0: 23 20 4e 6f 74 65 20 74 68 61 74 20 74 68 65 20  # Note that the 
29c0: 2d 72 65 61 64 6f 6e 6c 79 20 66 6c 61 67 20 6d  -readonly flag m
29d0: 75 73 74 20 62 65 20 63 6c 65 61 72 65 64 20 62  ust be cleared b
29e0: 65 66 6f 72 65 20 74 68 65 20 2d 70 65 72 6d 69  efore the -permi
29f0: 73 73 69 6f 6e 73 0a 20 20 20 20 20 20 23 20 61  ssions.      # a
2a00: 72 65 20 73 65 74 2e 20 4f 74 68 65 72 77 69 73  re set. Otherwis
2a10: 65 2c 20 77 68 65 6e 20 75 73 69 6e 67 20 74 63  e, when using tc
2a20: 6c 20 38 2e 35 20 6f 6e 20 6d 61 63 2c 20 74 68  l 8.5 on mac, th
2a30: 65 20 66 61 63 74 20 74 68 61 74 20 74 68 65 20  e fact that the 
2a40: 0a 20 20 20 20 20 20 23 20 2d 72 65 61 64 6f 6e  .      # -readon
2a50: 6c 79 20 66 6c 61 67 20 69 73 20 73 65 74 20 63  ly flag is set c
2a60: 61 75 73 65 73 20 74 68 65 20 61 74 74 65 6d 70  auses the attemp
2a70: 74 20 74 6f 20 73 65 74 20 74 68 65 20 70 65 72  t to set the per
2a80: 6d 69 73 73 69 6f 6e 73 0a 20 20 20 20 20 20 23  missions.      #
2a90: 20 74 6f 20 66 61 69 6c 2e 0a 20 20 20 20 20 20   to fail..      
2aa0: 63 61 74 63 68 20 7b 66 69 6c 65 20 61 74 74 72  catch {file attr
2ab0: 69 62 75 74 65 73 20 74 65 73 74 2e 64 62 2d 6a  ibutes test.db-j
2ac0: 6f 75 72 6e 61 6c 20 2d 72 65 61 64 6f 6e 6c 79  ournal -readonly
2ad0: 20 30 7d 0a 20 20 20 20 20 20 63 61 74 63 68 20   0}.      catch 
2ae0: 7b 66 69 6c 65 20 61 74 74 72 69 62 75 74 65 73  {file attributes
2af0: 20 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c   test.db-journal
2b00: 20 2d 70 65 72 6d 69 73 73 69 6f 6e 73 20 72 77   -permissions rw
2b10: 2d 2d 2d 2d 2d 2d 2d 7d 0a 20 20 20 20 20 20 63  -------}.      c
2b20: 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 20 20  atchsql {.      
2b30: 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a    SELECT count(*
2b40: 29 20 46 52 4f 4d 20 74 33 3b 0a 20 20 20 20 20  ) FROM t3;.     
2b50: 20 7d 0a 20 20 20 20 7d 20 7b 30 20 33 32 7d 0a   }.    } {0 32}.
2b60: 20 20 20 20 0a 20 20 20 20 73 65 74 20 3a 3a 70      .    set ::p
2b70: 65 6e 64 69 6e 67 5f 62 79 74 65 5f 70 61 67 65  ending_byte_page
2b80: 20 5b 65 78 70 72 20 28 24 3a 3a 73 71 6c 69 74   [expr ($::sqlit
2b90: 65 5f 70 65 6e 64 69 6e 67 5f 62 79 74 65 20 2f  e_pending_byte /
2ba0: 20 31 30 32 34 29 20 2b 20 31 5d 0a 20 20 20 20   1024) + 1].    
2bb0: 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d 31 37  do_test misc7-17
2bc0: 2e 33 20 7b 0a 20 20 20 20 20 20 64 62 20 65 76  .3 {.      db ev
2bd0: 61 6c 20 7b 0a 20 20 20 20 20 20 20 20 70 72 61  al {.        pra
2be0: 67 6d 61 20 77 72 69 74 61 62 6c 65 5f 73 63 68  gma writable_sch
2bf0: 65 6d 61 20 3d 20 74 72 75 65 3b 0a 20 20 20 20  ema = true;.    
2c00: 20 20 20 20 55 50 44 41 54 45 20 73 71 6c 69 74      UPDATE sqlit
2c10: 65 5f 6d 61 73 74 65 72 20 0a 20 20 20 20 20 20  e_master .      
2c20: 20 20 20 20 53 45 54 20 72 6f 6f 74 70 61 67 65      SET rootpage
2c30: 20 3d 20 24 70 65 6e 64 69 6e 67 5f 62 79 74 65   = $pending_byte
2c40: 5f 70 61 67 65 0a 20 20 20 20 20 20 20 20 20 20  _page.          
2c50: 57 48 45 52 45 20 74 79 70 65 20 3d 20 27 74 61  WHERE type = 'ta
2c60: 62 6c 65 27 20 41 4e 44 20 6e 61 6d 65 20 3d 20  ble' AND name = 
2c70: 27 74 33 27 3b 0a 20 20 20 20 20 20 7d 0a 20 20  't3';.      }.  
2c80: 20 20 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20      execsql {.  
2c90: 20 20 20 20 20 20 53 45 4c 45 43 54 20 72 6f 6f        SELECT roo
2ca0: 74 70 61 67 65 20 46 52 4f 4d 20 73 71 6c 69 74  tpage FROM sqlit
2cb0: 65 5f 6d 61 73 74 65 72 20 57 48 45 52 45 20 74  e_master WHERE t
2cc0: 79 70 65 20 3d 20 27 74 61 62 6c 65 27 20 41 4e  ype = 'table' AN
2cd0: 44 20 6e 61 6d 65 20 3d 20 27 74 33 27 3b 0a 20  D name = 't3';. 
2ce0: 20 20 20 20 20 7d 0a 20 20 20 20 7d 20 24 3a 3a       }.    } $::
2cf0: 70 65 6e 64 69 6e 67 5f 62 79 74 65 5f 70 61 67  pending_byte_pag
2d00: 65 0a 20 20 20 20 0a 20 20 20 20 64 6f 5f 74 65  e.    .    do_te
2d10: 73 74 20 6d 69 73 63 37 2d 31 37 2e 34 20 7b 0a  st misc7-17.4 {.
2d20: 20 20 20 20 20 20 64 62 20 63 6c 6f 73 65 0a 20        db close. 
2d30: 20 20 20 20 20 73 71 6c 69 74 65 33 20 64 62 20       sqlite3 db 
2d40: 74 65 73 74 2e 64 62 0a 20 20 20 20 20 20 63 61  test.db.      ca
2d50: 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 20 20 20  tchsql {.       
2d60: 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29   SELECT count(*)
2d70: 20 46 52 4f 4d 20 74 33 3b 0a 20 20 20 20 20 20   FROM t3;.      
2d80: 7d 20 0a 20 20 20 20 7d 20 7b 31 20 7b 64 61 74  } .    } {1 {dat
2d90: 61 62 61 73 65 20 64 69 73 6b 20 69 6d 61 67 65  abase disk image
2da0: 20 69 73 20 6d 61 6c 66 6f 72 6d 65 64 7d 7d 0a   is malformed}}.
2db0: 20 20 7d 0a 7d 0a 0a 23 20 54 69 63 6b 65 74 20    }.}..# Ticket 
2dc0: 23 32 34 37 30 0a 23 0a 64 6f 5f 74 65 73 74 20  #2470.#.do_test 
2dd0: 6d 69 73 63 37 2d 31 38 2e 31 20 7b 0a 20 20 65  misc7-18.1 {.  e
2de0: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45  xecsql {.    CRE
2df0: 41 54 45 20 54 41 42 4c 45 20 74 61 62 6c 65 5f  ATE TABLE table_
2e00: 31 20 28 63 6f 6c 5f 31 30 29 3b 0a 20 20 20 20  1 (col_10);.    
2e10: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 61 62  CREATE TABLE tab
2e20: 6c 65 5f 32 20 28 0a 20 20 20 20 20 20 63 6f 6c  le_2 (.      col
2e30: 5f 31 2c 20 63 6f 6c 5f 32 2c 20 63 6f 6c 5f 33  _1, col_2, col_3
2e40: 2c 20 63 6f 6c 5f 34 2c 20 63 6f 6c 5f 35 2c 0a  , col_4, col_5,.
2e50: 20 20 20 20 20 20 63 6f 6c 5f 36 2c 20 63 6f 6c        col_6, col
2e60: 5f 37 2c 20 63 6f 6c 5f 38 2c 20 63 6f 6c 5f 39  _7, col_8, col_9
2e70: 2c 20 63 6f 6c 5f 31 30 0a 20 20 20 20 29 3b 0a  , col_10.    );.
2e80: 20 20 20 20 53 45 4c 45 43 54 20 61 2e 63 6f 6c      SELECT a.col
2e90: 5f 31 30 0a 20 20 20 20 46 52 4f 4d 0a 20 20 20  _10.    FROM.   
2ea0: 20 20 20 28 53 45 4c 45 43 54 20 74 61 62 6c 65     (SELECT table
2eb0: 5f 31 2e 63 6f 6c 5f 31 30 20 41 53 20 63 6f 6c  _1.col_10 AS col
2ec0: 5f 31 30 20 46 52 4f 4d 20 74 61 62 6c 65 5f 31  _10 FROM table_1
2ed0: 29 20 61 2c 0a 20 20 20 20 20 20 28 53 45 4c 45  ) a,.      (SELE
2ee0: 43 54 20 74 61 62 6c 65 5f 31 2e 63 6f 6c 5f 31  CT table_1.col_1
2ef0: 30 2c 20 74 61 62 6c 65 5f 32 2e 63 6f 6c 5f 39  0, table_2.col_9
2f00: 20 41 53 20 71 63 6f 6c 5f 39 0a 20 20 20 20 20   AS qcol_9.     
2f10: 20 20 20 20 46 52 4f 4d 20 74 61 62 6c 65 5f 31      FROM table_1
2f20: 2c 20 74 61 62 6c 65 5f 32 0a 20 20 20 20 20 20  , table_2.      
2f30: 20 20 47 52 4f 55 50 20 42 59 20 74 61 62 6c 65    GROUP BY table
2f40: 5f 31 2e 63 6f 6c 5f 31 30 2c 20 71 63 6f 6c 5f  _1.col_10, qcol_
2f50: 39 29 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 23 20  9);.  }.} {}..# 
2f60: 54 65 73 74 69 6e 67 20 62 6f 75 6e 64 61 72 79  Testing boundary
2f70: 20 63 6f 6e 64 69 74 69 6f 6e 73 20 6f 6e 20 73   conditions on s
2f80: 71 6c 69 74 65 33 5f 73 74 61 74 75 73 28 29 0a  qlite3_status().
2f90: 23 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 37 2d  #.do_test misc7-
2fa0: 31 39 2e 31 20 7b 0a 20 20 73 71 6c 69 74 65 33  19.1 {.  sqlite3
2fb0: 5f 73 74 61 74 75 73 20 2d 31 20 30 0a 7d 20 7b  _status -1 0.} {
2fc0: 32 31 20 30 20 30 7d 0a 64 6f 5f 74 65 73 74 20  21 0 0}.do_test 
2fd0: 6d 69 73 63 37 2d 31 39 2e 32 20 7b 0a 20 20 73  misc7-19.2 {.  s
2fe0: 71 6c 69 74 65 33 5f 73 74 61 74 75 73 20 31 30  qlite3_status 10
2ff0: 30 30 20 30 0a 7d 20 7b 32 31 20 30 20 30 7d 0a  00 0.} {21 0 0}.
3000: 0a 0a 23 20 73 71 6c 69 74 65 33 5f 67 6c 6f 62  ..# sqlite3_glob
3010: 61 6c 5f 72 65 63 6f 76 65 72 28 29 20 69 73 20  al_recover() is 
3020: 61 20 6e 6f 2d 6f 70 2e 20 20 42 75 74 20 77 65  a no-op.  But we
3030: 20 6d 69 67 68 74 20 61 73 20 77 65 6c 6c 20 74   might as well t
3040: 65 73 74 20 69 74 0a 23 20 69 66 20 6f 6e 6c 79  est it.# if only
3050: 20 74 6f 20 67 65 74 20 74 68 65 20 74 65 73 74   to get the test
3060: 20 63 6f 76 65 72 61 67 65 2e 0a 23 0a 64 6f 5f   coverage..#.do_
3070: 74 65 73 74 20 6d 69 73 63 37 2d 32 30 2e 31 20  test misc7-20.1 
3080: 7b 0a 20 20 73 71 6c 69 74 65 33 5f 67 6c 6f 62  {.  sqlite3_glob
3090: 61 6c 5f 72 65 63 6f 76 65 72 0a 7d 20 7b 53 51  al_recover.} {SQ
30a0: 4c 49 54 45 5f 4f 4b 7d 0a 0a 0a 64 62 20 63 6c  LITE_OK}...db cl
30b0: 6f 73 65 0a 66 69 6c 65 20 64 65 6c 65 74 65 20  ose.file delete 
30c0: 2d 66 6f 72 63 65 20 74 65 73 74 2e 64 62 0a 0a  -force test.db..
30d0: 66 69 6e 69 73 68 5f 74 65 73 74 0a              finish_test.