/ Hex Artifact Content
Login

Artifact 81827ef286ff0d156cad84fb192590d69337c393:


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