/ Hex Artifact Content
Login

Artifact ede9874fc0ffbfa1ebfbc84cbe5d283cfa00f772:


0000: 23 20 32 30 30 37 20 4d 61 79 20 38 0a 23 0a 23  # 2007 May 8.#.#
0010: 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73 63   The author disc
0020: 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74 20  laims copyright 
0030: 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20 63  to this source c
0040: 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20 6f  ode.  In place o
0050: 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74 69  f.# a legal noti
0060: 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62 6c  ce, here is a bl
0070: 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20 4d  essing:.#.#    M
0080: 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20 61  ay you do good a
0090: 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20 20  nd not evil..#  
00a0: 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20 66    May you find f
00b0: 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20 79  orgiveness for y
00c0: 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72 67  ourself and forg
00d0: 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20 20  ive others..#   
00e0: 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20 66   May you share f
00f0: 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61 6b  reely, never tak
0100: 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79 6f  ing more than yo
0110: 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a 2a  u 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 0a 23 0a 23 20 54 68 69 73 20 66 69 6c 65  **.#.# This file
0170: 20 63 6f 6e 74 61 69 6e 73 20 74 65 73 74 73 20   contains tests 
0180: 74 6f 20 76 65 72 69 66 79 20 74 68 61 74 20 74  to verify that t
0190: 68 65 20 6c 69 6d 69 74 73 20 64 65 66 69 6e 65  he limits define
01a0: 64 20 69 6e 0a 23 20 73 71 6c 69 74 65 20 73 6f  d in.# sqlite so
01b0: 75 72 63 65 20 66 69 6c 65 20 6c 69 6d 69 74 73  urce file limits
01c0: 2e 68 20 61 72 65 20 65 6e 66 6f 72 63 65 64 2e  .h are enforced.
01d0: 0a 23 0a 23 20 24 49 64 3a 20 73 71 6c 6c 69 6d  .#.# $Id: sqllim
01e0: 69 74 73 31 2e 74 65 73 74 2c 76 20 31 2e 32 31  its1.test,v 1.21
01f0: 20 32 30 30 37 2f 31 32 2f 31 37 20 31 36 3a 32   2007/12/17 16:2
0200: 30 3a 30 37 20 64 72 68 20 45 78 70 20 24 0a 0a  0:07 drh Exp $..
0210: 73 65 74 20 74 65 73 74 64 69 72 20 5b 66 69 6c  set testdir [fil
0220: 65 20 64 69 72 6e 61 6d 65 20 24 61 72 67 76 30  e dirname $argv0
0230: 5d 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69  ].source $testdi
0240: 72 2f 74 65 73 74 65 72 2e 74 63 6c 0a 0a 23 20  r/tester.tcl..# 
0250: 54 65 73 74 20 6f 72 67 61 6e 69 7a 61 74 69 6f  Test organizatio
0260: 6e 3a 0a 23 0a 23 20 20 20 20 20 73 71 6c 6c 69  n:.#.#     sqlli
0270: 6d 69 74 73 2d 31 2e 2a 3a 20 20 53 51 4c 49 54  mits-1.*:  SQLIT
0280: 45 5f 4d 41 58 5f 4c 45 4e 47 54 48 0a 23 20 20  E_MAX_LENGTH.#  
0290: 20 20 20 73 71 6c 6c 69 6d 69 74 73 2d 32 2e 2a     sqllimits-2.*
02a0: 3a 20 20 53 51 4c 49 54 45 5f 4d 41 58 5f 53 51  :  SQLITE_MAX_SQ
02b0: 4c 5f 4c 45 4e 47 54 48 0a 23 20 20 20 20 20 73  L_LENGTH.#     s
02c0: 71 6c 6c 69 6d 69 74 73 2d 33 2e 2a 3a 20 20 53  qllimits-3.*:  S
02d0: 51 4c 49 54 45 5f 4d 41 58 5f 50 41 47 45 5f 43  QLITE_MAX_PAGE_C
02e0: 4f 55 4e 54 20 28 61 6e 64 20 74 68 65 20 6d 61  OUNT (and the ma
02f0: 78 5f 70 61 67 65 5f 63 6f 75 6e 74 20 70 72 61  x_page_count pra
0300: 67 6d 61 29 0a 23 20 20 20 20 20 73 71 6c 6c 69  gma).#     sqlli
0310: 6d 69 74 73 2d 34 2e 2a 3a 20 20 53 51 4c 49 54  mits-4.*:  SQLIT
0320: 45 5f 4d 41 58 5f 43 4f 4c 55 4d 4e 0a 23 0a 23  E_MAX_COLUMN.#.#
0330: 0a 23 20 20 20 20 20 73 71 6c 6c 69 6d 69 74 73  .#     sqllimits
0340: 2d 37 2e 2a 3a 20 20 20 53 51 4c 49 54 45 5f 4d  -7.*:   SQLITE_M
0350: 41 58 5f 46 55 4e 43 54 49 4f 4e 5f 41 52 47 20  AX_FUNCTION_ARG 
0360: 20 0a 23 20 20 20 20 20 73 71 6c 6c 69 6d 69 74   .#     sqllimit
0370: 73 2d 38 2e 2a 3a 20 20 20 53 51 4c 49 54 45 5f  s-8.*:   SQLITE_
0380: 4d 41 58 5f 41 54 54 41 43 48 45 44 0a 23 20 20  MAX_ATTACHED.#  
0390: 20 20 20 73 71 6c 6c 69 6d 69 74 73 2d 39 2e 2a     sqllimits-9.*
03a0: 3a 20 20 20 53 51 4c 49 54 45 5f 4d 41 58 5f 56  :   SQLITE_MAX_V
03b0: 41 52 49 41 42 4c 45 5f 4e 55 4d 42 45 52 0a 23  ARIABLE_NUMBER.#
03c0: 20 20 20 20 20 73 71 6c 6c 69 6d 69 74 73 2d 31       sqllimits-1
03d0: 30 2e 2a 3a 20 20 53 51 4c 49 54 45 5f 4d 41 58  0.*:  SQLITE_MAX
03e0: 5f 50 41 47 45 5f 53 49 5a 45 0a 23 20 20 20 20  _PAGE_SIZE.#    
03f0: 20 73 71 6c 6c 69 6d 69 74 73 2d 31 31 2e 2a 3a   sqllimits-11.*:
0400: 20 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4c 49 4b    SQLITE_MAX_LIK
0410: 45 5f 50 41 54 54 45 52 4e 5f 4c 45 4e 47 54 48  E_PATTERN_LENGTH
0420: 0a 23 0a 23 20 54 6f 64 6f 3a 0a 23 0a 23 20 20  .#.# Todo:.#.#  
0430: 20 20 20 73 71 6c 6c 69 6d 69 74 73 2d 35 2e 2a     sqllimits-5.*
0440: 3a 20 20 20 53 51 4c 49 54 45 5f 4d 41 58 5f 45  :   SQLITE_MAX_E
0450: 58 50 52 5f 44 45 50 54 48 20 20 20 20 20 20 20  XPR_DEPTH       
0460: 20 20 20 20 20 28 73 71 6c 69 74 65 20 74 6f 64       (sqlite tod
0470: 6f 29 0a 23 20 20 20 20 20 73 71 6c 6c 69 6d 69  o).#     sqllimi
0480: 74 73 2d 36 2e 2a 3a 20 20 20 53 51 4c 49 54 45  ts-6.*:   SQLITE
0490: 5f 4d 41 58 5f 56 44 42 45 5f 4f 50 20 20 20 20  _MAX_VDBE_OP    
04a0: 20 20 20 20 20 20 20 20 20 20 20 28 73 71 6c 69             (sqli
04b0: 74 65 20 74 6f 64 6f 29 0a 23 20 20 20 20 20 73  te todo).#     s
04c0: 71 6c 6c 69 6d 69 74 73 2d 31 32 2e 2a 3a 20 20  qllimits-12.*:  
04d0: 53 51 4c 49 54 45 5f 4d 41 58 5f 50 41 47 45 5f  SQLITE_MAX_PAGE_
04e0: 43 4f 55 4e 54 20 20 20 20 20 20 20 20 20 20 20  COUNT           
04f0: 20 28 73 71 6c 69 74 65 20 74 6f 64 6f 29 0a 23   (sqlite todo).#
0500: 0a 0a 75 6e 73 65 74 20 2d 6e 6f 63 6f 6d 70 6c  ..unset -nocompl
0510: 61 69 6e 20 73 61 76 65 64 0a 66 6f 72 65 61 63  ain saved.foreac
0520: 68 20 76 61 72 20 5b 69 6e 66 6f 20 76 61 72 73  h var [info vars
0530: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 2a 5d 20 7b   SQLITE_MAX_*] {
0540: 0a 20 20 73 65 74 20 73 61 76 65 64 28 24 76 61  .  set saved($va
0550: 72 29 20 5b 73 65 74 20 24 76 61 72 5d 0a 7d 0a  r) [set $var].}.
0560: 0a 73 65 74 20 53 51 4c 49 54 45 5f 4d 41 58 5f  .set SQLITE_MAX_
0570: 4c 45 4e 47 54 48 20 20 20 20 20 20 20 20 20 20  LENGTH          
0580: 20 20 20 20 20 20 20 31 30 30 30 30 30 0a 73 65         100000.se
0590: 74 20 53 51 4c 49 54 45 5f 4d 41 58 5f 43 4f 4c  t SQLITE_MAX_COL
05a0: 55 4d 4e 0a 73 65 74 20 53 51 4c 49 54 45 5f 4d  UMN.set SQLITE_M
05b0: 41 58 5f 53 51 4c 5f 4c 45 4e 47 54 48 20 20 20  AX_SQL_LENGTH   
05c0: 20 20 20 20 20 20 20 20 20 20 20 35 30 30 30 30             50000
05d0: 0a 73 65 74 20 53 51 4c 49 54 45 5f 4d 41 58 5f  .set SQLITE_MAX_
05e0: 45 58 50 52 5f 44 45 50 54 48 20 20 20 20 20 20  EXPR_DEPTH      
05f0: 20 20 20 20 20 20 20 20 20 31 30 30 30 0a 73 65           1000.se
0600: 74 20 53 51 4c 49 54 45 5f 4d 41 58 5f 43 4f 4d  t SQLITE_MAX_COM
0610: 50 4f 55 4e 44 5f 53 45 4c 45 43 54 20 20 20 20  POUND_SELECT    
0620: 20 20 20 20 20 20 20 20 20 35 0a 73 65 74 20 53           5.set S
0630: 51 4c 49 54 45 5f 4d 41 58 5f 56 44 42 45 5f 4f  QLITE_MAX_VDBE_O
0640: 50 0a 73 65 74 20 53 51 4c 49 54 45 5f 4d 41 58  P.set SQLITE_MAX
0650: 5f 46 55 4e 43 54 49 4f 4e 5f 41 52 47 0a 73 65  _FUNCTION_ARG.se
0660: 74 20 53 51 4c 49 54 45 5f 4d 41 58 5f 56 41 52  t SQLITE_MAX_VAR
0670: 49 41 42 4c 45 5f 4e 55 4d 42 45 52 0a 73 65 74  IABLE_NUMBER.set
0680: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 50 41 47 45   SQLITE_MAX_PAGE
0690: 5f 53 49 5a 45 0a 73 65 74 20 53 51 4c 49 54 45  _SIZE.set SQLITE
06a0: 5f 4d 41 58 5f 50 41 47 45 5f 43 4f 55 4e 54 0a  _MAX_PAGE_COUNT.
06b0: 73 65 74 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4c  set SQLITE_MAX_L
06c0: 49 4b 45 5f 50 41 54 54 45 52 4e 5f 4c 45 4e 47  IKE_PATTERN_LENG
06d0: 54 48 20 20 20 20 20 20 31 30 30 30 0a 0a 23 2d  TH      1000..#-
06e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
06f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0700: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0710: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0720: 2d 2d 2d 0a 23 20 54 65 73 74 20 63 61 73 65 73  ---.# Test cases
0730: 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 2a 20 74   sqllimits-1.* t
0740: 65 73 74 20 74 68 61 74 20 74 68 65 20 53 51 4c  est that the SQL
0750: 49 54 45 5f 4d 41 58 5f 4c 45 4e 47 54 48 20 6c  ITE_MAX_LENGTH l
0760: 69 6d 69 74 0a 23 20 69 73 20 65 6e 66 6f 72 63  imit.# is enforc
0770: 65 64 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 73 71  ed..#.do_test sq
0780: 6c 6c 69 6d 69 74 73 2d 31 2e 31 2e 31 20 7b 0a  llimits-1.1.1 {.
0790: 20 20 63 61 74 63 68 73 71 6c 20 7b 20 53 45 4c    catchsql { SEL
07a0: 45 43 54 20 72 61 6e 64 6f 6d 62 6c 6f 62 28 32  ECT randomblob(2
07b0: 31 34 37 34 38 33 36 34 37 29 20 7d 0a 7d 20 7b  147483647) }.} {
07c0: 31 20 7b 73 74 72 69 6e 67 20 6f 72 20 62 6c 6f  1 {string or blo
07d0: 62 20 74 6f 6f 20 62 69 67 7d 7d 0a 64 6f 5f 74  b too big}}.do_t
07e0: 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e  est sqllimits-1.
07f0: 31 2e 32 20 7b 0a 20 20 63 61 74 63 68 73 71 6c  1.2 {.  catchsql
0800: 20 7b 20 53 45 4c 45 43 54 20 7a 65 72 6f 62 6c   { SELECT zerobl
0810: 6f 62 28 32 31 34 37 34 38 33 36 34 37 29 20 7d  ob(2147483647) }
0820: 0a 7d 20 7b 31 20 7b 73 74 72 69 6e 67 20 6f 72  .} {1 {string or
0830: 20 62 6c 6f 62 20 74 6f 6f 20 62 69 67 7d 7d 0a   blob too big}}.
0840: 0a 23 20 4c 61 72 67 65 2c 20 62 75 74 20 61 6c  .# Large, but al
0850: 6c 6f 77 61 62 6c 65 2c 20 62 6c 6f 62 2d 73 69  lowable, blob-si
0860: 7a 65 2e 0a 23 0a 73 65 74 20 3a 3a 4c 41 52 47  ze..#.set ::LARG
0870: 45 53 49 5a 45 20 5b 65 78 70 72 20 24 53 51 4c  ESIZE [expr $SQL
0880: 49 54 45 5f 4d 41 58 5f 4c 45 4e 47 54 48 20 2d  ITE_MAX_LENGTH -
0890: 20 31 5d 20 0a 0a 64 6f 5f 74 65 73 74 20 73 71   1] ..do_test sq
08a0: 6c 6c 69 6d 69 74 73 2d 31 2e 32 20 7b 0a 20 20  llimits-1.2 {.  
08b0: 63 61 74 63 68 73 71 6c 20 7b 20 53 45 4c 45 43  catchsql { SELEC
08c0: 54 20 4c 45 4e 47 54 48 28 72 61 6e 64 6f 6d 62  T LENGTH(randomb
08d0: 6c 6f 62 28 24 3a 3a 4c 41 52 47 45 53 49 5a 45  lob($::LARGESIZE
08e0: 29 29 20 7d 0a 7d 20 22 30 20 24 3a 3a 4c 41 52  )) }.} "0 $::LAR
08f0: 47 45 53 49 5a 45 22 0a 0a 64 6f 5f 74 65 73 74  GESIZE"..do_test
0900: 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 33 20 7b   sqllimits-1.3 {
0910: 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 20 53 45  .  catchsql { SE
0920: 4c 45 43 54 20 71 75 6f 74 65 28 72 61 6e 64 6f  LECT quote(rando
0930: 6d 62 6c 6f 62 28 24 3a 3a 4c 41 52 47 45 53 49  mblob($::LARGESI
0940: 5a 45 29 29 20 7d 0a 7d 20 7b 31 20 7b 73 74 72  ZE)) }.} {1 {str
0950: 69 6e 67 20 6f 72 20 62 6c 6f 62 20 74 6f 6f 20  ing or blob too 
0960: 62 69 67 7d 7d 0a 0a 64 6f 5f 74 65 73 74 20 73  big}}..do_test s
0970: 71 6c 6c 69 6d 69 74 73 2d 31 2e 34 20 7b 0a 20  qllimits-1.4 {. 
0980: 20 63 61 74 63 68 73 71 6c 20 7b 20 53 45 4c 45   catchsql { SELE
0990: 43 54 20 4c 45 4e 47 54 48 28 7a 65 72 6f 62 6c  CT LENGTH(zerobl
09a0: 6f 62 28 24 3a 3a 4c 41 52 47 45 53 49 5a 45 29  ob($::LARGESIZE)
09b0: 29 20 7d 0a 7d 20 22 30 20 24 3a 3a 4c 41 52 47  ) }.} "0 $::LARG
09c0: 45 53 49 5a 45 22 0a 0a 64 6f 5f 74 65 73 74 20  ESIZE"..do_test 
09d0: 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 35 20 7b 0a  sqllimits-1.5 {.
09e0: 20 20 63 61 74 63 68 73 71 6c 20 7b 20 53 45 4c    catchsql { SEL
09f0: 45 43 54 20 71 75 6f 74 65 28 7a 65 72 6f 62 6c  ECT quote(zerobl
0a00: 6f 62 28 24 3a 3a 4c 41 52 47 45 53 49 5a 45 29  ob($::LARGESIZE)
0a10: 29 20 7d 0a 7d 20 7b 31 20 7b 73 74 72 69 6e 67  ) }.} {1 {string
0a20: 20 6f 72 20 62 6c 6f 62 20 74 6f 6f 20 62 69 67   or blob too big
0a30: 7d 7d 0a 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c  }}..do_test sqll
0a40: 69 6d 69 74 73 2d 31 2e 36 20 7b 0a 20 20 63 61  imits-1.6 {.  ca
0a50: 74 63 68 73 71 6c 20 7b 20 53 45 4c 45 43 54 20  tchsql { SELECT 
0a60: 7a 65 72 6f 62 6c 6f 62 28 2d 31 29 20 7d 0a 7d  zeroblob(-1) }.}
0a70: 20 7b 30 20 7b 7b 7d 7d 7d 0a 0a 64 6f 5f 74 65   {0 {{}}}..do_te
0a80: 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 39  st sqllimits-1.9
0a90: 20 7b 0a 20 20 73 65 74 20 3a 3a 73 74 72 20 5b   {.  set ::str [
0aa0: 73 74 72 69 6e 67 20 72 65 70 65 61 74 20 41 20  string repeat A 
0ab0: 36 35 35 33 37 5d 0a 20 20 73 65 74 20 3a 3a 72  65537].  set ::r
0ac0: 65 70 20 5b 73 74 72 69 6e 67 20 72 65 70 65 61  ep [string repea
0ad0: 74 20 42 20 36 35 35 33 37 5d 0a 20 20 63 61 74  t B 65537].  cat
0ae0: 63 68 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 72  chsql { SELECT r
0af0: 65 70 6c 61 63 65 28 24 3a 3a 73 74 72 2c 20 27  eplace($::str, '
0b00: 41 27 2c 20 24 3a 3a 72 65 70 29 20 7d 0a 7d 20  A', $::rep) }.} 
0b10: 7b 31 20 7b 73 74 72 69 6e 67 20 6f 72 20 62 6c  {1 {string or bl
0b20: 6f 62 20 74 6f 6f 20 62 69 67 7d 7d 0a 0a 64 6f  ob too big}}..do
0b30: 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d  _test sqllimits-
0b40: 31 2e 31 30 20 7b 0a 20 20 73 65 74 20 3a 3a 73  1.10 {.  set ::s
0b50: 74 72 20 5b 73 74 72 69 6e 67 20 72 65 70 65 61  tr [string repea
0b60: 74 20 25 4a 20 32 31 30 30 5d 0a 20 20 63 61 74  t %J 2100].  cat
0b70: 63 68 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 73  chsql { SELECT s
0b80: 74 72 66 74 69 6d 65 28 24 3a 3a 73 74 72 2c 20  trftime($::str, 
0b90: 27 32 30 30 33 2d 31 30 2d 33 31 27 29 20 7d 0a  '2003-10-31') }.
0ba0: 7d 20 7b 31 20 7b 73 74 72 69 6e 67 20 6f 72 20  } {1 {string or 
0bb0: 62 6c 6f 62 20 74 6f 6f 20 62 69 67 7d 7d 0a 0a  blob too big}}..
0bc0: 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74  do_test sqllimit
0bd0: 73 2d 31 2e 31 31 20 7b 0a 20 20 73 65 74 20 3a  s-1.11 {.  set :
0be0: 3a 73 74 72 31 20 5b 73 74 72 69 6e 67 20 72 65  :str1 [string re
0bf0: 70 65 61 74 20 41 20 5b 65 78 70 72 20 7b 24 53  peat A [expr {$S
0c00: 51 4c 49 54 45 5f 4d 41 58 5f 4c 45 4e 47 54 48  QLITE_MAX_LENGTH
0c10: 20 2d 20 31 30 7d 5d 5d 0a 20 20 73 65 74 20 3a   - 10}]].  set :
0c20: 3a 73 74 72 32 20 5b 73 74 72 69 6e 67 20 72 65  :str2 [string re
0c30: 70 65 61 74 20 42 20 5b 65 78 70 72 20 7b 24 53  peat B [expr {$S
0c40: 51 4c 49 54 45 5f 4d 41 58 5f 4c 45 4e 47 54 48  QLITE_MAX_LENGTH
0c50: 20 2d 20 31 30 7d 5d 5d 0a 20 20 63 61 74 63 68   - 10}]].  catch
0c60: 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 24 3a 3a  sql { SELECT $::
0c70: 73 74 72 31 20 7c 7c 20 24 3a 3a 73 74 72 32 20  str1 || $::str2 
0c80: 7d 0a 7d 20 7b 31 20 7b 73 74 72 69 6e 67 20 6f  }.} {1 {string o
0c90: 72 20 62 6c 6f 62 20 74 6f 6f 20 62 69 67 7d 7d  r blob too big}}
0ca0: 0a 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d  ..do_test sqllim
0cb0: 69 74 73 2d 31 2e 31 32 20 7b 0a 20 20 73 65 74  its-1.12 {.  set
0cc0: 20 3a 3a 73 74 72 31 20 5b 73 74 72 69 6e 67 20   ::str1 [string 
0cd0: 72 65 70 65 61 74 20 27 20 5b 65 78 70 72 20 7b  repeat ' [expr {
0ce0: 24 53 51 4c 49 54 45 5f 4d 41 58 5f 4c 45 4e 47  $SQLITE_MAX_LENG
0cf0: 54 48 20 2d 20 31 30 7d 5d 5d 0a 20 20 63 61 74  TH - 10}]].  cat
0d00: 63 68 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 71  chsql { SELECT q
0d10: 75 6f 74 65 28 24 3a 3a 73 74 72 31 29 20 7d 0a  uote($::str1) }.
0d20: 7d 20 7b 31 20 7b 73 74 72 69 6e 67 20 6f 72 20  } {1 {string or 
0d30: 62 6c 6f 62 20 74 6f 6f 20 62 69 67 7d 7d 0a 0a  blob too big}}..
0d40: 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74  do_test sqllimit
0d50: 73 2d 31 2e 31 33 20 7b 0a 20 20 73 65 74 20 3a  s-1.13 {.  set :
0d60: 3a 73 74 72 31 20 5b 73 74 72 69 6e 67 20 72 65  :str1 [string re
0d70: 70 65 61 74 20 27 20 5b 65 78 70 72 20 7b 24 53  peat ' [expr {$S
0d80: 51 4c 49 54 45 5f 4d 41 58 5f 4c 45 4e 47 54 48  QLITE_MAX_LENGTH
0d90: 20 2d 20 31 30 7d 5d 5d 0a 20 20 63 61 74 63 68   - 10}]].  catch
0da0: 73 71 6c 20 7b 20 53 45 4c 45 43 54 20 68 65 78  sql { SELECT hex
0db0: 28 24 3a 3a 73 74 72 31 29 20 7d 0a 7d 20 7b 31  ($::str1) }.} {1
0dc0: 20 7b 73 74 72 69 6e 67 20 6f 72 20 62 6c 6f 62   {string or blob
0dd0: 20 74 6f 6f 20 62 69 67 7d 7d 0a 0a 64 6f 5f 74   too big}}..do_t
0de0: 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e  est sqllimits-1.
0df0: 31 34 2e 31 20 7b 0a 20 20 73 65 74 20 3a 3a 53  14.1 {.  set ::S
0e00: 54 4d 54 20 5b 73 71 6c 69 74 65 33 5f 70 72 65  TMT [sqlite3_pre
0e10: 70 61 72 65 20 24 3a 3a 44 42 20 22 53 45 4c 45  pare $::DB "SELE
0e20: 43 54 20 3f 22 20 2d 31 20 54 41 49 4c 5d 0a 20  CT ?" -1 TAIL]. 
0e30: 20 73 71 6c 69 74 65 33 5f 62 69 6e 64 5f 7a 65   sqlite3_bind_ze
0e40: 72 6f 62 6c 6f 62 20 24 3a 3a 53 54 4d 54 20 31  roblob $::STMT 1
0e50: 20 5b 65 78 70 72 20 7b 24 53 51 4c 49 54 45 5f   [expr {$SQLITE_
0e60: 4d 41 58 5f 4c 45 4e 47 54 48 20 2b 20 31 7d 5d  MAX_LENGTH + 1}]
0e70: 0a 7d 20 7b 7d 0a 64 6f 5f 74 65 73 74 20 73 71  .} {}.do_test sq
0e80: 6c 6c 69 6d 69 74 73 2d 31 2e 31 34 2e 32 20 7b  llimits-1.14.2 {
0e90: 0a 20 20 73 71 6c 69 74 65 33 5f 73 74 65 70 20  .  sqlite3_step 
0ea0: 24 3a 3a 53 54 4d 54 20 0a 7d 20 7b 53 51 4c 49  $::STMT .} {SQLI
0eb0: 54 45 5f 45 52 52 4f 52 7d 0a 64 6f 5f 74 65 73  TE_ERROR}.do_tes
0ec0: 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 31 34  t sqllimits-1.14
0ed0: 2e 33 20 7b 0a 20 20 73 71 6c 69 74 65 33 5f 66  .3 {.  sqlite3_f
0ee0: 69 6e 61 6c 69 7a 65 20 24 3a 3a 53 54 4d 54 20  inalize $::STMT 
0ef0: 0a 7d 20 7b 53 51 4c 49 54 45 5f 54 4f 4f 42 49  .} {SQLITE_TOOBI
0f00: 47 7d 0a 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c  G}..do_test sqll
0f10: 69 6d 69 74 73 2d 31 2e 31 35 20 7b 0a 20 20 65  imits-1.15 {.  e
0f20: 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45  xecsql {.    CRE
0f30: 41 54 45 20 54 41 42 4c 45 20 74 34 28 78 29 3b  ATE TABLE t4(x);
0f40: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
0f50: 20 74 34 20 56 41 4c 55 45 53 28 31 29 3b 0a 20   t4 VALUES(1);. 
0f60: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74     INSERT INTO t
0f70: 34 20 56 41 4c 55 45 53 28 32 29 3b 0a 20 20 20  4 VALUES(2);.   
0f80: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 34 20   INSERT INTO t4 
0f90: 53 45 4c 45 43 54 20 32 2b 78 20 46 52 4f 4d 20  SELECT 2+x FROM 
0fa0: 74 34 3b 0a 20 20 7d 0a 20 20 63 61 74 63 68 73  t4;.  }.  catchs
0fb0: 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20  ql {.    SELECT 
0fc0: 67 72 6f 75 70 5f 63 6f 6e 63 61 74 28 68 65 78  group_concat(hex
0fd0: 28 72 61 6e 64 6f 6d 62 6c 6f 62 28 32 30 30 30  (randomblob(2000
0fe0: 30 29 29 29 20 46 52 4f 4d 20 74 34 3b 0a 20 20  0))) FROM t4;.  
0ff0: 7d 0a 7d 20 7b 31 20 7b 73 74 72 69 6e 67 20 6f  }.} {1 {string o
1000: 72 20 62 6c 6f 62 20 74 6f 6f 20 62 69 67 7d 7d  r blob too big}}
1010: 0a 64 62 20 65 76 61 6c 20 7b 44 52 4f 50 20 54  .db eval {DROP T
1020: 41 42 4c 45 20 74 34 7d 0a 0a 73 65 74 20 3a 3a  ABLE t4}..set ::
1030: 53 51 4c 49 54 45 5f 4d 41 58 5f 53 51 4c 5f 4c  SQLITE_MAX_SQL_L
1040: 45 4e 47 54 48 20 30 0a 73 65 74 20 73 74 72 76  ENGTH 0.set strv
1050: 61 6c 75 65 20 5b 73 74 72 69 6e 67 20 72 65 70  alue [string rep
1060: 65 61 74 20 41 20 24 3a 3a 53 51 4c 49 54 45 5f  eat A $::SQLITE_
1070: 4d 41 58 5f 4c 45 4e 47 54 48 5d 0a 64 6f 5f 74  MAX_LENGTH].do_t
1080: 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e  est sqllimits-1.
1090: 31 36 20 7b 0a 20 20 63 61 74 63 68 73 71 6c 20  16 {.  catchsql 
10a0: 22 53 45 4c 45 43 54 20 27 24 73 74 72 76 61 6c  "SELECT '$strval
10b0: 75 65 27 22 0a 7d 20 5b 6c 69 73 74 20 30 20 24  ue'".} [list 0 $
10c0: 73 74 72 76 61 6c 75 65 5d 0a 64 6f 5f 74 65 73  strvalue].do_tes
10d0: 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 31 37  t sqllimits-1.17
10e0: 20 7b 0a 20 20 63 61 74 63 68 73 71 6c 20 22 53   {.  catchsql "S
10f0: 45 4c 45 43 54 20 27 41 24 73 74 72 76 61 6c 75  ELECT 'A$strvalu
1100: 65 27 22 0a 7d 20 5b 6c 69 73 74 20 31 20 7b 73  e'".} [list 1 {s
1110: 74 72 69 6e 67 20 6f 72 20 62 6c 6f 62 20 74 6f  tring or blob to
1120: 6f 20 62 69 67 7d 5d 0a 73 65 74 20 62 6c 6f 62  o big}].set blob
1130: 76 61 6c 75 65 20 5b 73 74 72 69 6e 67 20 72 65  value [string re
1140: 70 65 61 74 20 34 31 20 24 3a 3a 53 51 4c 49 54  peat 41 $::SQLIT
1150: 45 5f 4d 41 58 5f 4c 45 4e 47 54 48 5d 0a 64 6f  E_MAX_LENGTH].do
1160: 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d  _test sqllimits-
1170: 31 2e 31 38 20 7b 0a 20 20 63 61 74 63 68 73 71  1.18 {.  catchsq
1180: 6c 20 22 53 45 4c 45 43 54 20 78 27 24 62 6c 6f  l "SELECT x'$blo
1190: 62 76 61 6c 75 65 27 22 0a 7d 20 5b 6c 69 73 74  bvalue'".} [list
11a0: 20 30 20 24 73 74 72 76 61 6c 75 65 5d 0a 64 6f   0 $strvalue].do
11b0: 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d  _test sqllimits-
11c0: 31 2e 31 39 20 7b 0a 20 20 63 61 74 63 68 73 71  1.19 {.  catchsq
11d0: 6c 20 22 53 45 4c 45 43 54 20 27 34 31 24 62 6c  l "SELECT '41$bl
11e0: 6f 62 76 61 6c 75 65 27 22 0a 7d 20 5b 6c 69 73  obvalue'".} [lis
11f0: 74 20 31 20 7b 73 74 72 69 6e 67 20 6f 72 20 62  t 1 {string or b
1200: 6c 6f 62 20 74 6f 6f 20 62 69 67 7d 5d 0a 75 6e  lob too big}].un
1210: 73 65 74 20 73 74 72 76 61 6c 75 65 0a 75 6e 73  set strvalue.uns
1220: 65 74 20 62 6c 6f 62 76 61 6c 75 65 0a 0a 23 2d  et blobvalue..#-
1230: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1240: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1250: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1260: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1270: 2d 2d 2d 0a 23 20 54 65 73 74 20 63 61 73 65 73  ---.# Test cases
1280: 20 73 71 6c 6c 69 6d 69 74 73 2d 32 2e 2a 20 74   sqllimits-2.* t
1290: 65 73 74 20 74 68 61 74 20 74 68 65 20 53 51 4c  est that the SQL
12a0: 49 54 45 5f 4d 41 58 5f 53 51 4c 5f 4c 45 4e 47  ITE_MAX_SQL_LENG
12b0: 54 48 20 6c 69 6d 69 74 0a 23 20 69 73 20 65 6e  TH limit.# is en
12c0: 66 6f 72 63 65 64 2e 0a 23 0a 64 6f 5f 74 65 73  forced..#.do_tes
12d0: 74 20 73 71 6c 6c 69 6d 69 74 73 2d 32 2e 31 20  t sqllimits-2.1 
12e0: 7b 0a 20 20 73 65 74 20 3a 3a 53 51 4c 49 54 45  {.  set ::SQLITE
12f0: 5f 4d 41 58 5f 53 51 4c 5f 4c 45 4e 47 54 48 20  _MAX_SQL_LENGTH 
1300: 35 30 30 30 30 0a 20 20 73 65 74 20 73 71 6c 20  50000.  set sql 
1310: 22 53 45 4c 45 43 54 20 31 20 57 48 45 52 45 20  "SELECT 1 WHERE 
1320: 31 3d 3d 31 22 0a 20 20 73 65 74 20 74 61 69 6c  1==1".  set tail
1330: 20 22 20 2f 2a 20 41 20 63 6f 6d 6d 65 6e 74 20   " /* A comment 
1340: 74 6f 20 74 61 6b 65 20 75 70 20 73 70 61 63 65  to take up space
1350: 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 6d 61 6b   in order to mak
1360: 65 20 74 68 65 20 73 74 72 69 6e 67 5c 0a 20 20  e the string\.  
1370: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 6c 6f                lo
1380: 6e 67 65 72 20 77 69 74 68 6f 75 74 20 69 6e 63  nger without inc
1390: 72 65 61 73 69 6e 67 20 74 68 65 20 65 78 70 72  reasing the expr
13a0: 65 73 73 69 6f 6e 20 64 65 70 74 68 20 2a 2f 5c  ession depth */\
13b0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20  .               
13c0: 20 41 4e 44 20 20 20 31 20 20 3d 3d 20 20 31 22   AND   1  ==  1"
13d0: 0a 20 20 73 65 74 20 4e 20 5b 65 78 70 72 20 7b  .  set N [expr {
13e0: 28 24 3a 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 53  ($::SQLITE_MAX_S
13f0: 51 4c 5f 4c 45 4e 47 54 48 20 2f 20 5b 73 74 72  QL_LENGTH / [str
1400: 69 6e 67 20 6c 65 6e 67 74 68 20 24 74 61 69 6c  ing length $tail
1410: 5d 29 2b 31 7d 5d 0a 20 20 61 70 70 65 6e 64 20  ])+1}].  append 
1420: 73 71 6c 20 5b 73 74 72 69 6e 67 20 72 65 70 65  sql [string repe
1430: 61 74 20 24 74 61 69 6c 20 24 4e 5d 0a 20 20 63  at $tail $N].  c
1440: 61 74 63 68 73 71 6c 20 24 73 71 6c 0a 7d 20 7b  atchsql $sql.} {
1450: 31 20 7b 53 74 72 69 6e 67 20 6f 72 20 42 4c 4f  1 {String or BLO
1460: 42 20 65 78 63 65 65 64 65 64 20 73 69 7a 65 20  B exceeded size 
1470: 6c 69 6d 69 74 7d 7d 0a 64 6f 5f 74 65 73 74 20  limit}}.do_test 
1480: 73 71 6c 6c 69 6d 69 74 73 2d 32 2e 32 20 7b 0a  sqllimits-2.2 {.
1490: 20 20 73 65 74 20 3a 3a 53 51 4c 49 54 45 5f 4d    set ::SQLITE_M
14a0: 41 58 5f 53 51 4c 5f 4c 45 4e 47 54 48 20 30 0a  AX_SQL_LENGTH 0.
14b0: 20 20 63 61 74 63 68 73 71 6c 20 24 73 71 6c 0a    catchsql $sql.
14c0: 7d 20 7b 30 20 31 7d 0a 0a 23 2d 2d 2d 2d 2d 2d  } {0 1}..#------
14d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
14f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
1500: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23  --------------.#
1510: 20 54 65 73 74 20 63 61 73 65 73 20 73 71 6c 6c   Test cases sqll
1520: 69 6d 69 74 73 2d 33 2e 2a 20 74 65 73 74 20 74  imits-3.* test t
1530: 68 61 74 20 74 68 65 20 6c 69 6d 69 74 20 73 65  hat the limit se
1540: 74 20 75 73 69 6e 67 20 74 68 65 0a 23 20 6d 61  t using the.# ma
1550: 78 5f 70 61 67 65 5f 63 6f 75 6e 74 20 70 72 61  x_page_count pra
1560: 67 6d 61 2e 0a 23 0a 64 6f 5f 74 65 73 74 20 73  gma..#.do_test s
1570: 71 6c 6c 69 6d 69 74 73 2d 33 2e 31 20 7b 0a 20  qllimits-3.1 {. 
1580: 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 50   execsql {.    P
1590: 52 41 47 4d 41 20 6d 61 78 5f 70 61 67 65 5f 63  RAGMA max_page_c
15a0: 6f 75 6e 74 20 3d 20 31 30 30 30 3b 0a 20 20 7d  ount = 1000;.  }
15b0: 0a 7d 20 7b 31 30 30 30 7d 0a 64 6f 5f 74 65 73  .} {1000}.do_tes
15c0: 74 20 73 71 6c 6c 69 6d 69 74 73 2d 33 2e 32 20  t sqllimits-3.2 
15d0: 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 20 43 52  {.  execsql { CR
15e0: 45 41 54 45 20 54 41 42 4c 45 20 74 72 69 67 20  EATE TABLE trig 
15f0: 28 61 20 49 4e 54 45 47 45 52 2c 20 62 20 49 4e  (a INTEGER, b IN
1600: 54 45 47 45 52 29 3b 20 7d 0a 0a 20 20 23 20 53  TEGER); }..  # S
1610: 65 74 20 75 70 20 61 20 74 72 65 65 20 6f 66 20  et up a tree of 
1620: 74 72 69 67 67 65 72 73 20 74 6f 20 66 69 72 65  triggers to fire
1630: 20 77 68 65 6e 20 61 20 72 6f 77 20 69 73 20 69   when a row is i
1640: 6e 73 65 72 74 65 64 0a 20 20 23 20 69 6e 74 6f  nserted.  # into
1650: 20 74 61 62 6c 65 20 22 74 72 69 67 22 2e 0a 20   table "trig".. 
1660: 20 23 0a 20 20 23 20 49 4e 53 45 52 54 20 2d 3e   #.  # INSERT ->
1670: 20 69 6e 73 65 72 74 5f 62 20 2d 3e 20 75 70 64   insert_b -> upd
1680: 61 74 65 5f 62 20 2d 3e 20 69 6e 73 65 72 74 5f  ate_b -> insert_
1690: 61 20 2d 3e 20 75 70 64 61 74 65 5f 61 20 20 20  a -> update_a   
16a0: 20 20 20 28 63 68 61 69 6e 20 31 29 0a 20 20 23     (chain 1).  #
16b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
16c0: 20 20 20 20 2d 3e 20 75 70 64 61 74 65 5f 61 20      -> update_a 
16d0: 2d 3e 20 69 6e 73 65 72 74 5f 61 20 2d 3e 20 75  -> insert_a -> u
16e0: 70 64 61 74 65 5f 62 20 20 20 20 20 20 28 63 68  pdate_b      (ch
16f0: 61 69 6e 20 32 29 0a 20 20 23 20 20 20 20 20 20  ain 2).  #      
1700: 20 20 2d 3e 20 69 6e 73 65 72 74 5f 61 20 2d 3e    -> insert_a ->
1710: 20 75 70 64 61 74 65 5f 62 20 2d 3e 20 69 6e 73   update_b -> ins
1720: 65 72 74 5f 62 20 2d 3e 20 75 70 64 61 74 65 5f  ert_b -> update_
1730: 61 20 20 20 20 20 20 28 63 68 61 69 6e 20 33 29  a      (chain 3)
1740: 0a 20 20 23 20 20 20 20 20 20 20 20 20 20 20 20  .  #            
1750: 20 20 20 20 20 20 20 20 2d 3e 20 75 70 64 61 74          -> updat
1760: 65 5f 61 20 2d 3e 20 69 6e 73 65 72 74 5f 62 20  e_a -> insert_b 
1770: 2d 3e 20 75 70 64 61 74 65 5f 62 20 20 20 20 20  -> update_b     
1780: 20 28 63 68 61 69 6e 20 34 29 0a 20 20 23 0a 20   (chain 4).  #. 
1790: 20 23 20 54 61 62 6c 65 20 73 74 61 72 74 73 20   # Table starts 
17a0: 77 69 74 68 20 4e 20 72 6f 77 73 2e 0a 20 20 23  with N rows..  #
17b0: 0a 20 20 23 20 20 20 43 68 61 69 6e 20 31 3a 20  .  #   Chain 1: 
17c0: 69 6e 73 65 72 74 5f 62 20 28 75 70 64 61 74 65  insert_b (update
17d0: 20 4e 20 72 6f 77 73 29 0a 20 20 23 20 20 20 20   N rows).  #    
17e0: 20 20 20 20 20 20 20 20 20 20 2d 3e 20 75 70 64            -> upd
17f0: 61 74 65 5f 62 20 28 69 6e 73 65 72 74 20 31 20  ate_b (insert 1 
1800: 72 6f 77 73 29 0a 20 20 23 20 20 20 20 20 20 20  rows).  #       
1810: 20 20 20 20 20 20 20 20 20 2d 3e 20 69 6e 73 65           -> inse
1820: 72 74 5f 61 20 28 75 70 64 61 74 65 20 4e 20 72  rt_a (update N r
1830: 6f 77 73 29 0a 20 20 23 20 20 20 20 20 20 20 20  ows).  #        
1840: 20 20 20 20 20 20 20 20 20 20 2d 3e 20 75 70 64            -> upd
1850: 61 74 65 5f 61 20 28 69 6e 73 65 72 74 20 31 20  ate_a (insert 1 
1860: 72 6f 77 73 29 0a 20 20 23 0a 20 20 23 20 63 68  rows).  #.  # ch
1870: 61 69 6e 73 20 32 2c 20 33 20 61 6e 64 20 34 20  ains 2, 3 and 4 
1880: 61 72 65 20 73 69 6d 69 6c 61 72 2e 20 45 61 63  are similar. Eac
1890: 68 20 69 6e 73 65 72 74 73 20 6d 6f 72 65 20 74  h inserts more t
18a0: 68 61 6e 20 4e 5e 32 20 72 6f 77 73 2c 20 77 68  han N^2 rows, wh
18b0: 65 72 65 0a 20 20 23 20 4e 20 69 73 20 74 68 65  ere.  # N is the
18c0: 20 6e 75 6d 62 65 72 20 6f 66 20 72 6f 77 73 20   number of rows 
18d0: 61 74 20 74 68 65 20 63 6f 6e 63 6c 75 73 69 6f  at the conclusio
18e0: 6e 20 6f 66 20 74 68 65 20 70 72 65 76 69 6f 75  n of the previou
18f0: 73 20 63 68 61 69 6e 2e 0a 20 20 23 0a 20 20 23  s chain..  #.  #
1900: 20 54 68 65 72 65 66 6f 72 65 2c 20 61 20 73 69   Therefore, a si
1910: 6e 67 6c 65 20 69 6e 73 65 72 74 20 61 64 64 73  ngle insert adds
1920: 20 28 4e 5e 31 36 20 70 6c 75 73 20 73 6f 6d 65   (N^16 plus some
1930: 29 20 72 6f 77 73 20 74 6f 20 74 68 65 20 64 61  ) rows to the da
1940: 74 61 62 61 73 65 2e 0a 20 20 23 20 41 20 72 65  tabase..  # A re
1950: 61 6c 6c 79 20 6c 6f 6e 67 20 6c 6f 6f 70 2e 2e  ally long loop..
1960: 2e 0a 20 20 23 20 20 20 20 20 0a 20 20 65 78 65  ..  #     .  exe
1970: 63 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41 54  csql {.    CREAT
1980: 45 20 54 52 49 47 47 45 52 20 75 70 64 61 74 65  E TRIGGER update
1990: 5f 62 20 42 45 46 4f 52 45 20 55 50 44 41 54 45  _b BEFORE UPDATE
19a0: 20 4f 4e 20 74 72 69 67 0a 20 20 20 20 20 20 46   ON trig.      F
19b0: 4f 52 20 45 41 43 48 20 52 4f 57 20 42 45 47 49  OR EACH ROW BEGI
19c0: 4e 0a 20 20 20 20 20 20 20 20 49 4e 53 45 52 54  N.        INSERT
19d0: 20 49 4e 54 4f 20 74 72 69 67 20 56 41 4c 55 45   INTO trig VALUE
19e0: 53 20 28 36 35 2c 20 27 75 70 64 61 74 65 5f 62  S (65, 'update_b
19f0: 27 29 3b 0a 20 20 20 20 20 20 45 4e 44 3b 0a 0a  ');.      END;..
1a00: 20 20 20 20 43 52 45 41 54 45 20 54 52 49 47 47      CREATE TRIGG
1a10: 45 52 20 75 70 64 61 74 65 5f 61 20 41 46 54 45  ER update_a AFTE
1a20: 52 20 55 50 44 41 54 45 20 4f 4e 20 74 72 69 67  R UPDATE ON trig
1a30: 0a 20 20 20 20 20 20 46 4f 52 20 45 41 43 48 20  .      FOR EACH 
1a40: 52 4f 57 20 42 45 47 49 4e 0a 20 20 20 20 20 20  ROW BEGIN.      
1a50: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 72    INSERT INTO tr
1a60: 69 67 20 56 41 4c 55 45 53 20 28 36 35 2c 20 27  ig VALUES (65, '
1a70: 75 70 64 61 74 65 5f 61 27 29 3b 0a 20 20 20 20  update_a');.    
1a80: 20 20 45 4e 44 3b 0a 0a 20 20 20 20 43 52 45 41    END;..    CREA
1a90: 54 45 20 54 52 49 47 47 45 52 20 69 6e 73 65 72  TE TRIGGER inser
1aa0: 74 5f 62 20 42 45 46 4f 52 45 20 49 4e 53 45 52  t_b BEFORE INSER
1ab0: 54 20 4f 4e 20 74 72 69 67 0a 20 20 20 20 20 20  T ON trig.      
1ac0: 46 4f 52 20 45 41 43 48 20 52 4f 57 20 42 45 47  FOR EACH ROW BEG
1ad0: 49 4e 0a 20 20 20 20 20 20 20 20 55 50 44 41 54  IN.        UPDAT
1ae0: 45 20 74 72 69 67 20 53 45 54 20 61 20 3d 20 31  E trig SET a = 1
1af0: 3b 0a 20 20 20 20 20 20 45 4e 44 3b 0a 0a 20 20  ;.      END;..  
1b00: 20 20 43 52 45 41 54 45 20 54 52 49 47 47 45 52    CREATE TRIGGER
1b10: 20 69 6e 73 65 72 74 5f 61 20 41 46 54 45 52 20   insert_a AFTER 
1b20: 49 4e 53 45 52 54 20 4f 4e 20 74 72 69 67 0a 20  INSERT ON trig. 
1b30: 20 20 20 20 20 46 4f 52 20 45 41 43 48 20 52 4f       FOR EACH RO
1b40: 57 20 42 45 47 49 4e 0a 20 20 20 20 20 20 20 20  W BEGIN.        
1b50: 55 50 44 41 54 45 20 74 72 69 67 20 53 45 54 20  UPDATE trig SET 
1b60: 61 20 3d 20 31 3b 0a 20 20 20 20 20 20 45 4e 44  a = 1;.      END
1b70: 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 64 6f 5f 74  ;.  }.} {}..do_t
1b80: 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 31 2d 33  est sqllimits1-3
1b90: 2e 33 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .3 {.  execsql {
1ba0: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
1bb0: 20 74 72 69 67 20 56 41 4c 55 45 53 20 28 31 2c   trig VALUES (1,
1bc0: 31 29 3b 20 0a 20 20 7d 0a 7d 20 7b 7d 0a 0a 64  1); .  }.} {}..d
1bd0: 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73  o_test sqllimits
1be0: 31 2d 33 2e 34 20 7b 0a 20 20 65 78 65 63 73 71  1-3.4 {.  execsq
1bf0: 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20 43  l {.    SELECT C
1c00: 4f 55 4e 54 28 2a 29 20 46 52 4f 4d 20 74 72 69  OUNT(*) FROM tri
1c10: 67 3b 0a 20 20 7d 0a 7d 20 7b 37 7d 0a 0a 23 20  g;.  }.} {7}..# 
1c20: 54 68 69 73 20 74 72 69 65 73 20 74 6f 20 69 6e  This tries to in
1c30: 73 65 72 74 20 73 6f 20 6d 61 6e 79 20 72 6f 77  sert so many row
1c40: 73 20 69 74 20 66 69 6c 6c 73 20 75 70 20 74 68  s it fills up th
1c50: 65 20 64 61 74 61 62 61 73 65 20 28 6c 69 6d 69  e database (limi
1c60: 74 65 64 0a 23 20 74 6f 20 31 4d 42 2c 20 73 6f  ted.# to 1MB, so
1c70: 20 6e 6f 74 20 74 68 61 74 20 6e 6f 74 65 77 6f   not that notewo
1c80: 72 74 68 79 20 61 6e 20 61 63 68 69 65 76 65 6d  rthy an achievem
1c90: 65 6e 74 29 2e 0a 23 0a 64 6f 5f 74 65 73 74 20  ent)..#.do_test 
1ca0: 73 71 6c 6c 69 6d 69 74 73 31 2d 33 2e 35 20 7b  sqllimits1-3.5 {
1cb0: 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20 20  .  catchsql {.  
1cc0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 72    INSERT INTO tr
1cd0: 69 67 20 56 41 4c 55 45 53 20 28 31 2c 31 30 29  ig VALUES (1,10)
1ce0: 3b 0a 20 20 7d 0a 7d 20 7b 31 20 7b 64 61 74 61  ;.  }.} {1 {data
1cf0: 62 61 73 65 20 6f 72 20 64 69 73 6b 20 69 73 20  base or disk is 
1d00: 66 75 6c 6c 7d 7d 0a 0a 64 6f 5f 74 65 73 74 20  full}}..do_test 
1d10: 73 71 6c 6c 69 6d 69 74 73 31 2d 33 2e 36 20 7b  sqllimits1-3.6 {
1d20: 0a 20 20 63 61 74 63 68 73 71 6c 20 7b 0a 20 20  .  catchsql {.  
1d30: 20 20 53 45 4c 45 43 54 20 43 4f 55 4e 54 28 2a    SELECT COUNT(*
1d40: 29 20 46 52 4f 4d 20 74 72 69 67 3b 0a 20 20 7d  ) FROM trig;.  }
1d50: 0a 7d 20 7b 30 20 37 7d 0a 0a 23 20 4e 6f 77 20  .} {0 7}..# Now 
1d60: 63 68 65 63 6b 20 74 68 65 20 72 65 73 70 6f 6e  check the respon
1d70: 73 65 20 6f 66 20 74 68 65 20 6c 69 62 72 61 72  se of the librar
1d80: 79 20 74 6f 20 6f 70 65 6e 69 6e 67 20 61 20 66  y to opening a f
1d90: 69 6c 65 20 6c 61 72 67 65 72 20 74 68 61 6e 0a  ile larger than.
1da0: 23 20 74 68 65 20 63 75 72 72 65 6e 74 20 6d 61  # the current ma
1db0: 78 5f 70 61 67 65 5f 63 6f 75 6e 74 20 76 61 6c  x_page_count val
1dc0: 75 65 2e 20 54 68 65 20 72 65 73 70 6f 6e 73 65  ue. The response
1dd0: 20 69 73 20 74 6f 20 63 68 61 6e 67 65 20 74 68   is to change th
1de0: 65 0a 23 20 69 6e 74 65 72 6e 61 6c 20 6d 61 78  e.# internal max
1df0: 5f 70 61 67 65 5f 63 6f 75 6e 74 20 76 61 6c 75  _page_count valu
1e00: 65 20 74 6f 20 6d 61 74 63 68 20 74 68 65 20 61  e to match the a
1e10: 63 74 75 61 6c 20 73 69 7a 65 20 6f 66 20 74 68  ctual size of th
1e20: 65 20 66 69 6c 65 2e 0a 64 6f 5f 74 65 73 74 20  e file..do_test 
1e30: 73 71 6c 6c 69 6d 69 74 73 31 2d 33 2e 37 2e 31  sqllimits1-3.7.1
1e40: 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20   {.  execsql {. 
1e50: 20 20 20 50 52 41 47 4d 41 20 6d 61 78 5f 70 61     PRAGMA max_pa
1e60: 67 65 5f 63 6f 75 6e 74 20 3d 20 31 30 30 30 30  ge_count = 10000
1e70: 30 30 3b 0a 20 20 20 20 43 52 45 41 54 45 20 54  00;.    CREATE T
1e80: 41 42 4c 45 20 61 62 63 28 61 2c 20 62 2c 20 63  ABLE abc(a, b, c
1e90: 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  );.    INSERT IN
1ea0: 54 4f 20 61 62 63 20 56 41 4c 55 45 53 28 31 2c  TO abc VALUES(1,
1eb0: 20 32 2c 20 33 29 3b 0a 20 20 20 20 49 4e 53 45   2, 3);.    INSE
1ec0: 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45  RT INTO abc SELE
1ed0: 43 54 20 61 7c 7c 62 7c 7c 63 2c 20 62 7c 7c 63  CT a||b||c, b||c
1ee0: 7c 7c 61 2c 20 63 7c 7c 61 7c 7c 62 20 46 52 4f  ||a, c||a||b FRO
1ef0: 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e 53 45 52  M abc;.    INSER
1f00: 54 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43  T INTO abc SELEC
1f10: 54 20 61 7c 7c 62 7c 7c 63 2c 20 62 7c 7c 63 7c  T a||b||c, b||c|
1f20: 7c 61 2c 20 63 7c 7c 61 7c 7c 62 20 46 52 4f 4d  |a, c||a||b FROM
1f30: 20 61 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54   abc;.    INSERT
1f40: 20 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54   INTO abc SELECT
1f50: 20 61 7c 7c 62 7c 7c 63 2c 20 62 7c 7c 63 7c 7c   a||b||c, b||c||
1f60: 61 2c 20 63 7c 7c 61 7c 7c 62 20 46 52 4f 4d 20  a, c||a||b FROM 
1f70: 61 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20  abc;.    INSERT 
1f80: 49 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20  INTO abc SELECT 
1f90: 61 7c 7c 62 7c 7c 63 2c 20 62 7c 7c 63 7c 7c 61  a||b||c, b||c||a
1fa0: 2c 20 63 7c 7c 61 7c 7c 62 20 46 52 4f 4d 20 61  , c||a||b FROM a
1fb0: 62 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49  bc;.    INSERT I
1fc0: 4e 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 61  NTO abc SELECT a
1fd0: 7c 7c 62 7c 7c 63 2c 20 62 7c 7c 63 7c 7c 61 2c  ||b||c, b||c||a,
1fe0: 20 63 7c 7c 61 7c 7c 62 20 46 52 4f 4d 20 61 62   c||a||b FROM ab
1ff0: 63 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e  c;.    INSERT IN
2000: 54 4f 20 61 62 63 20 53 45 4c 45 43 54 20 61 7c  TO abc SELECT a|
2010: 7c 62 7c 7c 63 2c 20 62 7c 7c 63 7c 7c 61 2c 20  |b||c, b||c||a, 
2020: 63 7c 7c 61 7c 7c 62 20 46 52 4f 4d 20 61 62 63  c||a||b FROM abc
2030: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54  ;.    INSERT INT
2040: 4f 20 61 62 63 20 53 45 4c 45 43 54 20 61 7c 7c  O abc SELECT a||
2050: 62 7c 7c 63 2c 20 62 7c 7c 63 7c 7c 61 2c 20 63  b||c, b||c||a, c
2060: 7c 7c 61 7c 7c 62 20 46 52 4f 4d 20 61 62 63 3b  ||a||b FROM abc;
2070: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
2080: 20 61 62 63 20 53 45 4c 45 43 54 20 61 7c 7c 62   abc SELECT a||b
2090: 7c 7c 63 2c 20 62 7c 7c 63 7c 7c 61 2c 20 63 7c  ||c, b||c||a, c|
20a0: 7c 61 7c 7c 62 20 46 52 4f 4d 20 61 62 63 3b 0a  |a||b FROM abc;.
20b0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20      INSERT INTO 
20c0: 61 62 63 20 53 45 4c 45 43 54 20 61 2c 20 62 2c  abc SELECT a, b,
20d0: 20 63 20 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20   c FROM abc;.   
20e0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 61 62 63   INSERT INTO abc
20f0: 20 53 45 4c 45 43 54 20 62 2c 20 61 2c 20 63 20   SELECT b, a, c 
2100: 46 52 4f 4d 20 61 62 63 3b 0a 20 20 20 20 49 4e  FROM abc;.    IN
2110: 53 45 52 54 20 49 4e 54 4f 20 61 62 63 20 53 45  SERT INTO abc SE
2120: 4c 45 43 54 20 63 2c 20 62 2c 20 61 20 46 52 4f  LECT c, b, a FRO
2130: 4d 20 61 62 63 3b 0a 20 20 7d 0a 20 20 65 78 70  M abc;.  }.  exp
2140: 72 20 5b 66 69 6c 65 20 73 69 7a 65 20 74 65 73  r [file size tes
2150: 74 2e 64 62 5d 20 2f 20 31 30 32 34 0a 7d 20 7b  t.db] / 1024.} {
2160: 31 36 39 31 7d 0a 64 6f 5f 74 65 73 74 20 73 71  1691}.do_test sq
2170: 6c 6c 69 6d 69 74 73 31 2d 33 2e 37 2e 32 20 7b  llimits1-3.7.2 {
2180: 0a 20 20 64 62 20 63 6c 6f 73 65 0a 20 20 73 71  .  db close.  sq
2190: 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e 64 62  lite3 db test.db
21a0: 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20 20  .  execsql {.   
21b0: 20 50 52 41 47 4d 41 20 6d 61 78 5f 70 61 67 65   PRAGMA max_page
21c0: 5f 63 6f 75 6e 74 20 3d 20 31 30 30 30 3b 0a 20  _count = 1000;. 
21d0: 20 7d 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20   }.  execsql {. 
21e0: 20 20 20 53 45 4c 45 43 54 20 63 6f 75 6e 74 28     SELECT count(
21f0: 2a 29 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d  *) FROM sqlite_m
2200: 61 73 74 65 72 3b 0a 20 20 7d 0a 7d 20 7b 36 7d  aster;.  }.} {6}
2210: 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69  .do_test sqllimi
2220: 74 73 31 2d 33 2e 37 2e 33 20 7b 0a 20 20 65 78  ts1-3.7.3 {.  ex
2230: 65 63 73 71 6c 20 7b 0a 20 20 20 20 50 52 41 47  ecsql {.    PRAG
2240: 4d 41 20 6d 61 78 5f 70 61 67 65 5f 63 6f 75 6e  MA max_page_coun
2250: 74 3b 0a 20 20 7d 0a 7d 20 7b 31 36 39 31 7d 0a  t;.  }.} {1691}.
2260: 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74  do_test sqllimit
2270: 73 31 2d 33 2e 37 2e 34 20 7b 0a 20 20 65 78 65  s1-3.7.4 {.  exe
2280: 63 73 71 6c 20 7b 0a 20 20 20 20 44 52 4f 50 20  csql {.    DROP 
2290: 54 41 42 4c 45 20 61 62 63 3b 0a 20 20 7d 0a 7d  TABLE abc;.  }.}
22a0: 20 7b 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   {}..#----------
22b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
22c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
22d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
22e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73  ----------.# Tes
22f0: 74 20 63 61 73 65 73 20 73 71 6c 6c 69 6d 69 74  t cases sqllimit
2300: 73 31 2d 34 2e 2a 20 74 65 73 74 20 74 68 65 20  s1-4.* test the 
2310: 53 51 4c 49 54 45 5f 4d 41 58 5f 43 4f 4c 55 4d  SQLITE_MAX_COLUM
2320: 4e 20 6c 69 6d 69 74 2e 0a 23 0a 64 6f 5f 74 65  N limit..#.do_te
2330: 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 34  st sqllimits-1.4
2340: 2e 31 20 7b 0a 20 20 23 20 43 6f 6c 75 6d 6e 73  .1 {.  # Columns
2350: 20 69 6e 20 61 20 74 61 62 6c 65 2e 0a 20 20 73   in a table..  s
2360: 65 74 20 63 6f 6c 73 20 5b 6c 69 73 74 5d 0a 20  et cols [list]. 
2370: 20 66 6f 72 20 7b 73 65 74 20 69 20 30 7d 20 7b   for {set i 0} {
2380: 24 69 20 3c 3d 20 24 53 51 4c 49 54 45 5f 4d 41  $i <= $SQLITE_MA
2390: 58 5f 43 4f 4c 55 4d 4e 7d 20 7b 69 6e 63 72 20  X_COLUMN} {incr 
23a0: 69 7d 20 7b 0a 20 20 20 20 6c 61 70 70 65 6e 64  i} {.    lappend
23b0: 20 63 6f 6c 73 20 22 63 24 69 22 0a 20 20 7d 0a   cols "c$i".  }.
23c0: 20 20 63 61 74 63 68 73 71 6c 20 22 43 52 45 41    catchsql "CREA
23d0: 54 45 20 54 41 42 4c 45 20 74 28 5b 6a 6f 69 6e  TE TABLE t([join
23e0: 20 24 63 6f 6c 73 20 2c 5d 29 22 20 0a 7d 20 7b   $cols ,])" .} {
23f0: 31 20 7b 74 6f 6f 20 6d 61 6e 79 20 63 6f 6c 75  1 {too many colu
2400: 6d 6e 73 20 6f 6e 20 74 7d 7d 0a 0a 64 6f 5f 74  mns on t}}..do_t
2410: 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e  est sqllimits-1.
2420: 34 2e 32 20 7b 0a 20 20 23 20 43 6f 6c 75 6d 6e  4.2 {.  # Column
2430: 73 20 69 6e 20 74 68 65 20 72 65 73 75 6c 74 2d  s in the result-
2440: 73 65 74 20 6f 66 20 61 20 53 45 4c 45 43 54 2e  set of a SELECT.
2450: 0a 20 20 73 65 74 20 63 6f 6c 73 20 5b 6c 69 73  .  set cols [lis
2460: 74 5d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20  t].  for {set i 
2470: 30 7d 20 7b 24 69 20 3c 3d 20 24 53 51 4c 49 54  0} {$i <= $SQLIT
2480: 45 5f 4d 41 58 5f 43 4f 4c 55 4d 4e 7d 20 7b 69  E_MAX_COLUMN} {i
2490: 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20 6c 61 70  ncr i} {.    lap
24a0: 70 65 6e 64 20 63 6f 6c 73 20 22 73 71 6c 20 41  pend cols "sql A
24b0: 53 20 73 71 6c 24 69 22 0a 20 20 7d 0a 20 20 63  S sql$i".  }.  c
24c0: 61 74 63 68 73 71 6c 20 22 53 45 4c 45 43 54 20  atchsql "SELECT 
24d0: 5b 6a 6f 69 6e 20 24 63 6f 6c 73 20 2c 5d 20 46  [join $cols ,] F
24e0: 52 4f 4d 20 73 71 6c 69 74 65 5f 6d 61 73 74 65  ROM sqlite_maste
24f0: 72 22 0a 7d 20 7b 31 20 7b 74 6f 6f 20 6d 61 6e  r".} {1 {too man
2500: 79 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 72 65 73  y columns in res
2510: 75 6c 74 20 73 65 74 7d 7d 0a 0a 64 6f 5f 74 65  ult set}}..do_te
2520: 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 34  st sqllimits-1.4
2530: 2e 33 20 7b 0a 20 20 23 20 43 6f 6c 75 6d 6e 73  .3 {.  # Columns
2540: 20 69 6e 20 74 68 65 20 72 65 73 75 6c 74 2d 73   in the result-s
2550: 65 74 20 6f 66 20 61 20 73 75 62 2d 53 45 4c 45  et of a sub-SELE
2560: 43 54 2e 0a 20 20 73 65 74 20 63 6f 6c 73 20 5b  CT..  set cols [
2570: 6c 69 73 74 5d 0a 20 20 66 6f 72 20 7b 73 65 74  list].  for {set
2580: 20 69 20 30 7d 20 7b 24 69 20 3c 3d 20 24 53 51   i 0} {$i <= $SQ
2590: 4c 49 54 45 5f 4d 41 58 5f 43 4f 4c 55 4d 4e 7d  LITE_MAX_COLUMN}
25a0: 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20   {incr i} {.    
25b0: 6c 61 70 70 65 6e 64 20 63 6f 6c 73 20 22 73 71  lappend cols "sq
25c0: 6c 20 41 53 20 73 71 6c 24 69 22 0a 20 20 7d 0a  l AS sql$i".  }.
25d0: 20 20 63 61 74 63 68 73 71 6c 20 22 53 45 4c 45    catchsql "SELE
25e0: 43 54 20 73 71 6c 34 20 46 52 4f 4d 20 28 53 45  CT sql4 FROM (SE
25f0: 4c 45 43 54 20 5b 6a 6f 69 6e 20 24 63 6f 6c 73  LECT [join $cols
2600: 20 2c 5d 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f   ,] FROM sqlite_
2610: 6d 61 73 74 65 72 29 22 0a 7d 20 7b 31 20 7b 74  master)".} {1 {t
2620: 6f 6f 20 6d 61 6e 79 20 63 6f 6c 75 6d 6e 73 20  oo many columns 
2630: 69 6e 20 72 65 73 75 6c 74 20 73 65 74 7d 7d 0a  in result set}}.
2640: 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69  .do_test sqllimi
2650: 74 73 2d 31 2e 34 2e 34 20 7b 0a 20 20 23 20 43  ts-1.4.4 {.  # C
2660: 6f 6c 75 6d 6e 73 20 69 6e 20 61 6e 20 69 6e 64  olumns in an ind
2670: 65 78 2e 0a 20 20 73 65 74 20 63 6f 6c 73 20 5b  ex..  set cols [
2680: 6c 69 73 74 5d 0a 20 20 66 6f 72 20 7b 73 65 74  list].  for {set
2690: 20 69 20 30 7d 20 7b 24 69 20 3c 3d 20 24 53 51   i 0} {$i <= $SQ
26a0: 4c 49 54 45 5f 4d 41 58 5f 43 4f 4c 55 4d 4e 7d  LITE_MAX_COLUMN}
26b0: 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20   {incr i} {.    
26c0: 6c 61 70 70 65 6e 64 20 63 6f 6c 73 20 63 0a 20  lappend cols c. 
26d0: 20 7d 0a 20 20 73 65 74 20 73 71 6c 31 20 22 43   }.  set sql1 "C
26e0: 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 63  REATE TABLE t1(c
26f0: 29 3b 22 0a 20 20 73 65 74 20 73 71 6c 32 20 22  );".  set sql2 "
2700: 43 52 45 41 54 45 20 49 4e 44 45 58 20 69 31 20  CREATE INDEX i1 
2710: 4f 4e 20 74 31 28 5b 6a 6f 69 6e 20 24 63 6f 6c  ON t1([join $col
2720: 73 20 2c 5d 29 3b 22 0a 20 20 63 61 74 63 68 73  s ,]);".  catchs
2730: 71 6c 20 22 24 73 71 6c 31 20 3b 20 24 73 71 6c  ql "$sql1 ; $sql
2740: 32 22 0a 7d 20 7b 31 20 7b 74 6f 6f 20 6d 61 6e  2".} {1 {too man
2750: 79 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 69 6e 64  y columns in ind
2760: 65 78 7d 7d 0a 0a 64 6f 5f 74 65 73 74 20 73 71  ex}}..do_test sq
2770: 6c 6c 69 6d 69 74 73 2d 31 2e 34 2e 35 20 7b 0a  llimits-1.4.5 {.
2780: 20 20 23 20 43 6f 6c 75 6d 6e 73 20 69 6e 20 61    # Columns in a
2790: 20 47 52 4f 55 50 20 42 59 20 63 6c 61 75 73 65   GROUP BY clause
27a0: 2e 0a 20 20 63 61 74 63 68 73 71 6c 20 22 53 45  ..  catchsql "SE
27b0: 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 47  LECT * FROM t1 G
27c0: 52 4f 55 50 20 42 59 20 5b 6a 6f 69 6e 20 24 63  ROUP BY [join $c
27d0: 6f 6c 73 20 2c 5d 22 0a 7d 20 7b 31 20 7b 74 6f  ols ,]".} {1 {to
27e0: 6f 20 6d 61 6e 79 20 74 65 72 6d 73 20 69 6e 20  o many terms in 
27f0: 47 52 4f 55 50 20 42 59 20 63 6c 61 75 73 65 7d  GROUP BY clause}
2800: 7d 0a 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69  }..do_test sqlli
2810: 6d 69 74 73 2d 31 2e 34 2e 36 20 7b 0a 20 20 23  mits-1.4.6 {.  #
2820: 20 43 6f 6c 75 6d 6e 73 20 69 6e 20 61 6e 20 4f   Columns in an O
2830: 52 44 45 52 20 42 59 20 63 6c 61 75 73 65 2e 0a  RDER BY clause..
2840: 20 20 63 61 74 63 68 73 71 6c 20 22 53 45 4c 45    catchsql "SELE
2850: 43 54 20 2a 20 46 52 4f 4d 20 74 31 20 4f 52 44  CT * FROM t1 ORD
2860: 45 52 20 42 59 20 5b 6a 6f 69 6e 20 24 63 6f 6c  ER BY [join $col
2870: 73 20 2c 5d 22 0a 7d 20 7b 31 20 7b 74 6f 6f 20  s ,]".} {1 {too 
2880: 6d 61 6e 79 20 74 65 72 6d 73 20 69 6e 20 4f 52  many terms in OR
2890: 44 45 52 20 42 59 20 63 6c 61 75 73 65 7d 7d 0a  DER BY clause}}.
28a0: 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69  .do_test sqllimi
28b0: 74 73 2d 31 2e 34 2e 37 20 7b 0a 20 20 23 20 41  ts-1.4.7 {.  # A
28c0: 73 73 69 67 6e 6d 65 6e 74 73 20 69 6e 20 61 6e  ssignments in an
28d0: 20 55 50 44 41 54 45 20 73 74 61 74 65 6d 65 6e   UPDATE statemen
28e0: 74 2e 0a 20 20 73 65 74 20 63 6f 6c 73 20 5b 6c  t..  set cols [l
28f0: 69 73 74 5d 0a 20 20 66 6f 72 20 7b 73 65 74 20  ist].  for {set 
2900: 69 20 30 7d 20 7b 24 69 20 3c 3d 20 24 53 51 4c  i 0} {$i <= $SQL
2910: 49 54 45 5f 4d 41 58 5f 43 4f 4c 55 4d 4e 7d 20  ITE_MAX_COLUMN} 
2920: 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20 6c  {incr i} {.    l
2930: 61 70 70 65 6e 64 20 63 6f 6c 73 20 22 63 20 3d  append cols "c =
2940: 20 31 22 0a 20 20 7d 0a 20 20 63 61 74 63 68 73   1".  }.  catchs
2950: 71 6c 20 22 55 50 44 41 54 45 20 74 31 20 53 45  ql "UPDATE t1 SE
2960: 54 20 5b 6a 6f 69 6e 20 24 63 6f 6c 73 20 2c 5d  T [join $cols ,]
2970: 3b 22 0a 7d 20 7b 31 20 7b 74 6f 6f 20 6d 61 6e  ;".} {1 {too man
2980: 79 20 63 6f 6c 75 6d 6e 73 20 69 6e 20 73 65 74  y columns in set
2990: 20 6c 69 73 74 7d 7d 0a 0a 64 6f 5f 74 65 73 74   list}}..do_test
29a0: 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 34 2e 38   sqllimits-1.4.8
29b0: 20 7b 0a 20 20 23 20 43 6f 6c 75 6d 6e 73 20 69   {.  # Columns i
29c0: 6e 20 61 20 76 69 65 77 20 64 65 66 69 6e 69 74  n a view definit
29d0: 69 6f 6e 3a 0a 20 20 73 65 74 20 63 6f 6c 73 20  ion:.  set cols 
29e0: 5b 6c 69 73 74 5d 0a 20 20 66 6f 72 20 7b 73 65  [list].  for {se
29f0: 74 20 69 20 30 7d 20 7b 24 69 20 3c 3d 20 24 53  t i 0} {$i <= $S
2a00: 51 4c 49 54 45 5f 4d 41 58 5f 43 4f 4c 55 4d 4e  QLITE_MAX_COLUMN
2a10: 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20  } {incr i} {.   
2a20: 20 6c 61 70 70 65 6e 64 20 63 6f 6c 73 20 22 63   lappend cols "c
2a30: 24 69 22 0a 20 20 7d 0a 20 20 63 61 74 63 68 73  $i".  }.  catchs
2a40: 71 6c 20 22 43 52 45 41 54 45 20 56 49 45 57 20  ql "CREATE VIEW 
2a50: 76 31 20 41 53 20 53 45 4c 45 43 54 20 5b 6a 6f  v1 AS SELECT [jo
2a60: 69 6e 20 24 63 6f 6c 73 20 2c 5d 20 46 52 4f 4d  in $cols ,] FROM
2a70: 20 74 31 3b 22 0a 7d 20 7b 31 20 7b 74 6f 6f 20   t1;".} {1 {too 
2a80: 6d 61 6e 79 20 63 6f 6c 75 6d 6e 73 20 69 6e 20  many columns in 
2a90: 72 65 73 75 6c 74 20 73 65 74 7d 7d 0a 0a 64 6f  result set}}..do
2aa0: 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d  _test sqllimits-
2ab0: 31 2e 34 2e 39 20 7b 0a 20 20 23 20 43 6f 6c 75  1.4.9 {.  # Colu
2ac0: 6d 6e 73 20 69 6e 20 61 20 76 69 65 77 20 64 65  mns in a view de
2ad0: 66 69 6e 69 74 69 6f 6e 20 28 74 65 73 74 69 6e  finition (testin
2ae0: 67 20 2a 20 65 78 70 61 6e 73 69 6f 6e 29 3a 0a  g * expansion):.
2af0: 20 20 73 65 74 20 63 6f 6c 73 20 5b 6c 69 73 74    set cols [list
2b00: 5d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20 30  ].  for {set i 0
2b10: 7d 20 7b 24 69 20 3c 20 24 53 51 4c 49 54 45 5f  } {$i < $SQLITE_
2b20: 4d 41 58 5f 43 4f 4c 55 4d 4e 7d 20 7b 69 6e 63  MAX_COLUMN} {inc
2b30: 72 20 69 7d 20 7b 0a 20 20 20 20 6c 61 70 70 65  r i} {.    lappe
2b40: 6e 64 20 63 6f 6c 73 20 22 63 24 69 22 0a 20 20  nd cols "c$i".  
2b50: 7d 0a 20 20 63 61 74 63 68 73 71 6c 20 22 43 52  }.  catchsql "CR
2b60: 45 41 54 45 20 54 41 42 4c 45 20 74 32 28 5b 6a  EATE TABLE t2([j
2b70: 6f 69 6e 20 24 63 6f 6c 73 20 2c 5d 29 22 0a 20  oin $cols ,])". 
2b80: 20 63 61 74 63 68 73 71 6c 20 22 43 52 45 41 54   catchsql "CREAT
2b90: 45 20 56 49 45 57 20 76 31 20 41 53 20 53 45 4c  E VIEW v1 AS SEL
2ba0: 45 43 54 20 2a 2c 20 63 31 20 41 53 20 6f 20 46  ECT *, c1 AS o F
2bb0: 52 4f 4d 20 74 32 3b 22 0a 7d 20 7b 31 20 7b 74  ROM t2;".} {1 {t
2bc0: 6f 6f 20 6d 61 6e 79 20 63 6f 6c 75 6d 6e 73 20  oo many columns 
2bd0: 69 6e 20 72 65 73 75 6c 74 20 73 65 74 7d 7d 0a  in result set}}.
2be0: 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .#--------------
2bf0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c20: 2d 2d 2d 2d 2d 2d 0a 23 20 54 68 65 73 65 20 74  ------.# These t
2c30: 65 73 74 73 20 2d 20 73 71 6c 6c 69 6d 69 74 73  ests - sqllimits
2c40: 2d 35 2e 2a 20 2d 20 74 65 73 74 20 74 68 61 74  -5.* - test that
2c50: 20 74 68 65 20 53 51 4c 49 54 45 5f 4d 41 58 5f   the SQLITE_MAX_
2c60: 45 58 50 52 5f 44 45 50 54 48 0a 23 20 6c 69 6d  EXPR_DEPTH.# lim
2c70: 69 74 20 69 73 20 65 6e 66 6f 72 63 65 64 2e 20  it is enforced. 
2c80: 54 68 65 20 6c 69 6d 69 74 20 72 65 66 65 72 73  The limit refers
2c90: 20 74 6f 20 74 68 65 20 6e 75 6d 62 65 72 20 6f   to the number o
2ca0: 66 20 74 65 72 6d 73 20 69 6e 20 0a 23 20 74 68  f terms in .# th
2cb0: 65 20 65 78 70 72 65 73 73 69 6f 6e 2e 0a 23 0a  e expression..#.
2cc0: 69 66 20 7b 24 3a 3a 53 51 4c 49 54 45 5f 4d 41  if {$::SQLITE_MA
2cd0: 58 5f 45 58 50 52 5f 44 45 50 54 48 20 21 3d 20  X_EXPR_DEPTH != 
2ce0: 31 30 30 30 7d 20 7b 0a 20 20 70 75 74 73 20 2d  1000} {.  puts -
2cf0: 6e 6f 6e 65 77 6c 69 6e 65 20 73 74 64 65 72 72  nonewline stderr
2d00: 20 22 57 41 52 4e 49 4e 47 3a 20 43 6f 6d 70 69   "WARNING: Compi
2d10: 6c 65 20 77 69 74 68 20 2d 44 53 51 4c 49 54 45  le with -DSQLITE
2d20: 5f 4d 41 58 5f 45 58 50 52 5f 44 45 50 54 48 20  _MAX_EXPR_DEPTH 
2d30: 74 6f 20 72 75 6e 20 22 0a 20 20 70 75 74 73 20  to run ".  puts 
2d40: 73 74 64 65 72 72 20 22 74 65 73 74 73 20 73 71  stderr "tests sq
2d50: 6c 6c 69 6d 69 74 73 2d 31 2e 35 2e 58 22 0a 7d  llimits-1.5.X".}
2d60: 20 65 6c 73 65 20 7b 0a 20 20 64 6f 5f 74 65 73   else {.  do_tes
2d70: 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 35 2e  t sqllimits-1.5.
2d80: 31 20 7b 0a 20 20 20 20 73 65 74 20 6d 61 78 20  1 {.    set max 
2d90: 24 3a 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 45 58  $::SQLITE_MAX_EX
2da0: 50 52 5f 44 45 50 54 48 0a 20 20 20 20 73 65 74  PR_DEPTH.    set
2db0: 20 65 78 70 72 20 22 28 31 20 5b 73 74 72 69 6e   expr "(1 [strin
2dc0: 67 20 72 65 70 65 61 74 20 7b 41 4e 44 20 31 20  g repeat {AND 1 
2dd0: 7d 20 24 6d 61 78 5d 29 22 0a 20 20 20 20 63 61  } $max])".    ca
2de0: 74 63 68 73 71 6c 20 5b 73 75 62 73 74 20 7b 0a  tchsql [subst {.
2df0: 20 20 20 20 20 20 53 45 4c 45 43 54 20 24 65 78        SELECT $ex
2e00: 70 72 0a 20 20 20 20 7d 5d 0a 20 20 7d 20 22 31  pr.    }].  } "1
2e10: 20 7b 45 78 70 72 65 73 73 69 6f 6e 20 74 72 65   {Expression tre
2e20: 65 20 69 73 20 74 6f 6f 20 6c 61 72 67 65 20 28  e is too large (
2e30: 6d 61 78 69 6d 75 6d 20 64 65 70 74 68 20 24 3a  maximum depth $:
2e40: 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 45 58 50 52  :SQLITE_MAX_EXPR
2e50: 5f 44 45 50 54 48 29 7d 22 0a 20 20 0a 20 20 23  _DEPTH)}".  .  #
2e60: 20 41 74 74 65 6d 70 74 69 6e 67 20 74 6f 20 62   Attempting to b
2e70: 65 61 74 20 74 68 65 20 65 78 70 72 65 73 73 69  eat the expressi
2e80: 6f 6e 20 64 65 70 74 68 20 6c 69 6d 69 74 20 75  on depth limit u
2e90: 73 69 6e 67 20 6e 65 73 74 65 64 20 53 45 4c 45  sing nested SELE
2ea0: 43 54 0a 20 20 23 20 71 75 65 72 69 65 73 20 63  CT.  # queries c
2eb0: 61 75 73 65 73 20 61 20 70 61 72 73 65 72 20 73  auses a parser s
2ec0: 74 61 63 6b 20 6f 76 65 72 66 6c 6f 77 2e 20 0a  tack overflow. .
2ed0: 20 20 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d    do_test sqllim
2ee0: 69 74 73 2d 31 2e 35 2e 32 20 7b 0a 20 20 20 20  its-1.5.2 {.    
2ef0: 73 65 74 20 6d 61 78 20 24 3a 3a 53 51 4c 49 54  set max $::SQLIT
2f00: 45 5f 4d 41 58 5f 45 58 50 52 5f 44 45 50 54 48  E_MAX_EXPR_DEPTH
2f10: 0a 20 20 20 20 73 65 74 20 65 78 70 72 20 22 53  .    set expr "S
2f20: 45 4c 45 43 54 20 31 22 0a 20 20 20 20 66 6f 72  ELECT 1".    for
2f30: 20 7b 73 65 74 20 69 20 30 7d 20 7b 24 69 20 3c   {set i 0} {$i <
2f40: 3d 20 24 6d 61 78 7d 20 7b 69 6e 63 72 20 69 7d  = $max} {incr i}
2f50: 20 7b 0a 20 20 20 20 20 20 73 65 74 20 65 78 70   {.      set exp
2f60: 72 20 22 53 45 4c 45 43 54 20 28 24 65 78 70 72  r "SELECT ($expr
2f70: 29 22 0a 20 20 20 20 7d 0a 20 20 20 20 63 61 74  )".    }.    cat
2f80: 63 68 73 71 6c 20 5b 73 75 62 73 74 20 7b 20 24  chsql [subst { $
2f90: 65 78 70 72 20 7d 5d 0a 20 20 7d 20 22 31 20 7b  expr }].  } "1 {
2fa0: 70 61 72 73 65 72 20 73 74 61 63 6b 20 6f 76 65  parser stack ove
2fb0: 72 66 6c 6f 77 7d 22 0a 20 20 0a 20 20 0a 20 20  rflow}".  .  .  
2fc0: 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74  do_test sqllimit
2fd0: 73 2d 31 2e 35 2e 33 20 7b 0a 20 20 20 20 65 78  s-1.5.3 {.    ex
2fe0: 65 63 73 71 6c 20 7b 0a 20 20 20 20 20 20 50 52  ecsql {.      PR
2ff0: 41 47 4d 41 20 6d 61 78 5f 70 61 67 65 5f 63 6f  AGMA max_page_co
3000: 75 6e 74 20 3d 20 31 30 30 30 30 30 30 3b 20 20  unt = 1000000;  
3010: 2d 2d 20 31 20 47 42 0a 20 20 20 20 20 20 43 52  -- 1 GB.      CR
3020: 45 41 54 45 20 54 41 42 4c 45 20 76 30 28 61 29  EATE TABLE v0(a)
3030: 3b 0a 20 20 20 20 20 20 49 4e 53 45 52 54 20 49  ;.      INSERT I
3040: 4e 54 4f 20 76 30 20 56 41 4c 55 45 53 28 31 29  NTO v0 VALUES(1)
3050: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 62 20 74  ;.    }.    db t
3060: 72 61 6e 73 61 63 74 69 6f 6e 20 7b 0a 20 20 20  ransaction {.   
3070: 20 20 20 66 6f 72 20 7b 73 65 74 20 69 20 31 7d     for {set i 1}
3080: 20 7b 24 69 20 3c 20 32 30 30 7d 20 7b 69 6e 63   {$i < 200} {inc
3090: 72 20 69 7d 20 7b 0a 20 20 20 20 20 20 20 20 73  r i} {.        s
30a0: 65 74 20 65 78 70 72 20 22 28 61 20 5b 73 74 72  et expr "(a [str
30b0: 69 6e 67 20 72 65 70 65 61 74 20 7b 41 4e 44 20  ing repeat {AND 
30c0: 31 20 7d 20 35 30 5d 29 20 41 53 20 61 22 0a 20  1 } 50]) AS a". 
30d0: 20 20 20 20 20 20 20 65 78 65 63 73 71 6c 20 5b         execsql [
30e0: 73 75 62 73 74 20 7b 0a 20 20 20 20 20 20 20 20  subst {.        
30f0: 20 20 43 52 45 41 54 45 20 56 49 45 57 20 76 24    CREATE VIEW v$
3100: 7b 69 7d 20 41 53 20 53 45 4c 45 43 54 20 24 65  {i} AS SELECT $e
3110: 78 70 72 20 46 52 4f 4d 20 76 5b 65 78 70 72 20  xpr FROM v[expr 
3120: 7b 24 69 2d 31 7d 5d 0a 20 20 20 20 20 20 20 20  {$i-1}].        
3130: 7d 5d 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 7d  }].      }.    }
3140: 0a 20 20 7d 20 7b 7d 0a 20 20 0a 20 20 64 6f 5f  .  } {}.  .  do_
3150: 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31  test sqllimits-1
3160: 2e 35 2e 34 20 7b 0a 20 20 20 20 63 61 74 63 68  .5.4 {.    catch
3170: 73 71 6c 20 7b 0a 20 20 20 20 20 20 53 45 4c 45  sql {.      SELE
3180: 43 54 20 61 20 46 52 4f 4d 20 76 31 39 39 0a 20  CT a FROM v199. 
3190: 20 20 20 7d 0a 20 20 7d 20 22 31 20 7b 45 78 70     }.  } "1 {Exp
31a0: 72 65 73 73 69 6f 6e 20 74 72 65 65 20 69 73 20  ression tree is 
31b0: 74 6f 6f 20 6c 61 72 67 65 20 28 6d 61 78 69 6d  too large (maxim
31c0: 75 6d 20 64 65 70 74 68 20 24 3a 3a 53 51 4c 49  um depth $::SQLI
31d0: 54 45 5f 4d 41 58 5f 45 58 50 52 5f 44 45 50 54  TE_MAX_EXPR_DEPT
31e0: 48 29 7d 22 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d  H)}".}..#-------
31f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3200: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3210: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3220: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
3230: 54 65 73 74 20 63 61 73 65 73 20 73 71 6c 6c 69  Test cases sqlli
3240: 6d 69 74 73 2d 36 2e 2a 20 74 65 73 74 20 74 68  mits-6.* test th
3250: 61 74 20 74 68 65 20 53 51 4c 49 54 45 5f 4d 41  at the SQLITE_MA
3260: 58 5f 56 44 42 45 5f 4f 50 0a 23 20 6c 69 6d 69  X_VDBE_OP.# limi
3270: 74 20 77 6f 72 6b 73 20 61 73 20 65 78 70 65 63  t works as expec
3280: 74 65 64 2e 20 54 68 65 20 6c 69 6d 69 74 20 72  ted. The limit r
3290: 65 66 65 72 73 20 74 6f 20 74 68 65 20 6e 75 6d  efers to the num
32a0: 62 65 72 20 6f 66 20 6f 70 63 6f 64 65 73 0a 23  ber of opcodes.#
32b0: 20 69 6e 20 61 20 73 69 6e 67 6c 65 20 56 44 42   in a single VDB
32c0: 45 20 70 72 6f 67 72 61 6d 2e 0a 23 0a 23 20 54  E program..#.# T
32d0: 4f 44 4f 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ODO..#----------
32e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
32f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3300: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3310: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20 54 65 73  ----------.# Tes
3320: 74 20 74 68 65 20 53 51 4c 49 54 45 5f 4d 41 58  t the SQLITE_MAX
3330: 5f 46 55 4e 43 54 49 4f 4e 5f 41 52 47 20 6c 69  _FUNCTION_ARG li
3340: 6d 69 74 20 77 6f 72 6b 73 2e 20 54 65 73 74 20  mit works. Test 
3350: 63 61 73 65 20 6e 61 6d 65 73 0a 23 20 6d 61 74  case names.# mat
3360: 63 68 20 74 68 65 20 70 61 74 74 65 72 6e 20 22  ch the pattern "
3370: 73 71 6c 6c 69 6d 69 74 73 2d 37 2e 2a 22 2e 0a  sqllimits-7.*"..
3380: 23 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d  #.do_test sqllim
3390: 69 74 73 2d 31 2e 37 2e 31 20 7b 0a 20 20 73 65  its-1.7.1 {.  se
33a0: 74 20 6d 61 78 20 24 3a 3a 53 51 4c 49 54 45 5f  t max $::SQLITE_
33b0: 4d 41 58 5f 46 55 4e 43 54 49 4f 4e 5f 41 52 47  MAX_FUNCTION_ARG
33c0: 0a 20 20 73 65 74 20 76 61 6c 73 20 5b 6c 69 73  .  set vals [lis
33d0: 74 5d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20  t].  for {set i 
33e0: 30 7d 20 7b 24 69 20 3c 20 24 53 51 4c 49 54 45  0} {$i < $SQLITE
33f0: 5f 4d 41 58 5f 46 55 4e 43 54 49 4f 4e 5f 41 52  _MAX_FUNCTION_AR
3400: 47 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20  G} {incr i} {.  
3410: 20 20 6c 61 70 70 65 6e 64 20 76 61 6c 73 20 24    lappend vals $
3420: 69 0a 20 20 7d 0a 20 20 63 61 74 63 68 73 71 6c  i.  }.  catchsql
3430: 20 22 53 45 4c 45 43 54 20 6d 61 78 28 5b 6a 6f   "SELECT max([jo
3440: 69 6e 20 24 76 61 6c 73 20 2c 5d 29 22 0a 7d 20  in $vals ,])".} 
3450: 22 30 20 5b 65 78 70 72 20 7b 24 3a 3a 53 51 4c  "0 [expr {$::SQL
3460: 49 54 45 5f 4d 41 58 5f 46 55 4e 43 54 49 4f 4e  ITE_MAX_FUNCTION
3470: 5f 41 52 47 20 2d 20 31 7d 5d 22 0a 64 6f 5f 74  _ARG - 1}]".do_t
3480: 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e  est sqllimits-1.
3490: 37 2e 32 20 7b 0a 20 20 73 65 74 20 6d 61 78 20  7.2 {.  set max 
34a0: 24 3a 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 46 55  $::SQLITE_MAX_FU
34b0: 4e 43 54 49 4f 4e 5f 41 52 47 0a 20 20 73 65 74  NCTION_ARG.  set
34c0: 20 76 61 6c 73 20 5b 6c 69 73 74 5d 0a 20 20 66   vals [list].  f
34d0: 6f 72 20 7b 73 65 74 20 69 20 30 7d 20 7b 24 69  or {set i 0} {$i
34e0: 20 3c 3d 20 24 53 51 4c 49 54 45 5f 4d 41 58 5f   <= $SQLITE_MAX_
34f0: 46 55 4e 43 54 49 4f 4e 5f 41 52 47 7d 20 7b 69  FUNCTION_ARG} {i
3500: 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20 6c 61 70  ncr i} {.    lap
3510: 70 65 6e 64 20 76 61 6c 73 20 24 69 0a 20 20 7d  pend vals $i.  }
3520: 0a 20 20 63 61 74 63 68 73 71 6c 20 22 53 45 4c  .  catchsql "SEL
3530: 45 43 54 20 6d 61 78 28 5b 6a 6f 69 6e 20 24 76  ECT max([join $v
3540: 61 6c 73 20 2c 5d 29 22 0a 7d 20 7b 31 20 7b 74  als ,])".} {1 {t
3550: 6f 6f 20 6d 61 6e 79 20 61 72 67 75 6d 65 6e 74  oo many argument
3560: 73 20 6f 6e 20 66 75 6e 63 74 69 6f 6e 20 6d 61  s on function ma
3570: 78 7d 7d 0a 0a 23 20 54 65 73 74 20 74 68 61 74  x}}..# Test that
3580: 20 69 74 20 69 73 20 53 51 4c 69 74 65 2c 20 61   it is SQLite, a
3590: 6e 64 20 6e 6f 74 20 74 68 65 20 69 6d 70 6c 65  nd not the imple
35a0: 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 74 68 65  mentation of the
35b0: 0a 23 20 75 73 65 72 20 66 75 6e 63 74 69 6f 6e  .# user function
35c0: 20 74 68 61 74 20 69 73 20 74 68 72 6f 77 69 6e   that is throwin
35d0: 67 20 74 68 65 20 65 72 72 6f 72 2e 0a 70 72 6f  g the error..pro
35e0: 63 20 6d 79 66 75 6e 63 20 7b 61 72 67 73 7d 20  c myfunc {args} 
35f0: 7b 65 72 72 6f 72 20 22 49 20 64 6f 6e 27 74 20  {error "I don't 
3600: 6c 69 6b 65 20 74 6f 20 62 65 20 63 61 6c 6c 65  like to be calle
3610: 64 21 22 7d 0a 64 6f 5f 74 65 73 74 20 73 71 6c  d!"}.do_test sql
3620: 6c 69 6d 69 74 73 2d 31 2e 37 2e 32 20 7b 0a 20  limits-1.7.2 {. 
3630: 20 64 62 20 66 75 6e 63 74 69 6f 6e 20 6d 79 66   db function myf
3640: 75 6e 63 20 6d 79 66 75 6e 63 0a 20 20 73 65 74  unc myfunc.  set
3650: 20 6d 61 78 20 24 3a 3a 53 51 4c 49 54 45 5f 4d   max $::SQLITE_M
3660: 41 58 5f 46 55 4e 43 54 49 4f 4e 5f 41 52 47 0a  AX_FUNCTION_ARG.
3670: 20 20 73 65 74 20 76 61 6c 73 20 5b 6c 69 73 74    set vals [list
3680: 5d 0a 20 20 66 6f 72 20 7b 73 65 74 20 69 20 30  ].  for {set i 0
3690: 7d 20 7b 24 69 20 3c 3d 20 24 53 51 4c 49 54 45  } {$i <= $SQLITE
36a0: 5f 4d 41 58 5f 46 55 4e 43 54 49 4f 4e 5f 41 52  _MAX_FUNCTION_AR
36b0: 47 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20 20  G} {incr i} {.  
36c0: 20 20 6c 61 70 70 65 6e 64 20 76 61 6c 73 20 24    lappend vals $
36d0: 69 0a 20 20 7d 0a 20 20 63 61 74 63 68 73 71 6c  i.  }.  catchsql
36e0: 20 22 53 45 4c 45 43 54 20 6d 79 66 75 6e 63 28   "SELECT myfunc(
36f0: 5b 6a 6f 69 6e 20 24 76 61 6c 73 20 2c 5d 29 22  [join $vals ,])"
3700: 0a 7d 20 7b 31 20 7b 74 6f 6f 20 6d 61 6e 79 20  .} {1 {too many 
3710: 61 72 67 75 6d 65 6e 74 73 20 6f 6e 20 66 75 6e  arguments on fun
3720: 63 74 69 6f 6e 20 6d 79 66 75 6e 63 7d 7d 0a 0a  ction myfunc}}..
3730: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
3740: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3750: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3760: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3770: 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 63 61 73  -----.# Test cas
3780: 65 73 20 73 71 6c 6c 69 6d 69 74 73 2d 38 2e 2a  es sqllimits-8.*
3790: 3a 20 54 65 73 74 20 74 68 65 20 53 51 4c 49 54  : Test the SQLIT
37a0: 45 5f 4d 41 58 5f 41 54 54 41 43 48 45 44 20 6c  E_MAX_ATTACHED l
37b0: 69 6d 69 74 2e 0a 23 0a 69 66 63 61 70 61 62 6c  imit..#.ifcapabl
37c0: 65 20 61 74 74 61 63 68 20 7b 0a 20 20 64 6f 5f  e attach {.  do_
37d0: 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31  test sqllimits-1
37e0: 2e 38 2e 31 20 7b 0a 20 20 20 20 73 65 74 20 6d  .8.1 {.    set m
37f0: 61 78 20 24 3a 3a 53 51 4c 49 54 45 5f 4d 41 58  ax $::SQLITE_MAX
3800: 5f 41 54 54 41 43 48 45 44 0a 20 20 20 20 66 6f  _ATTACHED.    fo
3810: 72 20 7b 73 65 74 20 69 20 30 7d 20 7b 24 69 20  r {set i 0} {$i 
3820: 3c 20 28 24 6d 61 78 29 7d 20 7b 69 6e 63 72 20  < ($max)} {incr 
3830: 69 7d 20 7b 0a 20 20 20 20 20 20 66 69 6c 65 20  i} {.      file 
3840: 64 65 6c 65 74 65 20 2d 66 6f 72 63 65 20 74 65  delete -force te
3850: 73 74 24 7b 69 7d 2e 64 62 20 74 65 73 74 24 7b  st${i}.db test${
3860: 69 7d 2e 64 62 2d 6a 6f 75 72 6e 61 6c 0a 20 20  i}.db-journal.  
3870: 20 20 7d 0a 20 20 20 20 66 6f 72 20 7b 73 65 74    }.    for {set
3880: 20 69 20 30 7d 20 7b 24 69 20 3c 20 28 24 6d 61   i 0} {$i < ($ma
3890: 78 29 7d 20 7b 69 6e 63 72 20 69 7d 20 7b 0a 20  x)} {incr i} {. 
38a0: 20 20 20 20 20 65 78 65 63 73 71 6c 20 22 41 54       execsql "AT
38b0: 54 41 43 48 20 27 74 65 73 74 24 7b 69 7d 2e 64  TACH 'test${i}.d
38c0: 62 27 20 41 53 20 61 75 78 24 7b 69 7d 22 0a 20  b' AS aux${i}". 
38d0: 20 20 20 7d 0a 20 20 20 20 63 61 74 63 68 73 71     }.    catchsq
38e0: 6c 20 22 41 54 54 41 43 48 20 27 74 65 73 74 24  l "ATTACH 'test$
38f0: 7b 69 7d 2e 64 62 27 20 41 53 20 61 75 78 24 7b  {i}.db' AS aux${
3900: 69 7d 22 0a 20 20 7d 20 22 31 20 7b 74 6f 6f 20  i}".  } "1 {too 
3910: 6d 61 6e 79 20 61 74 74 61 63 68 65 64 20 64 61  many attached da
3920: 74 61 62 61 73 65 73 20 2d 20 6d 61 78 20 24 3a  tabases - max $:
3930: 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54 41  :SQLITE_MAX_ATTA
3940: 43 48 45 44 7d 22 0a 20 20 64 6f 5f 74 65 73 74  CHED}".  do_test
3950: 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 38 2e 32   sqllimits-1.8.2
3960: 20 7b 0a 20 20 20 20 73 65 74 20 6d 61 78 20 24   {.    set max $
3970: 3a 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 41 54 54  ::SQLITE_MAX_ATT
3980: 41 43 48 45 44 0a 20 20 20 20 66 6f 72 20 7b 73  ACHED.    for {s
3990: 65 74 20 69 20 30 7d 20 7b 24 69 20 3c 20 28 24  et i 0} {$i < ($
39a0: 6d 61 78 29 7d 20 7b 69 6e 63 72 20 69 7d 20 7b  max)} {incr i} {
39b0: 0a 20 20 20 20 20 20 65 78 65 63 73 71 6c 20 22  .      execsql "
39c0: 44 45 54 41 43 48 20 61 75 78 24 7b 69 7d 22 0a  DETACH aux${i}".
39d0: 20 20 20 20 7d 0a 20 20 7d 20 7b 7d 0a 7d 0a 0a      }.  } {}.}..
39e0: 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  #---------------
39f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3a00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3a10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3a20: 2d 2d 2d 2d 2d 0a 23 20 54 65 73 74 20 63 61 73  -----.# Test cas
3a30: 65 73 20 73 71 6c 6c 69 6d 69 74 73 2d 39 2e 2a  es sqllimits-9.*
3a40: 3a 20 43 68 65 63 6b 20 74 68 61 74 20 74 68 65  : Check that the
3a50: 20 53 51 4c 49 54 45 5f 4d 41 58 5f 56 41 52 49   SQLITE_MAX_VARI
3a60: 41 42 4c 45 5f 4e 55 4d 42 45 52 20 0a 23 20 6c  ABLE_NUMBER .# l
3a70: 69 6d 69 74 20 77 6f 72 6b 73 2e 0a 23 0a 64 6f  imit works..#.do
3a80: 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d  _test sqllimits-
3a90: 31 2e 39 2e 31 20 7b 0a 20 20 73 65 74 20 6d 61  1.9.1 {.  set ma
3aa0: 78 20 24 3a 3a 53 51 4c 49 54 45 5f 4d 41 58 5f  x $::SQLITE_MAX_
3ab0: 56 41 52 49 41 42 4c 45 5f 4e 55 4d 42 45 52 0a  VARIABLE_NUMBER.
3ac0: 20 20 63 61 74 63 68 73 71 6c 20 22 53 45 4c 45    catchsql "SELE
3ad0: 43 54 20 3f 5b 65 78 70 72 20 7b 24 6d 61 78 2b  CT ?[expr {$max+
3ae0: 31 7d 5d 20 46 52 4f 4d 20 74 31 22 0a 7d 20 22  1}] FROM t1".} "
3af0: 31 20 7b 76 61 72 69 61 62 6c 65 20 6e 75 6d 62  1 {variable numb
3b00: 65 72 20 6d 75 73 74 20 62 65 20 62 65 74 77 65  er must be betwe
3b10: 65 6e 20 3f 31 20 61 6e 64 20 3f 24 3a 3a 53 51  en ?1 and ?$::SQ
3b20: 4c 49 54 45 5f 4d 41 58 5f 56 41 52 49 41 42 4c  LITE_MAX_VARIABL
3b30: 45 5f 4e 55 4d 42 45 52 7d 22 0a 64 6f 5f 74 65  E_NUMBER}".do_te
3b40: 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 39  st sqllimits-1.9
3b50: 2e 32 20 7b 0a 20 20 73 65 74 20 6d 61 78 20 24  .2 {.  set max $
3b60: 3a 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 56 41 52  ::SQLITE_MAX_VAR
3b70: 49 41 42 4c 45 5f 4e 55 4d 42 45 52 0a 20 20 73  IABLE_NUMBER.  s
3b80: 65 74 20 76 61 6c 73 20 5b 6c 69 73 74 5d 0a 20  et vals [list]. 
3b90: 20 66 6f 72 20 7b 73 65 74 20 69 20 30 7d 20 7b   for {set i 0} {
3ba0: 24 69 20 3c 20 28 24 6d 61 78 2b 33 29 7d 20 7b  $i < ($max+3)} {
3bb0: 69 6e 63 72 20 69 7d 20 7b 0a 20 20 20 20 6c 61  incr i} {.    la
3bc0: 70 70 65 6e 64 20 76 61 6c 73 20 3f 0a 20 20 7d  ppend vals ?.  }
3bd0: 0a 20 20 63 61 74 63 68 73 71 6c 20 22 53 45 4c  .  catchsql "SEL
3be0: 45 43 54 20 5b 6a 6f 69 6e 20 24 76 61 6c 73 20  ECT [join $vals 
3bf0: 2c 5d 20 46 52 4f 4d 20 74 31 22 0a 7d 20 22 31  ,] FROM t1".} "1
3c00: 20 7b 74 6f 6f 20 6d 61 6e 79 20 53 51 4c 20 76   {too many SQL v
3c10: 61 72 69 61 62 6c 65 73 7d 22 0a 0a 0a 23 2d 2d  ariables}"...#--
3c20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3c30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3c40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3c50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
3c60: 2d 2d 0a 23 20 73 71 6c 6c 69 6d 69 74 73 2d 31  --.# sqllimits-1
3c70: 30 2e 2a 3a 20 20 54 65 73 74 20 74 68 65 20 53  0.*:  Test the S
3c80: 51 4c 49 54 45 5f 4d 41 58 5f 50 41 47 45 5f 53  QLITE_MAX_PAGE_S
3c90: 49 5a 45 20 64 65 66 69 6e 65 20 69 73 20 65 6e  IZE define is en
3ca0: 66 6f 72 63 65 64 2e 20 0a 23 20 54 68 69 73 20  forced. .# This 
3cb0: 69 73 20 70 72 6f 62 61 62 6c 79 20 74 65 73 74  is probably test
3cc0: 65 64 20 65 6c 73 65 77 68 65 72 65 20 74 6f 6f  ed elsewhere too
3cd0: 20 28 70 61 67 65 72 58 2e 74 65 73 74 29 2e 20   (pagerX.test). 
3ce0: 41 74 74 65 6d 70 74 73 0a 23 20 74 6f 20 72 61  Attempts.# to ra
3cf0: 69 73 65 20 74 68 65 20 70 61 67 65 20 73 69 7a  ise the page siz
3d00: 65 20 61 62 6f 76 65 20 74 68 69 73 20 6c 69 6d  e above this lim
3d10: 69 74 20 61 72 65 20 73 69 6c 65 6e 74 6c 79 20  it are silently 
3d20: 69 67 6e 6f 72 65 64 2e 0a 23 0a 64 6f 5f 74 65  ignored..#.do_te
3d30: 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 31  st sqllimits-1.1
3d40: 30 2e 31 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65  0.1 {.  db close
3d50: 0a 20 20 66 69 6c 65 20 64 65 6c 65 74 65 20 2d  .  file delete -
3d60: 66 6f 72 63 65 20 74 65 73 74 2e 64 62 20 74 65  force test.db te
3d70: 73 74 2e 64 62 2d 6a 6f 75 72 6e 61 6c 0a 20 20  st.db-journal.  
3d80: 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74 2e  sqlite3 db test.
3d90: 64 62 0a 20 20 73 65 74 20 6d 61 78 20 24 3a 3a  db.  set max $::
3da0: 53 51 4c 49 54 45 5f 4d 41 58 5f 50 41 47 45 5f  SQLITE_MAX_PAGE_
3db0: 53 49 5a 45 0a 20 20 63 61 74 63 68 73 71 6c 20  SIZE.  catchsql 
3dc0: 22 50 52 41 47 4d 41 20 70 61 67 65 5f 73 69 7a  "PRAGMA page_siz
3dd0: 65 20 3d 20 5b 65 78 70 72 20 7b 24 6d 61 78 2a  e = [expr {$max*
3de0: 32 7d 5d 22 0a 7d 20 7b 30 20 7b 7d 7d 0a 64 6f  2}]".} {0 {}}.do
3df0: 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d  _test sqllimits-
3e00: 31 2e 31 30 2e 32 20 7b 0a 20 20 63 61 74 63 68  1.10.2 {.  catch
3e10: 73 71 6c 20 22 50 52 41 47 4d 41 20 70 61 67 65  sql "PRAGMA page
3e20: 5f 73 69 7a 65 22 0a 7d 20 7b 30 20 31 30 32 34  _size".} {0 1024
3e30: 7d 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d  }.do_test sqllim
3e40: 69 74 73 2d 31 2e 31 30 2e 33 20 7b 0a 20 20 73  its-1.10.3 {.  s
3e50: 65 74 20 6d 61 78 20 24 3a 3a 53 51 4c 49 54 45  et max $::SQLITE
3e60: 5f 4d 41 58 5f 50 41 47 45 5f 53 49 5a 45 0a 20  _MAX_PAGE_SIZE. 
3e70: 20 63 61 74 63 68 73 71 6c 20 22 50 52 41 47 4d   catchsql "PRAGM
3e80: 41 20 70 61 67 65 5f 73 69 7a 65 20 3d 20 24 6d  A page_size = $m
3e90: 61 78 22 0a 7d 20 7b 30 20 7b 7d 7d 0a 64 6f 5f  ax".} {0 {}}.do_
3ea0: 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31  test sqllimits-1
3eb0: 2e 31 30 2e 34 20 7b 0a 20 20 65 78 65 63 73 71  .10.4 {.  execsq
3ec0: 6c 20 22 70 72 61 67 6d 61 20 70 61 67 65 5f 73  l "pragma page_s
3ed0: 69 7a 65 22 0a 7d 20 24 3a 3a 53 51 4c 49 54 45  ize".} $::SQLITE
3ee0: 5f 4d 41 58 5f 50 41 47 45 5f 53 49 5a 45 0a 64  _MAX_PAGE_SIZE.d
3ef0: 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73  o_test sqllimits
3f00: 2d 31 2e 31 30 2e 35 20 7b 0a 20 20 73 65 74 20  -1.10.5 {.  set 
3f10: 6d 61 78 20 24 3a 3a 53 51 4c 49 54 45 5f 4d 41  max $::SQLITE_MA
3f20: 58 5f 50 41 47 45 5f 53 49 5a 45 0a 20 20 65 78  X_PAGE_SIZE.  ex
3f30: 65 63 73 71 6c 20 22 70 72 61 67 6d 61 20 70 61  ecsql "pragma pa
3f40: 67 65 5f 73 69 7a 65 20 3d 20 5b 65 78 70 72 20  ge_size = [expr 
3f50: 7b 24 6d 61 78 20 2d 20 35 7d 5d 22 0a 20 20 65  {$max - 5}]".  e
3f60: 78 65 63 73 71 6c 20 22 70 72 61 67 6d 61 20 70  xecsql "pragma p
3f70: 61 67 65 5f 73 69 7a 65 22 0a 7d 20 24 3a 3a 53  age_size".} $::S
3f80: 51 4c 49 54 45 5f 4d 41 58 5f 50 41 47 45 5f 53  QLITE_MAX_PAGE_S
3f90: 49 5a 45 0a 0a 23 20 4f 70 65 6e 69 6e 67 20 61  IZE..# Opening a
3fa0: 20 64 61 74 61 62 61 73 65 20 77 68 65 72 65 20   database where 
3fb0: 74 68 65 20 70 61 67 65 20 73 69 7a 65 20 69 73  the page size is
3fc0: 20 74 6f 6f 20 6c 61 72 67 65 20 73 68 6f 75 6c   too large shoul
3fd0: 64 20 67 65 6e 65 72 61 74 65 0a 23 20 61 6e 20  d generate.# an 
3fe0: 65 72 72 6f 72 2e 0a 23 0a 64 6f 5f 74 65 73 74  error..#.do_test
3ff0: 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 31 30 2e   sqllimits-1.10.
4000: 35 20 7b 0a 20 20 64 62 20 63 6c 6f 73 65 0a 20  5 {.  db close. 
4010: 20 66 69 6c 65 20 64 65 6c 65 74 65 20 2d 66 6f   file delete -fo
4020: 72 63 65 20 74 65 73 74 2e 64 62 0a 20 20 73 65  rce test.db.  se
4030: 74 20 3a 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 50  t ::SQLITE_MAX_P
4040: 41 47 45 5f 53 49 5a 45 20 33 32 37 36 38 0a 20  AGE_SIZE 32768. 
4050: 20 73 71 6c 69 74 65 33 20 64 62 20 74 65 73 74   sqlite3 db test
4060: 2e 64 62 0a 20 20 64 62 20 65 76 61 6c 20 7b 50  .db.  db eval {P
4070: 52 41 47 4d 41 20 70 61 67 65 5f 73 69 7a 65 3d  RAGMA page_size=
4080: 33 32 37 36 38 7d 0a 20 20 64 62 20 65 76 61 6c  32768}.  db eval
4090: 20 7b 43 52 45 41 54 45 20 54 41 42 4c 45 20 74   {CREATE TABLE t
40a0: 31 28 78 29 3b 7d 0a 20 20 64 62 20 65 76 61 6c  1(x);}.  db eval
40b0: 20 7b 50 52 41 47 4d 41 20 70 61 67 65 5f 73 69   {PRAGMA page_si
40c0: 7a 65 7d 0a 7d 20 7b 33 32 37 36 38 7d 0a 64 6f  ze}.} {32768}.do
40d0: 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d  _test sqllimits-
40e0: 31 2e 31 30 2e 36 20 7b 0a 20 20 64 62 20 63 6c  1.10.6 {.  db cl
40f0: 6f 73 65 0a 20 20 73 65 74 20 3a 3a 53 51 4c 49  ose.  set ::SQLI
4100: 54 45 5f 4d 41 58 5f 50 41 47 45 5f 53 49 5a 45  TE_MAX_PAGE_SIZE
4110: 20 38 31 39 32 0a 20 20 73 71 6c 69 74 65 33 20   8192.  sqlite3 
4120: 64 62 20 74 65 73 74 2e 64 62 0a 20 20 63 61 74  db test.db.  cat
4130: 63 68 73 71 6c 20 7b 53 45 4c 45 43 54 20 6e 61  chsql {SELECT na
4140: 6d 65 20 46 52 4f 4d 20 73 71 6c 69 74 65 5f 6d  me FROM sqlite_m
4150: 61 73 74 65 72 7d 0a 7d 20 7b 31 20 7b 66 69 6c  aster}.} {1 {fil
4160: 65 20 69 73 20 65 6e 63 72 79 70 74 65 64 20 6f  e is encrypted o
4170: 72 20 69 73 20 6e 6f 74 20 61 20 64 61 74 61 62  r is not a datab
4180: 61 73 65 7d 7d 0a 64 62 20 63 6c 6f 73 65 0a 66  ase}}.db close.f
4190: 69 6c 65 20 64 65 6c 65 74 65 20 2d 66 6f 72 63  ile delete -forc
41a0: 65 20 74 65 73 74 2e 64 62 0a 73 71 6c 69 74 65  e test.db.sqlite
41b0: 33 20 64 62 20 74 65 73 74 2e 64 62 0a 0a 23 2d  3 db test.db..#-
41c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
41d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
41e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
41f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
4200: 2d 2d 2d 0a 23 20 54 65 73 74 20 63 61 73 65 73  ---.# Test cases
4210: 20 73 71 6c 6c 69 6d 69 74 73 2d 31 31 2e 2a 20   sqllimits-11.* 
4220: 76 65 72 69 66 79 20 74 68 61 74 20 74 68 65 20  verify that the 
4230: 0a 23 20 53 51 4c 49 54 45 5f 4d 41 58 5f 4c 49  .# SQLITE_MAX_LI
4240: 4b 45 5f 50 41 54 54 45 52 4e 5f 4c 45 4e 47 54  KE_PATTERN_LENGT
4250: 48 20 6c 69 6d 69 74 20 69 73 20 65 6e 66 6f 72  H limit is enfor
4260: 63 65 64 2e 20 54 68 69 73 20 6c 69 6d 69 74 20  ced. This limit 
4270: 6f 6e 6c 79 0a 23 20 61 70 70 6c 69 65 73 20 74  only.# applies t
4280: 6f 20 74 68 65 20 62 75 69 6c 74 2d 69 6e 20 4c  o the built-in L
4290: 49 4b 45 20 6f 70 65 72 61 74 6f 72 2c 20 73 75  IKE operator, su
42a0: 70 70 6c 79 69 6e 67 20 61 6e 20 65 78 74 65 72  pplying an exter
42b0: 6e 61 6c 20 0a 23 20 69 6d 70 6c 65 6d 65 6e 74  nal .# implement
42c0: 61 74 69 6f 6e 20 62 79 20 6f 76 65 72 72 69 64  ation by overrid
42d0: 69 6e 67 20 74 68 65 20 6c 69 6b 65 28 29 20 73  ing the like() s
42e0: 63 61 6c 61 72 20 66 75 6e 63 74 69 6f 6e 20 62  calar function b
42f0: 79 70 61 73 73 65 73 0a 23 20 74 68 69 73 20 6c  ypasses.# this l
4300: 69 6d 69 74 61 74 69 6f 6e 2e 0a 23 0a 23 20 54  imitation..#.# T
4310: 68 65 73 65 20 74 65 73 74 73 20 63 68 65 63 6b  hese tests check
4320: 20 74 68 61 74 20 74 68 65 20 6c 69 6d 69 74 20   that the limit 
4330: 69 73 20 6e 6f 74 20 69 6e 63 6f 72 72 65 63 74  is not incorrect
4340: 6c 79 20 61 70 70 6c 69 65 64 20 74 6f 0a 23 20  ly applied to.# 
4350: 74 68 65 20 6c 65 66 74 2d 68 61 6e 64 2d 73 69  the left-hand-si
4360: 64 65 20 6f 66 20 74 68 65 20 4c 49 4b 45 20 6f  de of the LIKE o
4370: 70 65 72 61 74 6f 72 20 28 74 68 65 20 73 74 72  perator (the str
4380: 69 6e 67 20 62 65 69 6e 67 20 74 65 73 74 65 64  ing being tested
4390: 0a 23 20 61 67 61 69 6e 73 74 20 74 68 65 20 70  .# against the p
43a0: 61 74 74 65 72 6e 29 2e 0a 23 0a 64 6f 5f 74 65  attern)..#.do_te
43b0: 73 74 20 73 71 6c 6c 69 6d 69 74 73 2d 31 2e 31  st sqllimits-1.1
43c0: 31 2e 31 20 7b 0a 20 20 73 65 74 20 6d 61 78 20  1.1 {.  set max 
43d0: 24 3a 3a 53 51 4c 49 54 45 5f 4d 41 58 5f 4c 49  $::SQLITE_MAX_LI
43e0: 4b 45 5f 50 41 54 54 45 52 4e 5f 4c 45 4e 47 54  KE_PATTERN_LENGT
43f0: 48 0a 20 20 73 65 74 20 3a 3a 70 61 74 74 65 72  H.  set ::patter
4400: 6e 20 5b 73 74 72 69 6e 67 20 72 65 70 65 61 74  n [string repeat
4410: 20 22 41 25 22 20 5b 65 78 70 72 20 24 6d 61 78   "A%" [expr $max
4420: 2f 32 5d 5d 0a 20 20 73 65 74 20 3a 3a 73 74 72  /2]].  set ::str
4430: 69 6e 67 20 20 5b 73 74 72 69 6e 67 20 72 65 70  ing  [string rep
4440: 65 61 74 20 22 41 22 20 5b 65 78 70 72 20 7b 24  eat "A" [expr {$
4450: 6d 61 78 2a 32 7d 5d 5d 0a 20 20 65 78 65 63 73  max*2}]].  execs
4460: 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45 43 54 20  ql {.    SELECT 
4470: 24 3a 3a 73 74 72 69 6e 67 20 4c 49 4b 45 20 24  $::string LIKE $
4480: 3a 3a 70 61 74 74 65 72 6e 3b 0a 20 20 7d 0a 7d  ::pattern;.  }.}
4490: 20 7b 31 7d 0a 64 6f 5f 74 65 73 74 20 73 71 6c   {1}.do_test sql
44a0: 6c 69 6d 69 74 73 2d 31 2e 31 31 2e 32 20 7b 0a  limits-1.11.2 {.
44b0: 20 20 73 65 74 20 6d 61 78 20 24 3a 3a 53 51 4c    set max $::SQL
44c0: 49 54 45 5f 4d 41 58 5f 4c 49 4b 45 5f 50 41 54  ITE_MAX_LIKE_PAT
44d0: 54 45 52 4e 5f 4c 45 4e 47 54 48 0a 20 20 73 65  TERN_LENGTH.  se
44e0: 74 20 3a 3a 70 61 74 74 65 72 6e 20 5b 73 74 72  t ::pattern [str
44f0: 69 6e 67 20 72 65 70 65 61 74 20 22 41 25 22 20  ing repeat "A%" 
4500: 5b 65 78 70 72 20 7b 28 24 6d 61 78 2f 32 29 20  [expr {($max/2) 
4510: 2b 20 31 7d 5d 5d 0a 20 20 73 65 74 20 3a 3a 73  + 1}]].  set ::s
4520: 74 72 69 6e 67 20 20 5b 73 74 72 69 6e 67 20 72  tring  [string r
4530: 65 70 65 61 74 20 22 41 22 20 5b 65 78 70 72 20  epeat "A" [expr 
4540: 7b 24 6d 61 78 2a 32 7d 5d 5d 0a 20 20 63 61 74  {$max*2}]].  cat
4550: 63 68 73 71 6c 20 7b 0a 20 20 20 20 53 45 4c 45  chsql {.    SELE
4560: 43 54 20 24 3a 3a 73 74 72 69 6e 67 20 4c 49 4b  CT $::string LIK
4570: 45 20 24 3a 3a 70 61 74 74 65 72 6e 3b 0a 20 20  E $::pattern;.  
4580: 7d 0a 7d 20 7b 31 20 7b 4c 49 4b 45 20 6f 72 20  }.} {1 {LIKE or 
4590: 47 4c 4f 42 20 70 61 74 74 65 72 6e 20 74 6f 6f  GLOB pattern too
45a0: 20 63 6f 6d 70 6c 65 78 7d 7d 0a 0a 23 2d 2d 2d   complex}}..#---
45b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
45c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
45d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
45e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
45f0: 2d 0a 23 20 54 68 69 73 20 74 65 73 74 20 63 61  -.# This test ca
4600: 73 65 20 64 6f 65 73 6e 27 74 20 72 65 61 6c 6c  se doesn't reall
4610: 79 20 62 65 6c 6f 6e 67 20 77 69 74 68 20 74 68  y belong with th
4620: 65 20 6f 74 68 65 72 20 6c 69 6d 69 74 73 20 74  e other limits t
4630: 65 73 74 73 2e 0a 23 20 49 74 20 69 73 20 69 6e  ests..# It is in
4640: 20 74 68 69 73 20 66 69 6c 65 20 62 65 63 61 75   this file becau
4650: 73 65 20 69 74 20 69 73 20 74 61 78 69 6e 67 20  se it is taxing 
4660: 74 6f 20 72 75 6e 2c 20 6c 69 6b 65 20 74 68 65  to run, like the
4670: 20 6c 69 6d 69 74 73 20 74 65 73 74 73 2e 0a 23   limits tests..#
4680: 0a 64 6f 5f 74 65 73 74 20 73 71 6c 6c 69 6d 69  .do_test sqllimi
4690: 74 73 2d 31 2e 31 32 2e 31 20 7b 0a 20 20 73 65  ts-1.12.1 {.  se
46a0: 74 20 3a 3a 4e 20 5b 65 78 70 72 20 69 6e 74 28  t ::N [expr int(
46b0: 28 5b 65 78 70 72 20 70 6f 77 28 32 2c 33 32 29  ([expr pow(2,32)
46c0: 5d 2f 35 30 29 20 2b 20 31 29 5d 0a 20 20 65 78  ]/50) + 1)].  ex
46d0: 70 72 20 28 28 24 3a 3a 4e 2a 35 30 29 20 26 20  pr (($::N*50) & 
46e0: 30 78 66 66 66 66 66 66 66 66 29 3c 35 35 0a 7d  0xffffffff)<55.}
46f0: 20 7b 31 7d 0a 64 6f 5f 74 65 73 74 20 73 71 6c   {1}.do_test sql
4700: 6c 69 6d 69 74 73 2d 31 2e 31 32 2e 32 20 7b 0a  limits-1.12.2 {.
4710: 20 20 73 65 74 20 3a 3a 66 6f 72 6d 61 74 20 22    set ::format "
4720: 5b 73 74 72 69 6e 67 20 72 65 70 65 61 74 20 41  [string repeat A
4730: 20 36 30 5d 5b 73 74 72 69 6e 67 20 72 65 70 65   60][string repe
4740: 61 74 20 22 25 4a 22 20 24 3a 3a 4e 5d 22 0a 20  at "%J" $::N]". 
4750: 20 63 61 74 63 68 73 71 6c 20 7b 0a 20 20 20 20   catchsql {.    
4760: 53 45 4c 45 43 54 20 73 74 72 66 74 69 6d 65 28  SELECT strftime(
4770: 24 3a 3a 66 6f 72 6d 61 74 2c 20 31 29 3b 0a 20  $::format, 1);. 
4780: 20 7d 0a 7d 20 7b 31 20 7b 73 74 72 69 6e 67 20   }.} {1 {string 
4790: 6f 72 20 62 6c 6f 62 20 74 6f 6f 20 62 69 67 7d  or blob too big}
47a0: 7d 0a 0a 0a 66 6f 72 65 61 63 68 20 7b 6b 65 79  }...foreach {key
47b0: 20 76 61 6c 75 65 7d 20 5b 61 72 72 61 79 20 67   value} [array g
47c0: 65 74 20 73 61 76 65 64 5d 20 7b 0a 20 20 63 61  et saved] {.  ca
47d0: 74 63 68 20 7b 73 65 74 20 24 6b 65 79 20 24 76  tch {set $key $v
47e0: 61 6c 75 65 7d 0a 7d 0a 66 69 6e 69 73 68 5f 74  alue}.}.finish_t
47f0: 65 73 74 0a                                      est.