/ Hex Artifact Content
Login

Artifact 7ce84b25df9872e7d7878613a96815d2ba5bc974ac4e15a50118dde8f3917599:


0000: 23 20 32 30 30 31 20 53 65 70 74 65 6d 62 65 72  # 2001 September
0010: 20 31 35 2e 0a 23 0a 23 20 54 68 65 20 61 75 74   15..#.# The aut
0020: 68 6f 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f  hor disclaims co
0030: 70 79 72 69 67 68 74 20 74 6f 20 74 68 69 73 20  pyright to this 
0040: 73 6f 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e  source code.  In
0050: 20 70 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65   place of.# a le
0060: 67 61 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65  gal notice, here
0070: 20 69 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a   is a blessing:.
0080: 23 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64  #.#    May you d
0090: 6f 20 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65  o good and not e
00a0: 76 69 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f  vil..#    May yo
00b0: 75 20 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65  u find forgivene
00c0: 73 73 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20  ss for yourself 
00d0: 61 6e 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65  and forgive othe
00e0: 72 73 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75  rs..#    May you
00f0: 20 73 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e   share freely, n
0100: 65 76 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65  ever taking more
0110: 20 74 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a   than you give..
0120: 23 0a 23 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 2a 2a 0a 23 20 54 68 69  **********.# Thi
0170: 73 20 66 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74  s file implement
0180: 73 20 72 65 67 72 65 73 73 69 6f 6e 20 74 65 73  s regression tes
0190: 74 73 20 66 6f 72 20 53 51 4c 69 74 65 20 6c 69  ts for SQLite li
01a0: 62 72 61 72 79 2e 0a 23 0a 23 20 54 68 69 73 20  brary..#.# This 
01b0: 66 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20  file implements 
01c0: 74 65 73 74 73 20 66 6f 72 20 6d 69 73 63 65 6c  tests for miscel
01d0: 6c 61 6e 6f 75 73 20 66 65 61 74 75 72 65 73 20  lanous features 
01e0: 74 68 61 74 20 77 65 72 65 0a 23 20 6c 65 66 74  that were.# left
01f0: 20 6f 75 74 20 6f 66 20 6f 74 68 65 72 20 74 65   out of other te
0200: 73 74 20 66 69 6c 65 73 2e 0a 23 0a 0a 73 65 74  st files..#..set
0210: 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65 20 64   testdir [file d
0220: 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d 0a 73  irname $argv0].s
0230: 6f 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 74  ource $testdir/t
0240: 65 73 74 65 72 2e 74 63 6c 0a 0a 23 20 4d 69 6d  ester.tcl..# Mim
0250: 69 63 20 74 68 65 20 53 51 4c 69 74 65 20 32 20  ic the SQLite 2 
0260: 63 6f 6c 6c 61 74 69 6f 6e 20 74 79 70 65 20 4e  collation type N
0270: 55 4d 45 52 49 43 2e 0a 64 62 20 63 6f 6c 6c 61  UMERIC..db colla
0280: 74 65 20 6e 75 6d 65 72 69 63 20 6e 75 6d 65 72  te numeric numer
0290: 69 63 5f 63 6f 6c 6c 61 74 65 0a 70 72 6f 63 20  ic_collate.proc 
02a0: 6e 75 6d 65 72 69 63 5f 63 6f 6c 6c 61 74 65 20  numeric_collate 
02b0: 7b 6c 68 73 20 72 68 73 7d 20 7b 0a 20 20 69 66  {lhs rhs} {.  if
02c0: 20 7b 24 6c 68 73 20 3d 3d 20 24 72 68 73 7d 20   {$lhs == $rhs} 
02d0: 7b 72 65 74 75 72 6e 20 30 7d 20 0a 20 20 72 65  {return 0} .  re
02e0: 74 75 72 6e 20 5b 65 78 70 72 20 28 24 6c 68 73  turn [expr ($lhs
02f0: 3e 24 72 68 73 29 3f 31 3a 2d 31 5d 0a 7d 0a 0a  >$rhs)?1:-1].}..
0300: 23 20 4d 69 6d 69 63 20 74 68 65 20 53 51 4c 69  # Mimic the SQLi
0310: 74 65 20 32 20 63 6f 6c 6c 61 74 69 6f 6e 20 74  te 2 collation t
0320: 79 70 65 20 54 45 58 54 2e 0a 64 62 20 63 6f 6c  ype TEXT..db col
0330: 6c 61 74 65 20 74 65 78 74 20 74 65 78 74 5f 63  late text text_c
0340: 6f 6c 6c 61 74 65 0a 70 72 6f 63 20 6e 75 6d 65  ollate.proc nume
0350: 72 69 63 5f 63 6f 6c 6c 61 74 65 20 7b 6c 68 73  ric_collate {lhs
0360: 20 72 68 73 7d 20 7b 0a 20 20 72 65 74 75 72 6e   rhs} {.  return
0370: 20 5b 73 74 72 69 6e 67 20 63 6f 6d 70 61 72 65   [string compare
0380: 20 24 6c 68 73 20 24 72 68 73 5d 0a 7d 0a 0a 23   $lhs $rhs].}..#
0390: 20 54 65 73 74 20 74 68 65 20 63 72 65 61 74 69   Test the creati
03a0: 6f 6e 20 61 6e 64 20 75 73 65 20 6f 66 20 74 61  on and use of ta
03b0: 62 6c 65 73 20 74 68 61 74 20 68 61 76 65 20 61  bles that have a
03c0: 20 6c 61 72 67 65 20 6e 75 6d 62 65 72 0a 23 20   large number.# 
03d0: 6f 66 20 63 6f 6c 75 6d 6e 73 2e 0a 23 0a 64 6f  of columns..#.do
03e0: 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 2e 31 20  _test misc1-1.1 
03f0: 7b 0a 20 20 73 65 74 20 63 6d 64 20 22 43 52 45  {.  set cmd "CRE
0400: 41 54 45 20 54 41 42 4c 45 20 6d 61 6e 79 63 6f  ATE TABLE manyco
0410: 6c 28 78 30 20 74 65 78 74 22 0a 20 20 66 6f 72  l(x0 text".  for
0420: 20 7b 73 65 74 20 69 20 31 7d 20 7b 24 69 3c 3d   {set i 1} {$i<=
0430: 39 39 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20  99} {incr i} {. 
0440: 20 20 20 61 70 70 65 6e 64 20 63 6d 64 20 22 2c     append cmd ",
0450: 78 24 69 20 74 65 78 74 22 0a 20 20 7d 0a 20 20  x$i text".  }.  
0460: 61 70 70 65 6e 64 20 63 6d 64 20 22 29 22 3b 0a  append cmd ")";.
0470: 20 20 65 78 65 63 73 71 6c 20 24 63 6d 64 0a 20    execsql $cmd. 
0480: 20 73 65 74 20 63 6d 64 20 22 49 4e 53 45 52 54   set cmd "INSERT
0490: 20 49 4e 54 4f 20 6d 61 6e 79 63 6f 6c 20 56 41   INTO manycol VA
04a0: 4c 55 45 53 28 30 22 0a 20 20 66 6f 72 20 7b 73  LUES(0".  for {s
04b0: 65 74 20 69 20 31 7d 20 7b 24 69 3c 3d 39 39 7d  et i 1} {$i<=99}
04c0: 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20   {incr i} {.    
04d0: 61 70 70 65 6e 64 20 63 6d 64 20 22 2c 24 69 22  append cmd ",$i"
04e0: 0a 20 20 7d 0a 20 20 61 70 70 65 6e 64 20 63 6d  .  }.  append cm
04f0: 64 20 22 29 22 3b 0a 20 20 65 78 65 63 73 71 6c  d ")";.  execsql
0500: 20 24 63 6d 64 0a 20 20 65 78 65 63 73 71 6c 20   $cmd.  execsql 
0510: 22 53 45 4c 45 43 54 20 78 39 39 20 46 52 4f 4d  "SELECT x99 FROM
0520: 20 6d 61 6e 79 63 6f 6c 22 0a 7d 20 39 39 0a 64   manycol".} 99.d
0530: 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 2e 32  o_test misc1-1.2
0540: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 53 45   {.  execsql {SE
0550: 4c 45 43 54 20 78 30 2c 20 78 31 30 2c 20 78 32  LECT x0, x10, x2
0560: 35 2c 20 78 35 30 2c 20 78 37 35 20 46 52 4f 4d  5, x50, x75 FROM
0570: 20 6d 61 6e 79 63 6f 6c 7d 0a 7d 20 7b 30 20 31   manycol}.} {0 1
0580: 30 20 32 35 20 35 30 20 37 35 7d 0a 64 6f 5f 74  0 25 50 75}.do_t
0590: 65 73 74 20 6d 69 73 63 31 2d 31 2e 33 2e 31 20  est misc1-1.3.1 
05a0: 7b 0a 20 20 66 6f 72 20 7b 73 65 74 20 6a 20 31  {.  for {set j 1
05b0: 30 30 7d 20 7b 24 6a 3c 3d 31 30 30 30 7d 20 7b  00} {$j<=1000} {
05c0: 69 6e 63 72 20 6a 20 31 30 30 7d 20 7b 0a 20 20  incr j 100} {.  
05d0: 20 20 73 65 74 20 63 6d 64 20 22 49 4e 53 45 52    set cmd "INSER
05e0: 54 20 49 4e 54 4f 20 6d 61 6e 79 63 6f 6c 20 56  T INTO manycol V
05f0: 41 4c 55 45 53 28 24 6a 22 0a 20 20 20 20 66 6f  ALUES($j".    fo
0600: 72 20 7b 73 65 74 20 69 20 31 7d 20 7b 24 69 3c  r {set i 1} {$i<
0610: 3d 39 39 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a  =99} {incr i} {.
0620: 20 20 20 20 20 20 61 70 70 65 6e 64 20 63 6d 64        append cmd
0630: 20 22 2c 5b 65 78 70 72 20 7b 24 69 2b 24 6a 7d   ",[expr {$i+$j}
0640: 5d 22 0a 20 20 20 20 7d 0a 20 20 20 20 61 70 70  ]".    }.    app
0650: 65 6e 64 20 63 6d 64 20 22 29 22 0a 20 20 20 20  end cmd ")".    
0660: 65 78 65 63 73 71 6c 20 24 63 6d 64 0a 20 20 7d  execsql $cmd.  }
0670: 0a 20 20 65 78 65 63 73 71 6c 20 7b 53 45 4c 45  .  execsql {SELE
0680: 43 54 20 78 35 30 20 46 52 4f 4d 20 6d 61 6e 79  CT x50 FROM many
0690: 63 6f 6c 20 4f 52 44 45 52 20 42 59 20 78 38 30  col ORDER BY x80
06a0: 2b 30 7d 0a 7d 20 7b 35 30 20 31 35 30 20 32 35  +0}.} {50 150 25
06b0: 30 20 33 35 30 20 34 35 30 20 35 35 30 20 36 35  0 350 450 550 65
06c0: 30 20 37 35 30 20 38 35 30 20 39 35 30 20 31 30  0 750 850 950 10
06d0: 35 30 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63  50}.do_test misc
06e0: 31 2d 31 2e 33 2e 32 20 7b 0a 20 20 65 78 65 63  1-1.3.2 {.  exec
06f0: 73 71 6c 20 7b 53 45 4c 45 43 54 20 78 35 30 20  sql {SELECT x50 
0700: 46 52 4f 4d 20 6d 61 6e 79 63 6f 6c 20 4f 52 44  FROM manycol ORD
0710: 45 52 20 42 59 20 78 38 30 7d 0a 7d 20 7b 31 30  ER BY x80}.} {10
0720: 35 30 20 31 35 30 20 32 35 30 20 33 35 30 20 34  50 150 250 350 4
0730: 35 30 20 35 35 30 20 36 35 30 20 37 35 30 20 35  50 550 650 750 5
0740: 30 20 38 35 30 20 39 35 30 7d 0a 64 6f 5f 74 65  0 850 950}.do_te
0750: 73 74 20 6d 69 73 63 31 2d 31 2e 34 20 7b 0a 20  st misc1-1.4 {. 
0760: 20 65 78 65 63 73 71 6c 20 7b 53 45 4c 45 43 54   execsql {SELECT
0770: 20 78 37 35 20 46 52 4f 4d 20 6d 61 6e 79 63 6f   x75 FROM manyco
0780: 6c 20 57 48 45 52 45 20 78 35 30 3d 33 35 30 7d  l WHERE x50=350}
0790: 0a 7d 20 33 37 35 0a 64 6f 5f 74 65 73 74 20 6d  .} 375.do_test m
07a0: 69 73 63 31 2d 31 2e 35 20 7b 0a 20 20 65 78 65  isc1-1.5 {.  exe
07b0: 63 73 71 6c 20 7b 53 45 4c 45 43 54 20 78 35 30  csql {SELECT x50
07c0: 20 46 52 4f 4d 20 6d 61 6e 79 63 6f 6c 20 57 48   FROM manycol WH
07d0: 45 52 45 20 78 39 39 3d 35 39 39 7d 0a 7d 20 35  ERE x99=599}.} 5
07e0: 35 30 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31  50.do_test misc1
07f0: 2d 31 2e 36 20 7b 0a 20 20 65 78 65 63 73 71 6c  -1.6 {.  execsql
0800: 20 7b 43 52 45 41 54 45 20 49 4e 44 45 58 20 6d   {CREATE INDEX m
0810: 61 6e 79 63 6f 6c 5f 69 64 78 31 20 4f 4e 20 6d  anycol_idx1 ON m
0820: 61 6e 79 63 6f 6c 28 78 39 39 29 7d 0a 20 20 65  anycol(x99)}.  e
0830: 78 65 63 73 71 6c 20 7b 53 45 4c 45 43 54 20 78  xecsql {SELECT x
0840: 35 30 20 46 52 4f 4d 20 6d 61 6e 79 63 6f 6c 20  50 FROM manycol 
0850: 57 48 45 52 45 20 78 39 39 3d 38 39 39 7d 0a 7d  WHERE x99=899}.}
0860: 20 38 35 30 0a 64 6f 5f 74 65 73 74 20 6d 69 73   850.do_test mis
0870: 63 31 2d 31 2e 37 20 7b 0a 20 20 65 78 65 63 73  c1-1.7 {.  execs
0880: 71 6c 20 7b 53 45 4c 45 43 54 20 63 6f 75 6e 74  ql {SELECT count
0890: 28 2a 29 20 46 52 4f 4d 20 6d 61 6e 79 63 6f 6c  (*) FROM manycol
08a0: 7d 0a 7d 20 31 31 0a 64 6f 5f 74 65 73 74 20 6d  }.} 11.do_test m
08b0: 69 73 63 31 2d 31 2e 38 20 7b 0a 20 20 65 78 65  isc1-1.8 {.  exe
08c0: 63 73 71 6c 20 7b 44 45 4c 45 54 45 20 46 52 4f  csql {DELETE FRO
08d0: 4d 20 6d 61 6e 79 63 6f 6c 20 57 48 45 52 45 20  M manycol WHERE 
08e0: 78 39 38 3d 31 32 33 34 7d 0a 20 20 65 78 65 63  x98=1234}.  exec
08f0: 73 71 6c 20 7b 53 45 4c 45 43 54 20 63 6f 75 6e  sql {SELECT coun
0900: 74 28 2a 29 20 46 52 4f 4d 20 6d 61 6e 79 63 6f  t(*) FROM manyco
0910: 6c 7d 0a 7d 20 31 31 0a 64 6f 5f 74 65 73 74 20  l}.} 11.do_test 
0920: 6d 69 73 63 31 2d 31 2e 39 20 7b 0a 20 20 65 78  misc1-1.9 {.  ex
0930: 65 63 73 71 6c 20 7b 44 45 4c 45 54 45 20 46 52  ecsql {DELETE FR
0940: 4f 4d 20 6d 61 6e 79 63 6f 6c 20 57 48 45 52 45  OM manycol WHERE
0950: 20 78 39 38 3d 39 39 38 7d 0a 20 20 65 78 65 63   x98=998}.  exec
0960: 73 71 6c 20 7b 53 45 4c 45 43 54 20 63 6f 75 6e  sql {SELECT coun
0970: 74 28 2a 29 20 46 52 4f 4d 20 6d 61 6e 79 63 6f  t(*) FROM manyco
0980: 6c 7d 0a 7d 20 31 30 0a 64 6f 5f 74 65 73 74 20  l}.} 10.do_test 
0990: 6d 69 73 63 31 2d 31 2e 31 30 20 7b 0a 20 20 65  misc1-1.10 {.  e
09a0: 78 65 63 73 71 6c 20 7b 44 45 4c 45 54 45 20 46  xecsql {DELETE F
09b0: 52 4f 4d 20 6d 61 6e 79 63 6f 6c 20 57 48 45 52  ROM manycol WHER
09c0: 45 20 78 39 39 3d 35 30 30 7d 0a 20 20 65 78 65  E x99=500}.  exe
09d0: 63 73 71 6c 20 7b 53 45 4c 45 43 54 20 63 6f 75  csql {SELECT cou
09e0: 6e 74 28 2a 29 20 46 52 4f 4d 20 6d 61 6e 79 63  nt(*) FROM manyc
09f0: 6f 6c 7d 0a 7d 20 31 30 0a 64 6f 5f 74 65 73 74  ol}.} 10.do_test
0a00: 20 6d 69 73 63 31 2d 31 2e 31 31 20 7b 0a 20 20   misc1-1.11 {.  
0a10: 65 78 65 63 73 71 6c 20 7b 44 45 4c 45 54 45 20  execsql {DELETE 
0a20: 46 52 4f 4d 20 6d 61 6e 79 63 6f 6c 20 57 48 45  FROM manycol WHE
0a30: 52 45 20 78 39 39 3d 35 39 39 7d 0a 20 20 65 78  RE x99=599}.  ex
0a40: 65 63 73 71 6c 20 7b 53 45 4c 45 43 54 20 63 6f  ecsql {SELECT co
0a50: 75 6e 74 28 2a 29 20 46 52 4f 4d 20 6d 61 6e 79  unt(*) FROM many
0a60: 63 6f 6c 7d 0a 7d 20 39 0a 0a 23 20 43 68 65 63  col}.} 9..# Chec
0a70: 6b 20 47 52 4f 55 50 20 42 59 20 65 78 70 72 65  k GROUP BY expre
0a80: 73 73 69 6f 6e 73 20 74 68 61 74 20 6e 61 6d 65  ssions that name
0a90: 20 74 77 6f 20 6f 72 20 6d 6f 72 65 20 63 6f 6c   two or more col
0aa0: 75 6d 6e 73 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  umns..#.do_test 
0ab0: 6d 69 73 63 31 2d 32 2e 31 20 7b 0a 20 20 65 78  misc1-2.1 {.  ex
0ac0: 65 63 73 71 6c 20 7b 0a 20 20 20 20 42 45 47 49  ecsql {.    BEGI
0ad0: 4e 20 54 52 41 4e 53 41 43 54 49 4f 4e 3b 0a 20  N TRANSACTION;. 
0ae0: 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20     CREATE TABLE 
0af0: 61 67 67 65 72 28 6f 6e 65 20 74 65 78 74 2c 20  agger(one text, 
0b00: 74 77 6f 20 74 65 78 74 2c 20 74 68 72 65 65 20  two text, three 
0b10: 74 65 78 74 2c 20 66 6f 75 72 20 74 65 78 74 29  text, four text)
0b20: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
0b30: 4f 20 61 67 67 65 72 20 56 41 4c 55 45 53 28 31  O agger VALUES(1
0b40: 2c 20 27 6f 6e 65 27 2c 20 27 68 65 6c 6c 6f 27  , 'one', 'hello'
0b50: 2c 20 27 79 65 73 27 29 3b 0a 20 20 20 20 49 4e  , 'yes');.    IN
0b60: 53 45 52 54 20 49 4e 54 4f 20 61 67 67 65 72 20  SERT INTO agger 
0b70: 56 41 4c 55 45 53 28 32 2c 20 27 74 77 6f 27 2c  VALUES(2, 'two',
0b80: 20 27 68 6f 77 64 79 27 2c 20 27 6e 6f 27 29 3b   'howdy', 'no');
0b90: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
0ba0: 20 61 67 67 65 72 20 56 41 4c 55 45 53 28 33 2c   agger VALUES(3,
0bb0: 20 27 74 68 72 27 2c 20 27 68 6f 77 61 72 65 79   'thr', 'howarey
0bc0: 61 27 2c 20 27 79 65 73 27 29 3b 0a 20 20 20 20  a', 'yes');.    
0bd0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 67 67 65  INSERT INTO agge
0be0: 72 20 56 41 4c 55 45 53 28 34 2c 20 27 74 77 6f  r VALUES(4, 'two
0bf0: 27 2c 20 27 6c 6f 74 68 65 72 65 27 2c 20 27 79  ', 'lothere', 'y
0c00: 65 73 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 54  es');.    INSERT
0c10: 20 49 4e 54 4f 20 61 67 67 65 72 20 56 41 4c 55   INTO agger VALU
0c20: 45 53 28 35 2c 20 27 6f 6e 65 27 2c 20 27 61 74  ES(5, 'one', 'at
0c30: 63 68 61 27 2c 20 27 79 65 73 27 29 3b 0a 20 20  cha', 'yes');.  
0c40: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 67    INSERT INTO ag
0c50: 67 65 72 20 56 41 4c 55 45 53 28 36 2c 20 27 74  ger VALUES(6, 't
0c60: 77 6f 27 2c 20 27 68 65 6c 6c 6f 27 2c 20 27 6e  wo', 'hello', 'n
0c70: 6f 27 29 3b 0a 20 20 20 20 43 4f 4d 4d 49 54 0a  o');.    COMMIT.
0c80: 20 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 53    }.  execsql {S
0c90: 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46  ELECT count(*) F
0ca0: 52 4f 4d 20 61 67 67 65 72 7d 0a 7d 20 36 0a 64  ROM agger}.} 6.d
0cb0: 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 32 2e 32  o_test misc1-2.2
0cc0: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 53 45   {.  execsql {SE
0cd0: 4c 45 43 54 20 73 75 6d 28 6f 6e 65 29 2c 20 74  LECT sum(one), t
0ce0: 77 6f 2c 20 66 6f 75 72 20 46 52 4f 4d 20 61 67  wo, four FROM ag
0cf0: 67 65 72 0a 20 20 20 20 20 20 20 20 20 20 20 47  ger.           G
0d00: 52 4f 55 50 20 42 59 20 74 77 6f 2c 20 66 6f 75  ROUP BY two, fou
0d10: 72 20 4f 52 44 45 52 20 42 59 20 73 75 6d 28 6f  r ORDER BY sum(o
0d20: 6e 65 29 20 64 65 73 63 7d 0a 7d 20 7b 38 20 74  ne) desc}.} {8 t
0d30: 77 6f 20 6e 6f 20 36 20 6f 6e 65 20 79 65 73 20  wo no 6 one yes 
0d40: 34 20 74 77 6f 20 79 65 73 20 33 20 74 68 72 20  4 two yes 3 thr 
0d50: 79 65 73 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73  yes}.do_test mis
0d60: 63 31 2d 32 2e 33 20 7b 0a 20 20 65 78 65 63 73  c1-2.3 {.  execs
0d70: 71 6c 20 7b 53 45 4c 45 43 54 20 73 75 6d 28 28  ql {SELECT sum((
0d80: 6f 6e 65 29 29 2c 20 28 74 77 6f 29 2c 20 28 66  one)), (two), (f
0d90: 6f 75 72 29 20 46 52 4f 4d 20 61 67 67 65 72 0a  our) FROM agger.
0da0: 20 20 20 20 20 20 20 20 20 20 20 47 52 4f 55 50             GROUP
0db0: 20 42 59 20 28 74 77 6f 29 2c 20 28 66 6f 75 72   BY (two), (four
0dc0: 29 20 4f 52 44 45 52 20 42 59 20 73 75 6d 28 6f  ) ORDER BY sum(o
0dd0: 6e 65 29 20 64 65 73 63 7d 0a 7d 20 7b 38 20 74  ne) desc}.} {8 t
0de0: 77 6f 20 6e 6f 20 36 20 6f 6e 65 20 79 65 73 20  wo no 6 one yes 
0df0: 34 20 74 77 6f 20 79 65 73 20 33 20 74 68 72 20  4 two yes 3 thr 
0e00: 79 65 73 7d 0a 0a 23 20 48 65 72 65 27 73 20 61  yes}..# Here's a
0e10: 20 74 65 73 74 20 66 6f 72 20 61 20 62 75 67 20   test for a bug 
0e20: 66 6f 75 6e 64 20 62 79 20 4a 6f 65 6c 20 4c 75  found by Joel Lu
0e30: 63 73 79 2e 20 20 54 68 65 20 63 6f 64 65 20 62  csy.  The code b
0e40: 65 6c 6f 77 0a 23 20 77 61 73 20 63 61 75 73 69  elow.# was causi
0e50: 6e 67 20 61 6e 20 61 73 73 65 72 74 69 6f 6e 20  ng an assertion 
0e60: 66 61 69 6c 75 72 65 2e 0a 23 0a 64 6f 5f 74 65  failure..#.do_te
0e70: 73 74 20 6d 69 73 63 31 2d 33 2e 31 20 7b 0a 20  st misc1-3.1 {. 
0e80: 20 73 65 74 20 72 20 5b 65 78 65 63 73 71 6c 20   set r [execsql 
0e90: 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54 41 42  {.    CREATE TAB
0ea0: 4c 45 20 74 31 28 61 29 3b 0a 20 20 20 20 49 4e  LE t1(a);.    IN
0eb0: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
0ec0: 55 45 53 28 27 68 69 27 29 3b 0a 20 20 20 20 50  UES('hi');.    P
0ed0: 52 41 47 4d 41 20 66 75 6c 6c 5f 63 6f 6c 75 6d  RAGMA full_colum
0ee0: 6e 5f 6e 61 6d 65 73 3d 6f 6e 3b 0a 20 20 20 20  n_names=on;.    
0ef0: 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 2a 20  SELECT rowid, * 
0f00: 46 52 4f 4d 20 74 31 3b 0a 20 20 7d 5d 0a 20 20  FROM t1;.  }].  
0f10: 6c 69 6e 64 65 78 20 24 72 20 31 0a 7d 20 7b 68  lindex $r 1.} {h
0f20: 69 7d 0a 0a 23 20 48 65 72 65 27 73 20 61 20 74  i}..# Here's a t
0f30: 65 73 74 20 66 6f 72 20 79 65 74 20 61 6e 6f 74  est for yet anot
0f40: 68 65 72 20 62 75 67 20 66 6f 75 6e 64 20 62 79  her bug found by
0f50: 20 4a 6f 65 6c 20 4c 75 63 73 79 2e 20 20 54 68   Joel Lucsy.  Th
0f60: 65 20 63 6f 64 65 0a 23 20 62 65 6c 6f 77 20 77  e code.# below w
0f70: 61 73 20 63 61 75 73 69 6e 67 20 61 6e 20 61 73  as causing an as
0f80: 73 65 72 74 69 6f 6e 20 66 61 69 6c 75 72 65 2e  sertion failure.
0f90: 0a 23 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31  .#.do_test misc1
0fa0: 2d 34 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c  -4.1 {.  execsql
0fb0: 20 7b 0a 20 20 20 20 42 45 47 49 4e 3b 0a 20 20   {.    BEGIN;.  
0fc0: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74    CREATE TABLE t
0fd0: 32 28 61 29 3b 0a 20 20 20 20 49 4e 53 45 52 54  2(a);.    INSERT
0fe0: 20 49 4e 54 4f 20 74 32 20 56 41 4c 55 45 53 28   INTO t2 VALUES(
0ff0: 27 54 68 69 73 20 69 73 20 61 20 6c 6f 6e 67 20  'This is a long 
1000: 73 74 72 69 6e 67 20 74 6f 20 75 73 65 20 75 70  string to use up
1010: 20 61 20 6c 6f 74 20 6f 66 20 64 69 73 6b 20 2d   a lot of disk -
1020: 27 29 3b 0a 20 20 20 20 55 50 44 41 54 45 20 74  ');.    UPDATE t
1030: 32 20 53 45 54 20 61 3d 61 7c 7c 61 7c 7c 61 7c  2 SET a=a||a||a|
1040: 7c 61 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  |a;.    INSERT I
1050: 4e 54 4f 20 74 32 20 53 45 4c 45 43 54 20 27 31  NTO t2 SELECT '1
1060: 20 2d 20 27 20 7c 7c 20 61 20 46 52 4f 4d 20 74   - ' || a FROM t
1070: 32 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  2;.    INSERT IN
1080: 54 4f 20 74 32 20 53 45 4c 45 43 54 20 27 32 20  TO t2 SELECT '2 
1090: 2d 20 27 20 7c 7c 20 61 20 46 52 4f 4d 20 74 32  - ' || a FROM t2
10a0: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
10b0: 4f 20 74 32 20 53 45 4c 45 43 54 20 27 33 20 2d  O t2 SELECT '3 -
10c0: 20 27 20 7c 7c 20 61 20 46 52 4f 4d 20 74 32 3b   ' || a FROM t2;
10d0: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
10e0: 20 74 32 20 53 45 4c 45 43 54 20 27 34 20 2d 20   t2 SELECT '4 - 
10f0: 27 20 7c 7c 20 61 20 46 52 4f 4d 20 74 32 3b 0a  ' || a FROM t2;.
1100: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
1110: 74 32 20 53 45 4c 45 43 54 20 27 35 20 2d 20 27  t2 SELECT '5 - '
1120: 20 7c 7c 20 61 20 46 52 4f 4d 20 74 32 3b 0a 20   || a FROM t2;. 
1130: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
1140: 32 20 53 45 4c 45 43 54 20 27 36 20 2d 20 27 20  2 SELECT '6 - ' 
1150: 7c 7c 20 61 20 46 52 4f 4d 20 74 32 3b 0a 20 20  || a FROM t2;.  
1160: 20 20 43 4f 4d 4d 49 54 3b 0a 20 20 20 20 53 45    COMMIT;.    SE
1170: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
1180: 4f 4d 20 74 32 3b 0a 20 20 7d 0a 7d 20 7b 36 34  OM t2;.  }.} {64
1190: 7d 0a 0a 23 20 4d 61 6b 65 20 73 75 72 65 20 77  }..# Make sure w
11a0: 65 20 61 63 74 75 61 6c 6c 79 20 73 65 65 20 61  e actually see a
11b0: 20 73 65 6d 69 63 6f 6c 6f 6e 20 6f 72 20 65 6e   semicolon or en
11c0: 64 2d 6f 66 2d 66 69 6c 65 20 69 6e 20 74 68 65  d-of-file in the
11d0: 20 53 51 4c 20 69 6e 70 75 74 0a 23 20 62 65 66   SQL input.# bef
11e0: 6f 72 65 20 65 78 65 63 75 74 69 6e 67 20 61 20  ore executing a 
11f0: 63 6f 6d 6d 61 6e 64 2e 20 20 54 68 75 73 20 69  command.  Thus i
1200: 66 20 22 57 48 45 52 45 22 20 69 73 20 6d 69 73  f "WHERE" is mis
1210: 73 70 65 6c 6c 65 64 20 6f 6e 20 61 6e 20 55 50  spelled on an UP
1220: 44 41 54 45 2c 0a 23 20 74 68 65 20 75 73 65 72  DATE,.# the user
1230: 20 77 6f 6e 27 74 20 61 63 63 69 64 65 6e 74 6c   won't accidentl
1240: 79 20 75 70 64 61 74 65 20 65 76 65 72 79 20 72  y update every r
1250: 65 63 6f 72 64 2e 0a 23 0a 64 6f 5f 74 65 73 74  ecord..#.do_test
1260: 20 6d 69 73 63 31 2d 35 2e 31 20 7b 0a 20 20 63   misc1-5.1 {.  c
1270: 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52  atchsql {.    CR
1280: 45 41 54 45 20 54 41 42 4c 45 20 74 33 28 61 2c  EATE TABLE t3(a,
1290: 62 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  b);.    INSERT I
12a0: 4e 54 4f 20 74 33 20 56 41 4c 55 45 53 28 31 2c  NTO t3 VALUES(1,
12b0: 32 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  2);.    INSERT I
12c0: 4e 54 4f 20 74 33 20 56 41 4c 55 45 53 28 33 2c  NTO t3 VALUES(3,
12d0: 34 29 3b 0a 20 20 20 20 55 50 44 41 54 45 20 74  4);.    UPDATE t
12e0: 33 20 53 45 54 20 61 3d 30 20 57 48 45 52 45 77  3 SET a=0 WHEREw
12f0: 77 77 20 62 3d 32 3b 0a 20 20 7d 0a 7d 20 7b 31  ww b=2;.  }.} {1
1300: 20 7b 6e 65 61 72 20 22 57 48 45 52 45 77 77 77   {near "WHEREwww
1310: 22 3a 20 73 79 6e 74 61 78 20 65 72 72 6f 72 7d  ": syntax error}
1320: 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d  }.do_test misc1-
1330: 35 2e 32 20 7b 0a 20 20 65 78 65 63 73 71 6c 20  5.2 {.  execsql 
1340: 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 2a 20 46  {.    SELECT * F
1350: 52 4f 4d 20 74 33 20 4f 52 44 45 52 20 42 59 20  ROM t3 ORDER BY 
1360: 61 3b 0a 20 20 7d 0a 7d 20 7b 31 20 32 20 33 20  a;.  }.} {1 2 3 
1370: 34 7d 0a 0a 23 20 43 65 72 74 61 69 6e 20 6b 65  4}..# Certain ke
1380: 79 77 6f 72 64 73 20 28 65 73 70 65 63 69 61 6c  ywords (especial
1390: 6c 79 20 6e 6f 6e 2d 73 74 61 6e 64 61 72 64 20  ly non-standard 
13a0: 6b 65 79 77 6f 72 64 73 20 6c 69 6b 65 20 22 52  keywords like "R
13b0: 45 50 4c 41 43 45 22 29 20 63 61 6e 0a 23 20 61  EPLACE") can.# a
13c0: 6c 73 6f 20 62 65 20 75 73 65 64 20 61 73 20 69  lso be used as i
13d0: 64 65 6e 74 69 66 69 65 72 73 2e 20 20 54 68 65  dentifiers.  The
13e0: 20 77 61 79 20 74 68 69 73 20 77 6f 72 6b 73 20   way this works 
13f0: 69 6e 20 74 68 65 20 70 61 72 73 65 72 20 69 73  in the parser is
1400: 20 74 68 61 74 0a 23 20 74 68 65 20 70 61 72 73   that.# the pars
1410: 65 72 20 66 69 72 73 74 20 64 65 74 65 63 74 73  er first detects
1420: 20 61 20 73 79 6e 74 61 78 20 65 72 72 6f 72 2c   a syntax error,
1430: 20 74 68 65 20 65 72 72 6f 72 20 68 61 6e 64 6c   the error handl
1440: 69 6e 67 20 72 6f 75 74 69 6e 65 0a 23 20 73 65  ing routine.# se
1450: 65 73 20 74 68 61 74 20 74 68 65 20 73 70 65 63  es that the spec
1460: 69 61 6c 20 6b 65 79 77 6f 72 64 20 63 61 75 73  ial keyword caus
1470: 65 64 20 74 68 65 20 65 72 72 6f 72 2c 20 74 68  ed the error, th
1480: 65 6e 20 72 65 70 6c 61 63 65 73 20 74 68 65 20  en replaces the 
1490: 6b 65 79 77 6f 72 64 0a 23 20 77 69 74 68 20 22  keyword.# with "
14a0: 49 44 22 20 61 6e 64 20 74 72 69 65 73 20 61 67  ID" and tries ag
14b0: 61 69 6e 2e 0a 23 0a 23 20 43 68 65 63 6b 20 74  ain..#.# Check t
14c0: 68 65 20 6f 70 65 72 61 74 69 6f 6e 20 6f 66 20  he operation of 
14d0: 74 68 69 73 20 6c 6f 67 69 63 2e 0a 23 0a 64 6f  this logic..#.do
14e0: 5f 74 65 73 74 20 6d 69 73 63 31 2d 36 2e 31 20  _test misc1-6.1 
14f0: 7b 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20  {.  catchsql {. 
1500: 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20     CREATE TABLE 
1510: 74 34 28 0a 20 20 20 20 20 20 61 62 6f 72 74 2c  t4(.      abort,
1520: 20 61 73 63 2c 20 62 65 67 69 6e 2c 20 63 6c 75   asc, begin, clu
1530: 73 74 65 72 2c 20 63 6f 6e 66 6c 69 63 74 2c 20  ster, conflict, 
1540: 63 6f 70 79 2c 20 64 65 6c 69 6d 69 74 65 72 73  copy, delimiters
1550: 2c 20 64 65 73 63 2c 20 65 6e 64 2c 0a 20 20 20  , desc, end,.   
1560: 20 20 20 65 78 70 6c 61 69 6e 2c 20 66 61 69 6c     explain, fail
1570: 2c 20 69 67 6e 6f 72 65 2c 20 6b 65 79 2c 20 6f  , ignore, key, o
1580: 66 66 73 65 74 2c 20 70 72 61 67 6d 61 2c 20 72  ffset, pragma, r
1590: 65 70 6c 61 63 65 2c 20 74 65 6d 70 2c 0a 20 20  eplace, temp,.  
15a0: 20 20 20 20 76 61 63 75 75 6d 2c 20 76 69 65 77      vacuum, view
15b0: 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 7d 20 7b 30  .    );.  }.} {0
15c0: 20 7b 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73   {}}.do_test mis
15d0: 63 31 2d 36 2e 32 20 7b 0a 20 20 63 61 74 63 68  c1-6.2 {.  catch
15e0: 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53 45 52 54  sql {.    INSERT
15f0: 20 49 4e 54 4f 20 74 34 0a 20 20 20 20 20 20 20   INTO t4.       
1600: 56 41 4c 55 45 53 28 31 2c 32 2c 33 2c 34 2c 35  VALUES(1,2,3,4,5
1610: 2c 36 2c 37 2c 38 2c 39 2c 31 30 2c 31 31 2c 31  ,6,7,8,9,10,11,1
1620: 32 2c 31 33 2c 31 34 2c 31 35 2c 31 36 2c 31 37  2,13,14,15,16,17
1630: 2c 31 38 2c 31 39 29 3b 0a 20 20 7d 0a 7d 20 7b  ,18,19);.  }.} {
1640: 30 20 7b 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d 69  0 {}}.do_test mi
1650: 73 63 31 2d 36 2e 33 20 7b 0a 20 20 65 78 65 63  sc1-6.3 {.  exec
1660: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
1670: 20 2a 20 46 52 4f 4d 20 74 34 0a 20 20 7d 0a 7d   * FROM t4.  }.}
1680: 20 7b 31 20 32 20 33 20 34 20 35 20 36 20 37 20   {1 2 3 4 5 6 7 
1690: 38 20 39 20 31 30 20 31 31 20 31 32 20 31 33 20  8 9 10 11 12 13 
16a0: 31 34 20 31 35 20 31 36 20 31 37 20 31 38 20 31  14 15 16 17 18 1
16b0: 39 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31  9}.do_test misc1
16c0: 2d 36 2e 34 20 7b 0a 20 20 65 78 65 63 73 71 6c  -6.4 {.  execsql
16d0: 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 61 62   {.    SELECT ab
16e0: 6f 72 74 2b 61 73 63 2c 6d 61 78 28 6b 65 79 2c  ort+asc,max(key,
16f0: 70 72 61 67 6d 61 2c 74 65 6d 70 29 20 46 52 4f  pragma,temp) FRO
1700: 4d 20 74 34 0a 20 20 7d 0a 7d 20 7b 33 20 31 37  M t4.  }.} {3 17
1710: 7d 0a 0a 23 20 54 65 73 74 20 66 6f 72 20 6d 75  }..# Test for mu
1720: 6c 74 69 2d 63 6f 6c 75 6d 6e 20 70 72 69 6d 61  lti-column prima
1730: 72 79 20 6b 65 79 73 2c 20 61 6e 64 20 66 6f 72  ry keys, and for
1740: 20 6d 75 6c 74 69 70 6c 65 20 70 72 69 6d 61 72   multiple primar
1750: 79 20 6b 65 79 73 2e 0a 23 0a 64 6f 5f 74 65 73  y keys..#.do_tes
1760: 74 20 6d 69 73 63 31 2d 37 2e 31 20 7b 0a 20 20  t misc1-7.1 {.  
1770: 63 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 43  catchsql {.    C
1780: 52 45 41 54 45 20 54 41 42 4c 45 20 65 72 72 6f  REATE TABLE erro
1790: 72 31 28 0a 20 20 20 20 20 20 61 20 54 59 50 45  r1(.      a TYPE
17a0: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 0a 20 20   PRIMARY KEY,.  
17b0: 20 20 20 20 62 20 54 59 50 45 20 50 52 49 4d 41      b TYPE PRIMA
17c0: 52 59 20 4b 45 59 0a 20 20 20 20 29 3b 0a 20 20  RY KEY.    );.  
17d0: 7d 0a 7d 20 7b 31 20 7b 74 61 62 6c 65 20 22 65  }.} {1 {table "e
17e0: 72 72 6f 72 31 22 20 68 61 73 20 6d 6f 72 65 20  rror1" has more 
17f0: 74 68 61 6e 20 6f 6e 65 20 70 72 69 6d 61 72 79  than one primary
1800: 20 6b 65 79 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d   key}}.do_test m
1810: 69 73 63 31 2d 37 2e 32 20 7b 0a 20 20 63 61 74  isc1-7.2 {.  cat
1820: 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41  chsql {.    CREA
1830: 54 45 20 54 41 42 4c 45 20 65 72 72 6f 72 31 28  TE TABLE error1(
1840: 0a 20 20 20 20 20 20 61 20 49 4e 54 45 47 45 52  .      a INTEGER
1850: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 0a 20 20   PRIMARY KEY,.  
1860: 20 20 20 20 62 20 54 59 50 45 20 50 52 49 4d 41      b TYPE PRIMA
1870: 52 59 20 4b 45 59 0a 20 20 20 20 29 3b 0a 20 20  RY KEY.    );.  
1880: 7d 0a 7d 20 7b 31 20 7b 74 61 62 6c 65 20 22 65  }.} {1 {table "e
1890: 72 72 6f 72 31 22 20 68 61 73 20 6d 6f 72 65 20  rror1" has more 
18a0: 74 68 61 6e 20 6f 6e 65 20 70 72 69 6d 61 72 79  than one primary
18b0: 20 6b 65 79 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d   key}}.do_test m
18c0: 69 73 63 31 2d 37 2e 33 20 7b 0a 20 20 65 78 65  isc1-7.3 {.  exe
18d0: 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41 54  csql {.    CREAT
18e0: 45 20 54 41 42 4c 45 20 74 35 28 61 2c 62 2c 63  E TABLE t5(a,b,c
18f0: 2c 50 52 49 4d 41 52 59 20 4b 45 59 28 61 2c 62  ,PRIMARY KEY(a,b
1900: 29 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  ));.    INSERT I
1910: 4e 54 4f 20 74 35 20 56 41 4c 55 45 53 28 31 2c  NTO t5 VALUES(1,
1920: 32 2c 33 29 3b 0a 20 20 20 20 53 45 4c 45 43 54  2,3);.    SELECT
1930: 20 2a 20 46 52 4f 4d 20 74 35 20 4f 52 44 45 52   * FROM t5 ORDER
1940: 20 42 59 20 61 3b 0a 20 20 7d 0a 7d 20 7b 31 20   BY a;.  }.} {1 
1950: 32 20 33 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73  2 3}.do_test mis
1960: 63 31 2d 37 2e 34 20 7b 0a 20 20 63 61 74 63 68  c1-7.4 {.  catch
1970: 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53 45 52 54  sql {.    INSERT
1980: 20 49 4e 54 4f 20 74 35 20 56 41 4c 55 45 53 28   INTO t5 VALUES(
1990: 31 2c 32 2c 34 29 3b 0a 20 20 7d 0a 7d 20 7b 31  1,2,4);.  }.} {1
19a0: 20 7b 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 61   {UNIQUE constra
19b0: 69 6e 74 20 66 61 69 6c 65 64 3a 20 74 35 2e 61  int failed: t5.a
19c0: 2c 20 74 35 2e 62 7d 7d 0a 64 6f 5f 74 65 73 74  , t5.b}}.do_test
19d0: 20 6d 69 73 63 31 2d 37 2e 35 20 7b 0a 20 20 63   misc1-7.5 {.  c
19e0: 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20 49 4e  atchsql {.    IN
19f0: 53 45 52 54 20 49 4e 54 4f 20 74 35 20 56 41 4c  SERT INTO t5 VAL
1a00: 55 45 53 28 30 2c 32 2c 34 29 3b 0a 20 20 7d 0a  UES(0,2,4);.  }.
1a10: 7d 20 7b 30 20 7b 7d 7d 0a 64 6f 5f 74 65 73 74  } {0 {}}.do_test
1a20: 20 6d 69 73 63 31 2d 37 2e 36 20 7b 0a 20 20 65   misc1-7.6 {.  e
1a30: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c  xecsql {.    SEL
1a40: 45 43 54 20 2a 20 46 52 4f 4d 20 74 35 20 4f 52  ECT * FROM t5 OR
1a50: 44 45 52 20 42 59 20 61 3b 0a 20 20 7d 0a 7d 20  DER BY a;.  }.} 
1a60: 7b 30 20 32 20 34 20 31 20 32 20 33 7d 0a 0a 64  {0 2 4 1 2 3}..d
1a70: 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 38 2e 31  o_test misc1-8.1
1a80: 20 7b 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a   {.  catchsql {.
1a90: 20 20 20 20 53 45 4c 45 43 54 20 2a 3b 0a 20 20      SELECT *;.  
1aa0: 7d 0a 7d 20 7b 31 20 7b 6e 6f 20 74 61 62 6c 65  }.} {1 {no table
1ab0: 73 20 73 70 65 63 69 66 69 65 64 7d 7d 0a 64 6f  s specified}}.do
1ac0: 5f 74 65 73 74 20 6d 69 73 63 31 2d 38 2e 32 20  _test misc1-8.2 
1ad0: 7b 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20  {.  catchsql {. 
1ae0: 20 20 20 53 45 4c 45 43 54 20 74 31 2e 2a 3b 0a     SELECT t1.*;.
1af0: 20 20 7d 0a 7d 20 7b 31 20 7b 6e 6f 20 73 75 63    }.} {1 {no suc
1b00: 68 20 74 61 62 6c 65 3a 20 74 31 7d 7d 0a 0a 65  h table: t1}}..e
1b10: 78 65 63 73 71 6c 20 7b 0a 20 20 44 52 4f 50 20  xecsql {.  DROP 
1b20: 54 41 42 4c 45 20 74 31 3b 0a 20 20 44 52 4f 50  TABLE t1;.  DROP
1b30: 20 54 41 42 4c 45 20 74 32 3b 0a 20 20 44 52 4f   TABLE t2;.  DRO
1b40: 50 20 54 41 42 4c 45 20 74 33 3b 0a 20 20 44 52  P TABLE t3;.  DR
1b50: 4f 50 20 54 41 42 4c 45 20 74 34 3b 0a 7d 0a 0a  OP TABLE t4;.}..
1b60: 23 20 36 34 2d 62 69 74 20 69 6e 74 65 67 65 72  # 64-bit integer
1b70: 73 20 61 72 65 20 72 65 70 72 65 73 65 6e 74 65  s are represente
1b80: 64 20 65 78 61 63 74 6c 79 2e 0a 23 0a 64 6f 5f  d exactly..#.do_
1b90: 74 65 73 74 20 6d 69 73 63 31 2d 39 2e 31 20 7b  test misc1-9.1 {
1ba0: 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20 20  .  catchsql {.  
1bb0: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74    CREATE TABLE t
1bc0: 31 28 61 20 75 6e 69 71 75 65 20 6e 6f 74 20 6e  1(a unique not n
1bd0: 75 6c 6c 2c 20 62 20 75 6e 69 71 75 65 20 6e 6f  ull, b unique no
1be0: 74 20 6e 75 6c 6c 29 3b 0a 20 20 20 20 49 4e 53  t null);.    INS
1bf0: 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c 55  ERT INTO t1 VALU
1c00: 45 53 28 27 61 27 2c 31 32 33 34 35 36 37 38 39  ES('a',123456789
1c10: 30 31 32 33 34 35 36 37 38 39 29 3b 0a 20 20 20  0123456789);.   
1c20: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
1c30: 56 41 4c 55 45 53 28 27 62 27 2c 31 32 33 34 35  VALUES('b',12345
1c40: 36 37 38 39 31 31 32 33 34 35 36 37 38 39 29 3b  67891123456789);
1c50: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
1c60: 20 74 31 20 56 41 4c 55 45 53 28 27 63 27 2c 31   t1 VALUES('c',1
1c70: 32 33 34 35 36 37 38 39 32 31 32 33 34 35 36 37  2345678921234567
1c80: 38 39 29 3b 0a 20 20 20 20 53 45 4c 45 43 54 20  89);.    SELECT 
1c90: 2a 20 46 52 4f 4d 20 74 31 3b 0a 20 20 7d 0a 7d  * FROM t1;.  }.}
1ca0: 20 7b 30 20 7b 61 20 31 32 33 34 35 36 37 38 39   {0 {a 123456789
1cb0: 30 31 32 33 34 35 36 37 38 39 20 62 20 31 32 33  0123456789 b 123
1cc0: 34 35 36 37 38 39 31 31 32 33 34 35 36 37 38 39  4567891123456789
1cd0: 20 63 20 31 32 33 34 35 36 37 38 39 32 31 32 33   c 1234567892123
1ce0: 34 35 36 37 38 39 7d 7d 0a 0a 23 20 41 20 57 48  456789}}..# A WH
1cf0: 45 52 45 20 63 6c 61 75 73 65 20 69 73 20 6e 6f  ERE clause is no
1d00: 74 20 61 6c 6c 6f 77 65 64 20 74 6f 20 63 6f 6e  t allowed to con
1d10: 74 61 69 6e 20 6d 6f 72 65 20 74 68 61 6e 20 39  tain more than 9
1d20: 39 20 74 65 72 6d 73 2e 20 20 43 68 65 63 6b 20  9 terms.  Check 
1d30: 74 6f 0a 23 20 6d 61 6b 65 20 73 75 72 65 20 74  to.# make sure t
1d40: 68 69 73 20 6c 69 6d 69 74 20 69 73 20 65 6e 66  his limit is enf
1d50: 6f 72 63 65 64 2e 0a 23 0a 23 20 32 30 30 35 2d  orced..#.# 2005-
1d60: 30 37 2d 31 36 3a 20 54 68 65 72 65 20 69 73 20  07-16: There is 
1d70: 6e 6f 20 6c 6f 6e 67 65 72 20 61 20 6c 69 6d 69  no longer a limi
1d80: 74 20 6f 6e 20 74 68 65 20 6e 75 6d 62 65 72 20  t on the number 
1d90: 6f 66 20 74 65 72 6d 73 20 69 6e 20 61 0a 23 20  of terms in a.# 
1da0: 57 48 45 52 45 20 63 6c 61 75 73 65 2e 20 20 42  WHERE clause.  B
1db0: 75 74 20 6b 65 65 70 20 74 68 65 73 65 20 74 65  ut keep these te
1dc0: 73 74 73 20 6a 75 73 74 20 73 6f 20 74 68 61 74  sts just so that
1dd0: 20 77 65 20 68 61 76 65 20 73 6f 6d 65 20 74 65   we have some te
1de0: 73 74 73 0a 23 20 74 68 61 74 20 75 73 65 20 61  sts.# that use a
1df0: 20 6c 61 72 67 65 20 6e 75 6d 62 65 72 20 6f 66   large number of
1e00: 20 74 65 72 6d 73 20 69 6e 20 74 68 65 20 57 48   terms in the WH
1e10: 45 52 45 20 63 6c 61 75 73 65 2e 0a 23 0a 64 6f  ERE clause..#.do
1e20: 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 30 2e 30  _test misc1-10.0
1e30: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 53 45   {.  execsql {SE
1e40: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
1e50: 4f 4d 20 6d 61 6e 79 63 6f 6c 7d 0a 7d 20 7b 39  OM manycol}.} {9
1e60: 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d  }.do_test misc1-
1e70: 31 30 2e 31 20 7b 0a 20 20 73 65 74 20 3a 3a 77  10.1 {.  set ::w
1e80: 68 65 72 65 20 7b 57 48 45 52 45 20 78 30 3e 3d  here {WHERE x0>=
1e90: 30 7d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20  0}.  for {set i 
1ea0: 31 7d 20 7b 24 69 3c 3d 39 39 7d 20 7b 69 6e 63  1} {$i<=99} {inc
1eb0: 72 20 69 7d 20 7b 0a 20 20 20 20 61 70 70 65 6e  r i} {.    appen
1ec0: 64 20 3a 3a 77 68 65 72 65 20 22 20 41 4e 44 20  d ::where " AND 
1ed0: 78 24 69 3c 3e 30 22 0a 20 20 7d 0a 20 20 63 61  x$i<>0".  }.  ca
1ee0: 74 63 68 73 71 6c 20 22 53 45 4c 45 43 54 20 63  tchsql "SELECT c
1ef0: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 6d 61 6e  ount(*) FROM man
1f00: 79 63 6f 6c 20 24 3a 3a 77 68 65 72 65 22 0a 7d  ycol $::where".}
1f10: 20 7b 30 20 39 7d 0a 64 6f 5f 74 65 73 74 20 6d   {0 9}.do_test m
1f20: 69 73 63 31 2d 31 30 2e 32 20 7b 0a 20 20 63 61  isc1-10.2 {.  ca
1f30: 74 63 68 73 71 6c 20 22 53 45 4c 45 43 54 20 63  tchsql "SELECT c
1f40: 6f 75 6e 74 28 2a 29 20 46 52 4f 4d 20 6d 61 6e  ount(*) FROM man
1f50: 79 63 6f 6c 20 24 3a 3a 77 68 65 72 65 20 41 4e  ycol $::where AN
1f60: 44 20 72 6f 77 69 64 3e 30 22 0a 7d 20 7b 30 20  D rowid>0".} {0 
1f70: 39 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31  9}.do_test misc1
1f80: 2d 31 30 2e 33 20 7b 0a 20 20 72 65 67 73 75 62  -10.3 {.  regsub
1f90: 20 22 78 30 3e 3d 30 22 20 24 3a 3a 77 68 65 72   "x0>=0" $::wher
1fa0: 65 20 22 78 30 3d 30 22 20 3a 3a 77 68 65 72 65  e "x0=0" ::where
1fb0: 0a 20 20 63 61 74 63 68 73 71 6c 20 22 44 45 4c  .  catchsql "DEL
1fc0: 45 54 45 20 46 52 4f 4d 20 6d 61 6e 79 63 6f 6c  ETE FROM manycol
1fd0: 20 24 3a 3a 77 68 65 72 65 22 0a 7d 20 7b 30 20   $::where".} {0 
1fe0: 7b 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63  {}}.do_test misc
1ff0: 31 2d 31 30 2e 34 20 7b 0a 20 20 65 78 65 63 73  1-10.4 {.  execs
2000: 71 6c 20 7b 53 45 4c 45 43 54 20 63 6f 75 6e 74  ql {SELECT count
2010: 28 2a 29 20 46 52 4f 4d 20 6d 61 6e 79 63 6f 6c  (*) FROM manycol
2020: 7d 0a 7d 20 7b 38 7d 0a 64 6f 5f 74 65 73 74 20  }.} {8}.do_test 
2030: 6d 69 73 63 31 2d 31 30 2e 35 20 7b 0a 20 20 63  misc1-10.5 {.  c
2040: 61 74 63 68 73 71 6c 20 22 44 45 4c 45 54 45 20  atchsql "DELETE 
2050: 46 52 4f 4d 20 6d 61 6e 79 63 6f 6c 20 24 3a 3a  FROM manycol $::
2060: 77 68 65 72 65 20 41 4e 44 20 72 6f 77 69 64 3e  where AND rowid>
2070: 30 22 0a 7d 20 7b 30 20 7b 7d 7d 0a 64 6f 5f 74  0".} {0 {}}.do_t
2080: 65 73 74 20 6d 69 73 63 31 2d 31 30 2e 36 20 7b  est misc1-10.6 {
2090: 0a 20 20 65 78 65 63 73 71 6c 20 7b 53 45 4c 45  .  execsql {SELE
20a0: 43 54 20 78 31 20 46 52 4f 4d 20 6d 61 6e 79 63  CT x1 FROM manyc
20b0: 6f 6c 20 57 48 45 52 45 20 78 30 3d 31 30 30 7d  ol WHERE x0=100}
20c0: 0a 7d 20 7b 31 30 31 7d 0a 64 6f 5f 74 65 73 74  .} {101}.do_test
20d0: 20 6d 69 73 63 31 2d 31 30 2e 37 20 7b 0a 20 20   misc1-10.7 {.  
20e0: 72 65 67 73 75 62 20 22 78 30 3d 30 22 20 24 3a  regsub "x0=0" $:
20f0: 3a 77 68 65 72 65 20 22 78 30 3d 31 30 30 22 20  :where "x0=100" 
2100: 3a 3a 77 68 65 72 65 0a 20 20 63 61 74 63 68 73  ::where.  catchs
2110: 71 6c 20 22 55 50 44 41 54 45 20 6d 61 6e 79 63  ql "UPDATE manyc
2120: 6f 6c 20 53 45 54 20 78 31 3d 78 31 2b 31 20 24  ol SET x1=x1+1 $
2130: 3a 3a 77 68 65 72 65 22 0a 7d 20 7b 30 20 7b 7d  ::where".} {0 {}
2140: 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d  }.do_test misc1-
2150: 31 30 2e 38 20 7b 0a 20 20 65 78 65 63 73 71 6c  10.8 {.  execsql
2160: 20 7b 53 45 4c 45 43 54 20 78 31 20 46 52 4f 4d   {SELECT x1 FROM
2170: 20 6d 61 6e 79 63 6f 6c 20 57 48 45 52 45 20 78   manycol WHERE x
2180: 30 3d 31 30 30 7d 0a 7d 20 7b 31 30 32 7d 0a 64  0=100}.} {102}.d
2190: 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 30 2e  o_test misc1-10.
21a0: 39 20 7b 0a 20 20 63 61 74 63 68 73 71 6c 20 22  9 {.  catchsql "
21b0: 55 50 44 41 54 45 20 6d 61 6e 79 63 6f 6c 20 53  UPDATE manycol S
21c0: 45 54 20 78 31 3d 78 31 2b 31 20 24 3a 3a 77 68  ET x1=x1+1 $::wh
21d0: 65 72 65 20 41 4e 44 20 72 6f 77 69 64 3e 30 22  ere AND rowid>0"
21e0: 0a 7d 20 7b 30 20 7b 7d 7d 0a 64 6f 5f 74 65 73  .} {0 {}}.do_tes
21f0: 74 20 6d 69 73 63 31 2d 31 30 2e 31 30 20 7b 0a  t misc1-10.10 {.
2200: 20 20 65 78 65 63 73 71 6c 20 7b 53 45 4c 45 43    execsql {SELEC
2210: 54 20 78 31 20 46 52 4f 4d 20 6d 61 6e 79 63 6f  T x1 FROM manyco
2220: 6c 20 57 48 45 52 45 20 78 30 3d 31 30 30 7d 0a  l WHERE x0=100}.
2230: 7d 20 7b 31 30 33 7d 0a 0a 23 20 4d 61 6b 65 20  } {103}..# Make 
2240: 73 75 72 65 20 74 68 65 20 69 6e 69 74 69 61 6c  sure the initial
2250: 69 7a 61 74 69 6f 6e 20 77 6f 72 6b 73 20 65 76  ization works ev
2260: 65 6e 20 69 66 20 61 20 64 61 74 61 62 61 73 65  en if a database
2270: 20 69 73 20 6f 70 65 6e 65 64 20 77 68 69 6c 65   is opened while
2280: 0a 23 20 61 6e 6f 74 68 65 72 20 70 72 6f 63 65  .# another proce
2290: 73 73 20 68 61 73 20 74 68 65 20 64 61 74 61 62  ss has the datab
22a0: 61 73 65 20 6c 6f 63 6b 65 64 2e 0a 23 0a 23 20  ase locked..#.# 
22b0: 55 70 64 61 74 65 20 66 6f 72 20 76 33 3a 20 54  Update for v3: T
22c0: 68 65 20 42 45 47 49 4e 20 64 6f 65 73 6e 27 74  he BEGIN doesn't
22d0: 20 6c 6f 63 6b 20 74 68 65 20 64 61 74 61 62 61   lock the databa
22e0: 73 65 20 73 6f 20 74 68 65 20 73 63 68 65 6d 61  se so the schema
22f0: 20 69 73 20 72 65 61 64 0a 23 20 61 6e 64 20 74   is read.# and t
2300: 68 65 20 53 45 4c 45 43 54 20 72 65 74 75 72 6e  he SELECT return
2310: 73 20 73 75 63 63 65 73 73 66 75 6c 6c 79 2e 0a  s successfully..
2320: 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 31  do_test misc1-11
2330: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
2340: 42 45 47 49 4e 7d 0a 20 20 65 78 65 63 73 71 6c  BEGIN}.  execsql
2350: 20 7b 55 50 44 41 54 45 20 74 31 20 53 45 54 20   {UPDATE t1 SET 
2360: 61 3d 30 20 57 48 45 52 45 20 30 7d 0a 20 20 73  a=0 WHERE 0}.  s
2370: 71 6c 69 74 65 33 20 64 62 32 20 74 65 73 74 2e  qlite3 db2 test.
2380: 64 62 0a 20 20 73 65 74 20 72 63 20 5b 63 61 74  db.  set rc [cat
2390: 63 68 20 7b 64 62 32 20 65 76 61 6c 20 7b 53 45  ch {db2 eval {SE
23a0: 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20 46 52  LECT count(*) FR
23b0: 4f 4d 20 74 31 7d 7d 20 6d 73 67 5d 0a 20 20 6c  OM t1}} msg].  l
23c0: 61 70 70 65 6e 64 20 72 63 20 24 6d 73 67 0a 23  append rc $msg.#
23d0: 20 76 32 20 72 65 73 75 6c 74 3a 20 7b 31 20 7b   v2 result: {1 {
23e0: 64 61 74 61 62 61 73 65 20 69 73 20 6c 6f 63 6b  database is lock
23f0: 65 64 7d 7d 0a 7d 20 7b 30 20 33 7d 0a 64 6f 5f  ed}}.} {0 3}.do_
2400: 74 65 73 74 20 6d 69 73 63 31 2d 31 31 2e 32 20  test misc1-11.2 
2410: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 43 4f 4d  {.  execsql {COM
2420: 4d 49 54 7d 0a 20 20 73 65 74 20 72 63 20 5b 63  MIT}.  set rc [c
2430: 61 74 63 68 20 7b 64 62 32 20 65 76 61 6c 20 7b  atch {db2 eval {
2440: 53 45 4c 45 43 54 20 63 6f 75 6e 74 28 2a 29 20  SELECT count(*) 
2450: 46 52 4f 4d 20 74 31 7d 7d 20 6d 73 67 5d 0a 20  FROM t1}} msg]. 
2460: 20 64 62 32 20 63 6c 6f 73 65 0a 20 20 6c 61 70   db2 close.  lap
2470: 70 65 6e 64 20 72 63 20 24 6d 73 67 0a 7d 20 7b  pend rc $msg.} {
2480: 30 20 33 7d 0a 0a 23 20 4d 61 6b 65 20 73 75 72  0 3}..# Make sur
2490: 65 20 73 74 72 69 6e 67 20 63 6f 6d 70 61 72 69  e string compari
24a0: 73 6f 6e 73 20 72 65 61 6c 6c 79 20 64 6f 20 63  sons really do c
24b0: 6f 6d 70 61 72 65 20 73 74 72 69 6e 67 73 20 69  ompare strings i
24c0: 6e 20 66 6f 72 6d 61 74 34 2b 2e 0a 23 20 53 69  n format4+..# Si
24d0: 6d 69 6c 61 72 20 74 65 73 74 73 20 69 6e 20 74  milar tests in t
24e0: 68 65 20 66 6f 72 6d 61 74 33 2e 74 65 73 74 20  he format3.test 
24f0: 66 69 6c 65 20 73 68 6f 77 20 74 68 61 74 20 66  file show that f
2500: 6f 72 20 66 6f 72 6d 61 74 33 20 61 6e 64 20 65  or format3 and e
2510: 61 72 6c 69 65 72 0a 23 20 61 6c 6c 20 63 6f 6d  arlier.# all com
2520: 70 61 72 69 73 69 6f 6e 73 20 77 68 65 72 65 20  parisions where 
2530: 6e 75 6d 65 72 69 63 20 69 66 20 65 69 74 68 65  numeric if eithe
2540: 72 20 6f 70 65 72 61 6e 64 20 6c 6f 6f 6b 65 64  r operand looked
2550: 20 6c 69 6b 65 20 61 20 6e 75 6d 62 65 72 2e 0a   like a number..
2560: 23 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d  #.do_test misc1-
2570: 31 32 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c  12.1 {.  execsql
2580: 20 7b 53 45 4c 45 43 54 20 27 30 27 3d 3d 27 30   {SELECT '0'=='0
2590: 2e 30 27 7d 0a 7d 20 7b 30 7d 0a 64 6f 5f 74 65  .0'}.} {0}.do_te
25a0: 73 74 20 6d 69 73 63 31 2d 31 32 2e 32 20 7b 0a  st misc1-12.2 {.
25b0: 20 20 65 78 65 63 73 71 6c 20 7b 53 45 4c 45 43    execsql {SELEC
25c0: 54 20 27 30 27 3d 3d 30 2e 30 7d 0a 7d 20 7b 30  T '0'==0.0}.} {0
25d0: 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d  }.do_test misc1-
25e0: 31 32 2e 33 20 7b 0a 20 20 65 78 65 63 73 71 6c  12.3 {.  execsql
25f0: 20 7b 53 45 4c 45 43 54 20 27 31 32 33 34 35 36   {SELECT '123456
2600: 37 38 39 30 31 32 33 34 35 36 37 38 39 30 27 3d  78901234567890'=
2610: 3d 27 31 32 33 34 35 36 37 38 39 30 31 32 33 34  ='12345678901234
2620: 35 36 37 38 39 31 27 7d 0a 7d 20 7b 30 7d 0a 64  567891'}.} {0}.d
2630: 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 32 2e  o_test misc1-12.
2640: 34 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  4 {.  execsql {.
2650: 20 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45      CREATE TABLE
2660: 20 74 36 28 61 20 49 4e 54 20 55 4e 49 51 55 45   t6(a INT UNIQUE
2670: 2c 20 62 20 54 45 58 54 20 55 4e 49 51 55 45 29  , b TEXT UNIQUE)
2680: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
2690: 4f 20 74 36 20 56 41 4c 55 45 53 28 27 30 27 2c  O t6 VALUES('0',
26a0: 27 30 2e 30 27 29 3b 0a 20 20 20 20 53 45 4c 45  '0.0');.    SELE
26b0: 43 54 20 2a 20 46 52 4f 4d 20 74 36 3b 0a 20 20  CT * FROM t6;.  
26c0: 7d 0a 7d 20 7b 30 20 30 2e 30 7d 0a 69 66 63 61  }.} {0 0.0}.ifca
26d0: 70 61 62 6c 65 20 63 6f 6e 66 6c 69 63 74 20 7b  pable conflict {
26e0: 0a 20 20 64 6f 5f 74 65 73 74 20 6d 69 73 63 31  .  do_test misc1
26f0: 2d 31 32 2e 35 20 7b 0a 20 20 20 20 65 78 65 63  -12.5 {.    exec
2700: 73 71 6c 20 7b 0a 20 20 20 20 20 20 49 4e 53 45  sql {.      INSE
2710: 52 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54  RT OR IGNORE INT
2720: 4f 20 74 36 20 56 41 4c 55 45 53 28 30 2e 30 2c  O t6 VALUES(0.0,
2730: 27 78 27 29 3b 0a 20 20 20 20 20 20 53 45 4c 45  'x');.      SELE
2740: 43 54 20 2a 20 46 52 4f 4d 20 74 36 3b 0a 20 20  CT * FROM t6;.  
2750: 20 20 7d 0a 20 20 7d 20 7b 30 20 30 2e 30 7d 0a    }.  } {0 0.0}.
2760: 20 20 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d    do_test misc1-
2770: 31 32 2e 36 20 7b 0a 20 20 20 20 65 78 65 63 73  12.6 {.    execs
2780: 71 6c 20 7b 0a 20 20 20 20 20 20 49 4e 53 45 52  ql {.      INSER
2790: 54 20 4f 52 20 49 47 4e 4f 52 45 20 49 4e 54 4f  T OR IGNORE INTO
27a0: 20 74 36 20 56 41 4c 55 45 53 28 27 79 27 2c 30   t6 VALUES('y',0
27b0: 29 3b 0a 20 20 20 20 20 20 53 45 4c 45 43 54 20  );.      SELECT 
27c0: 2a 20 46 52 4f 4d 20 74 36 3b 0a 20 20 20 20 7d  * FROM t6;.    }
27d0: 0a 20 20 7d 20 7b 30 20 30 2e 30 20 79 20 30 7d  .  } {0 0.0 y 0}
27e0: 0a 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31  .}.do_test misc1
27f0: 2d 31 32 2e 37 20 7b 0a 20 20 65 78 65 63 73 71  -12.7 {.  execsq
2800: 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54  l {.    CREATE T
2810: 41 42 4c 45 20 74 37 28 78 20 49 4e 54 45 47 45  ABLE t7(x INTEGE
2820: 52 2c 20 79 20 54 45 58 54 2c 20 7a 29 3b 0a 20  R, y TEXT, z);. 
2830: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
2840: 37 20 56 41 4c 55 45 53 28 30 2c 30 2c 31 29 3b  7 VALUES(0,0,1);
2850: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
2860: 20 74 37 20 56 41 4c 55 45 53 28 30 2e 30 2c 30   t7 VALUES(0.0,0
2870: 2c 32 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20  ,2);.    INSERT 
2880: 49 4e 54 4f 20 74 37 20 56 41 4c 55 45 53 28 30  INTO t7 VALUES(0
2890: 2c 30 2e 30 2c 33 29 3b 0a 20 20 20 20 49 4e 53  ,0.0,3);.    INS
28a0: 45 52 54 20 49 4e 54 4f 20 74 37 20 56 41 4c 55  ERT INTO t7 VALU
28b0: 45 53 28 30 2e 30 2c 30 2e 30 2c 34 29 3b 0a 20  ES(0.0,0.0,4);. 
28c0: 20 20 20 53 45 4c 45 43 54 20 44 49 53 54 49 4e     SELECT DISTIN
28d0: 43 54 20 78 2c 20 79 20 46 52 4f 4d 20 74 37 20  CT x, y FROM t7 
28e0: 4f 52 44 45 52 20 42 59 20 7a 3b 0a 20 20 7d 0a  ORDER BY z;.  }.
28f0: 7d 20 7b 30 20 30 20 30 20 30 2e 30 7d 0a 64 6f  } {0 0 0 0.0}.do
2900: 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 32 2e 38  _test misc1-12.8
2910: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20   {.  execsql {. 
2920: 20 20 20 53 45 4c 45 43 54 20 6d 69 6e 28 7a 29     SELECT min(z)
2930: 2c 20 6d 61 78 28 7a 29 2c 20 63 6f 75 6e 74 28  , max(z), count(
2940: 7a 29 20 46 52 4f 4d 20 74 37 20 47 52 4f 55 50  z) FROM t7 GROUP
2950: 20 42 59 20 78 20 4f 52 44 45 52 20 42 59 20 31   BY x ORDER BY 1
2960: 3b 0a 20 20 7d 0a 7d 20 7b 31 20 34 20 34 7d 0a  ;.  }.} {1 4 4}.
2970: 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 32  do_test misc1-12
2980: 2e 39 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .9 {.  execsql {
2990: 0a 20 20 20 20 53 45 4c 45 43 54 20 6d 69 6e 28  .    SELECT min(
29a0: 7a 29 2c 20 6d 61 78 28 7a 29 2c 20 63 6f 75 6e  z), max(z), coun
29b0: 74 28 7a 29 20 46 52 4f 4d 20 74 37 20 47 52 4f  t(z) FROM t7 GRO
29c0: 55 50 20 42 59 20 79 20 4f 52 44 45 52 20 42 59  UP BY y ORDER BY
29d0: 20 31 3b 0a 20 20 7d 0a 7d 20 7b 31 20 32 20 32   1;.  }.} {1 2 2
29e0: 20 33 20 34 20 32 7d 0a 0a 23 20 54 68 69 73 20   3 4 2}..# This 
29f0: 75 73 65 64 20 74 6f 20 62 65 20 61 6e 20 65 72  used to be an er
2a00: 72 6f 72 2e 20 20 42 75 74 20 77 65 20 63 68 61  ror.  But we cha
2a10: 6e 67 65 64 20 74 68 65 20 63 6f 64 65 20 73 6f  nged the code so
2a20: 20 74 68 61 74 20 61 72 62 69 74 72 61 72 79 0a   that arbitrary.
2a30: 23 20 69 64 65 6e 74 69 66 69 65 72 73 20 63 61  # identifiers ca
2a40: 6e 20 62 65 20 75 73 65 64 20 61 73 20 61 20 63  n be used as a c
2a50: 6f 6c 6c 61 74 69 6e 67 20 73 65 71 75 65 6e 63  ollating sequenc
2a60: 65 2e 20 20 43 6f 6c 6c 61 74 69 6f 6e 20 69 73  e.  Collation is
2a70: 20 62 79 20 74 65 78 74 0a 23 20 69 66 20 74 68   by text.# if th
2a80: 65 20 69 64 65 6e 74 69 66 69 65 72 20 63 6f 6e  e identifier con
2a90: 74 61 69 6e 73 20 22 74 65 78 74 22 2c 20 22 62  tains "text", "b
2aa0: 6c 6f 62 22 2c 20 6f 72 20 22 63 6c 6f 62 22 20  lob", or "clob" 
2ab0: 61 6e 64 20 69 73 20 6e 75 6d 65 72 69 63 0a 23  and is numeric.#
2ac0: 20 6f 74 68 65 72 77 69 73 65 2e 0a 23 0a 23 20   otherwise..#.# 
2ad0: 55 70 64 61 74 65 3a 20 49 6e 20 76 33 2c 20 69  Update: In v3, i
2ae0: 74 20 69 73 20 61 6e 20 65 72 72 6f 72 20 61 67  t is an error ag
2af0: 61 69 6e 2e 0a 23 0a 23 64 6f 5f 74 65 73 74 20  ain..#.#do_test 
2b00: 6d 69 73 63 31 2d 31 32 2e 31 30 20 7b 0a 23 20  misc1-12.10 {.# 
2b10: 20 63 61 74 63 68 73 71 6c 20 7b 0a 23 20 20 20   catchsql {.#   
2b20: 20 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74   SELECT * FROM t
2b30: 36 20 4f 52 44 45 52 20 42 59 20 61 20 43 4f 4c  6 ORDER BY a COL
2b40: 4c 41 54 45 20 75 6e 6b 6e 6f 77 6e 3b 0a 23 20  LATE unknown;.# 
2b50: 20 7d 0a 23 7d 20 7b 30 20 7b 30 20 30 20 79 20   }.#} {0 {0 0 y 
2b60: 30 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63  0}}.do_test misc
2b70: 31 2d 31 32 2e 31 31 20 7b 0a 20 20 65 78 65 63  1-12.11 {.  exec
2b80: 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45  sql {.    CREATE
2b90: 20 54 41 42 4c 45 20 74 38 28 78 20 54 45 58 54   TABLE t8(x TEXT
2ba0: 20 43 4f 4c 4c 41 54 45 20 6e 75 6d 65 72 69 63   COLLATE numeric
2bb0: 2c 20 79 20 49 4e 54 45 47 45 52 20 43 4f 4c 4c  , y INTEGER COLL
2bc0: 41 54 45 20 74 65 78 74 2c 20 7a 29 3b 0a 20 20  ATE text, z);.  
2bd0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 38    INSERT INTO t8
2be0: 20 56 41 4c 55 45 53 28 30 2c 30 2c 31 29 3b 0a   VALUES(0,0,1);.
2bf0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
2c00: 74 38 20 56 41 4c 55 45 53 28 30 2e 30 2c 30 2c  t8 VALUES(0.0,0,
2c10: 32 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  2);.    INSERT I
2c20: 4e 54 4f 20 74 38 20 56 41 4c 55 45 53 28 30 2c  NTO t8 VALUES(0,
2c30: 30 2e 30 2c 33 29 3b 0a 20 20 20 20 49 4e 53 45  0.0,3);.    INSE
2c40: 52 54 20 49 4e 54 4f 20 74 38 20 56 41 4c 55 45  RT INTO t8 VALUE
2c50: 53 28 30 2e 30 2c 30 2e 30 2c 34 29 3b 0a 20 20  S(0.0,0.0,4);.  
2c60: 20 20 53 45 4c 45 43 54 20 44 49 53 54 49 4e 43    SELECT DISTINC
2c70: 54 20 78 2c 20 79 20 46 52 4f 4d 20 74 38 20 4f  T x, y FROM t8 O
2c80: 52 44 45 52 20 42 59 20 7a 3b 0a 20 20 7d 0a 7d  RDER BY z;.  }.}
2c90: 20 7b 30 20 30 20 30 2e 30 20 30 7d 0a 64 6f 5f   {0 0 0.0 0}.do_
2ca0: 74 65 73 74 20 6d 69 73 63 31 2d 31 32 2e 31 32  test misc1-12.12
2cb0: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20   {.  execsql {. 
2cc0: 20 20 20 53 45 4c 45 43 54 20 6d 69 6e 28 7a 29     SELECT min(z)
2cd0: 2c 20 6d 61 78 28 7a 29 2c 20 63 6f 75 6e 74 28  , max(z), count(
2ce0: 7a 29 20 46 52 4f 4d 20 74 38 20 47 52 4f 55 50  z) FROM t8 GROUP
2cf0: 20 42 59 20 78 20 4f 52 44 45 52 20 42 59 20 31   BY x ORDER BY 1
2d00: 3b 0a 20 20 7d 0a 7d 20 7b 31 20 33 20 32 20 32  ;.  }.} {1 3 2 2
2d10: 20 34 20 32 7d 0a 64 6f 5f 74 65 73 74 20 6d 69   4 2}.do_test mi
2d20: 73 63 31 2d 31 32 2e 31 33 20 7b 0a 20 20 65 78  sc1-12.13 {.  ex
2d30: 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45  ecsql {.    SELE
2d40: 43 54 20 6d 69 6e 28 7a 29 2c 20 6d 61 78 28 7a  CT min(z), max(z
2d50: 29 2c 20 63 6f 75 6e 74 28 7a 29 20 46 52 4f 4d  ), count(z) FROM
2d60: 20 74 38 20 47 52 4f 55 50 20 42 59 20 79 20 4f   t8 GROUP BY y O
2d70: 52 44 45 52 20 42 59 20 31 3b 0a 20 20 7d 0a 7d  RDER BY 1;.  }.}
2d80: 20 7b 31 20 34 20 34 7d 0a 0a 23 20 54 68 65 72   {1 4 4}..# Ther
2d90: 65 20 77 61 73 20 61 20 70 72 6f 62 6c 65 6d 20  e was a problem 
2da0: 77 69 74 68 20 72 65 61 6c 6c 6f 63 28 29 20 69  with realloc() i
2db0: 6e 20 74 68 65 20 4f 50 5f 4d 65 6d 53 74 6f 72  n the OP_MemStor
2dc0: 65 20 6f 70 65 72 61 74 69 6f 6e 20 6f 66 0a 23  e operation of.#
2dd0: 20 74 68 65 20 56 44 42 45 2e 20 20 41 20 62 75   the VDBE.  A bu
2de0: 66 66 65 72 20 77 61 73 20 62 65 69 6e 67 20 72  ffer was being r
2df0: 65 61 6c 6c 6f 63 61 74 65 64 20 62 75 74 20 73  eallocated but s
2e00: 6f 6d 65 20 70 6f 69 6e 74 65 72 73 20 69 6e 74  ome pointers int
2e10: 6f 20 0a 23 20 74 68 65 20 6f 6c 64 20 63 6f 70  o .# the old cop
2e20: 79 20 6f 66 20 74 68 65 20 62 75 66 66 65 72 20  y of the buffer 
2e30: 77 65 72 65 20 6e 6f 74 20 62 65 69 6e 67 20 6d  were not being m
2e40: 6f 76 65 64 20 6f 76 65 72 20 74 6f 20 74 68 65  oved over to the
2e50: 20 6e 65 77 20 63 6f 70 79 2e 0a 23 20 54 68 65   new copy..# The
2e60: 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 6f 64 65 20   following code 
2e70: 74 65 73 74 73 20 66 6f 72 20 74 68 65 20 70 72  tests for the pr
2e80: 6f 62 6c 65 6d 2e 0a 23 0a 69 66 63 61 70 61 62  oblem..#.ifcapab
2e90: 6c 65 20 73 75 62 71 75 65 72 79 20 7b 0a 20 20  le subquery {.  
2ea0: 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 33  do_test misc1-13
2eb0: 2e 31 20 7b 0a 20 20 20 20 20 65 78 65 63 73 71  .1 {.     execsq
2ec0: 6c 20 7b 0a 20 20 20 20 20 20 20 43 52 45 41 54  l {.       CREAT
2ed0: 45 20 54 41 42 4c 45 20 74 39 28 78 2c 79 29 3b  E TABLE t9(x,y);
2ee0: 0a 20 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  .       INSERT I
2ef0: 4e 54 4f 20 74 39 20 56 41 4c 55 45 53 28 27 6f  NTO t9 VALUES('o
2f00: 6e 65 27 2c 31 29 3b 0a 20 20 20 20 20 20 20 49  ne',1);.       I
2f10: 4e 53 45 52 54 20 49 4e 54 4f 20 74 39 20 56 41  NSERT INTO t9 VA
2f20: 4c 55 45 53 28 27 74 77 6f 27 2c 32 29 3b 0a 20  LUES('two',2);. 
2f30: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
2f40: 4f 20 74 39 20 56 41 4c 55 45 53 28 27 74 68 72  O t9 VALUES('thr
2f50: 65 65 27 2c 33 29 3b 0a 20 20 20 20 20 20 20 49  ee',3);.       I
2f60: 4e 53 45 52 54 20 49 4e 54 4f 20 74 39 20 56 41  NSERT INTO t9 VA
2f70: 4c 55 45 53 28 27 66 6f 75 72 27 2c 34 29 3b 0a  LUES('four',4);.
2f80: 20 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e         INSERT IN
2f90: 54 4f 20 74 39 20 56 41 4c 55 45 53 28 27 66 69  TO t9 VALUES('fi
2fa0: 76 65 27 2c 35 29 3b 0a 20 20 20 20 20 20 20 49  ve',5);.       I
2fb0: 4e 53 45 52 54 20 49 4e 54 4f 20 74 39 20 56 41  NSERT INTO t9 VA
2fc0: 4c 55 45 53 28 27 73 69 78 27 2c 36 29 3b 0a 20  LUES('six',6);. 
2fd0: 20 20 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54        INSERT INT
2fe0: 4f 20 74 39 20 56 41 4c 55 45 53 28 27 73 65 76  O t9 VALUES('sev
2ff0: 65 6e 27 2c 37 29 3b 0a 20 20 20 20 20 20 20 49  en',7);.       I
3000: 4e 53 45 52 54 20 49 4e 54 4f 20 74 39 20 56 41  NSERT INTO t9 VA
3010: 4c 55 45 53 28 27 65 69 67 68 74 27 2c 38 29 3b  LUES('eight',8);
3020: 0a 20 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  .       INSERT I
3030: 4e 54 4f 20 74 39 20 56 41 4c 55 45 53 28 27 6e  NTO t9 VALUES('n
3040: 69 6e 65 27 2c 39 29 3b 0a 20 20 20 20 20 20 20  ine',9);.       
3050: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 39 20 56  INSERT INTO t9 V
3060: 41 4c 55 45 53 28 27 74 65 6e 27 2c 31 30 29 3b  ALUES('ten',10);
3070: 0a 20 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  .       INSERT I
3080: 4e 54 4f 20 74 39 20 56 41 4c 55 45 53 28 27 65  NTO t9 VALUES('e
3090: 6c 65 76 65 6e 27 2c 31 31 29 3b 0a 20 20 20 20  leven',11);.    
30a0: 20 20 20 53 45 4c 45 43 54 20 79 20 46 52 4f 4d     SELECT y FROM
30b0: 20 74 39 0a 20 20 20 20 20 20 20 57 48 45 52 45   t9.       WHERE
30c0: 20 78 3d 28 53 45 4c 45 43 54 20 78 20 46 52 4f   x=(SELECT x FRO
30d0: 4d 20 74 39 20 57 48 45 52 45 20 79 3d 31 29 0a  M t9 WHERE y=1).
30e0: 20 20 20 20 20 20 20 20 20 20 4f 52 20 78 3d 28            OR x=(
30f0: 53 45 4c 45 43 54 20 78 20 46 52 4f 4d 20 74 39  SELECT x FROM t9
3100: 20 57 48 45 52 45 20 79 3d 32 29 0a 20 20 20 20   WHERE y=2).    
3110: 20 20 20 20 20 20 4f 52 20 78 3d 28 53 45 4c 45        OR x=(SELE
3120: 43 54 20 78 20 46 52 4f 4d 20 74 39 20 57 48 45  CT x FROM t9 WHE
3130: 52 45 20 79 3d 33 29 0a 20 20 20 20 20 20 20 20  RE y=3).        
3140: 20 20 4f 52 20 78 3d 28 53 45 4c 45 43 54 20 78    OR x=(SELECT x
3150: 20 46 52 4f 4d 20 74 39 20 57 48 45 52 45 20 79   FROM t9 WHERE y
3160: 3d 34 29 0a 20 20 20 20 20 20 20 20 20 20 4f 52  =4).          OR
3170: 20 78 3d 28 53 45 4c 45 43 54 20 78 20 46 52 4f   x=(SELECT x FRO
3180: 4d 20 74 39 20 57 48 45 52 45 20 79 3d 35 29 0a  M t9 WHERE y=5).
3190: 20 20 20 20 20 20 20 20 20 20 4f 52 20 78 3d 28            OR x=(
31a0: 53 45 4c 45 43 54 20 78 20 46 52 4f 4d 20 74 39  SELECT x FROM t9
31b0: 20 57 48 45 52 45 20 79 3d 36 29 0a 20 20 20 20   WHERE y=6).    
31c0: 20 20 20 20 20 20 4f 52 20 78 3d 28 53 45 4c 45        OR x=(SELE
31d0: 43 54 20 78 20 46 52 4f 4d 20 74 39 20 57 48 45  CT x FROM t9 WHE
31e0: 52 45 20 79 3d 37 29 0a 20 20 20 20 20 20 20 20  RE y=7).        
31f0: 20 20 4f 52 20 78 3d 28 53 45 4c 45 43 54 20 78    OR x=(SELECT x
3200: 20 46 52 4f 4d 20 74 39 20 57 48 45 52 45 20 79   FROM t9 WHERE y
3210: 3d 38 29 0a 20 20 20 20 20 20 20 20 20 20 4f 52  =8).          OR
3220: 20 78 3d 28 53 45 4c 45 43 54 20 78 20 46 52 4f   x=(SELECT x FRO
3230: 4d 20 74 39 20 57 48 45 52 45 20 79 3d 39 29 0a  M t9 WHERE y=9).
3240: 20 20 20 20 20 20 20 20 20 20 4f 52 20 78 3d 28            OR x=(
3250: 53 45 4c 45 43 54 20 78 20 46 52 4f 4d 20 74 39  SELECT x FROM t9
3260: 20 57 48 45 52 45 20 79 3d 31 30 29 0a 20 20 20   WHERE y=10).   
3270: 20 20 20 20 20 20 20 4f 52 20 78 3d 28 53 45 4c         OR x=(SEL
3280: 45 43 54 20 78 20 46 52 4f 4d 20 74 39 20 57 48  ECT x FROM t9 WH
3290: 45 52 45 20 79 3d 31 31 29 0a 20 20 20 20 20 20  ERE y=11).      
32a0: 20 20 20 20 4f 52 20 78 3d 28 53 45 4c 45 43 54      OR x=(SELECT
32b0: 20 78 20 46 52 4f 4d 20 74 39 20 57 48 45 52 45   x FROM t9 WHERE
32c0: 20 79 3d 31 32 29 0a 20 20 20 20 20 20 20 20 20   y=12).         
32d0: 20 4f 52 20 78 3d 28 53 45 4c 45 43 54 20 78 20   OR x=(SELECT x 
32e0: 46 52 4f 4d 20 74 39 20 57 48 45 52 45 20 79 3d  FROM t9 WHERE y=
32f0: 31 33 29 0a 20 20 20 20 20 20 20 20 20 20 4f 52  13).          OR
3300: 20 78 3d 28 53 45 4c 45 43 54 20 78 20 46 52 4f   x=(SELECT x FRO
3310: 4d 20 74 39 20 57 48 45 52 45 20 79 3d 31 34 29  M t9 WHERE y=14)
3320: 0a 20 20 20 20 20 20 20 3b 0a 20 20 20 20 20 7d  .       ;.     }
3330: 0a 20 20 7d 20 7b 31 20 32 20 33 20 34 20 35 20  .  } {1 2 3 4 5 
3340: 36 20 37 20 38 20 39 20 31 30 20 31 31 7d 0a 7d  6 7 8 9 10 11}.}
3350: 0a 0a 23 0a 23 20 54 68 65 20 66 6f 6c 6c 6f 77  ..#.# The follow
3360: 69 6e 67 20 74 65 73 74 73 20 63 61 6e 20 6f 6e  ing tests can on
3370: 6c 79 20 77 6f 72 6b 20 69 66 20 74 68 65 20 63  ly work if the c
3380: 75 72 72 65 6e 74 20 53 51 4c 69 74 65 20 56 46  urrent SQLite VF
3390: 53 20 68 61 73 20 74 68 65 20 63 6f 6e 63 65 70  S has the concep
33a0: 74 0a 23 20 6f 66 20 61 20 63 75 72 72 65 6e 74  t.# of a current
33b0: 20 64 69 72 65 63 74 6f 72 79 2e 0a 23 0a 69 66   directory..#.if
33c0: 63 61 70 61 62 6c 65 20 63 75 72 64 69 72 20 7b  capable curdir {
33d0: 0a 23 20 4d 61 6b 65 20 73 75 72 65 20 61 20 64  .# Make sure a d
33e0: 61 74 61 62 61 73 65 20 63 6f 6e 6e 65 63 74 69  atabase connecti
33f0: 6f 6e 20 73 74 69 6c 6c 20 77 6f 72 6b 73 20 61  on still works a
3400: 66 74 65 72 20 63 68 61 6e 67 69 6e 67 20 74 68  fter changing th
3410: 65 0a 23 20 77 6f 72 6b 69 6e 67 20 64 69 72 65  e.# working dire
3420: 63 74 6f 72 79 2e 0a 23 0a 69 66 20 7b 5b 61 74  ctory..#.if {[at
3430: 6f 6d 69 63 5f 62 61 74 63 68 5f 77 72 69 74 65  omic_batch_write
3440: 20 74 65 73 74 2e 64 62 5d 3d 3d 30 7d 20 7b 0a   test.db]==0} {.
3450: 20 20 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d    do_test misc1-
3460: 31 34 2e 31 20 7b 0a 20 20 20 20 66 69 6c 65 20  14.1 {.    file 
3470: 6d 6b 64 69 72 20 74 65 6d 70 64 69 72 0a 20 20  mkdir tempdir.  
3480: 20 20 63 64 20 74 65 6d 70 64 69 72 0a 20 20 20    cd tempdir.   
3490: 20 65 78 65 63 73 71 6c 20 7b 42 45 47 49 4e 7d   execsql {BEGIN}
34a0: 0a 20 20 20 20 66 69 6c 65 20 65 78 69 73 74 73  .    file exists
34b0: 20 2e 2f 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e   ./test.db-journ
34c0: 61 6c 0a 20 20 7d 20 7b 30 7d 0a 20 20 64 6f 5f  al.  } {0}.  do_
34d0: 74 65 73 74 20 6d 69 73 63 31 2d 31 34 2e 32 61  test misc1-14.2a
34e0: 20 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b   {.    execsql {
34f0: 55 50 44 41 54 45 20 74 31 20 53 45 54 20 61 3d  UPDATE t1 SET a=
3500: 61 7c 7c 27 78 27 20 57 48 45 52 45 20 30 7d 0a  a||'x' WHERE 0}.
3510: 20 20 20 20 66 69 6c 65 20 65 78 69 73 74 73 20      file exists 
3520: 2e 2e 2f 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e  ../test.db-journ
3530: 61 6c 0a 20 20 7d 20 7b 30 7d 0a 20 20 64 6f 5f  al.  } {0}.  do_
3540: 74 65 73 74 20 6d 69 73 63 31 2d 31 34 2e 32 62  test misc1-14.2b
3550: 20 7b 0a 20 20 20 20 65 78 65 63 73 71 6c 20 7b   {.    execsql {
3560: 55 50 44 41 54 45 20 74 31 20 53 45 54 20 61 3d  UPDATE t1 SET a=
3570: 61 7c 7c 27 79 27 20 57 48 45 52 45 20 31 7d 0a  a||'y' WHERE 1}.
3580: 20 20 20 20 66 69 6c 65 20 65 78 69 73 74 73 20      file exists 
3590: 2e 2e 2f 74 65 73 74 2e 64 62 2d 6a 6f 75 72 6e  ../test.db-journ
35a0: 61 6c 0a 20 20 7d 20 7b 31 7d 0a 20 20 64 6f 5f  al.  } {1}.  do_
35b0: 74 65 73 74 20 6d 69 73 63 31 2d 31 34 2e 33 20  test misc1-14.3 
35c0: 7b 0a 20 20 20 20 63 64 20 2e 2e 0a 20 20 20 20  {.    cd ...    
35d0: 66 6f 72 63 65 64 65 6c 65 74 65 20 74 65 6d 70  forcedelete temp
35e0: 64 69 72 0a 20 20 20 20 65 78 65 63 73 71 6c 20  dir.    execsql 
35f0: 7b 43 4f 4d 4d 49 54 7d 0a 20 20 20 20 66 69 6c  {COMMIT}.    fil
3600: 65 20 65 78 69 73 74 73 20 2e 2f 74 65 73 74 2e  e exists ./test.
3610: 64 62 2d 6a 6f 75 72 6e 61 6c 0a 20 20 7d 20 7b  db-journal.  } {
3620: 30 7d 0a 7d 0a 7d 0a 0a 23 20 41 20 66 61 69 6c  0}.}.}..# A fail
3630: 65 64 20 63 72 65 61 74 65 20 74 61 62 6c 65 20  ed create table 
3640: 73 68 6f 75 6c 64 20 6e 6f 74 20 6c 65 61 76 65  should not leave
3650: 20 74 68 65 20 74 61 62 6c 65 20 69 6e 20 74 68   the table in th
3660: 65 20 69 6e 74 65 72 6e 61 6c 0a 23 20 64 61 74  e internal.# dat
3670: 61 20 73 74 72 75 63 74 75 72 65 73 2e 20 20 54  a structures.  T
3680: 69 63 6b 65 74 20 23 32 33 38 2e 0a 23 0a 64 6f  icket #238..#.do
3690: 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 35 2e 31  _test misc1-15.1
36a0: 2e 31 20 7b 0a 20 20 63 61 74 63 68 73 71 6c 20  .1 {.  catchsql 
36b0: 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54 41 42  {.    CREATE TAB
36c0: 4c 45 20 74 31 30 20 41 53 20 53 45 4c 45 43 54  LE t10 AS SELECT
36d0: 20 63 31 3b 0a 20 20 7d 0a 7d 20 7b 31 20 7b 6e   c1;.  }.} {1 {n
36e0: 6f 20 73 75 63 68 20 63 6f 6c 75 6d 6e 3a 20 63  o such column: c
36f0: 31 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63  1}}.do_test misc
3700: 31 2d 31 35 2e 31 2e 32 20 7b 0a 20 20 63 61 74  1-15.1.2 {.  cat
3710: 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41  chsql {.    CREA
3720: 54 45 20 54 41 42 4c 45 20 74 31 30 20 41 53 20  TE TABLE t10 AS 
3730: 53 45 4c 45 43 54 20 74 39 2e 63 31 3b 0a 20 20  SELECT t9.c1;.  
3740: 7d 0a 7d 20 7b 31 20 7b 6e 6f 20 73 75 63 68 20  }.} {1 {no such 
3750: 63 6f 6c 75 6d 6e 3a 20 74 39 2e 63 31 7d 7d 0a  column: t9.c1}}.
3760: 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 35  do_test misc1-15
3770: 2e 31 2e 33 20 7b 0a 20 20 63 61 74 63 68 73 71  .1.3 {.  catchsq
3780: 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54  l {.    CREATE T
3790: 41 42 4c 45 20 74 31 30 20 41 53 20 53 45 4c 45  ABLE t10 AS SELE
37a0: 43 54 20 6d 61 69 6e 2e 74 39 2e 63 31 3b 0a 20  CT main.t9.c1;. 
37b0: 20 7d 0a 7d 20 7b 31 20 7b 6e 6f 20 73 75 63 68   }.} {1 {no such
37c0: 20 63 6f 6c 75 6d 6e 3a 20 6d 61 69 6e 2e 74 39   column: main.t9
37d0: 2e 63 31 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d 69  .c1}}.do_test mi
37e0: 73 63 31 2d 31 35 2e 32 20 7b 0a 20 20 63 61 74  sc1-15.2 {.  cat
37f0: 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41  chsql {.    CREA
3800: 54 45 20 54 41 42 4c 45 20 74 31 30 20 41 53 20  TE TABLE t10 AS 
3810: 53 45 4c 45 43 54 20 31 3b 0a 20 20 7d 0a 20 20  SELECT 1;.  }.  
3820: 23 20 54 68 65 20 62 75 67 20 69 6e 20 74 69 63  # The bug in tic
3830: 6b 65 74 20 23 32 33 38 20 63 61 75 73 65 73 20  ket #238 causes 
3840: 74 68 65 20 73 74 61 74 65 6d 65 6e 74 20 61 62  the statement ab
3850: 6f 76 65 20 74 6f 20 66 61 69 6c 20 77 69 74 68  ove to fail with
3860: 0a 20 20 23 20 74 68 65 20 65 72 72 6f 72 20 22  .  # the error "
3870: 74 61 62 6c 65 20 74 31 30 20 61 6c 72 65 61 64  table t10 alread
3880: 20 65 78 69 73 74 73 22 0a 7d 20 7b 30 20 7b 7d   exists".} {0 {}
3890: 7d 0a 0a 23 20 54 65 73 74 20 66 6f 72 20 6d 65  }..# Test for me
38a0: 6d 6f 72 79 20 6c 65 61 6b 73 20 77 68 65 6e 20  mory leaks when 
38b0: 61 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 63  a CREATE TABLE c
38c0: 6f 6e 74 61 69 6e 69 6e 67 20 61 20 70 72 69 6d  ontaining a prim
38d0: 61 72 79 20 6b 65 79 0a 23 20 66 61 69 6c 73 2e  ary key.# fails.
38e0: 20 20 54 69 63 6b 65 74 20 23 32 34 39 2e 0a 23    Ticket #249..#
38f0: 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31  .do_test misc1-1
3900: 36 2e 31 20 7b 0a 20 20 63 61 74 63 68 73 71 6c  6.1 {.  catchsql
3910: 20 7b 53 45 4c 45 43 54 20 6e 61 6d 65 20 46 52   {SELECT name FR
3920: 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65 72  OM sqlite_master
3930: 20 4c 49 4d 49 54 20 31 7d 0a 20 20 63 61 74 63   LIMIT 1}.  catc
3940: 68 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41 54  hsql {.    CREAT
3950: 45 20 54 41 42 4c 45 20 74 65 73 74 28 61 20 69  E TABLE test(a i
3960: 6e 74 65 67 65 72 2c 20 70 72 69 6d 61 72 79 20  nteger, primary 
3970: 6b 65 79 28 61 29 29 3b 0a 20 20 7d 0a 7d 20 7b  key(a));.  }.} {
3980: 30 20 7b 7d 7d 0a 64 6f 5f 74 65 73 74 20 6d 69  0 {}}.do_test mi
3990: 73 63 31 2d 31 36 2e 32 20 7b 0a 20 20 63 61 74  sc1-16.2 {.  cat
39a0: 63 68 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41  chsql {.    CREA
39b0: 54 45 20 54 41 42 4c 45 20 74 65 73 74 28 61 20  TE TABLE test(a 
39c0: 69 6e 74 65 67 65 72 2c 20 70 72 69 6d 61 72 79  integer, primary
39d0: 20 6b 65 79 28 61 29 29 3b 0a 20 20 7d 0a 7d 20   key(a));.  }.} 
39e0: 7b 31 20 7b 74 61 62 6c 65 20 74 65 73 74 20 61  {1 {table test a
39f0: 6c 72 65 61 64 79 20 65 78 69 73 74 73 7d 7d 0a  lready exists}}.
3a00: 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 36  do_test misc1-16
3a10: 2e 33 20 7b 0a 20 20 63 61 74 63 68 73 71 6c 20  .3 {.  catchsql 
3a20: 7b 0a 20 20 20 20 43 52 45 41 54 45 20 54 41 42  {.    CREATE TAB
3a30: 4c 45 20 74 65 73 74 32 28 61 20 74 65 78 74 20  LE test2(a text 
3a40: 70 72 69 6d 61 72 79 20 6b 65 79 2c 20 62 20 74  primary key, b t
3a50: 65 78 74 2c 20 70 72 69 6d 61 72 79 20 6b 65 79  ext, primary key
3a60: 28 61 2c 62 29 29 3b 0a 20 20 7d 0a 7d 20 7b 31  (a,b));.  }.} {1
3a70: 20 7b 74 61 62 6c 65 20 22 74 65 73 74 32 22 20   {table "test2" 
3a80: 68 61 73 20 6d 6f 72 65 20 74 68 61 6e 20 6f 6e  has more than on
3a90: 65 20 70 72 69 6d 61 72 79 20 6b 65 79 7d 7d 0a  e primary key}}.
3aa0: 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 36  do_test misc1-16
3ab0: 2e 34 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .4 {.  execsql {
3ac0: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
3ad0: 20 74 65 73 74 20 56 41 4c 55 45 53 28 31 29 3b   test VALUES(1);
3ae0: 0a 20 20 20 20 53 45 4c 45 43 54 20 72 6f 77 69  .    SELECT rowi
3af0: 64 2c 20 61 20 46 52 4f 4d 20 74 65 73 74 3b 0a  d, a FROM test;.
3b00: 20 20 7d 0a 7d 20 7b 31 20 31 7d 0a 64 6f 5f 74    }.} {1 1}.do_t
3b10: 65 73 74 20 6d 69 73 63 31 2d 31 36 2e 35 20 7b  est misc1-16.5 {
3b20: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
3b30: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 65 73   INSERT INTO tes
3b40: 74 20 56 41 4c 55 45 53 28 35 29 3b 0a 20 20 20  t VALUES(5);.   
3b50: 20 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 61   SELECT rowid, a
3b60: 20 46 52 4f 4d 20 74 65 73 74 3b 0a 20 20 7d 0a   FROM test;.  }.
3b70: 7d 20 7b 31 20 31 20 35 20 35 7d 0a 64 6f 5f 74  } {1 1 5 5}.do_t
3b80: 65 73 74 20 6d 69 73 63 31 2d 31 36 2e 36 20 7b  est misc1-16.6 {
3b90: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
3ba0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 65 73   INSERT INTO tes
3bb0: 74 20 56 41 4c 55 45 53 28 4e 55 4c 4c 29 3b 0a  t VALUES(NULL);.
3bc0: 20 20 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64      SELECT rowid
3bd0: 2c 20 61 20 46 52 4f 4d 20 74 65 73 74 3b 0a 20  , a FROM test;. 
3be0: 20 7d 0a 7d 20 7b 31 20 31 20 35 20 35 20 36 20   }.} {1 1 5 5 6 
3bf0: 36 7d 0a 0a 69 66 63 61 70 61 62 6c 65 20 74 72  6}..ifcapable tr
3c00: 69 67 67 65 72 26 26 74 65 6d 70 64 62 20 7b 0a  igger&&tempdb {.
3c10: 23 20 54 69 63 6b 65 74 20 23 33 33 33 3a 20 54  # Ticket #333: T
3c20: 65 6d 70 20 74 72 69 67 67 65 72 73 20 74 68 61  emp triggers tha
3c30: 74 20 6d 6f 64 69 66 79 20 70 65 72 73 69 73 74  t modify persist
3c40: 65 6e 74 20 74 61 62 6c 65 73 2e 0a 23 0a 64 6f  ent tables..#.do
3c50: 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 37 2e 31  _test misc1-17.1
3c60: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20   {.  execsql {. 
3c70: 20 20 20 42 45 47 49 4e 3b 0a 20 20 20 20 43 52     BEGIN;.    CR
3c80: 45 41 54 45 20 54 41 42 4c 45 20 52 65 61 6c 54  EATE TABLE RealT
3c90: 61 62 6c 65 28 54 65 73 74 49 44 20 49 4e 54 45  able(TestID INTE
3ca0: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c  GER PRIMARY KEY,
3cb0: 20 54 65 73 74 53 74 72 69 6e 67 20 54 45 58 54   TestString TEXT
3cc0: 29 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54 45  );.    CREATE TE
3cd0: 4d 50 20 54 41 42 4c 45 20 54 65 6d 70 54 61 62  MP TABLE TempTab
3ce0: 6c 65 28 54 65 73 74 49 44 20 49 4e 54 45 47 45  le(TestID INTEGE
3cf0: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 54  R PRIMARY KEY, T
3d00: 65 73 74 53 74 72 69 6e 67 20 54 45 58 54 29 3b  estString TEXT);
3d10: 0a 20 20 20 20 43 52 45 41 54 45 20 54 45 4d 50  .    CREATE TEMP
3d20: 20 54 52 49 47 47 45 52 20 74 72 69 67 54 65 73   TRIGGER trigTes
3d30: 74 5f 31 20 41 46 54 45 52 20 55 50 44 41 54 45  t_1 AFTER UPDATE
3d40: 20 4f 4e 20 54 65 6d 70 54 61 62 6c 65 20 42 45   ON TempTable BE
3d50: 47 49 4e 0a 20 20 20 20 20 20 49 4e 53 45 52 54  GIN.      INSERT
3d60: 20 49 4e 54 4f 20 52 65 61 6c 54 61 62 6c 65 28   INTO RealTable(
3d70: 54 65 73 74 53 74 72 69 6e 67 29 20 0a 20 20 20  TestString) .   
3d80: 20 20 20 20 20 20 53 45 4c 45 43 54 20 6e 65 77        SELECT new
3d90: 2e 54 65 73 74 53 74 72 69 6e 67 20 46 52 4f 4d  .TestString FROM
3da0: 20 54 65 6d 70 54 61 62 6c 65 20 4c 49 4d 49 54   TempTable LIMIT
3db0: 20 31 3b 0a 20 20 20 20 45 4e 44 3b 0a 20 20 20   1;.    END;.   
3dc0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 54 65 6d   INSERT INTO Tem
3dd0: 70 54 61 62 6c 65 28 54 65 73 74 53 74 72 69 6e  pTable(TestStrin
3de0: 67 29 20 56 41 4c 55 45 53 20 28 27 31 27 29 3b  g) VALUES ('1');
3df0: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
3e00: 20 54 65 6d 70 54 61 62 6c 65 28 54 65 73 74 53   TempTable(TestS
3e10: 74 72 69 6e 67 29 20 56 41 4c 55 45 53 20 28 27  tring) VALUES ('
3e20: 32 27 29 3b 0a 20 20 20 20 55 50 44 41 54 45 20  2');.    UPDATE 
3e30: 54 65 6d 70 54 61 62 6c 65 20 53 45 54 20 54 65  TempTable SET Te
3e40: 73 74 53 74 72 69 6e 67 20 3d 20 54 65 73 74 53  stString = TestS
3e50: 74 72 69 6e 67 20 2b 20 31 20 57 48 45 52 45 20  tring + 1 WHERE 
3e60: 54 65 73 74 49 44 3d 31 20 4f 52 20 54 65 73 74  TestID=1 OR Test
3e70: 49 64 3d 32 3b 0a 20 20 20 20 43 4f 4d 4d 49 54  Id=2;.    COMMIT
3e80: 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 54 65 73  ;.    SELECT Tes
3e90: 74 53 74 72 69 6e 67 20 46 52 4f 4d 20 52 65 61  tString FROM Rea
3ea0: 6c 54 61 62 6c 65 20 4f 52 44 45 52 20 42 59 20  lTable ORDER BY 
3eb0: 31 3b 0a 20 20 7d 0a 7d 20 7b 32 20 33 7d 0a 7d  1;.  }.} {2 3}.}
3ec0: 0a 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31 2d  ..do_test misc1-
3ed0: 31 38 2e 31 20 7b 0a 20 20 73 65 74 20 6e 20 5b  18.1 {.  set n [
3ee0: 73 71 6c 69 74 65 33 5f 73 6c 65 65 70 20 31 30  sqlite3_sleep 10
3ef0: 30 5d 0a 20 20 65 78 70 72 20 7b 24 6e 3e 3d 31  0].  expr {$n>=1
3f00: 30 30 7d 0a 7d 20 7b 31 7d 0a 0a 23 20 32 30 31  00}.} {1}..# 201
3f10: 34 2d 30 31 2d 31 30 3a 20 20 49 6e 20 61 20 43  4-01-10:  In a C
3f20: 52 45 41 54 45 20 54 41 42 4c 45 20 41 53 2c 20  REATE TABLE AS, 
3f30: 69 66 20 6f 6e 65 20 6f 72 20 6d 6f 72 65 20 6f  if one or more o
3f40: 66 20 74 68 65 20 63 6f 6c 75 6d 6e 20 6e 61 6d  f the column nam
3f50: 65 73 0a 23 20 61 72 65 20 61 6e 20 65 6d 70 74  es.# are an empt
3f60: 79 20 73 74 72 69 6e 67 2c 20 74 68 61 74 20 69  y string, that i
3f70: 73 20 73 74 69 6c 6c 20 4f 4b 2e 0a 23 0a 64 6f  s still OK..#.do
3f80: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 6d 69  _execsql_test mi
3f90: 73 63 31 2d 31 39 2e 31 20 7b 0a 20 20 43 52 45  sc1-19.1 {.  CRE
3fa0: 41 54 45 20 54 41 42 4c 45 20 74 31 39 20 41 53  ATE TABLE t19 AS
3fb0: 20 53 45 4c 45 43 54 20 31 2c 20 32 20 41 53 20   SELECT 1, 2 AS 
3fc0: 27 27 2c 20 33 3b 0a 20 20 53 45 4c 45 43 54 20  '', 3;.  SELECT 
3fd0: 2a 20 46 52 4f 4d 20 74 31 39 3b 0a 7d 20 7b 31  * FROM t19;.} {1
3fe0: 20 32 20 33 7d 0a 64 6f 5f 65 78 65 63 73 71 6c   2 3}.do_execsql
3ff0: 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 39 2e 32  _test misc1-19.2
4000: 20 7b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c   {.  CREATE TABL
4010: 45 20 74 31 39 62 20 41 53 20 53 45 4c 45 43 54  E t19b AS SELECT
4020: 20 34 20 41 53 20 27 27 2c 20 35 20 41 53 20 27   4 AS '', 5 AS '
4030: 27 2c 20 20 36 20 41 53 20 27 27 3b 0a 20 20 53  ',  6 AS '';.  S
4040: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 39  ELECT * FROM t19
4050: 62 3b 0a 7d 20 7b 34 20 35 20 36 7d 0a 0a 23 20  b;.} {4 5 6}..# 
4060: 32 30 31 35 2d 30 35 2d 32 30 3a 20 20 43 52 45  2015-05-20:  CRE
4070: 41 54 45 20 54 41 42 4c 45 20 41 53 20 73 68 6f  ATE TABLE AS sho
4080: 75 6c 64 20 6e 6f 74 20 73 74 6f 72 65 20 49 4e  uld not store IN
4090: 54 20 76 61 6c 75 65 20 69 73 20 61 20 54 45 58  T value is a TEX
40a0: 54 0a 23 20 63 6f 6c 75 6d 6e 2e 0a 23 0a 64 6f  T.# column..#.do
40b0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 6d 69  _execsql_test mi
40c0: 73 63 31 2d 31 39 2e 33 20 7b 0a 20 20 43 52 45  sc1-19.3 {.  CRE
40d0: 41 54 45 20 54 41 42 4c 45 20 74 31 39 63 28 78  ATE TABLE t19c(x
40e0: 20 54 45 58 54 29 3b 0a 20 20 43 52 45 41 54 45   TEXT);.  CREATE
40f0: 20 54 41 42 4c 45 20 74 31 39 64 20 41 53 20 53   TABLE t19d AS S
4100: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 39  ELECT * FROM t19
4110: 63 20 55 4e 49 4f 4e 20 41 4c 4c 20 53 45 4c 45  c UNION ALL SELE
4120: 43 54 20 31 32 33 34 3b 0a 20 20 53 45 4c 45 43  CT 1234;.  SELEC
4130: 54 20 78 2c 20 74 79 70 65 6f 66 28 78 29 20 46  T x, typeof(x) F
4140: 52 4f 4d 20 74 31 39 64 3b 0a 7d 20 7b 31 32 33  ROM t19d;.} {123
4150: 34 20 74 65 78 74 7d 0a 0a 23 20 32 30 31 34 2d  4 text}..# 2014-
4160: 30 35 2d 31 36 3a 20 20 54 65 73 74 73 20 66 6f  05-16:  Tests fo
4170: 72 20 74 68 65 20 53 51 4c 49 54 45 5f 54 45 53  r the SQLITE_TES
4180: 54 43 54 52 4c 5f 46 41 55 4c 54 5f 49 4e 53 54  TCTRL_FAULT_INST
4190: 41 4c 4c 20 66 65 61 74 75 72 65 2e 0a 23 0a 75  ALL feature..#.u
41a0: 6e 73 65 74 20 2d 6e 6f 63 6f 6d 70 6c 61 69 6e  nset -nocomplain
41b0: 20 66 61 75 6c 74 5f 63 61 6c 6c 62 61 63 6b 73   fault_callbacks
41c0: 0a 73 65 74 20 66 61 75 6c 74 5f 63 61 6c 6c 62  .set fault_callb
41d0: 61 63 6b 73 20 7b 7d 0a 70 72 6f 63 20 66 61 75  acks {}.proc fau
41e0: 6c 74 5f 63 61 6c 6c 62 61 63 6b 20 7b 6e 7d 20  lt_callback {n} 
41f0: 7b 0a 20 20 6c 61 70 70 65 6e 64 20 3a 3a 66 61  {.  lappend ::fa
4200: 75 6c 74 5f 63 61 6c 6c 62 61 63 6b 73 20 24 6e  ult_callbacks $n
4210: 0a 20 20 72 65 74 75 72 6e 20 30 0a 7d 0a 64 6f  .  return 0.}.do
4220: 5f 74 65 73 74 20 6d 69 73 63 31 2d 31 39 2e 31  _test misc1-19.1
4230: 20 7b 0a 20 20 73 71 6c 69 74 65 33 5f 74 65 73   {.  sqlite3_tes
4240: 74 5f 63 6f 6e 74 72 6f 6c 5f 66 61 75 6c 74 5f  t_control_fault_
4250: 69 6e 73 74 61 6c 6c 20 66 61 75 6c 74 5f 63 61  install fault_ca
4260: 6c 6c 62 61 63 6b 0a 20 20 73 65 74 20 66 61 75  llback.  set fau
4270: 6c 74 5f 63 61 6c 6c 62 61 63 6b 73 0a 7d 20 7b  lt_callbacks.} {
4280: 30 7d 0a 64 6f 5f 74 65 73 74 20 6d 69 73 63 31  0}.do_test misc1
4290: 2d 31 39 2e 32 20 7b 0a 20 20 73 71 6c 69 74 65  -19.2 {.  sqlite
42a0: 33 5f 74 65 73 74 5f 63 6f 6e 74 72 6f 6c 5f 66  3_test_control_f
42b0: 61 75 6c 74 5f 69 6e 73 74 61 6c 6c 0a 20 20 73  ault_install.  s
42c0: 65 74 20 66 61 75 6c 74 5f 63 61 6c 6c 62 61 63  et fault_callbac
42d0: 6b 73 0a 7d 20 7b 30 7d 0a 0a 23 20 32 30 31 35  ks.} {0}..# 2015
42e0: 2d 30 31 2d 32 36 3a 20 20 56 61 6c 67 72 69 6e  -01-26:  Valgrin
42f0: 64 2d 64 65 74 65 63 74 65 64 20 6f 76 65 72 2d  d-detected over-
4300: 72 65 61 64 2e 0a 23 20 52 65 70 6f 72 74 65 64  read..# Reported
4310: 20 6f 6e 20 73 71 6c 69 74 65 2d 75 73 65 72 73   on sqlite-users
4320: 40 73 71 6c 69 74 65 2e 6f 72 67 20 62 79 20 4d  @sqlite.org by M
4330: 69 63 68 61 6c 20 5a 61 6c 65 77 73 6b 69 2e 20  ichal Zalewski. 
4340: 20 46 6f 75 6e 64 20 62 79 20 61 66 6c 2d 66 75   Found by afl-fu
4350: 7a 7a 0a 23 20 70 72 65 73 75 6d 61 62 6c 79 2e  zz.# presumably.
4360: 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  .#.do_execsql_te
4370: 73 74 20 6d 69 73 63 31 2d 32 30 2e 31 20 7b 0a  st misc1-20.1 {.
4380: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74    CREATE TABLE t
4390: 30 28 78 20 49 4e 54 45 47 45 52 20 44 45 46 41  0(x INTEGER DEFA
43a0: 55 4c 54 28 30 3d 3d 30 29 20 4e 4f 54 20 4e 55  ULT(0==0) NOT NU
43b0: 4c 4c 29 3b 0a 20 20 52 45 50 4c 41 43 45 20 49  LL);.  REPLACE I
43c0: 4e 54 4f 20 74 30 28 78 29 20 56 41 4c 55 45 53  NTO t0(x) VALUES
43d0: 28 27 27 29 3b 0a 20 20 53 45 4c 45 43 54 20 72  ('');.  SELECT r
43e0: 6f 77 69 64 2c 20 71 75 6f 74 65 28 78 29 20 46  owid, quote(x) F
43f0: 52 4f 4d 20 74 30 3b 0a 7d 20 7b 31 20 27 27 7d  ROM t0;.} {1 ''}
4400: 0a 0a 23 20 32 30 31 35 2d 30 33 2d 32 32 3a 20  ..# 2015-03-22: 
4410: 4e 55 4c 4c 20 70 6f 69 6e 74 65 72 20 64 65 72  NULL pointer der
4420: 65 66 65 72 65 6e 63 65 20 61 66 74 65 72 20 61  eference after a
4430: 20 73 79 6e 74 61 78 20 65 72 72 6f 72 0a 23 0a   syntax error.#.
4440: 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74  do_catchsql_test
4450: 20 6d 69 73 63 31 2d 32 31 2e 31 20 7b 0a 20 20   misc1-21.1 {.  
4460: 73 65 6c 65 63 74 27 27 6c 69 6b 65 27 27 6c 69  select''like''li
4470: 6b 65 27 27 6c 69 6b 65 23 30 3b 0a 7d 20 7b 31  ke''like#0;.} {1
4480: 20 7b 6e 65 61 72 20 22 23 30 22 3a 20 73 79 6e   {near "#0": syn
4490: 74 61 78 20 65 72 72 6f 72 7d 7d 0a 64 6f 5f 63  tax error}}.do_c
44a0: 61 74 63 68 73 71 6c 5f 74 65 73 74 20 6d 69 73  atchsql_test mis
44b0: 63 31 2d 32 31 2e 32 20 7b 0a 20 20 56 41 4c 55  c1-21.2 {.  VALU
44c0: 45 53 28 30 2c 30 78 30 4d 41 54 43 48 23 30 3b  ES(0,0x0MATCH#0;
44d0: 0a 7d 20 7b 31 20 7b 6e 65 61 72 20 22 3b 22 3a  .} {1 {near ";":
44e0: 20 73 79 6e 74 61 78 20 65 72 72 6f 72 7d 7d 0a   syntax error}}.
44f0: 0a 23 20 32 30 31 35 2d 30 34 2d 31 35 0a 64 6f  .# 2015-04-15.do
4500: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 6d 69  _execsql_test mi
4510: 73 63 31 2d 32 32 2e 31 20 7b 0a 20 20 53 45 4c  sc1-22.1 {.  SEL
4520: 45 43 54 20 22 22 2b 33 20 46 52 4f 4d 20 28 53  ECT ""+3 FROM (S
4530: 45 4c 45 43 54 20 22 22 2b 35 29 3b 0a 7d 20 7b  ELECT ""+5);.} {
4540: 33 7d 0a 0a 23 20 32 30 31 35 2d 30 34 2d 31 39  3}..# 2015-04-19
4550: 3a 20 4e 55 4c 4c 20 70 6f 69 6e 74 65 72 20 64  : NULL pointer d
4560: 65 72 65 66 65 72 65 6e 63 65 20 6f 6e 20 61 20  ereference on a 
4570: 63 6f 72 72 75 70 74 20 73 63 68 65 6d 61 0a 23  corrupt schema.#
4580: 0a 64 62 20 63 6c 6f 73 65 0a 73 71 6c 69 74 65  .db close.sqlite
4590: 33 20 64 62 20 3a 6d 65 6d 6f 72 79 3a 0a 73 71  3 db :memory:.sq
45a0: 6c 69 74 65 33 5f 64 62 5f 63 6f 6e 66 69 67 20  lite3_db_config 
45b0: 64 62 20 44 45 46 45 4e 53 49 56 45 20 30 0a 64  db DEFENSIVE 0.d
45c0: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 6d  o_execsql_test m
45d0: 69 73 63 31 2d 32 33 2e 31 20 7b 0a 20 20 43 52  isc1-23.1 {.  CR
45e0: 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 78 29  EATE TABLE t1(x)
45f0: 3b 0a 20 20 50 52 41 47 4d 41 20 77 72 69 74 61  ;.  PRAGMA writa
4600: 62 6c 65 5f 73 63 68 65 6d 61 3d 4f 4e 3b 0a 20  ble_schema=ON;. 
4610: 20 55 50 44 41 54 45 20 73 71 6c 69 74 65 5f 6d   UPDATE sqlite_m
4620: 61 73 74 65 72 20 53 45 54 20 73 71 6c 3d 27 43  aster SET sql='C
4630: 52 45 41 54 45 20 74 61 62 6c 65 20 74 28 64 20  REATE table t(d 
4640: 43 48 45 43 4b 28 54 28 23 30 29 27 3b 0a 20 20  CHECK(T(#0)';.  
4650: 42 45 47 49 4e 3b 0a 20 20 43 52 45 41 54 45 20  BEGIN;.  CREATE 
4660: 54 41 42 4c 45 20 74 32 28 79 29 3b 0a 20 20 52  TABLE t2(y);.  R
4670: 4f 4c 4c 42 41 43 4b 3b 0a 20 20 44 52 4f 50 20  OLLBACK;.  DROP 
4680: 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20  TABLE IF EXISTS 
4690: 74 33 3b 0a 7d 20 7b 7d 0a 0a 23 20 32 30 31 35  t3;.} {}..# 2015
46a0: 2d 30 34 2d 31 39 3a 20 20 46 61 75 6c 74 79 20  -04-19:  Faulty 
46b0: 61 73 73 65 72 74 28 29 20 73 74 61 74 65 6d 65  assert() stateme
46c0: 6e 74 0a 23 0a 64 62 20 63 6c 6f 73 65 0a 64 61  nt.#.db close.da
46d0: 74 61 62 61 73 65 5f 6d 61 79 5f 62 65 5f 63 6f  tabase_may_be_co
46e0: 72 72 75 70 74 0a 73 71 6c 69 74 65 33 20 64 62  rrupt.sqlite3 db
46f0: 20 3a 6d 65 6d 6f 72 79 3a 0a 73 71 6c 69 74 65   :memory:.sqlite
4700: 33 5f 64 62 5f 63 6f 6e 66 69 67 20 64 62 20 44  3_db_config db D
4710: 45 46 45 4e 53 49 56 45 20 30 0a 64 6f 5f 63 61  EFENSIVE 0.do_ca
4720: 74 63 68 73 71 6c 5f 74 65 73 74 20 6d 69 73 63  tchsql_test misc
4730: 31 2d 32 33 2e 32 20 7b 0a 20 20 43 52 45 41 54  1-23.2 {.  CREAT
4740: 45 20 54 41 42 4c 45 20 74 31 28 78 20 55 4e 49  E TABLE t1(x UNI
4750: 51 55 45 29 3b 0a 20 20 50 52 41 47 4d 41 20 77  QUE);.  PRAGMA w
4760: 72 69 74 61 62 6c 65 5f 73 63 68 65 6d 61 3d 4f  ritable_schema=O
4770: 4e 3b 0a 20 20 55 50 44 41 54 45 20 73 71 6c 69  N;.  UPDATE sqli
4780: 74 65 5f 6d 61 73 74 65 72 20 53 45 54 20 73 71  te_master SET sq
4790: 6c 3d 27 43 52 45 41 54 45 20 54 41 42 4c 45 20  l='CREATE TABLE 
47a0: 49 46 20 6e 6f 74 20 45 58 49 53 54 53 20 74 28  IF not EXISTS t(
47b0: 63 29 27 3b 0a 20 20 42 45 47 49 4e 3b 0a 20 20  c)';.  BEGIN;.  
47c0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 28  CREATE TABLE t2(
47d0: 78 29 3b 0a 20 20 52 4f 4c 4c 42 41 43 4b 3b 0a  x);.  ROLLBACK;.
47e0: 20 20 44 52 4f 50 20 54 41 42 4c 45 20 46 3b 0a    DROP TABLE F;.
47f0: 7d 20 7b 31 20 7b 6e 6f 20 73 75 63 68 20 74 61  } {1 {no such ta
4800: 62 6c 65 3a 20 46 7d 7d 0a 64 62 20 63 6c 6f 73  ble: F}}.db clos
4810: 65 0a 73 71 6c 69 74 65 33 20 64 62 20 3a 6d 65  e.sqlite3 db :me
4820: 6d 6f 72 79 3a 0a 73 71 6c 69 74 65 33 5f 64 62  mory:.sqlite3_db
4830: 5f 63 6f 6e 66 69 67 20 64 62 20 44 45 46 45 4e  _config db DEFEN
4840: 53 49 56 45 20 30 0a 64 6f 5f 63 61 74 63 68 73  SIVE 0.do_catchs
4850: 71 6c 5f 74 65 73 74 20 6d 69 73 63 31 2d 32 33  ql_test misc1-23
4860: 2e 33 20 7b 0a 20 20 43 52 45 41 54 45 20 54 41  .3 {.  CREATE TA
4870: 42 4c 45 20 74 31 28 78 20 55 4e 49 51 55 45 29  BLE t1(x UNIQUE)
4880: 3b 0a 20 20 50 52 41 47 4d 41 20 77 72 69 74 61  ;.  PRAGMA writa
4890: 62 6c 65 5f 73 63 68 65 6d 61 3d 4f 4e 3b 0a 20  ble_schema=ON;. 
48a0: 20 55 50 44 41 54 45 20 73 71 6c 69 74 65 5f 6d   UPDATE sqlite_m
48b0: 61 73 74 65 72 20 53 45 54 20 73 71 6c 3d 27 43  aster SET sql='C
48c0: 52 45 41 54 45 20 74 61 62 6c 65 20 79 28 61 20  REATE table y(a 
48d0: 54 45 58 54 2c 20 61 20 54 45 58 54 29 27 3b 0a  TEXT, a TEXT)';.
48e0: 20 20 42 45 47 49 4e 3b 0a 20 20 43 52 45 41 54    BEGIN;.  CREAT
48f0: 45 20 54 41 42 4c 45 20 74 32 28 79 29 3b 0a 20  E TABLE t2(y);. 
4900: 20 52 4f 4c 4c 42 41 43 4b 3b 0a 20 20 44 52 4f   ROLLBACK;.  DRO
4910: 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54  P TABLE IF EXIST
4920: 53 20 74 3b 0a 7d 20 7b 30 20 7b 7d 7d 0a 0a 0a  S t;.} {0 {}}...
4930: 23 20 41 74 20 6f 6e 65 20 70 6f 69 6e 74 2c 20  # At one point, 
4940: 72 75 6e 6e 69 6e 67 20 74 68 69 73 20 77 6f 75  running this wou
4950: 6c 64 20 72 65 61 64 20 6f 6e 65 20 62 79 74 65  ld read one byte
4960: 20 70 61 73 73 65 64 20 74 68 65 20 65 6e 64 20   passed the end 
4970: 6f 66 20 61 20 0a 23 20 62 75 66 66 65 72 2c 20  of a .# buffer, 
4980: 75 70 73 65 74 74 69 6e 67 20 76 61 6c 67 72 69  upsetting valgri
4990: 6e 64 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 6d 69  nd..#.do_test mi
49a0: 73 63 31 2d 32 34 2e 30 20 7b 0a 20 20 6c 69 73  sc1-24.0 {.  lis
49b0: 74 20 5b 63 61 74 63 68 20 7b 20 73 71 6c 69 74  t [catch { sqlit
49c0: 65 33 5f 70 72 65 70 61 72 65 5f 76 32 20 64 62  e3_prepare_v2 db
49d0: 20 21 20 2d 31 20 64 75 6d 6d 79 20 7d 20 6d 73   ! -1 dummy } ms
49e0: 67 5d 20 24 6d 73 67 0a 7d 20 7b 31 20 7b 28 31  g] $msg.} {1 {(1
49f0: 29 20 75 6e 72 65 63 6f 67 6e 69 7a 65 64 20 74  ) unrecognized t
4a00: 6f 6b 65 6e 3a 20 22 21 22 7d 7d 0a 0a 23 20 54  oken: "!"}}..# T
4a10: 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 71 75 65  he following que
4a20: 72 79 20 28 70 72 6f 76 69 64 65 64 20 62 79 20  ry (provided by 
4a30: 4b 6f 73 74 79 61 20 53 65 72 65 62 72 79 61 6e  Kostya Serebryan
4a40: 79 29 20 75 73 65 64 20 74 6f 20 74 61 6b 65 20  y) used to take 
4a50: 32 35 0a 23 20 6d 69 6e 75 74 65 73 20 74 6f 20  25.# minutes to 
4a60: 70 72 65 70 61 72 65 2e 20 20 54 68 69 73 20 68  prepare.  This h
4a70: 61 73 20 62 65 65 6e 20 73 70 65 65 64 65 64 20  as been speeded 
4a80: 75 70 20 74 6f 20 61 62 6f 75 74 20 32 35 30 20  up to about 250 
4a90: 6d 69 6c 6c 69 73 65 63 6f 6e 64 73 2e 0a 23 0a  milliseconds..#.
4aa0: 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74  do_catchsql_test
4ab0: 20 6d 69 73 63 31 2d 32 35 2e 30 20 7b 0a 53 45   misc1-25.0 {.SE
4ac0: 4c 45 43 54 2d 31 20 55 4e 49 4f 4e 20 20 53 45  LECT-1 UNION  SE
4ad0: 4c 45 43 54 20 35 20 55 4e 49 4f 4e 20 53 45 4c  LECT 5 UNION SEL
4ae0: 45 43 54 20 30 20 55 4e 49 4f 4e 20 53 45 6c 45  ECT 0 UNION SElE
4af0: 43 54 2a 66 72 6f 6d 28 53 45 4c 45 43 54 2d 35  CT*from(SELECT-5
4b00: 29 20 55 4e 49 4f 4e 20 53 45 4c 45 43 54 2a 66  ) UNION SELECT*f
4b10: 72 6f 6d 28 53 45 4c 45 43 54 2d 30 29 20 55 4e  rom(SELECT-0) UN
4b20: 49 4f 4e 20 20 53 45 4c 45 43 54 3a 53 45 4c 45  ION  SELECT:SELE
4b30: 43 54 2d 30 20 55 4e 49 4f 4e 20 53 45 4c 45 43  CT-0 UNION SELEC
4b40: 54 2d 31 20 55 4e 49 4f 4e 20 53 45 4c 45 43 54  T-1 UNION SELECT
4b50: 20 31 20 55 4e 49 4f 4e 20 53 45 4c 45 43 54 20   1 UNION SELECT 
4b60: 31 20 4f 52 44 45 52 20 42 59 20 53 20 20 69 6e  1 ORDER BY S  in
4b70: 28 57 49 54 48 20 4b 20 41 53 28 57 49 54 48 20  (WITH K AS(WITH 
4b80: 4b 20 41 53 28 73 65 6c 65 63 74 27 43 52 45 49  K AS(select'CREI
4b90: 4e 44 45 52 63 68 61 72 52 45 41 44 45 56 49 52  NDERcharREADEVIR
4ba0: 54 55 4c 35 54 41 42 4c 45 43 4f 4e 46 4c 49 43  TUL5TABLECONFLIC
4bb0: 54 20 21 31 20 55 53 49 4e 27 27 20 4d 46 74 4f  T !1 USIN'' MFtO
4bc0: 52 28 62 33 38 71 2c 65 57 49 54 48 20 4b 20 41  R(b38q,eWITH K A
4bd0: 53 28 73 65 6c 65 63 74 43 52 45 41 54 65 20 54  S(selectCREATe T
4be0: 41 42 4c 45 20 74 30 28 61 2c 62 2c 63 2c 64 2c  ABLE t0(a,b,c,d,
4bf0: 65 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28 61  e, PRIMARY KEY(a
4c00: 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,b,c,d,c,a,b,b,c
4c10: 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64  ,d,c,a,b,c,e,c,d
4c20: 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 61  ,c,a,b,b,c,d,c,a
4c30: 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62  ,b,c,e,d,d,c,a,b
4c40: 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62  ,b,c,d,c,d,c,a,b
4c50: 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62  ,c,e,c,d,c,a,b,b
4c60: 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,c,d,c,d,c,a,b,c
4c70: 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,d,d,c,a,b,b,c
4c80: 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64  ,c,a,b,b,c,d,c,d
4c90: 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63  ,c,a,b,c,e,d,d,c
4ca0: 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63  ,a,b,b,c,d,c,d,c
4cb0: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64  ,c,d,c,a,b,c,e,d
4cc0: 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63  ,d,c,a,b,b,c,d,c
4cd0: 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64  ,d,c,a,b,c,e,c,d
4ce0: 2c 63 2c 61 2c 62 2c 62 2c 63 2c 61 2c 62 2c 62  ,c,a,b,b,c,a,b,b
4cf0: 2c 63 2c 64 2c 63 2c 61 2c 63 2c 64 2c 63 2c 64  ,c,d,c,a,c,d,c,d
4d00: 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62  ,c,e,d,d,c,a,b,b
4d10: 2c 63 2c 63 2c 61 2c 62 2c 62 2c 45 2c 64 2c 63  ,c,c,a,b,b,E,d,c
4d20: 2c 64 2c 63 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63  ,d,c,b,c,d,c,d,c
4d30: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64  ,c,d,c,a,b,c,e,d
4d40: 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63  ,d,c,a,b,b,c,d,c
4d50: 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64  ,d,c,a,b,c,e,c,d
4d60: 2c 63 2c 61 2c 62 2c 62 2c 63 2c 61 2c 62 2c 63  ,c,a,b,b,c,a,b,c
4d70: 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,d,d,c,a,b,b,c
4d80: 2c 64 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64  ,d,d,c,a,b,c,e,d
4d90: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63  ,c,d,c,a,b,c,e,c
4da0: 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63  ,d,c,a,b,b,c,d,c
4db0: 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61  ,a,b,c,e,d,d,c,a
4dc0: 2c 62 2c 62 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63  ,b,b,b,c,e,d,d,c
4dd0: 2c 61 2c 62 2c 62 2c 63 2c 63 2c 61 2c 62 2c 62  ,a,b,b,c,c,a,b,b
4de0: 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,c,d,c,d,c,a,b,c
4df0: 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,d,d,c,a,b,b,c
4e00: 2c 64 2c 63 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61  ,d,c,d,c,c,d,c,a
4e10: 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62  ,b,c,e,d,d,c,a,b
4e20: 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62  ,b,c,d,c,d,c,a,b
4e30: 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62  ,c,e,c,d,c,a,b,b
4e40: 2c 63 2c 64 2c 63 2c 64 2c 63 2c 65 2c 64 2c 64  ,c,d,c,d,c,e,d,d
4e50: 2c 63 2c 61 2c 62 2c 62 2c 63 2c 63 2c 61 2c 62  ,c,a,b,b,c,c,a,b
4e60: 2c 62 2c 45 2c 64 2c 63 2c 64 2c 63 2c 62 2c 63  ,b,E,d,c,d,c,b,c
4e70: 2c 64 2c 63 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61  ,d,c,d,c,c,d,c,a
4e80: 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62  ,b,c,e,d,d,c,a,b
4e90: 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62  ,b,c,d,c,d,c,a,b
4ea0: 2c 63 2c 65 2c 63 2c 64 27 43 45 49 6c 2c 6b 27  ,c,e,c,d'CEIl,k'
4eb0: 27 2c 61 62 2c 20 67 2c 20 61 2c 62 2c 6f 31 31  ',ab, g, a,b,o11
4ec0: 62 2c 20 69 27 6e 45 58 2f 63 68 61 72 52 45 44  b, i'nEX/charRED
4ed0: 45 20 49 56 54 20 4c 52 21 56 41 42 4c 74 35 53  E IVT LR!VABLt5S
4ee0: 47 27 2c 4e 20 20 2c 4e 20 69 6e 20 72 65 6d 65  G',N  ,N in reme
4ef0: 6e 74 2c 6c 5f 76 61 63 75 75 6d 2c 4d 26 55 2c  nt,l_vacuum,M&U,
4f00: 27 74 65 33 28 27 27 35 6c 27 20 61 2c 62 42 2c  'te3(''5l' a,bB,
4f10: 62 2c 6c 2a 65 29 53 45 4c 45 43 54 3a 53 45 4c  b,l*e)SELECT:SEL
4f20: 45 43 54 2c 20 2a 2c 2a 2c 2a 66 72 6f 6d 28 28  ECT, *,*,*from((
4f30: 20 53 45 4c 45 43 54 0a 24 67 72 6f 75 70 2c 3a   SELECT.$group,:
4f40: 63 6f 6e 63 20 61 70 30 2c 31 29 66 72 6f 2c 28  conc ap0,1)fro,(
4f50: 73 65 6c 65 63 74 22 22 2c 3a 50 42 41 47 2c 63  select"",:PBAG,c
4f60: 2c 61 2c 62 2c 62 2c 63 2c 61 2c 62 2c 63 2c 65  ,a,b,b,c,a,b,c,e
4f70: 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64  ,d,d,c,a,b,b,c,d
4f80: 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 63  ,d,c,a,b,c,e,d,c
4f90: 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64  ,d,c,a,b,c,e,c,d
4fa0: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64  ,c,d,c,a,b,b,c,d
4fb0: 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63  ,c,a,b,c,e,c,d,c
4fc0: 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62  ,a,b,b,c,d,c,a,b
4fd0: 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62  ,c,e,d,d,c,a,b,b
4fe0: 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,c,d,c,d,c,a,b,c
4ff0: 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,c,d,c,a,b,b,c
5000: 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65  ,d,c,d,c,a,b,c,e
5010: 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 63  ,d,d,c,a,b,b,c,c
5020: 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63  ,a,b,b,c,d,c,d,c
5030: 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61  ,a,b,c,e,d,d,c,a
5040: 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 63  ,b,b,c,d,c,d,c,c
5050: 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64  ,d,c,a,b,c,e,d,d
5060: 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64  ,c,a,b,b,c,d,c,d
5070: 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 63 2c 64  ,c,a,b,c,e,d,c,d
5080: 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63  ,c,a,b,c,e,c,d,c
5090: 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62  ,a,b,b,c,d,c,a,b
50a0: 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62  ,c,e,d,d,c,a,b,b
50b0: 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62  ,b,c,e,d,d,c,a,b
50c0: 2c 62 2c 63 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64  ,b,c,c,a,b,b,c,d
50d0: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64  ,c,d,c,a,b,c,e,d
50e0: 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63  ,d,c,a,b,b,c,d,c
50f0: 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,d,c,c,d,c,a,b,c
5100: 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,d,d,c,a,b,b,c
5110: 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65  ,d,c,d,c,a,b,c,e
5120: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64  ,c,d,c,a,b,b,c,d
5130: 2c 63 2c 64 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61  ,c,d,c,e,d,d,c,a
5140: 2c 62 2c 62 2c 63 2c 63 2c 61 2c 62 2c 62 2c 45  ,b,b,c,c,a,b,b,E
5150: 2c 64 2c 63 2c 64 2c 63 2c 62 2c 63 2c 64 2c 63  ,d,c,d,c,b,c,d,c
5160: 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,d,c,c,d,c,a,b,c
5170: 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,d,d,c,a,b,b,c
5180: 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65  ,d,c,d,c,a,b,c,e
5190: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 61  ,c,d,c,a,b,b,c,a
51a0: 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62  ,b,c,e,d,d,c,a,b
51b0: 2c 62 2c 63 2c 64 2c 64 2c 63 2c 61 2c 62 2c 63  ,b,c,d,d,c,a,b,c
51c0: 2c 65 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,e,d,c,d,c,a,b,c
51d0: 2c 65 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62  ,e,c,d,c,d,c,a,b
51e0: 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65  ,b,c,d,c,a,b,c,e
51f0: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64  ,c,d,c,a,b,b,c,d
5200: 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63  ,c,a,b,c,e,d,d,c
5210: 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63  ,a,b,b,c,d,c,d,c
5220: 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61  ,a,b,c,e,c,d,c,a
5230: 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61  ,b,b,c,d,c,d,c,a
5240: 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62  ,b,c,e,d,d,c,a,b
5250: 2c 62 2c 63 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64  ,b,c,c,a,b,b,c,d
5260: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64  ,c,d,c,a,b,c,e,d
5270: 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63  ,d,c,a,b,b,c,d,c
5280: 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,d,c,c,d,c,a,b,c
5290: 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,d,d,c,a,b,b,c
52a0: 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65  ,d,c,d,c,a,b,c,e
52b0: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64  ,c,d,c,a,b,b,c,d
52c0: 2c 63 2c 64 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61  ,c,d,c,e,d,d,c,a
52d0: 2c 62 2c 62 2c 63 2c 63 2c 61 2c 62 2c 62 2c 45  ,b,b,c,c,a,b,b,E
52e0: 2c 64 2c 63 2c 64 2c 63 2c 62 2c 63 2c 64 2c 63  ,d,c,d,c,b,c,d,c
52f0: 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,d,c,c,d,c,a,b,c
5300: 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,d,d,c,a,b,b,c
5310: 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65  ,d,c,d,c,a,b,c,e
5320: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 61  ,c,d,c,a,b,b,c,a
5330: 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62  ,b,c,e,d,d,c,a,b
5340: 2c 62 2c 63 2c 64 2c 64 2c 63 2c 61 2c 62 2c 63  ,b,c,d,d,c,a,b,c
5350: 2c 65 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,e,d,c,d,c,a,b,c
5360: 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,c,d,c,a,b,b,c
5370: 2c 63 2c 64 2c 63 2c 63 2c 61 2c 61 2c 62 2c 64  ,c,d,c,c,a,a,b,d
5380: 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63  ,d,c,a,b,b,c,d,c
5390: 2c 61 2c 62 2c 65 2c 65 2c 64 2c 62 2c 63 2c 64  ,a,b,e,e,d,b,c,d
53a0: 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 61  ,c,a,b,b,c,d,c,a
53b0: 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62  ,b,c,e,c,d,c,a,b
53c0: 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65  ,b,c,d,c,a,b,c,e
53d0: 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64  ,d,d,c,a,b,b,c,d
53e0: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63  ,c,d,c,a,b,c,e,c
53f0: 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63  ,d,c,a,b,b,c,d,c
5400: 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64  ,d,c,a,b,c,e,d,d
5410: 2c 63 2c 61 2c 62 2c 62 2c 63 2c 63 2c 61 2c 62  ,c,a,b,b,c,c,a,b
5420: 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62  ,b,c,d,c,d,c,a,b
5430: 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62  ,c,e,d,d,c,a,b,b
5440: 2c 63 2c 64 2c 63 2c 64 2c 63 2c 63 2c 64 2c 63  ,c,d,c,d,c,c,d,c
5450: 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61  ,a,b,c,e,d,d,c,a
5460: 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61  ,b,b,c,d,c,d,c,a
5470: 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62  ,b,c,e,c,d,c,a,b
5480: 2c 62 2c 63 2c 64 2c 20 66 6f 72 65 69 67 6e 5f  ,b,c,d, foreign_
5490: 6b 65 79 73 63 2c 64 2c 63 2c 65 2c 64 2c 64 2c  keysc,d,c,e,d,d,
54a0: 63 2c 61 2c 62 2c 62 2c 63 2c 63 2c 61 2c 62 2c  c,a,b,b,c,c,a,b,
54b0: 62 2c 45 2c 64 2c 63 2c 64 2c 63 2c 62 2c 63 2c  b,E,d,c,d,c,b,c,
54c0: 64 2c 63 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61 2c  d,c,d,c,c,d,c,a,
54d0: 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c  b,c,e,d,d,c,a,b,
54e0: 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 61 2c  b,c,d,c,d,c,a,a,
54f0: 62 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c  b,d,d,c,a,b,b,c,
5500: 64 2c 63 2c 61 2c 62 2c 65 2c 65 2c 64 2c 62 2c  d,c,a,b,e,e,d,b,
5510: 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c  c,d,c,a,b,b,c,d,
5520: 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c  c,a,b,c,e,c,d,c,
5530: 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62 2c  a,b,b,c,d,c,a,b,
5540: 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c  c,e,d,d,c,a,b,b,
5550: 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c  c,d,c,d,c,a,b,c,
5560: 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c  e,c,d,c,a,b,b,c,
5570: 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 64 2c  d,c,d,c,a,b,c,d,
5580: 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c  c,a,b,c,e,c,d,c,
5590: 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c  a,b,b,c,d,c,d,c,
55a0: 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c  e,d,d,c,a,b,b,c,
55b0: 63 2c 61 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c  c,a,d,c,a,b,c,e,
55c0: 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c  d,d,c,a,b,b,c,d,
55d0: 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c  c,d,c,a,b,c,e,c,
55e0: 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c  d,c,a,b,b,c,d,c,
55f0: 64 2c 63 2c 61 2c 62 2c 63 2c 64 2c 63 2c 61 2c  d,c,a,b,c,d,c,a,
5600: 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c  b,c,e,c,d,c,a,b,
5610: 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 65 2c 64 2c  b,c,d,c,d,c,e,d,
5620: 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 63 2c 61 2c  d,c,a,b,b,c,c,a,
5630: 62 2c 62 2c 45 2c 64 2c 63 2c 64 2c 63 2c 62 2c  b,b,E,d,c,d,c,b,
5640: 63 2c 64 2c 63 2c 64 2c 63 2c 63 2c 64 2c 63 2c  c,d,c,d,c,c,d,c,
5650: 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c  a,b,c,e,d,d,c,a,
5660: 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c  b,b,c,d,c,d,c,a,
5670: 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c  b,c,e,c,d,c,a,b,
5680: 62 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c  b,c,a,b,c,e,d,d,
5690: 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 64 2c 63 2c  c,a,b,b,c,d,d,c,
56a0: 61 2c 62 2c 63 2c 65 2c 64 2c 63 2c 64 2c 63 2c  a,b,c,e,d,c,d,c,
56b0: 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c  a,b,c,e,c,d,c,a,
56c0: 62 2c 62 2c 63 2c 63 2c 64 2c 63 2c 61 2c 62 2c  b,b,c,c,d,c,a,b,
56d0: 64 2c 64 2c 63 2c 61 2c 61 2c 62 2c 64 2c 64 2c  d,d,c,a,a,b,d,d,
56e0: 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 61 2c  c,a,b,b,c,d,c,a,
56f0: 62 2c 65 2c 65 2c 64 2c 62 2c 63 2c 64 2c 63 2c  b,e,e,d,b,c,d,c,
5700: 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62 2c  a,b,b,c,d,c,a,b,
5710: 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c  c,e,c,d,c,a,b,b,
5720: 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c  c,d,c,a,b,c,e,d,
5730: 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c  d,c,a,b,b,c,d,c,
5740: 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c  d,c,a,b,c,e,c,d,
5750: 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c  c,a,b,b,c,d,c,d,
5760: 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c  c,a,b,c,e,d,d,c,
5770: 61 2c 62 2c 62 2c 63 2c 63 2c 61 2c 62 2c 62 2c  a,b,b,c,c,a,b,b,
5780: 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c  c,d,c,d,c,a,b,c,
5790: 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c  e,d,d,c,a,b,b,c,
57a0: 64 2c 63 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61 2c  d,c,d,c,c,d,c,a,
57b0: 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c  b,c,e,d,d,c,a,b,
57c0: 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c  b,c,d,c,d,c,a,b,
57d0: 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c  c,e,c,d,c,a,b,b,
57e0: 63 2c 64 2c 63 2c 64 2c 63 2c 65 2c 64 2c 64 2c  c,d,c,d,c,e,d,d,
57f0: 63 2c 61 2c 62 2c 62 2c 63 2c 63 2c 61 2c 62 2c  c,a,b,b,c,c,a,b,
5800: 62 2c 45 2c 64 2c 63 2c 64 2c 63 2c 62 2c 63 2c  b,E,d,c,d,c,b,c,
5810: 64 2c 63 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61 2c  d,c,d,c,c,d,c,a,
5820: 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c  b,c,e,d,d,c,a,b,
5830: 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 61 2c  b,c,d,c,d,c,a,a,
5840: 62 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c  b,d,d,c,a,b,b,c,
5850: 64 2c 63 2c 61 2c 62 2c 65 2c 65 2c 64 2c 62 2c  d,c,a,b,e,e,d,b,
5860: 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c  c,d,c,a,b,b,c,d,
5870: 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c  c,a,b,c,e,c,d,c,
5880: 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62 2c  a,b,b,c,d,c,a,b,
5890: 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c  c,e,d,d,c,a,b,b,
58a0: 63 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c  c,d,c,d,c,a,b,c,
58b0: 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c  e,c,d,c,a,b,b,c,
58c0: 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c  d,c,d,c,a,b,c,e,
58d0: 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 63 2c  d,d,c,a,b,b,c,c,
58e0: 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c  a,b,b,c,d,c,d,c,
58f0: 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c  a,b,c,e,d,d,c,a,
5900: 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 63 2c  b,b,c,d,c,d,c,c,
5910: 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c  d,c,a,b,c,e,d,d,
5920: 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c  c,a,b,b,c,d,c,d,
5930: 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c  c,a,b,c,e,c,d,c,
5940: 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c  a,b,b,c,d,c,d,c,
5950: 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c  e,d,d,c,a,b,b,c,
5960: 63 2c 61 2c 62 2c 62 2c 45 2c 64 2c 63 2c 64 2c  c,a,b,b,E,d,c,d,
5970: 63 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 63 2c  c,b,c,d,c,d,c,c,
5980: 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c  d,c,a,b,c,e,d,d,
5990: 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c  c,a,b,b,c,d,c,d,
59a0: 63 2c 61 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c  c,a,b,c,e,c,d,c,
59b0: 61 2c 62 2c 62 2c 63 2c 61 2c 62 62 2c 62 2c 45  a,b,b,c,a,bb,b,E
59c0: 2c 64 2c 63 2c 64 2c 63 2c 62 2c 63 2c 64 2c 63  ,d,c,d,c,b,c,d,c
59d0: 2c 64 2c 63 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,d,c,c,d,c,a,b,c
59e0: 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,d,d,c,a,b,b,c
59f0: 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65  ,d,c,d,c,a,b,c,e
5a00: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 61  ,c,d,c,a,b,b,c,a
5a10: 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61 2c 62  ,b,c,e,d,d,c,a,b
5a20: 2c 62 2c 63 2c 64 2c 64 2c 63 2c 61 2c 62 2c 63  ,b,c,d,d,c,a,b,c
5a30: 2c 65 2c 64 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63  ,e,d,c,d,c,a,b,c
5a40: 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63  ,e,c,d,c,a,b,b,c
5a50: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 64 2c 64 2c 63  ,c,d,c,a,b,d,d,c
5a60: 2c 61 2c 61 2c 62 2c 64 2c 64 2c 63 2c 61 2c 62  ,a,a,b,d,d,c,a,b
5a70: 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62 2c 65 2c 65  ,b,c,d,c,a,b,e,e
5a80: 2c 64 2c 62 2c 63 2c 64 2c 63 2c 61 2c 62 2c 62  ,d,b,c,d,c,a,b,b
5a90: 2c 63 2c 64 2c 63 2c 61 2c 62 2c 63 2c 65 2c 63  ,c,d,c,a,b,c,e,c
5aa0: 2c 64 2c 63 2c 61 2c 62 2c 62 2c 63 2c 64 2c 63  ,d,c,a,b,b,c,d,c
5ab0: 2c 61 2c 62 2c 63 2c 65 2c 64 2c 64 2c 63 2c 61  ,a,b,c,e,d,d,c,a
5ac0: 2c 62 2c 62 2c 63 2c 64 2c 63 2c 64 2c 63 2c 61  ,b,b,c,d,c,d,c,a
5ad0: 2c 62 2c 63 2c 65 2c 63 2c 64 2c 63 2c 61 2c 62  ,b,c,e,c,d,c,a,b
5ae0: 2c 62 2c 63 2c 64 2c 4d 41 61 74 6f 5f 61 65 63  ,b,c,d,MAato_aec
5af0: 53 45 4c 45 43 2c 2b 3f 62 2c 22 20 22 4f 2c 22  SELEC,+?b," "O,"
5b00: 69 22 2c 22 61 22 2c 22 22 62 20 20 2c 35 20 29  i","a",""b  ,5 )
5b10: 29 4b 45 59 29 53 45 4c 45 43 54 2a 46 52 4f 4d  )KEY)SELECT*FROM
5b20: 28 28 6b 28 29 72 65 61 43 2c 6b 2c 4b 29 20 65  ((k()reaC,k,K) e
5b30: 41 2c 6b 20 27 27 20 29 74 20 2c 4b 20 20 4d 29  A,k '' )t ,K  M)
5b40: 3b 0a 7d 20 7b 31 20 7b 27 6b 27 20 69 73 20 6e  ;.} {1 {'k' is n
5b50: 6f 74 20 61 20 66 75 6e 63 74 69 6f 6e 7d 7d 0a  ot a function}}.
5b60: 0a 23 20 32 30 31 37 2d 30 39 2d 31 37 0a 23 0a  .# 2017-09-17.#.
5b70: 23 20 53 6f 6d 65 74 69 6d 65 73 20 73 71 6c 69  # Sometimes sqli
5b80: 74 65 33 45 78 70 72 4c 69 73 74 41 70 70 65 6e  te3ExprListAppen
5b90: 64 28 29 20 63 61 6e 20 62 65 20 69 6e 76 6f 6b  d() can be invok
5ba0: 65 64 20 6f 6e 20 61 6e 20 45 78 70 72 4c 69 73  ed on an ExprLis
5bb0: 74 20 74 68 61 74 0a 23 20 77 61 73 20 6f 62 74  t that.# was obt
5bc0: 61 69 6e 65 64 20 66 72 6f 6d 20 73 71 6c 69 74  ained from sqlit
5bd0: 65 33 45 78 70 72 4c 69 73 74 44 75 70 28 29 2e  e3ExprListDup().
5be0: 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65  .#.do_execsql_te
5bf0: 73 74 20 6d 69 73 63 31 2d 32 36 2e 30 20 7b 0a  st misc1-26.0 {.
5c00: 20 20 44 52 4f 50 20 54 41 42 4c 45 20 49 46 20    DROP TABLE IF 
5c10: 45 58 49 53 54 53 20 61 62 63 3b 0a 20 20 43 52  EXISTS abc;.  CR
5c20: 45 41 54 45 20 54 41 42 4c 45 20 61 62 63 28 61  EATE TABLE abc(a
5c30: 2c 20 62 2c 20 63 29 3b 0a 20 20 53 45 4c 45 43  , b, c);.  SELEC
5c40: 54 20 72 61 6e 64 6f 6d 62 6c 6f 62 28 6d 69 6e  T randomblob(min
5c50: 28 6d 61 78 28 63 6f 61 6c 65 73 63 65 28 45 58  (max(coalesce(EX
5c60: 49 53 54 53 20 28 53 45 4c 45 43 54 20 31 20 46  ISTS (SELECT 1 F
5c70: 52 4f 4d 20 28 20 53 45 4c 45 43 54 20 28 53 45  ROM ( SELECT (SE
5c80: 4c 45 43 54 20 32 31 34 37 34 38 33 36 34 37 29  LECT 2147483647)
5c90: 20 4e 4f 54 20 49 4e 20 28 53 45 4c 45 43 54 20   NOT IN (SELECT 
5ca0: 32 31 34 37 34 38 33 36 34 39 20 55 4e 49 4f 4e  2147483649 UNION
5cb0: 20 41 4c 4c 20 53 45 4c 45 43 54 20 44 49 53 54   ALL SELECT DIST
5cc0: 49 4e 43 54 20 2d 31 29 20 49 4e 20 28 53 45 4c  INCT -1) IN (SEL
5cd0: 45 43 54 20 32 31 34 37 34 38 33 36 34 39 29 2c  ECT 2147483649),
5ce0: 20 27 66 61 75 6c 74 27 2c 20 28 53 45 4c 45 43   'fault', (SELEC
5cf0: 54 20 41 4c 4c 20 2d 31 20 49 4e 54 45 52 53 45  T ALL -1 INTERSE
5d00: 43 54 20 53 45 4c 45 43 54 20 27 65 78 70 65 72  CT SELECT 'exper
5d10: 69 6d 65 6e 74 73 27 29 20 49 4e 20 28 53 45 4c  iments') IN (SEL
5d20: 45 43 54 20 41 4c 4c 20 35 36 2e 31 20 4f 52 44  ECT ALL 56.1 ORD
5d30: 45 52 20 42 59 20 27 65 78 70 65 72 69 6d 65 6e  ER BY 'experimen
5d40: 74 73 27 20 44 45 53 43 29 20 46 52 4f 4d 20 28  ts' DESC) FROM (
5d50: 53 45 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20  SELECT DISTINCT 
5d60: 32 31 34 37 34 38 33 36 34 38 2c 20 27 68 61 72  2147483648, 'har
5d70: 64 77 61 72 65 27 20 55 4e 49 4f 4e 20 41 4c 4c  dware' UNION ALL
5d80: 20 53 45 4c 45 43 54 20 2d 32 31 34 37 34 38 33   SELECT -2147483
5d90: 36 34 38 2c 20 27 65 78 70 65 72 69 6d 65 6e 74  648, 'experiment
5da0: 73 27 20 4f 52 44 45 52 20 42 59 20 32 31 34 37  s' ORDER BY 2147
5db0: 34 38 33 36 34 38 20 4c 49 4d 49 54 20 31 20 4f  483648 LIMIT 1 O
5dc0: 46 46 53 45 54 20 31 32 33 34 35 36 37 38 39 2e  FFSET 123456789.
5dd0: 31 32 33 34 35 36 37 38 39 39 29 20 47 52 4f 55  1234567899) GROU
5de0: 50 20 42 59 20 28 53 45 4c 45 43 54 20 41 4c 4c  P BY (SELECT ALL
5df0: 20 30 20 49 4e 54 45 52 53 45 43 54 20 53 45 4c   0 INTERSECT SEL
5e00: 45 43 54 20 27 69 6e 27 29 20 49 4e 20 28 53 45  ECT 'in') IN (SE
5e10: 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20 27 65  LECT DISTINCT 'e
5e20: 78 70 65 72 69 6d 65 6e 74 73 27 20 4f 52 44 45  xperiments' ORDE
5e30: 52 20 42 59 20 7a 65 72 6f 62 6c 6f 62 28 31 30  R BY zeroblob(10
5e40: 30 30 29 20 4c 49 4d 49 54 20 35 36 2e 31 20 4f  00) LIMIT 56.1 O
5e50: 46 46 53 45 54 20 2d 34 35 36 29 20 48 41 56 49  FFSET -456) HAVI
5e60: 4e 47 20 45 58 49 53 54 53 20 28 53 45 4c 45 43  NG EXISTS (SELEC
5e70: 54 20 27 66 61 75 6c 74 27 20 45 58 43 45 50 54  T 'fault' EXCEPT
5e80: 20 20 20 20 53 45 4c 45 43 54 20 44 49 53 54 49      SELECT DISTI
5e90: 4e 43 54 20 35 36 2e 31 29 20 55 4e 49 4f 4e 20  NCT 56.1) UNION 
5ea0: 53 45 4c 45 43 54 20 27 54 68 65 27 2c 20 27 54  SELECT 'The', 'T
5eb0: 68 65 27 2c 20 32 31 34 37 34 38 33 36 34 39 20  he', 2147483649 
5ec0: 55 4e 49 4f 4e 20 41 4c 4c 20 53 45 4c 45 43 54  UNION ALL SELECT
5ed0: 20 44 49 53 54 49 4e 43 54 20 27 68 61 72 64 77   DISTINCT 'hardw
5ee0: 61 72 65 27 2c 20 27 66 69 72 73 74 27 2c 20 27  are', 'first', '
5ef0: 65 78 70 65 72 69 6d 65 6e 74 73 27 20 4f 52 44  experiments' ORD
5f00: 45 52 20 42 59 20 27 68 61 72 64 77 61 72 65 27  ER BY 'hardware'
5f10: 20 4c 49 4d 49 54 20 31 32 33 34 35 36 37 38 39   LIMIT 123456789
5f20: 2e 31 32 33 34 35 36 37 38 39 39 20 4f 46 46 53  .1234567899 OFFS
5f30: 45 54 20 2d 32 31 34 37 34 38 33 36 34 37 29 29  ET -2147483647))
5f40: 20 4e 4f 54 20 49 4e 20 28 53 45 4c 45 43 54 20   NOT IN (SELECT 
5f50: 28 53 45 4c 45 43 54 20 44 49 53 54 49 4e 43 54  (SELECT DISTINCT
5f60: 20 28 53 45 4c 45 43 54 20 27 54 68 65 27 29 20   (SELECT 'The') 
5f70: 46 52 4f 4d 20 61 62 63 20 4f 52 44 45 52 20 42  FROM abc ORDER B
5f80: 59 20 45 58 49 53 54 53 20 28 53 45 4c 45 43 54  Y EXISTS (SELECT
5f90: 20 2d 31 20 49 4e 54 45 52 53 45 43 54 20 53 45   -1 INTERSECT SE
5fa0: 4c 45 43 54 20 41 4c 4c 20 4e 55 4c 4c 29 20 41  LECT ALL NULL) A
5fb0: 53 43 29 20 49 4e 20 28 53 45 4c 45 43 54 20 44  SC) IN (SELECT D
5fc0: 49 53 54 49 4e 43 54 20 45 58 49 53 54 53 20 28  ISTINCT EXISTS (
5fd0: 53 45 4c 45 43 54 20 41 4c 4c 20 31 32 33 34 35  SELECT ALL 12345
5fe0: 36 37 38 39 2e 31 32 33 34 35 36 37 38 39 39 20  6789.1234567899 
5ff0: 4f 52 44 45 52 20 42 59 20 31 20 41 53 43 2c 20  ORDER BY 1 ASC, 
6000: 4e 55 4c 4c 20 44 45 53 43 29 20 46 52 4f 4d 20  NULL DESC) FROM 
6010: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 49 4e  sqlite_master IN
6020: 54 45 52 53 45 43 54 20 53 45 4c 45 43 54 20 34  TERSECT SELECT 4
6030: 35 36 29 29 2c 20 28 53 45 4c 45 43 54 20 41 4c  56)), (SELECT AL
6040: 4c 20 27 69 6e 6a 65 63 74 69 6f 6e 27 20 55 4e  L 'injection' UN
6050: 49 4f 4e 20 41 4c 4c 20 53 45 4c 45 43 54 20 41  ION ALL SELECT A
6060: 4c 4c 20 28 53 45 4c 45 43 54 20 44 49 53 54 49  LL (SELECT DISTI
6070: 4e 43 54 20 27 66 69 72 73 74 27 20 55 4e 49 4f  NCT 'first' UNIO
6080: 4e 20 20 20 20 20 53 45 4c 45 43 54 20 44 49 53  N     SELECT DIS
6090: 54 49 4e 43 54 20 27 54 68 65 27 29 20 46 52 4f  TINCT 'The') FRO
60a0: 4d 20 28 53 45 4c 45 43 54 20 34 35 36 2c 20 27  M (SELECT 456, '
60b0: 69 6e 27 2c 20 32 31 34 37 34 38 33 36 34 39 29  in', 2147483649)
60c0: 29 29 2c 31 29 2c 20 35 30 30 29 29 2c 20 27 66  )),1), 500)), 'f
60d0: 69 72 73 74 27 2c 20 45 58 49 53 54 53 20 28 53  irst', EXISTS (S
60e0: 45 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20 34  ELECT DISTINCT 4
60f0: 35 36 20 46 52 4f 4d 20 61 62 63 20 4f 52 44 45  56 FROM abc ORDE
6100: 52 20 42 59 20 27 65 78 70 65 72 69 6d 65 6e 74  R BY 'experiment
6110: 73 27 20 44 45 53 43 29 20 46 52 4f 4d 20 61 62  s' DESC) FROM ab
6120: 63 3b 0a 7d 20 7b 7d 0a 0a 23 20 32 30 31 37 2d  c;.} {}..# 2017-
6130: 31 32 2d 32 39 0a 23 0a 23 20 54 68 65 20 66 6f  12-29.#.# The fo
6140: 6c 6c 6f 77 69 6e 67 20 62 65 68 61 76 69 6f 72  llowing behavior
6150: 73 20 28 64 75 70 6c 69 63 61 74 65 20 63 6f 6c  s (duplicate col
6160: 75 6d 6e 20 6e 61 6d 65 73 20 6f 6e 20 61 6e 20  umn names on an 
6170: 49 4e 53 45 52 54 20 6f 72 20 55 50 44 41 54 45  INSERT or UPDATE
6180: 29 0a 23 20 61 72 65 20 75 6e 64 6f 63 75 6d 65  ).# are undocume
6190: 6e 74 65 64 2e 20 20 54 68 65 73 65 20 74 65 73  nted.  These tes
61a0: 74 73 20 61 72 65 20 61 64 64 65 64 20 74 6f 20  ts are added to 
61b0: 65 6e 73 75 72 65 20 74 68 61 74 20 68 69 73 74  ensure that hist
61c0: 6f 72 69 63 61 6c 20 62 65 68 61 76 69 6f 72 0a  orical behavior.
61d0: 23 20 64 6f 65 73 20 6e 6f 74 20 63 68 61 6e 67  # does not chang
61e0: 65 20 61 63 63 69 64 65 6e 74 61 6c 6c 79 2e 0a  e accidentally..
61f0: 23 0a 23 20 46 6f 72 20 64 75 70 6c 69 63 61 74  #.# For duplicat
6200: 69 6f 6e 20 63 6f 6c 75 6d 6e 73 20 6f 6e 20 61  ion columns on a
6210: 6e 20 49 4e 53 45 52 54 2c 20 74 68 65 20 66 69  n INSERT, the fi
6220: 72 73 74 20 76 61 6c 75 65 20 69 73 20 75 73 65  rst value is use
6230: 64 2e 0a 23 20 46 6f 72 20 64 75 70 6c 69 63 61  d..# For duplica
6240: 74 69 6f 6e 20 63 6f 6c 75 6d 6e 73 20 6f 6e 20  tion columns on 
6250: 61 6e 20 55 50 44 41 54 45 2c 20 74 68 65 20 6c  an UPDATE, the l
6260: 61 73 74 20 76 61 6c 75 65 20 69 73 20 75 73 65  ast value is use
6270: 64 2e 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f  d..#.do_execsql_
6280: 74 65 73 74 20 6d 69 73 63 31 2d 32 37 2e 30 20  test misc1-27.0 
6290: 7b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45  {.  CREATE TABLE
62a0: 20 64 75 70 31 28 61 2c 62 2c 63 29 3b 0a 20 20   dup1(a,b,c);.  
62b0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 64 75 70 31  INSERT INTO dup1
62c0: 28 61 2c 62 2c 63 2c 61 2c 62 2c 63 29 20 56 41  (a,b,c,a,b,c) VA
62d0: 4c 55 45 53 28 31 2c 32 2c 33 2c 34 2c 35 2c 36  LUES(1,2,3,4,5,6
62e0: 29 3b 0a 20 20 53 45 4c 45 43 54 20 61 2c 62 2c  );.  SELECT a,b,
62f0: 63 20 46 52 4f 4d 20 64 75 70 31 3b 0a 7d 20 7b  c FROM dup1;.} {
6300: 31 20 32 20 33 7d 0a 64 6f 5f 65 78 65 63 73 71  1 2 3}.do_execsq
6310: 6c 5f 74 65 73 74 20 6d 69 73 63 31 2d 32 37 2e  l_test misc1-27.
6320: 31 20 7b 0a 20 20 55 50 44 41 54 45 20 64 75 70  1 {.  UPDATE dup
6330: 31 20 53 45 54 20 61 3d 37 2c 20 62 3d 38 2c 20  1 SET a=7, b=8, 
6340: 63 3d 39 2c 20 61 3d 31 30 2c 20 62 3d 31 31 2c  c=9, a=10, b=11,
6350: 20 63 3d 31 32 3b 0a 20 20 53 45 4c 45 43 54 20   c=12;.  SELECT 
6360: 61 2c 62 2c 63 20 46 52 4f 4d 20 64 75 70 31 3b  a,b,c FROM dup1;
6370: 0a 7d 20 7b 31 30 20 31 31 20 31 32 7d 0a 0a 23  .} {10 11 12}..#
6380: 20 32 30 31 38 2d 31 32 2d 32 30 0a 23 0a 23 20   2018-12-20.#.# 
6390: 54 68 65 20 43 75 72 73 6f 72 2e 73 65 65 6b 4f  The Cursor.seekO
63a0: 70 20 64 65 62 75 67 67 69 6e 67 20 76 61 6c 75  p debugging valu
63b0: 65 20 73 65 74 20 69 6e 63 6f 72 72 65 63 74 6c  e set incorrectl
63c0: 79 0a 23 20 69 6e 20 4f 50 5f 4e 6f 74 45 78 69  y.# in OP_NotExi
63d0: 73 74 73 2e 0a 23 0a 73 71 6c 69 74 65 33 20 64  sts..#.sqlite3 d
63e0: 62 20 3a 6d 65 6d 6f 72 79 3a 0a 64 6f 5f 65 78  b :memory:.do_ex
63f0: 65 63 73 71 6c 5f 74 65 73 74 20 6d 69 73 63 31  ecsql_test misc1
6400: 2d 32 38 2e 30 20 7b 0a 20 20 43 52 45 41 54 45  -28.0 {.  CREATE
6410: 20 54 41 42 4c 45 20 74 31 28 78 29 3b 0a 20 20   TABLE t1(x);.  
6420: 43 52 45 41 54 45 20 55 4e 49 51 55 45 20 49 4e  CREATE UNIQUE IN
6430: 44 45 58 20 74 31 78 20 4f 4e 20 74 31 28 78 29  DEX t1x ON t1(x)
6440: 20 57 48 45 52 45 20 78 3d 31 3b 0a 20 20 49 4e   WHERE x=1;.  IN
6450: 53 45 52 54 20 4f 52 20 41 42 4f 52 54 20 49 4e  SERT OR ABORT IN
6460: 54 4f 20 74 31 20 44 45 46 41 55 4c 54 20 56 41  TO t1 DEFAULT VA
6470: 4c 55 45 53 3b 0a 20 20 55 50 44 41 54 45 20 4f  LUES;.  UPDATE O
6480: 52 20 52 45 50 4c 41 43 45 20 74 31 20 53 45 54  R REPLACE t1 SET
6490: 20 78 20 3d 20 31 3b 0a 20 20 50 52 41 47 4d 41   x = 1;.  PRAGMA
64a0: 20 69 6e 74 65 67 72 69 74 79 5f 63 68 65 63 6b   integrity_check
64b0: 3b 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f  ;.  SELECT * FRO
64c0: 4d 20 74 31 3b 0a 7d 20 7b 6f 6b 20 31 7d 0a 0a  M t1;.} {ok 1}..
64d0: 66 69 6e 69 73 68 5f 74 65 73 74 0a              finish_test.