/ Hex Artifact Content
Login

Artifact 2b61d118b522ac13b6fec307352ec31edd060da2:


0000: 23 20 32 30 30 37 20 4d 61 79 20 31 30 0a 23 0a  # 2007 May 10.#.
0010: 23 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73  # The author dis
0020: 63 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74  claims copyright
0030: 20 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20   to this source 
0040: 63 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20  code.  In place 
0050: 6f 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74  of.# a legal not
0060: 69 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62  ice, here is a b
0070: 6c 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20  lessing:.#.#    
0080: 4d 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20  May you do good 
0090: 61 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20  and not evil..# 
00a0: 20 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20     May you find 
00b0: 66 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20  forgiveness for 
00c0: 79 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72  yourself and for
00d0: 67 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20  give others..#  
00e0: 20 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20    May you share 
00f0: 66 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61  freely, never ta
0100: 6b 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79  king more than y
0110: 6f 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a  ou give..#.#****
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 0a 23 20 54 68 69 73 20 66 69 6c 65 20  ***.# This file 
0170: 69 6d 70 6c 65 6d 65 6e 74 73 20 72 65 67 72 65  implements regre
0180: 73 73 69 6f 6e 20 74 65 73 74 73 20 66 6f 72 20  ssion tests for 
0190: 53 51 4c 69 74 65 20 6c 69 62 72 61 72 79 2e 20  SQLite library. 
01a0: 20 54 68 65 0a 23 20 66 6f 63 75 73 20 6f 66 20   The.# focus of 
01b0: 74 68 69 73 20 66 69 6c 65 20 69 73 20 67 65 6e  this file is gen
01c0: 65 72 61 74 69 6e 67 20 73 65 6d 69 2d 72 61 6e  erating semi-ran
01d0: 64 6f 6d 20 73 74 72 69 6e 67 73 20 6f 66 20 53  dom strings of S
01e0: 51 4c 0a 23 20 28 61 2e 6b 2e 61 2e 20 22 66 75  QL.# (a.k.a. "fu
01f0: 7a 7a 22 29 20 61 6e 64 20 73 65 6e 64 69 6e 67  zz") and sending
0200: 20 69 74 20 69 6e 74 6f 20 74 68 65 20 70 61 72   it into the par
0210: 73 65 72 20 74 6f 20 74 72 79 20 74 6f 20 0a 23  ser to try to .#
0220: 20 67 65 6e 65 72 61 74 65 20 65 72 72 6f 72 73   generate errors
0230: 2e 0a 23 0a 23 20 54 68 65 20 74 65 73 74 73 20  ..#.# The tests 
0240: 69 6e 20 74 68 69 73 20 66 69 6c 65 20 61 72 65  in this file are
0250: 20 72 65 61 6c 6c 79 20 61 62 6f 75 74 20 74 65   really about te
0260: 73 74 69 6e 67 20 66 75 7a 7a 69 6c 79 20 67 65  sting fuzzily ge
0270: 6e 65 72 61 74 65 64 0a 23 20 53 51 4c 20 70 61  nerated.# SQL pa
0280: 72 73 65 2d 74 72 65 65 73 2e 20 54 68 65 20 6d  rse-trees. The m
0290: 61 6a 6f 72 69 74 79 20 6f 66 20 74 68 65 20 66  ajority of the f
02a0: 75 7a 7a 69 6c 79 20 67 65 6e 65 72 61 74 65 64  uzzily generated
02b0: 20 53 51 4c 20 69 73 20 0a 23 20 76 61 6c 69 64   SQL is .# valid
02c0: 20 61 73 20 66 61 72 20 61 73 20 74 68 65 20 70   as far as the p
02d0: 61 72 73 65 72 20 69 73 20 63 6f 6e 63 65 72 6e  arser is concern
02e0: 65 64 2e 20 0a 23 0a 23 20 54 68 65 20 6d 6f 73  ed. .#.# The mos
02f0: 74 20 63 6f 6d 70 6c 69 63 61 74 65 64 20 74 72  t complicated tr
0300: 65 65 73 20 61 72 65 20 66 6f 72 20 53 45 4c 45  ees are for SELE
0310: 43 54 20 73 74 61 74 65 6d 65 6e 74 73 2e 0a 23  CT statements..#
0320: 0a 23 20 24 49 64 3a 20 66 75 7a 7a 2e 74 65 73  .# $Id: fuzz.tes
0330: 74 2c 76 20 31 2e 31 35 20 32 30 30 39 2f 30 31  t,v 1.15 2009/01
0340: 2f 30 35 20 31 39 3a 33 36 3a 33 30 20 64 72 68  /05 19:36:30 drh
0350: 20 45 78 70 20 24 0a 0a 73 65 74 20 74 65 73 74   Exp $..set test
0360: 64 69 72 20 5b 66 69 6c 65 20 64 69 72 6e 61 6d  dir [file dirnam
0370: 65 20 24 61 72 67 76 30 5d 0a 73 6f 75 72 63 65  e $argv0].source
0380: 20 24 74 65 73 74 64 69 72 2f 74 65 73 74 65 72   $testdir/tester
0390: 2e 74 63 6c 0a 0a 73 65 74 20 3a 3a 52 45 50 45  .tcl..set ::REPE
03a0: 41 54 53 20 35 30 30 30 0a 0a 23 20 49 66 20 72  ATS 5000..# If r
03b0: 75 6e 6e 69 6e 67 20 71 75 69 63 6b 2e 74 65 73  unning quick.tes
03c0: 74 2c 20 64 6f 6e 27 74 20 64 6f 20 73 6f 20 6d  t, don't do so m
03d0: 61 6e 79 20 69 74 65 72 61 74 69 6f 6e 73 2e 0a  any iterations..
03e0: 69 66 20 7b 5b 69 6e 66 6f 20 65 78 69 73 74 73  if {[info exists
03f0: 20 3a 3a 49 53 51 55 49 43 4b 5d 7d 20 7b 0a 20   ::ISQUICK]} {. 
0400: 20 69 66 20 7b 24 3a 3a 49 53 51 55 49 43 4b 7d   if {$::ISQUICK}
0410: 20 7b 20 73 65 74 20 3a 3a 52 45 50 45 41 54 53   { set ::REPEATS
0420: 20 32 30 20 7d 0a 7d 0a 0a 73 6f 75 72 63 65 20   20 }.}..source 
0430: 24 74 65 73 74 64 69 72 2f 66 75 7a 7a 5f 63 6f  $testdir/fuzz_co
0440: 6d 6d 6f 6e 2e 74 63 6c 0a 65 78 70 72 20 73 72  mmon.tcl.expr sr
0450: 61 6e 64 28 30 29 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  and(0)..#-------
0460: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0470: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0480: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0490: 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 68 65 73  ---------.# Thes
04a0: 65 20 74 65 73 74 73 20 63 61 75 73 65 64 20 65  e tests caused e
04b0: 72 72 6f 72 73 20 74 68 61 74 20 77 65 72 65 20  rrors that were 
04c0: 66 69 72 73 74 20 63 61 75 67 68 74 20 62 79 20  first caught by 
04d0: 74 68 65 20 74 65 73 74 73 0a 23 20 69 6e 20 74  the tests.# in t
04e0: 68 69 73 20 66 69 6c 65 2e 20 54 68 65 79 20 61  his file. They a
04f0: 72 65 20 73 74 69 6c 6c 20 68 65 72 65 2e 0a 64  re still here..d
0500: 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e 31 20  o_test fuzz-1.1 
0510: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20  {.  execsql {.  
0520: 20 20 53 45 4c 45 43 54 20 27 61 62 63 27 20 4c    SELECT 'abc' L
0530: 49 4b 45 20 58 27 41 42 43 44 27 3b 0a 20 20 7d  IKE X'ABCD';.  }
0540: 0a 7d 20 7b 30 7d 0a 64 6f 5f 74 65 73 74 20 66  .} {0}.do_test f
0550: 75 7a 7a 2d 31 2e 32 20 7b 0a 20 20 65 78 65 63  uzz-1.2 {.  exec
0560: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
0570: 20 27 61 62 63 27 20 4c 49 4b 45 20 7a 65 72 6f   'abc' LIKE zero
0580: 62 6c 6f 62 28 31 30 29 3b 0a 20 20 7d 0a 7d 20  blob(10);.  }.} 
0590: 7b 30 7d 0a 64 6f 5f 74 65 73 74 20 66 75 7a 7a  {0}.do_test fuzz
05a0: 2d 31 2e 33 20 7b 0a 20 20 65 78 65 63 73 71 6c  -1.3 {.  execsql
05b0: 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 7a 65   {.    SELECT ze
05c0: 72 6f 62 6c 6f 62 28 31 30 29 20 4c 49 4b 45 20  roblob(10) LIKE 
05d0: 27 61 62 63 27 3b 0a 20 20 7d 0a 7d 20 7b 30 7d  'abc';.  }.} {0}
05e0: 0a 64 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e  .do_test fuzz-1.
05f0: 34 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  4 {.  execsql {.
0600: 20 20 20 20 53 45 4c 45 43 54 20 28 2d 20 2d 32      SELECT (- -2
0610: 31 29 20 25 20 4e 4f 54 20 28 34 35 36 20 4c 49  1) % NOT (456 LI
0620: 4b 45 20 7a 65 72 6f 62 6c 6f 62 28 31 30 29 29  KE zeroblob(10))
0630: 3b 0a 20 20 7d 0a 7d 20 7b 30 7d 0a 64 6f 5f 74  ;.  }.} {0}.do_t
0640: 65 73 74 20 66 75 7a 7a 2d 31 2e 35 20 7b 0a 20  est fuzz-1.5 {. 
0650: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53   execsql {.    S
0660: 45 4c 45 43 54 20 28 53 45 4c 45 43 54 20 28 0a  ELECT (SELECT (.
0670: 20 20 20 20 20 20 20 20 53 45 4c 45 43 54 20 28          SELECT (
0680: 53 45 4c 45 43 54 20 2d 32 31 34 37 34 38 33 36  SELECT -21474836
0690: 34 38 29 20 46 52 4f 4d 20 28 53 45 4c 45 43 54  48) FROM (SELECT
06a0: 20 31 29 20 4f 52 44 45 52 20 42 59 20 31 0a 20   1) ORDER BY 1. 
06b0: 20 20 20 29 29 0a 20 20 7d 0a 7d 20 7b 2d 32 31     )).  }.} {-21
06c0: 34 37 34 38 33 36 34 38 7d 0a 64 6f 5f 74 65 73  47483648}.do_tes
06d0: 74 20 66 75 7a 7a 2d 31 2e 36 20 7b 0a 20 20 65  t fuzz-1.6 {.  e
06e0: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c  xecsql {.    SEL
06f0: 45 43 54 20 27 61 62 63 27 2c 20 7a 65 72 6f 62  ECT 'abc', zerob
0700: 6c 6f 62 28 31 29 20 46 52 4f 4d 20 28 53 45 4c  lob(1) FROM (SEL
0710: 45 43 54 20 31 29 20 4f 52 44 45 52 20 42 59 20  ECT 1) ORDER BY 
0720: 31 0a 20 20 7d 0a 7d 20 5b 65 78 65 63 73 71 6c  1.  }.} [execsql
0730: 20 7b 53 45 4c 45 43 54 20 27 61 62 63 27 2c 20   {SELECT 'abc', 
0740: 7a 65 72 6f 62 6c 6f 62 28 31 29 7d 5d 0a 0a 64  zeroblob(1)}]..d
0750: 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e 37 20  o_test fuzz-1.7 
0760: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20  {.  execsql {.  
0770: 20 20 53 45 4c 45 43 54 20 28 20 53 45 4c 45 43    SELECT ( SELEC
0780: 54 20 7a 65 72 6f 62 6c 6f 62 28 31 30 30 30 29  T zeroblob(1000)
0790: 20 46 52 4f 4d 20 28 20 0a 20 20 20 20 20 20 53   FROM ( .      S
07a0: 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 28 53 45  ELECT * FROM (SE
07b0: 4c 45 43 54 20 27 66 69 72 73 74 27 29 20 4f 52  LECT 'first') OR
07c0: 44 45 52 20 42 59 20 4e 4f 54 20 27 69 6e 27 29  DER BY NOT 'in')
07d0: 20 0a 20 20 20 20 29 0a 20 20 7d 0a 7d 20 5b 65   .    ).  }.} [e
07e0: 78 65 63 73 71 6c 20 7b 53 45 4c 45 43 54 20 7a  xecsql {SELECT z
07f0: 65 72 6f 62 6c 6f 62 28 31 30 30 30 29 7d 5d 0a  eroblob(1000)}].
0800: 0a 64 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e  .do_test fuzz-1.
0810: 38 20 7b 0a 20 20 23 20 50 72 6f 62 6c 65 6d 73  8 {.  # Problems
0820: 20 77 69 74 68 20 6f 70 63 6f 64 65 20 4f 50 5f   with opcode OP_
0830: 54 6f 54 65 78 74 20 28 64 69 64 20 6e 6f 74 20  ToText (did not 
0840: 61 63 63 6f 75 6e 74 20 66 6f 72 20 4d 45 4d 5f  account for MEM_
0850: 5a 65 72 6f 29 2e 0a 20 20 23 20 41 6c 73 6f 20  Zero)..  # Also 
0860: 4d 65 6d 45 78 70 61 6e 64 42 6c 6f 62 28 29 20  MemExpandBlob() 
0870: 77 61 73 20 6d 61 72 6b 69 6e 67 20 65 78 70 61  was marking expa
0880: 6e 64 65 64 20 62 6c 6f 62 73 20 61 73 20 6e 75  nded blobs as nu
0890: 6c 2d 74 65 72 6d 69 6e 61 74 65 64 2e 0a 20 20  l-terminated..  
08a0: 23 20 54 68 65 79 20 61 72 65 20 6e 6f 74 2e 0a  # They are not..
08b0: 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20    execsql {.    
08c0: 53 45 4c 45 43 54 20 43 41 53 54 28 7a 65 72 6f  SELECT CAST(zero
08d0: 62 6c 6f 62 28 31 30 30 30 29 20 41 53 20 74 65  blob(1000) AS te
08e0: 78 74 29 3b 0a 20 20 7d 0a 7d 20 7b 7b 7d 7d 0a  xt);.  }.} {{}}.
08f0: 0a 64 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e  .do_test fuzz-1.
0900: 39 20 7b 0a 20 20 23 20 54 68 69 73 20 77 61 73  9 {.  # This was
0910: 20 63 61 75 73 69 6e 67 20 61 20 4e 55 4c 4c 20   causing a NULL 
0920: 70 6f 69 6e 74 65 72 20 64 65 72 65 66 65 72 65  pointer derefere
0930: 6e 63 65 20 6f 66 20 45 78 70 72 2e 70 4c 69 73  nce of Expr.pLis
0940: 74 2e 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20  t..  execsql {. 
0950: 20 20 20 53 45 4c 45 43 54 20 31 20 46 52 4f 4d     SELECT 1 FROM
0960: 20 28 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20   (SELECT * FROM 
0970: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 20 57 48  sqlite_master WH
0980: 45 52 45 20 72 61 6e 64 6f 6d 28 29 29 0a 20 20  ERE random()).  
0990: 7d 0a 7d 20 7b 7d 0a 0a 64 6f 5f 74 65 73 74 20  }.} {}..do_test 
09a0: 66 75 7a 7a 2d 31 2e 31 30 20 7b 0a 20 20 23 20  fuzz-1.10 {.  # 
09b0: 42 75 67 20 69 6e 20 63 61 6c 63 75 6c 61 74 69  Bug in calculati
09c0: 6f 6e 20 6f 66 20 50 61 72 73 65 2e 63 6b 4f 66  on of Parse.ckOf
09d0: 66 73 65 74 20 63 61 75 73 69 6e 67 20 61 6e 20  fset causing an 
09e0: 61 73 73 65 72 74 28 29 20 0a 20 20 23 20 74 6f  assert() .  # to
09f0: 20 66 61 69 6c 2e 20 50 72 6f 62 61 62 6c 79 20   fail. Probably 
0a00: 68 61 72 6d 6c 65 73 73 2e 0a 20 20 65 78 65 63  harmless..  exec
0a10: 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54  sql {.    SELECT
0a20: 20 63 6f 61 6c 65 73 63 65 28 31 2c 20 73 75 62   coalesce(1, sub
0a30: 73 74 72 28 20 31 2c 20 32 2c 20 6c 65 6e 67 74  str( 1, 2, lengt
0a40: 68 28 27 69 6e 27 20 49 4e 20 28 53 45 4c 45 43  h('in' IN (SELEC
0a50: 54 20 31 29 29 29 29 0a 20 20 7d 0a 7d 20 7b 31  T 1)))).  }.} {1
0a60: 7d 0a 0a 64 6f 5f 74 65 73 74 20 66 75 7a 7a 2d  }..do_test fuzz-
0a70: 31 2e 31 31 20 7b 0a 20 20 23 20 54 68 65 20 6c  1.11 {.  # The l
0a80: 69 74 65 72 61 6c 73 20 28 41 2c 20 42 2c 20 43  iterals (A, B, C
0a90: 2c 20 44 29 20 61 72 65 20 6e 6f 74 20 69 6d 70  , D) are not imp
0aa0: 6f 72 74 61 6e 74 2c 20 74 68 65 79 20 61 72 65  ortant, they are
0ab0: 20 6a 75 73 74 20 75 73 65 64 0a 20 20 23 20 74   just used.  # t
0ac0: 6f 20 6d 61 6b 65 20 74 68 65 20 45 58 50 4c 41  o make the EXPLA
0ad0: 49 4e 20 6f 75 74 70 75 74 20 65 61 73 69 65 72  IN output easier
0ae0: 20 74 6f 20 72 65 61 64 2e 0a 20 20 23 0a 20 20   to read..  #.  
0af0: 23 20 54 68 65 20 70 72 6f 62 6c 65 6d 20 68 65  # The problem he
0b00: 72 65 20 69 73 20 74 68 61 74 20 74 68 65 20 45  re is that the E
0b10: 58 49 53 54 53 28 2e 2e 2e 29 20 65 78 70 72 65  XISTS(...) expre
0b20: 73 73 69 6f 6e 20 6c 65 61 76 65 73 20 61 6e 0a  ssion leaves an.
0b30: 20 20 23 20 65 78 74 72 61 20 76 61 6c 75 65 20    # extra value 
0b40: 6f 6e 20 74 68 65 20 56 44 42 45 20 73 74 61 63  on the VDBE stac
0b50: 6b 2e 20 54 68 69 73 20 69 73 20 63 6f 6e 66 75  k. This is confu
0b60: 73 69 6e 67 20 74 68 65 20 70 61 72 65 6e 74 20  sing the parent 
0b70: 61 6e 64 0a 20 20 23 20 6c 65 61 64 73 20 74 6f  and.  # leads to
0b80: 20 61 6e 20 61 73 73 65 72 74 28 29 20 66 61 69   an assert() fai
0b90: 6c 75 72 65 20 77 68 65 6e 20 4f 50 5f 49 6e 73  lure when OP_Ins
0ba0: 65 72 74 20 65 6e 63 6f 75 6e 74 65 72 73 20 61  ert encounters a
0bb0: 6e 20 69 6e 74 65 67 65 72 0a 20 20 23 20 77 68  n integer.  # wh
0bc0: 65 6e 20 69 74 20 65 78 70 65 63 74 73 20 61 20  en it expects a 
0bd0: 72 65 63 6f 72 64 20 62 6c 6f 62 2e 0a 20 20 23  record blob..  #
0be0: 0a 20 20 23 20 55 70 64 61 74 65 3a 20 41 6e 79  .  # Update: Any
0bf0: 20 71 75 65 72 79 20 77 69 74 68 20 28 4c 49 4d   query with (LIM
0c00: 49 54 20 30 29 20 77 61 73 20 6c 65 61 6b 69 6e  IT 0) was leakin
0c10: 67 20 73 74 61 63 6b 2e 0a 20 20 23 0a 20 20 65  g stack..  #.  e
0c20: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c  xecsql {.    SEL
0c30: 45 43 54 20 27 41 27 20 46 52 4f 4d 20 28 53 45  ECT 'A' FROM (SE
0c40: 4c 45 43 54 20 27 42 27 29 20 4f 52 44 45 52 20  LECT 'B') ORDER 
0c50: 42 59 20 45 58 49 53 54 53 20 28 0a 20 20 20 20  BY EXISTS (.    
0c60: 20 20 53 45 4c 45 43 54 20 27 43 27 20 46 52 4f    SELECT 'C' FRO
0c70: 4d 20 28 53 45 4c 45 43 54 20 27 44 27 20 4c 49  M (SELECT 'D' LI
0c80: 4d 49 54 20 30 29 0a 20 20 20 20 29 0a 20 20 7d  MIT 0).    ).  }
0c90: 0a 7d 20 7b 41 7d 0a 0a 64 6f 5f 74 65 73 74 20  .} {A}..do_test 
0ca0: 66 75 7a 7a 2d 31 2e 31 32 2e 31 20 7b 0a 20 20  fuzz-1.12.1 {.  
0cb0: 23 20 43 72 65 61 74 65 20 61 20 74 61 62 6c 65  # Create a table
0cc0: 20 77 69 74 68 20 61 20 73 69 6e 67 6c 65 20 72   with a single r
0cd0: 6f 77 2e 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  ow..  execsql {.
0ce0: 20 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45      CREATE TABLE
0cf0: 20 61 62 63 28 62 29 3b 0a 20 20 20 20 49 4e 53   abc(b);.    INS
0d00: 45 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41 4c  ERT INTO abc VAL
0d10: 55 45 53 28 27 41 42 43 44 45 27 29 3b 0a 20 20  UES('ABCDE');.  
0d20: 7d 0a 0a 20 20 23 20 54 68 65 20 66 6f 6c 6c 6f  }..  # The follo
0d30: 77 69 6e 67 20 71 75 65 72 79 20 77 61 73 20 63  wing query was c
0d40: 72 61 73 68 69 6e 67 2e 20 54 68 65 20 6c 61 74  rashing. The lat
0d50: 65 72 20 73 75 62 71 75 65 72 79 20 28 69 6e 20  er subquery (in 
0d60: 74 68 65 20 46 52 4f 4d 29 0a 20 20 23 20 63 6c  the FROM).  # cl
0d70: 61 75 73 65 20 77 61 73 20 66 6c 61 74 74 65 6e  ause was flatten
0d80: 65 64 20 69 6e 74 6f 20 74 68 65 20 70 61 72 65  ed into the pare
0d90: 6e 74 2c 20 62 75 74 20 74 68 65 20 63 6f 64 65  nt, but the code
0da0: 20 77 61 73 20 6e 6f 74 20 72 65 70 61 69 72 6e   was not repairn
0db0: 67 0a 20 20 23 20 74 68 65 20 22 62 22 20 72 65  g.  # the "b" re
0dc0: 66 65 72 65 6e 63 65 20 69 6e 20 74 68 65 20 6f  ference in the o
0dd0: 74 68 65 72 20 73 75 62 2d 71 75 65 72 79 2e 20  ther sub-query. 
0de0: 57 68 65 6e 20 74 68 65 20 71 75 65 72 79 20 77  When the query w
0df0: 61 73 20 65 78 65 63 75 74 65 64 2c 0a 20 20 23  as executed,.  #
0e00: 20 74 68 61 74 20 22 62 22 20 72 65 66 65 72 65   that "b" refere
0e10: 64 20 74 6f 20 61 20 6e 6f 6e 2d 65 78 69 73 74  d to a non-exist
0e20: 61 6e 74 20 76 64 62 65 20 74 61 62 6c 65 2d 63  ant vdbe table-c
0e30: 75 72 73 6f 72 2e 0a 20 20 23 0a 20 20 65 78 65  ursor..  #.  exe
0e40: 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43  csql {.    SELEC
0e50: 54 20 31 20 49 4e 20 28 20 53 45 4c 45 43 54 20  T 1 IN ( SELECT 
0e60: 62 20 55 4e 49 4f 4e 20 53 45 4c 45 43 54 20 31  b UNION SELECT 1
0e70: 20 29 20 46 52 4f 4d 20 28 53 45 4c 45 43 54 20   ) FROM (SELECT 
0e80: 62 20 46 52 4f 4d 20 61 62 63 29 3b 0a 20 20 7d  b FROM abc);.  }
0e90: 0a 7d 20 7b 31 7d 0a 64 6f 5f 74 65 73 74 20 66  .} {1}.do_test f
0ea0: 75 7a 7a 2d 31 2e 31 32 2e 32 20 7b 0a 20 20 23  uzz-1.12.2 {.  #
0eb0: 20 43 6c 65 61 6e 20 75 70 20 61 66 74 65 72 20   Clean up after 
0ec0: 74 68 65 20 70 72 65 76 69 6f 75 73 20 71 75 65  the previous que
0ed0: 72 79 2e 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  ry..  execsql {.
0ee0: 20 20 20 20 44 52 4f 50 20 54 41 42 4c 45 20 61      DROP TABLE a
0ef0: 62 63 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 0a 64  bc;.  }.} {}...d
0f00: 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e 31 33  o_test fuzz-1.13
0f10: 20 7b 0a 20 20 23 20 54 68 65 20 70 72 6f 62 6c   {.  # The probl
0f20: 65 6d 20 68 65 72 65 20 77 61 73 20 74 68 61 74  em here was that
0f30: 20 77 68 65 6e 20 74 68 65 72 65 20 77 65 72 65   when there were
0f40: 20 6d 6f 72 65 20 65 78 70 72 65 73 73 69 6f 6e   more expression
0f50: 73 20 69 6e 0a 20 20 23 20 74 68 65 20 4f 52 44  s in.  # the ORD
0f60: 45 52 20 42 59 20 6c 69 73 74 20 74 68 61 6e 20  ER BY list than 
0f70: 74 68 65 20 72 65 73 75 6c 74 2d 73 65 74 20 6c  the result-set l
0f80: 69 73 74 2e 20 54 68 65 20 74 65 6d 70 6f 72 61  ist. The tempora
0f90: 72 79 20 62 2d 74 72 65 65 0a 20 20 23 20 75 73  ry b-tree.  # us
0fa0: 65 64 20 66 6f 72 20 73 6f 72 74 69 6e 67 20 77  ed for sorting w
0fb0: 61 73 20 62 65 69 6e 67 20 6d 69 73 63 6f 6e 66  as being misconf
0fc0: 69 67 75 72 65 64 20 69 6e 20 74 68 69 73 20 63  igured in this c
0fd0: 61 73 65 2e 0a 20 20 23 0a 20 20 65 78 65 63 73  ase..  #.  execs
0fe0: 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20  ql {.    SELECT 
0ff0: 27 61 62 63 64 27 20 55 4e 49 4f 4e 20 53 45 4c  'abcd' UNION SEL
1000: 45 43 54 20 27 65 66 67 68 27 20 4f 52 44 45 52  ECT 'efgh' ORDER
1010: 20 42 59 20 31 20 41 53 43 2c 20 31 20 41 53 43   BY 1 ASC, 1 ASC
1020: 3b 0a 20 20 7d 0a 7d 20 7b 61 62 63 64 20 65 66  ;.  }.} {abcd ef
1030: 67 68 7d 0a 0a 64 6f 5f 74 65 73 74 20 66 75 7a  gh}..do_test fuz
1040: 7a 2d 31 2e 31 34 2e 31 20 7b 0a 20 20 65 78 65  z-1.14.1 {.  exe
1050: 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41 54  csql {.    CREAT
1060: 45 20 54 41 42 4c 45 20 61 62 63 28 61 2c 20 62  E TABLE abc(a, b
1070: 2c 20 63 29 3b 0a 20 20 20 20 49 4e 53 45 52 54  , c);.    INSERT
1080: 20 49 4e 54 4f 20 61 62 63 20 56 41 4c 55 45 53   INTO abc VALUES
1090: 28 31 32 33 2c 20 34 35 36 2c 20 37 38 39 29 3b  (123, 456, 789);
10a0: 0a 20 20 7d 0a 20 0a 20 20 23 20 54 68 65 20 5b  .  }. .  # The [
10b0: 61 5d 20 72 65 66 65 72 65 6e 63 65 20 69 6e 20  a] reference in 
10c0: 74 68 65 20 73 75 62 2d 73 65 6c 65 63 74 20 77  the sub-select w
10d0: 61 73 20 63 61 75 73 69 6e 67 20 61 20 70 72 6f  as causing a pro
10e0: 62 6c 65 6d 2e 20 42 65 63 61 75 73 65 0a 20 20  blem. Because.  
10f0: 23 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 77  # the internal w
1100: 61 6c 6b 53 65 6c 65 63 74 45 78 70 72 28 29 20  alkSelectExpr() 
1110: 66 75 6e 63 74 69 6f 6e 20 77 61 73 20 6e 6f 74  function was not
1120: 20 63 6f 6e 73 69 64 65 72 69 6e 67 20 63 6f 6d   considering com
1130: 70 6f 75 6e 64 0a 20 20 23 20 53 45 4c 45 43 54  pound.  # SELECT
1140: 20 6f 70 65 72 61 74 6f 72 73 2e 0a 20 20 65 78   operators..  ex
1150: 65 63 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45  ecsql {.    SELE
1160: 43 54 20 31 20 46 52 4f 4d 20 61 62 63 0a 20 20  CT 1 FROM abc.  
1170: 20 20 47 52 4f 55 50 20 42 59 20 63 20 48 41 56    GROUP BY c HAV
1180: 49 4e 47 20 45 58 49 53 54 53 20 28 53 45 4c 45  ING EXISTS (SELE
1190: 43 54 20 61 20 55 4e 49 4f 4e 20 53 45 4c 45 43  CT a UNION SELEC
11a0: 54 20 31 32 33 29 3b 0a 20 20 7d 0a 7d 20 7b 31  T 123);.  }.} {1
11b0: 7d 0a 64 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31  }.do_test fuzz-1
11c0: 2e 31 34 2e 32 20 7b 0a 20 20 65 78 65 63 73 71  .14.2 {.  execsq
11d0: 6c 20 7b 0a 20 20 20 20 44 52 4f 50 20 54 41 42  l {.    DROP TAB
11e0: 4c 45 20 61 62 63 3b 0a 20 20 7d 0a 7d 20 7b 7d  LE abc;.  }.} {}
11f0: 0a 0a 23 20 4d 61 6b 69 6e 67 20 73 75 72 65 20  ..# Making sure 
1200: 70 72 65 76 69 6f 75 73 6c 79 20 64 69 73 63 6f  previously disco
1210: 76 65 72 65 64 20 65 72 72 6f 72 73 20 68 61 76  vered errors hav
1220: 65 20 62 65 65 6e 20 66 69 78 65 64 2e 0a 23 0a  e been fixed..#.
1230: 64 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e 31  do_test fuzz-1.1
1240: 35 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  5 {.  execsql {.
1250: 20 20 20 20 53 45 4c 45 43 54 20 68 65 78 28 43      SELECT hex(C
1260: 41 53 54 28 7a 65 72 6f 62 6c 6f 62 28 31 30 30  AST(zeroblob(100
1270: 30 29 20 41 53 20 69 6e 74 65 67 65 72 29 29 0a  0) AS integer)).
1280: 20 20 7d 0a 7d 20 7b 33 30 7d 0a 0a 64 6f 5f 74    }.} {30}..do_t
1290: 65 73 74 20 66 75 7a 7a 2d 31 2e 31 36 2e 31 20  est fuzz-1.16.1 
12a0: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20  {.  execsql {.  
12b0: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 61    CREATE TABLE a
12c0: 62 63 28 61 2c 20 62 2c 20 63 29 3b 0a 20 20 20  bc(a, b, c);.   
12d0: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 64 65   CREATE TABLE de
12e0: 66 28 61 2c 20 62 2c 20 63 29 3b 0a 20 20 20 20  f(a, b, c);.    
12f0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 67 68 69  CREATE TABLE ghi
1300: 28 61 2c 20 62 2c 20 63 29 3b 0a 20 20 7d 0a 7d  (a, b, c);.  }.}
1310: 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 66 75 7a 7a   {}.do_test fuzz
1320: 2d 31 2e 31 36 2e 32 20 7b 0a 62 72 65 61 6b 70  -1.16.2 {.breakp
1330: 6f 69 6e 74 0a 20 20 63 61 74 63 68 73 71 6c 20  oint.  catchsql 
1340: 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 44 49 53  {.    SELECT DIS
1350: 54 49 4e 43 54 20 45 58 49 53 54 53 28 0a 20 20  TINCT EXISTS(.  
1360: 20 20 20 20 20 53 45 4c 45 43 54 20 31 0a 20 20       SELECT 1.  
1370: 20 20 20 20 20 46 52 4f 4d 20 28 0a 20 20 20 20       FROM (.    
1380: 20 20 20 20 20 53 45 4c 45 43 54 20 43 20 46 52       SELECT C FR
1390: 4f 4d 20 28 53 45 4c 45 43 54 20 31 29 0a 20 20  OM (SELECT 1).  
13a0: 20 20 20 20 20 29 0a 20 20 20 20 20 20 20 57 48       ).       WH
13b0: 45 52 45 20 28 53 45 4c 45 43 54 20 63 29 0a 20  ERE (SELECT c). 
13c0: 20 20 20 29 0a 20 20 20 20 46 52 4f 4d 20 61 62     ).    FROM ab
13d0: 63 0a 20 20 7d 0a 7d 20 7b 30 20 7b 7d 7d 0a 64  c.  }.} {0 {}}.d
13e0: 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e 31 36  o_test fuzz-1.16
13f0: 2e 33 20 7b 0a 20 20 63 61 74 63 68 73 71 6c 20  .3 {.  catchsql 
1400: 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 44 49 53  {.    SELECT DIS
1410: 54 49 4e 43 54 20 73 75 62 73 74 72 28 2d 34 35  TINCT substr(-45
1420: 36 20 49 53 4e 55 4c 4c 2c 7a 65 72 6f 62 6c 6f  6 ISNULL,zeroblo
1430: 62 28 31 30 30 30 29 2c 20 45 58 49 53 54 53 28  b(1000), EXISTS(
1440: 0a 20 20 20 20 20 20 20 20 20 53 45 4c 45 43 54  .         SELECT
1450: 20 44 49 53 54 49 4e 43 54 20 45 58 49 53 54 53   DISTINCT EXISTS
1460: 28 0a 20 20 20 20 20 20 20 20 20 20 20 53 45 4c  (.           SEL
1470: 45 43 54 20 44 49 53 54 49 4e 43 54 20 62 20 46  ECT DISTINCT b F
1480: 52 4f 4d 20 61 62 63 0a 20 20 20 20 20 20 20 20  ROM abc.        
1490: 20 20 20 4f 52 44 45 52 20 42 59 20 45 58 49 53     ORDER BY EXIS
14a0: 54 53 20 28 0a 20 20 20 20 20 20 20 20 20 20 20  TS (.           
14b0: 20 20 53 45 4c 45 43 54 20 44 49 53 54 49 4e 43    SELECT DISTINC
14c0: 54 20 32 31 34 37 34 38 33 36 34 37 20 55 4e 49  T 2147483647 UNI
14d0: 4f 4e 20 41 4c 4c 20 53 45 4c 45 43 54 20 2d 32  ON ALL SELECT -2
14e0: 31 34 37 34 38 33 36 34 38 0a 20 20 20 20 20 20  147483648.      
14f0: 20 20 20 20 20 29 20 41 53 43 0a 20 20 20 20 20       ) ASC.     
1500: 20 20 20 20 29 0a 20 20 20 20 20 20 20 20 20 46      ).         F
1510: 52 4f 4d 20 28 0a 20 20 20 20 20 20 20 20 20 20  ROM (.          
1520: 20 53 45 4c 45 43 54 20 63 2c 20 63 20 46 52 4f   SELECT c, c FRO
1530: 4d 20 28 0a 20 20 20 20 20 20 20 20 20 20 20 20  M (.            
1540: 20 53 45 4c 45 43 54 20 34 35 36 2c 20 27 69 6e   SELECT 456, 'in
1550: 6a 65 63 74 69 6f 6e 27 20 4f 52 44 45 52 20 42  jection' ORDER B
1560: 59 20 35 36 2e 31 20 41 53 43 2c 20 2d 35 36 2e  Y 56.1 ASC, -56.
1570: 31 20 44 45 53 43 0a 20 20 20 20 20 20 20 20 20  1 DESC.         
1580: 20 20 29 0a 20 20 20 20 20 20 20 20 20 29 0a 20    ).         ). 
1590: 20 20 20 20 20 20 20 20 47 52 4f 55 50 20 42 59          GROUP BY
15a0: 20 28 53 45 4c 45 43 54 20 41 4c 4c 20 28 53 45   (SELECT ALL (SE
15b0: 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20 27 68  LECT DISTINCT 'h
15c0: 61 72 64 77 61 72 65 27 29 29 20 0a 20 20 20 20  ardware')) .    
15d0: 20 20 20 20 20 48 41 56 49 4e 47 20 28 0a 20 20       HAVING (.  
15e0: 20 20 20 20 20 20 20 20 20 53 45 4c 45 43 54 20           SELECT 
15f0: 44 49 53 54 49 4e 43 54 20 63 0a 20 20 20 20 20  DISTINCT c.     
1600: 20 20 20 20 20 20 46 52 4f 4d 20 28 0a 20 20 20        FROM (.   
1610: 20 20 20 20 20 20 20 20 20 20 53 45 4c 45 43 54            SELECT
1620: 20 41 4c 4c 20 2d 32 31 34 37 34 38 33 36 34 38   ALL -2147483648
1630: 2c 20 27 65 78 70 65 72 69 6d 65 6e 74 73 27 0a  , 'experiments'.
1640: 20 20 20 20 20 20 20 20 20 20 20 20 20 4f 52 44               ORD
1650: 45 52 20 42 59 20 2d 35 36 2e 31 20 41 53 43 2c  ER BY -56.1 ASC,
1660: 20 2d 35 36 2e 31 20 44 45 53 43 0a 20 20 20 20   -56.1 DESC.    
1670: 20 20 20 20 20 20 20 29 0a 20 20 20 20 20 20 20         ).       
1680: 20 20 20 20 47 52 4f 55 50 20 42 59 20 28 53 45      GROUP BY (SE
1690: 4c 45 43 54 20 44 49 53 54 49 4e 43 54 20 34 35  LECT DISTINCT 45
16a0: 36 29 20 49 4e 20 0a 20 20 20 20 20 20 20 20 20  6) IN .         
16b0: 20 20 20 20 20 20 20 20 20 20 28 53 45 4c 45 43            (SELEC
16c0: 54 20 44 49 53 54 49 4e 43 54 20 27 69 6e 6a 65  T DISTINCT 'inje
16d0: 63 74 69 6f 6e 27 29 20 4e 4f 54 20 49 4e 20 28  ction') NOT IN (
16e0: 53 45 4c 45 43 54 20 41 4c 4c 20 2d 34 35 36 29  SELECT ALL -456)
16f0: 0a 20 20 20 20 20 20 20 20 20 20 20 48 41 56 49  .           HAVI
1700: 4e 47 20 45 58 49 53 54 53 20 28 0a 20 20 20 20  NG EXISTS (.    
1710: 20 20 20 20 20 20 20 20 20 53 45 4c 45 43 54 20           SELECT 
1720: 41 4c 4c 20 27 69 6e 6a 65 63 74 69 6f 6e 27 0a  ALL 'injection'.
1730: 20 20 20 20 20 20 20 20 20 20 20 29 0a 20 20 20             ).   
1740: 20 20 20 20 20 20 29 0a 20 20 20 20 20 20 20 20        ).        
1750: 20 55 4e 49 4f 4e 20 41 4c 4c 0a 20 20 20 20 20   UNION ALL.     
1760: 20 20 20 20 53 45 4c 45 43 54 20 61 20 49 4e 20      SELECT a IN 
1770: 28 0a 20 20 20 20 20 20 20 20 20 20 20 53 45 4c  (.           SEL
1780: 45 43 54 20 2d 32 31 34 37 34 38 33 36 34 37 0a  ECT -2147483647.
1790: 20 20 20 20 20 20 20 20 20 20 20 55 4e 49 4f 4e             UNION
17a0: 20 41 4c 4c 0a 20 20 20 20 20 20 20 20 20 20 20   ALL.           
17b0: 53 45 4c 45 43 54 20 41 4c 4c 20 27 69 6e 6a 65  SELECT ALL 'inje
17c0: 63 74 69 6f 6e 27 0a 20 20 20 20 20 20 20 20 20  ction'.         
17d0: 29 0a 20 20 20 20 20 20 20 20 20 46 52 4f 4d 20  ).         FROM 
17e0: 73 71 6c 69 74 65 5f 6d 61 73 74 65 72 0a 20 20  sqlite_master.  
17f0: 20 20 20 20 20 29 20 2d 2d 20 65 6e 64 20 45 58       ) -- end EX
1800: 49 53 54 53 0a 20 20 20 20 29 20 2f 2a 20 65 6e  ISTS.    ) /* en
1810: 64 20 53 55 42 53 54 52 28 29 20 2a 2f 2c 20 63  d SUBSTR() */, c
1820: 20 4e 4f 54 4e 55 4c 4c 20 49 53 4e 55 4c 4c 0a   NOTNULL ISNULL.
1830: 20 20 20 20 46 52 4f 4d 20 61 62 63 0a 20 20 20      FROM abc.   
1840: 20 4f 52 44 45 52 20 42 59 20 43 41 53 54 28 2d   ORDER BY CAST(-
1850: 35 36 2e 31 20 41 53 20 62 6c 6f 62 29 20 41 53  56.1 AS blob) AS
1860: 43 0a 20 20 7d 0a 7d 20 7b 30 20 7b 7d 7d 0a 64  C.  }.} {0 {}}.d
1870: 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 31 2e 31 36  o_test fuzz-1.16
1880: 2e 34 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .4 {.  execsql {
1890: 0a 20 20 20 20 44 52 4f 50 20 54 41 42 4c 45 20  .    DROP TABLE 
18a0: 61 62 63 3b 20 44 52 4f 50 20 54 41 42 4c 45 20  abc; DROP TABLE 
18b0: 64 65 66 3b 20 44 52 4f 50 20 54 41 42 4c 45 20  def; DROP TABLE 
18c0: 67 68 69 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 23  ghi;.  }.} {}..#
18d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
18e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
18f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1900: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1910: 0a 23 20 54 65 73 74 20 73 6f 6d 65 20 66 75 7a  .# Test some fuz
1920: 7a 69 6c 79 20 67 65 6e 65 72 61 74 65 64 20 65  zily generated e
1930: 78 70 72 65 73 73 69 6f 6e 73 2e 0a 23 0a 64 6f  xpressions..#.do
1940: 5f 66 75 7a 7a 79 5f 74 65 73 74 20 66 75 7a 7a  _fuzzy_test fuzz
1950: 2d 32 20 2d 74 65 6d 70 6c 61 74 65 20 20 7b 20  -2 -template  { 
1960: 53 45 4c 45 43 54 20 5b 45 78 70 72 5d 20 7d 0a  SELECT [Expr] }.
1970: 0a 64 6f 5f 74 65 73 74 20 66 75 7a 7a 2d 33 2e  .do_test fuzz-3.
1980: 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a  1 {.  execsql {.
1990: 20 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45      CREATE TABLE
19a0: 20 61 62 63 28 61 2c 20 62 2c 20 63 29 3b 0a 20   abc(a, b, c);. 
19b0: 20 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20     CREATE TABLE 
19c0: 64 65 66 28 61 2c 20 62 2c 20 63 29 3b 0a 20 20  def(a, b, c);.  
19d0: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 67    CREATE TABLE g
19e0: 68 69 28 61 2c 20 62 2c 20 63 29 3b 0a 20 20 7d  hi(a, b, c);.  }
19f0: 0a 7d 20 7b 7d 0a 73 65 74 20 3a 3a 54 61 62 6c  .} {}.set ::Tabl
1a00: 65 4c 69 73 74 20 20 5b 6c 69 73 74 20 61 62 63  eList  [list abc
1a10: 20 64 65 66 20 67 68 69 5d 0a 0a 23 2d 2d 2d 2d   def ghi]..#----
1a20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1a30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1a40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54  ------------.# T
1a60: 65 73 74 20 73 6f 6d 65 20 66 75 7a 7a 69 6c 79  est some fuzzily
1a70: 20 67 65 6e 65 72 61 74 65 64 20 53 45 4c 45 43   generated SELEC
1a80: 54 20 73 74 61 74 65 6d 65 6e 74 73 2e 0a 23 0a  T statements..#.
1a90: 64 6f 5f 66 75 7a 7a 79 5f 74 65 73 74 20 66 75  do_fuzzy_test fu
1aa0: 7a 7a 2d 33 2e 32 20 2d 74 65 6d 70 6c 61 74 65  zz-3.2 -template
1ab0: 20 20 7b 5b 53 65 6c 65 63 74 5d 7d 0a 0a 23 2d    {[Select]}..#-
1ac0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1ae0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1af0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
1b00: 23 20 49 6e 73 65 72 74 20 61 20 73 6d 61 6c 6c  # Insert a small
1b10: 20 61 6d 6f 75 6e 74 20 6f 66 20 64 61 74 61 20   amount of data 
1b20: 69 6e 74 6f 20 74 68 65 20 64 61 74 61 62 61 73  into the databas
1b30: 65 20 61 6e 64 20 74 68 65 6e 20 72 75 6e 20 0a  e and then run .
1b40: 23 20 73 6f 6d 65 20 6d 6f 72 65 20 67 65 6e 65  # some more gene
1b50: 72 61 74 65 64 20 53 45 4c 45 43 54 20 73 74 61  rated SELECT sta
1b60: 74 65 6d 65 6e 74 73 2e 0a 23 0a 64 6f 5f 74 65  tements..#.do_te
1b70: 73 74 20 66 75 7a 7a 2d 34 2e 31 20 7b 0a 20 20  st fuzz-4.1 {.  
1b80: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e  execsql {.    IN
1b90: 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 56 41  SERT INTO abc VA
1ba0: 4c 55 45 53 28 31 2c 20 32 2c 20 33 29 3b 0a 20  LUES(1, 2, 3);. 
1bb0: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61     INSERT INTO a
1bc0: 62 63 20 56 41 4c 55 45 53 28 34 2c 20 35 2c 20  bc VALUES(4, 5, 
1bd0: 36 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  6);.    INSERT I
1be0: 4e 54 4f 20 61 62 63 20 56 41 4c 55 45 53 28 37  NTO abc VALUES(7
1bf0: 2c 20 38 2c 20 39 29 3b 0a 20 20 20 20 49 4e 53  , 8, 9);.    INS
1c00: 45 52 54 20 49 4e 54 4f 20 64 65 66 20 56 41 4c  ERT INTO def VAL
1c10: 55 45 53 28 31 2c 20 32 2c 20 33 29 3b 0a 20 20  UES(1, 2, 3);.  
1c20: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 64 65    INSERT INTO de
1c30: 66 20 56 41 4c 55 45 53 28 34 2c 20 35 2c 20 36  f VALUES(4, 5, 6
1c40: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
1c50: 54 4f 20 64 65 66 20 56 41 4c 55 45 53 28 37 2c  TO def VALUES(7,
1c60: 20 38 2c 20 39 29 3b 0a 20 20 20 20 49 4e 53 45   8, 9);.    INSE
1c70: 52 54 20 49 4e 54 4f 20 67 68 69 20 56 41 4c 55  RT INTO ghi VALU
1c80: 45 53 28 31 2c 20 32 2c 20 33 29 3b 0a 20 20 20  ES(1, 2, 3);.   
1c90: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 67 68 69   INSERT INTO ghi
1ca0: 20 56 41 4c 55 45 53 28 34 2c 20 35 2c 20 36 29   VALUES(4, 5, 6)
1cb0: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
1cc0: 4f 20 67 68 69 20 56 41 4c 55 45 53 28 37 2c 20  O ghi VALUES(7, 
1cd0: 38 2c 20 39 29 3b 0a 20 20 20 20 43 52 45 41 54  8, 9);.    CREAT
1ce0: 45 20 49 4e 44 45 58 20 61 62 63 5f 69 20 4f 4e  E INDEX abc_i ON
1cf0: 20 61 62 63 28 61 2c 20 62 2c 20 63 29 3b 0a 20   abc(a, b, c);. 
1d00: 20 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 20     CREATE INDEX 
1d10: 64 65 66 5f 69 20 4f 4e 20 64 65 66 28 63 2c 20  def_i ON def(c, 
1d20: 61 2c 20 62 29 3b 0a 20 20 20 20 43 52 45 41 54  a, b);.    CREAT
1d30: 45 20 49 4e 44 45 58 20 67 68 69 5f 69 20 4f 4e  E INDEX ghi_i ON
1d40: 20 67 68 69 28 62 2c 20 63 2c 20 61 29 3b 0a 20   ghi(b, c, a);. 
1d50: 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 66 75 7a 7a 79   }.} {}.do_fuzzy
1d60: 5f 74 65 73 74 20 66 75 7a 7a 2d 34 2e 32 20 2d  _test fuzz-4.2 -
1d70: 74 65 6d 70 6c 61 74 65 20 7b 5b 53 65 6c 65 63  template {[Selec
1d80: 74 5d 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  t]}..#----------
1d90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1da0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1db0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1dc0: 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 73 6f  ------.# Test so
1dd0: 6d 65 20 66 75 7a 7a 79 20 49 4e 53 45 52 54 20  me fuzzy INSERT 
1de0: 73 74 61 74 65 6d 65 6e 74 73 3a 0a 23 0a 64 6f  statements:.#.do
1df0: 5f 74 65 73 74 20 20 20 20 20 20 20 20 20 66 75  _test         fu
1e00: 7a 7a 2d 35 2e 31 20 7b 65 78 65 63 73 71 6c 20  zz-5.1 {execsql 
1e10: 42 45 47 49 4e 7d 20 7b 7d 0a 64 6f 5f 66 75 7a  BEGIN} {}.do_fuz
1e20: 7a 79 5f 74 65 73 74 20 20 20 66 75 7a 7a 2d 35  zy_test   fuzz-5
1e30: 2e 32 20 2d 74 65 6d 70 6c 61 74 65 20 20 7b 5b  .2 -template  {[
1e40: 49 6e 73 65 72 74 5d 7d 20 2d 65 72 72 6f 72 6c  Insert]} -errorl
1e50: 69 73 74 20 74 61 62 6c 65 0a 69 6e 74 65 67 72  ist table.integr
1e60: 69 74 79 5f 63 68 65 63 6b 20 66 75 7a 7a 2d 35  ity_check fuzz-5
1e70: 2e 32 2e 69 6e 74 65 67 72 69 74 79 0a 64 6f 5f  .2.integrity.do_
1e80: 74 65 73 74 20 20 20 20 20 20 20 20 20 66 75 7a  test         fuz
1e90: 7a 2d 35 2e 33 20 7b 65 78 65 63 73 71 6c 20 43  z-5.3 {execsql C
1ea0: 4f 4d 4d 49 54 7d 20 7b 7d 0a 69 6e 74 65 67 72  OMMIT} {}.integr
1eb0: 69 74 79 5f 63 68 65 63 6b 20 66 75 7a 7a 2d 35  ity_check fuzz-5
1ec0: 2e 34 2e 69 6e 74 65 67 72 69 74 79 0a 0a 23 2d  .4.integrity..#-
1ed0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1ee0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1ef0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1f00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a  ---------------.
1f10: 23 20 4e 6f 77 20 74 68 61 74 20 74 68 65 72 65  # Now that there
1f20: 20 69 73 20 64 61 74 61 20 69 6e 20 74 68 65 20   is data in the 
1f30: 64 61 74 61 62 61 73 65 2c 20 72 75 6e 20 73 6f  database, run so
1f40: 6d 65 20 6d 6f 72 65 20 53 45 4c 45 43 54 20 0a  me more SELECT .
1f50: 23 20 73 74 61 74 65 6d 65 6e 74 73 0a 23 0a 73  # statements.#.s
1f60: 65 74 20 3a 3a 43 6f 6c 75 6d 6e 4c 69 73 74 20  et ::ColumnList 
1f70: 5b 6c 69 73 74 20 61 20 62 20 63 5d 0a 73 65 74  [list a b c].set
1f80: 20 45 20 7b 7b 6e 6f 20 73 75 63 68 20 63 6f 6c   E {{no such col
1f90: 7d 20 7b 61 6d 62 69 67 75 6f 75 73 20 63 6f 6c  } {ambiguous col
1fa0: 75 6d 6e 20 6e 61 6d 65 7d 7d 0a 64 6f 5f 66 75  umn name}}.do_fu
1fb0: 7a 7a 79 5f 74 65 73 74 20 66 75 7a 7a 2d 36 2e  zzy_test fuzz-6.
1fc0: 31 20 2d 74 65 6d 70 6c 61 74 65 20 7b 5b 53 65  1 -template {[Se
1fd0: 6c 65 63 74 5d 7d 20 2d 65 72 72 6f 72 6c 69 73  lect]} -errorlis
1fe0: 74 20 24 45 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d  t $E..#---------
1ff0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2000: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2010: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2020: 2d 2d 2d 2d 2d 2d 2d 0a 23 20 52 75 6e 20 73 6f  -------.# Run so
2030: 6d 65 20 53 45 4c 45 43 54 73 2c 20 49 4e 53 45  me SELECTs, INSE
2040: 52 54 73 2c 20 55 50 44 41 54 45 73 20 61 6e 64  RTs, UPDATEs and
2050: 20 44 45 4c 45 54 45 73 20 69 6e 20 61 20 74 72   DELETEs in a tr
2060: 61 6e 73 61 63 74 69 6f 6e 2e 0a 23 0a 73 65 74  ansaction..#.set
2070: 20 45 20 7b 7b 6e 6f 20 73 75 63 68 20 63 6f 6c   E {{no such col
2080: 7d 20 7b 61 6d 62 69 67 75 6f 75 73 20 63 6f 6c  } {ambiguous col
2090: 75 6d 6e 20 6e 61 6d 65 7d 20 7b 74 61 62 6c 65  umn name} {table
20a0: 7d 7d 0a 64 6f 5f 74 65 73 74 20 20 20 20 20 20  }}.do_test      
20b0: 20 20 20 66 75 7a 7a 2d 37 2e 31 20 7b 65 78 65     fuzz-7.1 {exe
20c0: 63 73 71 6c 20 42 45 47 49 4e 7d 20 7b 7d 0a 64  csql BEGIN} {}.d
20d0: 6f 5f 66 75 7a 7a 79 5f 74 65 73 74 20 20 20 66  o_fuzzy_test   f
20e0: 75 7a 7a 2d 37 2e 32 20 2d 74 65 6d 70 6c 61 74  uzz-7.2 -templat
20f0: 65 20 7b 5b 53 74 61 74 65 6d 65 6e 74 5d 7d 20  e {[Statement]} 
2100: 2d 65 72 72 6f 72 6c 69 73 74 20 24 45 0a 69 6e  -errorlist $E.in
2110: 74 65 67 72 69 74 79 5f 63 68 65 63 6b 20 66 75  tegrity_check fu
2120: 7a 7a 2d 37 2e 33 2e 69 6e 74 65 67 72 69 74 79  zz-7.3.integrity
2130: 0a 64 6f 5f 74 65 73 74 20 20 20 20 20 20 20 20  .do_test        
2140: 20 66 75 7a 7a 2d 37 2e 34 20 7b 65 78 65 63 73   fuzz-7.4 {execs
2150: 71 6c 20 43 4f 4d 4d 49 54 7d 20 7b 7d 0a 69 6e  ql COMMIT} {}.in
2160: 74 65 67 72 69 74 79 5f 63 68 65 63 6b 20 66 75  tegrity_check fu
2170: 7a 7a 2d 37 2e 35 2e 69 6e 74 65 67 72 69 74 79  zz-7.5.integrity
2180: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
2190: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
21a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
21b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
21c0: 2d 2d 2d 0a 23 20 4d 61 6e 79 20 43 52 45 41 54  ---.# Many CREAT
21d0: 45 20 61 6e 64 20 44 52 4f 50 20 54 41 42 4c 45  E and DROP TABLE
21e0: 20 73 74 61 74 65 6d 65 6e 74 73 3a 0a 23 0a 73   statements:.#.s
21f0: 65 74 20 45 20 5b 6c 69 73 74 20 74 61 62 6c 65  et E [list table
2200: 20 64 75 70 6c 69 63 61 74 65 20 7b 6e 6f 20 73   duplicate {no s
2210: 75 63 68 20 63 6f 6c 7d 20 7b 61 6d 62 69 67 75  uch col} {ambigu
2220: 6f 75 73 20 63 6f 6c 75 6d 6e 20 6e 61 6d 65 7d  ous column name}
2230: 20 7b 75 73 65 20 44 52 4f 50 7d 5d 0a 64 6f 5f   {use DROP}].do_
2240: 66 75 7a 7a 79 5f 74 65 73 74 20 66 75 7a 7a 2d  fuzzy_test fuzz-
2250: 38 2e 31 20 2d 74 65 6d 70 6c 61 74 65 20 7b 5b  8.1 -template {[
2260: 43 72 65 61 74 65 4f 72 44 72 6f 70 54 61 62 6c  CreateOrDropTabl
2270: 65 4f 72 56 69 65 77 5d 7d 20 2d 65 72 72 6f 72  eOrView]} -error
2280: 6c 69 73 74 20 24 45 0a 0a 63 6c 6f 73 65 20 24  list $E..close $
2290: 3a 3a 6c 6f 67 0a 66 69 6e 69 73 68 5f 74 65 73  ::log.finish_tes
22a0: 74 0a                                            t.