3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
12 # This file contains tests to verify that the limits defined in
13 # sqlite source file limits.h are enforced.
15 # $Id: sqllimits1.test,v 1.33 2009/06/25 01:47:12 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
20 # Verify that the default per-connection limits are the same as
21 # the compile-time hard limits.
24 do_test sqllimits1-1.1 {
25 sqlite3_limit db SQLITE_LIMIT_LENGTH -1
27 do_test sqllimits1-1.2 {
28 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
29 } $SQLITE_MAX_SQL_LENGTH
30 do_test sqllimits1-1.3 {
31 sqlite3_limit db SQLITE_LIMIT_COLUMN -1
33 do_test sqllimits1-1.4 {
34 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
35 } $SQLITE_MAX_EXPR_DEPTH
36 do_test sqllimits1-1.5 {
37 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
38 } $SQLITE_MAX_COMPOUND_SELECT
39 do_test sqllimits1-1.6 {
40 sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
42 do_test sqllimits1-1.7 {
43 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
44 } $SQLITE_MAX_FUNCTION_ARG
45 do_test sqllimits1-1.8 {
46 sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
47 } $SQLITE_MAX_ATTACHED
48 do_test sqllimits1-1.9 {
49 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
50 } $SQLITE_MAX_LIKE_PATTERN_LENGTH
51 do_test sqllimits1-1.10 {
52 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
53 } $SQLITE_MAX_VARIABLE_NUMBER
54 do_test sqllimits1-1.11 {
55 sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH -1
56 } $SQLITE_MAX_TRIGGER_DEPTH
57 do_test sqllimits1-1.12 {
58 sqlite3_limit db SQLITE_LIMIT_WORKER_THREADS 99999
59 sqlite3_limit db SQLITE_LIMIT_WORKER_THREADS -1
60 } $SQLITE_MAX_WORKER_THREADS
62 # Limit parameters out of range.
64 do_test sqllimits1-1.20 {
65 sqlite3_limit db SQLITE_LIMIT_TOOSMALL 123
67 do_test sqllimits1-1.21 {
68 sqlite3_limit db SQLITE_LIMIT_TOOSMALL 123
70 do_test sqllimits1-1.22 {
71 sqlite3_limit db SQLITE_LIMIT_TOOBIG 123
73 do_test sqllimits1-1.23 {
74 sqlite3_limit db SQLITE_LIMIT_TOOBIG 123
78 # Decrease all limits by half. Verify that the new limits take.
80 if {$SQLITE_MAX_LENGTH>=2} {
81 do_test sqllimits1-2.1.1 {
82 sqlite3_limit db SQLITE_LIMIT_LENGTH \
83 [expr {$::SQLITE_MAX_LENGTH/2}]
85 do_test sqllimits1-2.1.2 {
86 sqlite3_limit db SQLITE_LIMIT_LENGTH -1
87 } [expr {$SQLITE_MAX_LENGTH/2}]
89 if {$SQLITE_MAX_SQL_LENGTH>=2} {
90 do_test sqllimits1-2.2.1 {
91 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH \
92 [expr {$::SQLITE_MAX_SQL_LENGTH/2}]
93 } $SQLITE_MAX_SQL_LENGTH
94 do_test sqllimits1-2.2.2 {
95 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
96 } [expr {$SQLITE_MAX_SQL_LENGTH/2}]
98 if {$SQLITE_MAX_COLUMN>=2} {
99 do_test sqllimits1-2.3.1 {
100 sqlite3_limit db SQLITE_LIMIT_COLUMN \
101 [expr {$::SQLITE_MAX_COLUMN/2}]
103 do_test sqllimits1-2.3.2 {
104 sqlite3_limit db SQLITE_LIMIT_COLUMN -1
105 } [expr {$SQLITE_MAX_COLUMN/2}]
107 if {$SQLITE_MAX_EXPR_DEPTH>=2} {
108 do_test sqllimits1-2.4.1 {
109 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH \
110 [expr {$::SQLITE_MAX_EXPR_DEPTH/2}]
111 } $SQLITE_MAX_EXPR_DEPTH
112 do_test sqllimits1-2.4.2 {
113 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
114 } [expr {$SQLITE_MAX_EXPR_DEPTH/2}]
116 if {$SQLITE_MAX_COMPOUND_SELECT>=2} {
117 do_test sqllimits1-2.5.1 {
118 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT \
119 [expr {$::SQLITE_MAX_COMPOUND_SELECT/2}]
120 } $SQLITE_MAX_COMPOUND_SELECT
121 do_test sqllimits1-2.5.2 {
122 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
123 } [expr {$SQLITE_MAX_COMPOUND_SELECT/2}]
125 if {$SQLITE_MAX_VDBE_OP>=2} {
126 do_test sqllimits1-2.6.1 {
127 sqlite3_limit db SQLITE_LIMIT_VDBE_OP \
128 [expr {$::SQLITE_MAX_VDBE_OP/2}]
129 } $SQLITE_MAX_VDBE_OP
130 do_test sqllimits1-2.6.2 {
131 sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
132 } [expr {$SQLITE_MAX_VDBE_OP/2}]
134 if {$SQLITE_MAX_FUNCTION_ARG>=2} {
135 do_test sqllimits1-2.7.1 {
136 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG \
137 [expr {$::SQLITE_MAX_FUNCTION_ARG/2}]
138 } $SQLITE_MAX_FUNCTION_ARG
139 do_test sqllimits1-2.7.2 {
140 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
141 } [expr {$SQLITE_MAX_FUNCTION_ARG/2}]
143 if {$SQLITE_MAX_ATTACHED>=2} {
144 do_test sqllimits1-2.8.1 {
145 sqlite3_limit db SQLITE_LIMIT_ATTACHED \
146 [expr {$::SQLITE_MAX_ATTACHED/2}]
147 } $SQLITE_MAX_ATTACHED
148 do_test sqllimits1-2.8.2 {
149 sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
150 } [expr {$SQLITE_MAX_ATTACHED/2}]
152 if {$SQLITE_MAX_LIKE_PATTERN_LENGTH>=2} {
153 do_test sqllimits1-2.9.1 {
154 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH \
155 [expr {$::SQLITE_MAX_LIKE_PATTERN_LENGTH/2}]
156 } $SQLITE_MAX_LIKE_PATTERN_LENGTH
157 do_test sqllimits1-2.9.2 {
158 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
159 } [expr {$SQLITE_MAX_LIKE_PATTERN_LENGTH/2}]
161 if {$SQLITE_MAX_VARIABLE_NUMBER>=2} {
162 do_test sqllimits1-2.10.1 {
163 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER \
164 [expr {$::SQLITE_MAX_VARIABLE_NUMBER/2}]
165 } $SQLITE_MAX_VARIABLE_NUMBER
166 do_test sqllimits1-2.10.2 {
167 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
168 } [expr {$SQLITE_MAX_VARIABLE_NUMBER/2}]
171 # In a separate database connection, verify that the limits are unchanged.
173 do_test sqllimits1-3.1 {
174 sqlite3_limit db2 SQLITE_LIMIT_LENGTH -1
176 do_test sqllimits1-3.2 {
177 sqlite3_limit db2 SQLITE_LIMIT_SQL_LENGTH -1
178 } $SQLITE_MAX_SQL_LENGTH
179 do_test sqllimits1-3.3 {
180 sqlite3_limit db2 SQLITE_LIMIT_COLUMN -1
182 do_test sqllimits1-3.4 {
183 sqlite3_limit db2 SQLITE_LIMIT_EXPR_DEPTH -1
184 } $SQLITE_MAX_EXPR_DEPTH
185 do_test sqllimits1-3.5 {
186 sqlite3_limit db2 SQLITE_LIMIT_COMPOUND_SELECT -1
187 } $SQLITE_MAX_COMPOUND_SELECT
188 do_test sqllimits1-3.6 {
189 sqlite3_limit db2 SQLITE_LIMIT_VDBE_OP -1
190 } $SQLITE_MAX_VDBE_OP
191 do_test sqllimits1-3.7 {
192 sqlite3_limit db2 SQLITE_LIMIT_FUNCTION_ARG -1
193 } $SQLITE_MAX_FUNCTION_ARG
194 do_test sqllimits1-3.8 {
195 sqlite3_limit db2 SQLITE_LIMIT_ATTACHED -1
196 } $SQLITE_MAX_ATTACHED
197 do_test sqllimits1-3.9 {
198 sqlite3_limit db2 SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
199 } $SQLITE_MAX_LIKE_PATTERN_LENGTH
200 do_test sqllimits1-3.10 {
201 sqlite3_limit db2 SQLITE_LIMIT_VARIABLE_NUMBER -1
202 } $SQLITE_MAX_VARIABLE_NUMBER
205 # Attempt to set all limits to the maximum 32-bit integer. Verify
206 # that the limit does not exceed the compile-time upper bound.
208 do_test sqllimits1-4.1.1 {
209 sqlite3_limit db SQLITE_LIMIT_LENGTH 0x7fffffff
210 sqlite3_limit db SQLITE_LIMIT_LENGTH -1
212 do_test sqllimits1-4.2.1 {
213 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 0x7fffffff
214 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
215 } $SQLITE_MAX_SQL_LENGTH
216 do_test sqllimits1-4.3.1 {
217 sqlite3_limit db SQLITE_LIMIT_COLUMN 0x7fffffff
218 sqlite3_limit db SQLITE_LIMIT_COLUMN -1
220 do_test sqllimits1-4.4.1 {
221 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH 0x7fffffff
222 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
223 } $SQLITE_MAX_EXPR_DEPTH
224 do_test sqllimits1-4.5.1 {
225 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 0x7fffffff
226 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
227 } $SQLITE_MAX_COMPOUND_SELECT
228 do_test sqllimits1-4.6.1 {
229 sqlite3_limit db SQLITE_LIMIT_VDBE_OP 0x7fffffff
230 sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
231 } $SQLITE_MAX_VDBE_OP
232 do_test sqllimits1-4.7.1 {
233 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG 0x7fffffff
234 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
235 } $SQLITE_MAX_FUNCTION_ARG
236 do_test sqllimits1-4.8.1 {
237 sqlite3_limit db SQLITE_LIMIT_ATTACHED 0x7fffffff
238 sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
239 } $SQLITE_MAX_ATTACHED
240 do_test sqllimits1-4.9.1 {
241 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH 0x7fffffff
242 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
243 } $SQLITE_MAX_LIKE_PATTERN_LENGTH
244 do_test sqllimits1-4.10.1 {
245 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER 0x7fffffff
246 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
247 } $SQLITE_MAX_VARIABLE_NUMBER
249 #--------------------------------------------------------------------
250 # Test cases sqllimits1-5.* test that the SQLITE_MAX_LENGTH limit
253 # EVIDENCE-OF: R-61987-00541 SQLITE_LIMIT_LENGTH The maximum size of any
254 # string or BLOB or table row, in bytes.
259 set SQLITE_LIMIT_LENGTH 100000
260 sqlite3_limit db SQLITE_LIMIT_LENGTH $SQLITE_LIMIT_LENGTH
262 do_test sqllimits1-5.1.1 {
263 catchsql { SELECT randomblob(2147483647) }
264 } {1 {string or blob too big}}
265 do_test sqllimits1-5.1.2 {
266 catchsql { SELECT zeroblob(2147483647) }
267 } {1 {string or blob too big}}
269 do_test sqllimits1-5.2 {
270 catchsql { SELECT LENGTH(randomblob($::LARGESIZE)) }
271 } [list 0 $LARGESIZE]
273 do_test sqllimits1-5.3 {
274 catchsql { SELECT quote(randomblob($::LARGESIZE)) }
275 } {1 {string or blob too big}}
277 do_test sqllimits1-5.4 {
278 catchsql { SELECT LENGTH(zeroblob($::LARGESIZE)) }
279 } [list 0 $LARGESIZE]
281 do_test sqllimits1-5.5 {
282 catchsql { SELECT quote(zeroblob($::LARGESIZE)) }
283 } {1 {string or blob too big}}
285 do_test sqllimits1-5.6 {
286 catchsql { SELECT zeroblob(-1) }
289 do_test sqllimits1-5.9 {
290 set ::str [string repeat A 65537]
291 set ::rep [string repeat B 65537]
292 catchsql { SELECT replace($::str, 'A', $::rep) }
293 } {1 {string or blob too big}}
295 do_test sqllimits1-5.10 {
296 # Prior to 3.37.0 strftime() allocated a large static buffer into
297 # which to format its output. Using that strategy, 2100 repeats was
298 # enough to exceed 100KiB and provoke the error. As of 3.37.0 strftime()
299 # uses the StrAccum functions, so it requires 12100 to fail.
301 # set ::str [string repeat %J 2100]
302 set ::str [string repeat %J 12100]
303 catchsql { SELECT length(strftime($::str, '2003-10-31')) }
304 } {1 {string or blob too big}}
306 do_test sqllimits1-5.11 {
307 set ::str1 [string repeat A [expr {$SQLITE_LIMIT_LENGTH - 10}]]
308 set ::str2 [string repeat B [expr {$SQLITE_LIMIT_LENGTH - 10}]]
309 catchsql { SELECT $::str1 || $::str2 }
310 } {1 {string or blob too big}}
312 do_test sqllimits1-5.12 {
313 set ::str1 [string repeat ' [expr {$SQLITE_LIMIT_LENGTH - 10}]]
314 catchsql { SELECT quote($::str1) }
315 } {1 {string or blob too big}}
317 do_test sqllimits1-5.13 {
318 set ::str1 [string repeat ' [expr {$SQLITE_LIMIT_LENGTH - 10}]]
319 catchsql { SELECT hex($::str1) }
320 } {1 {string or blob too big}}
322 do_test sqllimits1-5.14.1 {
323 set ::STMT [sqlite3_prepare db "SELECT ?" -1 TAIL]
324 sqlite3_bind_zeroblob $::STMT 1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
326 do_test sqllimits1-5.14.2 {
329 do_test sqllimits1-5.14.3 {
330 sqlite3_reset $::STMT
332 do_test sqllimits1-5.14.4 {
333 set np1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
334 set ::str1 [string repeat A $np1]
335 catch {sqlite3_bind_text $::STMT 1 $::str1 -1} res
339 do_test sqllimits1-5.14.5 {
340 catch {sqlite3_bind_text16 $::STMT 1 $::str1 -1} res
344 do_test sqllimits1-5.14.6 {
345 catch {sqlite3_bind_text $::STMT 1 $::str1 $np1} res
349 do_test sqllimits1-5.14.7 {
350 catch {sqlite3_bind_text16 $::STMT 1 $::str1 $np1} res
354 do_test sqllimits1-5.14.8 {
355 set n [expr {$np1-1}]
356 catch {sqlite3_bind_text $::STMT 1 $::str1 $n} res
359 do_test sqllimits1-5.14.9 {
360 catch {sqlite3_bind_text16 $::STMT 1 $::str1 $n} res
363 sqlite3_finalize $::STMT
365 do_test sqllimits1-5.15 {
368 INSERT INTO t4 VALUES(1);
369 INSERT INTO t4 VALUES(2);
370 INSERT INTO t4 SELECT 2+x FROM t4;
373 SELECT group_concat(hex(randomblob(20000))) FROM t4;
375 } {1 {string or blob too big}}
376 db eval {DROP TABLE t4}
378 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 0x7fffffff
379 set strvalue [string repeat A $::SQLITE_LIMIT_LENGTH]
380 do_test sqllimits1-5.16 {
381 catchsql "SELECT '$strvalue' AS x"
383 do_test sqllimits1-5.17.1 {
384 catchsql "SELECT 'A$strvalue'"
385 } [list 1 {string or blob too big}]
386 do_test sqllimits1-5.17.2 {
387 sqlite3_limit db SQLITE_LIMIT_LENGTH 0x7fffffff
388 catchsql {SELECT 'A' || $::strvalue}
389 } [list 0 A$strvalue]
390 do_test sqllimits1-5.17.3 {
391 sqlite3_limit db SQLITE_LIMIT_LENGTH $SQLITE_LIMIT_LENGTH
392 catchsql {SELECT 'A' || $::strvalue}
393 } [list 1 {string or blob too big}]
394 set blobvalue [string repeat 41 $::SQLITE_LIMIT_LENGTH]
395 do_test sqllimits1-5.18 {
396 catchsql "SELECT x'$blobvalue' AS x"
398 do_test sqllimits1-5.19 {
399 catchsql "SELECT '41$blobvalue'"
400 } [list 1 {string or blob too big}]
404 set strvalue [string repeat D [expr {$SQLITE_LIMIT_LENGTH-11}]]
405 do_test sqllimits1-5.20 {
406 catchsql {SELECT strftime('%Y ' || $::strvalue, '2008-01-02')}
407 } [list 0 [list "2008 $strvalue"]]
408 do_test sqllimits1-5.21 {
409 catchsql {SELECT strftime('%Y-%m-%d ' || $::strvalue, '2008-01-02')}
410 } {1 {string or blob too big}}
414 #--------------------------------------------------------------------
415 # Test cases sqllimits1-6.* test that the SQLITE_MAX_SQL_LENGTH limit
418 # EVIDENCE-OF: R-09808-17554 SQLITE_LIMIT_SQL_LENGTH The maximum length
419 # of an SQL statement, in bytes.
421 do_test sqllimits1-6.1 {
422 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 50000
423 set sql "SELECT 1 WHERE 1==1"
424 set tail " /* A comment to take up space in order to make the string\
425 longer without increasing the expression depth */\
427 set N [expr {(50000 / [string length $tail])+1}]
428 append sql [string repeat $tail $N]
430 } {1 {string or blob too big}}
431 do_test sqllimits1-6.3 {
432 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 50000
433 set sql "SELECT 1 WHERE 1==1"
434 set tail " /* A comment to take up space in order to make the string\
435 longer without increasing the expression depth */\
437 set N [expr {(50000 / [string length $tail])+1}]
438 append sql [string repeat $tail $N]
439 set nbytes [string length $sql]
441 set rc [catch {sqlite3_prepare db $sql $nbytes TAIL} STMT]
443 } {1 {(18) statement too long}}
444 do_test sqllimits1-6.4 {
446 } {statement too long}
448 #--------------------------------------------------------------------
449 # Test cases sqllimits1-7.* test that the limit set using the
450 # max_page_count pragma.
452 do_test sqllimits1-7.1 {
454 PRAGMA max_page_count = 1000;
457 do_test sqllimits1-7.2 {
458 execsql { CREATE TABLE trig (a INTEGER, b INTEGER); }
460 # Set up a tree of triggers to fire when a row is inserted
463 # INSERT -> insert_b -> update_b -> insert_a -> update_a (chain 1)
464 # -> update_a -> insert_a -> update_b (chain 2)
465 # -> insert_a -> update_b -> insert_b -> update_a (chain 3)
466 # -> update_a -> insert_b -> update_b (chain 4)
468 # Table starts with N rows.
470 # Chain 1: insert_b (update N rows)
471 # -> update_b (insert 1 rows)
472 # -> insert_a (update N rows)
473 # -> update_a (insert 1 rows)
475 # chains 2, 3 and 4 are similar. Each inserts more than N^2 rows, where
476 # N is the number of rows at the conclusion of the previous chain.
478 # Therefore, a single insert adds (N^16 plus some) rows to the database.
479 # A really long loop...
482 CREATE TRIGGER update_b BEFORE UPDATE ON trig
484 INSERT INTO trig VALUES (65, 'update_b');
487 CREATE TRIGGER update_a AFTER UPDATE ON trig
489 INSERT INTO trig VALUES (65, 'update_a');
492 CREATE TRIGGER insert_b BEFORE INSERT ON trig
494 UPDATE trig SET a = 1;
497 CREATE TRIGGER insert_a AFTER INSERT ON trig
499 UPDATE trig SET a = 1;
504 do_test sqllimits1-7.3 {
506 INSERT INTO trig VALUES (1,1);
510 do_test sqllimits1-7.4 {
512 SELECT COUNT(*) FROM trig;
516 # This tries to insert so many rows it fills up the database (limited
517 # to 1MB, so not that noteworthy an achievement).
519 do_test sqllimits1-7.5 {
521 INSERT INTO trig VALUES (1,10);
523 } {1 {database or disk is full}}
525 do_test sqllimits1-7.6 {
527 SELECT COUNT(*) FROM trig;
531 # Now check the response of the library to opening a file larger than
532 # the current max_page_count value. The response is to change the
533 # internal max_page_count value to match the actual size of the file.
534 if {[db eval {PRAGMA auto_vacuum}]} {
539 do_test sqllimits1-7.7.1 {
541 PRAGMA max_page_count = 1000000;
542 CREATE TABLE abc(a, b, c);
543 INSERT INTO abc VALUES(1, 2, 3);
544 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
545 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
546 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
547 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
548 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
549 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
550 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
551 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
552 INSERT INTO abc SELECT a, b, c FROM abc;
553 INSERT INTO abc SELECT b, a, c FROM abc;
554 INSERT INTO abc SELECT c, b, a FROM abc;
556 expr [file size test.db] / 1024
558 do_test sqllimits1-7.7.2 {
562 PRAGMA max_page_count = 1000;
565 SELECT count(*) FROM sqlite_master;
568 do_test sqllimits1-7.7.3 {
570 PRAGMA max_page_count;
573 do_test sqllimits1-7.7.4 {
579 #--------------------------------------------------------------------
580 # Test cases sqllimits1-8.* test the SQLITE_MAX_COLUMN limit.
582 # EVIDENCE-OF: R-43996-29471 SQLITE_LIMIT_COLUMN The maximum number of
583 # columns in a table definition or in the result set of a SELECT or the
584 # maximum number of columns in an index or in an ORDER BY or GROUP BY
587 set SQLITE_LIMIT_COLUMN 200
588 sqlite3_limit db SQLITE_LIMIT_COLUMN $SQLITE_LIMIT_COLUMN
589 do_test sqllimits1-8.1 {
590 # Columns in a table.
592 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
595 catchsql "CREATE TABLE t([join $cols ,])"
596 } {1 {too many columns on t}}
598 do_test sqllimits1-8.2 {
599 # Columns in the result-set of a SELECT.
601 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
602 lappend cols "sql AS sql$i"
604 catchsql "SELECT [join $cols ,] FROM sqlite_master"
605 } {1 {too many columns in result set}}
607 do_test sqllimits1-8.3 {
608 # Columns in the result-set of a sub-SELECT.
610 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
611 lappend cols "sql AS sql$i"
613 catchsql "SELECT sql4 FROM (SELECT [join $cols ,] FROM sqlite_master)"
614 } {1 {too many columns in result set}}
616 do_test sqllimits1-8.4 {
617 # Columns in an index.
619 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
622 set sql1 "CREATE TABLE t1(c);"
623 set sql2 "CREATE INDEX i1 ON t1([join $cols ,]);"
624 catchsql "$sql1 ; $sql2"
625 } {1 {too many columns in index}}
627 do_test sqllimits1-8.5 {
628 # Columns in a GROUP BY clause.
629 catchsql "SELECT * FROM t1 GROUP BY [join $cols ,]"
630 } {1 {too many terms in GROUP BY clause}}
632 do_test sqllimits1-8.6 {
633 # Columns in an ORDER BY clause.
634 catchsql "SELECT * FROM t1 ORDER BY [join $cols ,]"
635 } {1 {too many terms in ORDER BY clause}}
637 do_test sqllimits1-8.7 {
638 # Assignments in an UPDATE statement.
640 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
643 catchsql "UPDATE t1 SET [join $cols ,];"
644 } {1 {too many columns in set list}}
646 do_test sqllimits1-8.8 {
647 # Columns in a view definition:
649 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
652 execsql "CREATE VIEW v1 AS SELECT [join $cols ,] FROM t1;"
653 catchsql {SELECT * FROM v1}
654 } {1 {too many columns in result set}}
656 do_test sqllimits1-8.9 {
657 # Columns in a view definition (testing * expansion):
659 for {set i 0} {$i < $SQLITE_LIMIT_COLUMN} {incr i} {
662 execsql {DROP VIEW IF EXISTS v1}
663 catchsql "CREATE TABLE t2([join $cols ,])"
664 catchsql "CREATE VIEW v1 AS SELECT *, c1 AS o FROM t2;"
665 catchsql "SELECT * FROM v1"
666 } {1 {too many columns in result set}}
668 do_test sqllimits1-8.10 {
671 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
674 set sql "SELECT c FROM t1 ORDER BY [join $cols ,]"
676 } {1 {too many terms in ORDER BY clause}}
677 do_test sqllimits1-8.11 {
680 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
681 lappend cols [expr {$i%3 + 1}]
683 set sql "SELECT c, c+1, c+2 FROM t1 UNION SELECT c-1, c-2, c-3 FROM t1"
684 append sql " ORDER BY [join $cols ,]"
686 } {1 {too many terms in ORDER BY clause}}
689 #--------------------------------------------------------------------
690 # These tests - sqllimits1-9.* - test that the SQLITE_LIMIT_EXPR_DEPTH
691 # limit is enforced. The limit refers to the number of terms in
694 # EVIDENCE-OF: R-12723-08526 SQLITE_LIMIT_EXPR_DEPTH The maximum depth
695 # of the parse tree on any expression.
697 if {$SQLITE_MAX_EXPR_DEPTH==0} {
698 puts -nonewline stderr "WARNING: Compile with -DSQLITE_MAX_EXPR_DEPTH to run "
699 puts stderr "tests sqllimits1-9.X"
701 do_test sqllimits1-9.1 {
702 set max $::SQLITE_MAX_EXPR_DEPTH
703 set expr "(1 [string repeat {AND 1 } $max])"
707 } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
709 # Attempting to beat the expression depth limit using nested SELECT
710 # queries causes a parser stack overflow.
711 do_test sqllimits1-9.2 {
712 set max $::SQLITE_MAX_EXPR_DEPTH
714 for {set i 0} {$i <= $max} {incr i} {
715 set expr "SELECT ($expr)"
717 catchsql [subst { $expr }]
718 } "1 {parser stack overflow}"
721 do_test sqllimits1-9.3 {
723 PRAGMA max_page_count = 1000000; -- 1 GB
725 INSERT INTO v0 VALUES(1);
728 for {set i 1} {$i < 200} {incr i} {
729 set expr "(a [string repeat {AND 1 } 50]) AS a"
731 CREATE VIEW v${i} AS SELECT $expr FROM v[expr {$i-1}]
737 do_test sqllimits1-9.4 {
741 } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
745 #--------------------------------------------------------------------
746 # Test cases sqllimits1-10.* test that the SQLITE_MAX_VDBE_OP
747 # limit works as expected. The limit refers to the number of opcodes
748 # in a single VDBE program.
752 #--------------------------------------------------------------------
753 # Test the SQLITE_LIMIT_FUNCTION_ARG limit works. Test case names
754 # match the pattern "sqllimits1-11.*".
756 # EVIDENCE-OF: R-59001-45278 SQLITE_LIMIT_FUNCTION_ARG The maximum
757 # number of arguments on a function.
759 for {set max 5} {$max<=$SQLITE_MAX_FUNCTION_ARG} {incr max} {
760 do_test sqllimits1-11.$max.1 {
762 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG $::max
763 for {set i 0} {$i < $::max} {incr i} {
766 catchsql "SELECT max([join $vals ,])"
767 } "0 [expr {$::max - 1}]"
768 do_test sqllimits1-11.$max.2 {
770 for {set i 0} {$i <= $::max} {incr i} {
773 catchsql "SELECT max([join $vals ,])"
774 } {1 {too many arguments on function max}}
776 # Test that it is SQLite, and not the implementation of the
777 # user function that is throwing the error.
778 proc myfunc {args} {error "I don't like to be called!"}
779 do_test sqllimits1-11.$max.2 {
780 db function myfunc myfunc
782 for {set i 0} {$i <= $::max} {incr i} {
785 catchsql "SELECT myfunc([join $vals ,])"
786 } {1 {too many arguments on function myfunc}}
789 #--------------------------------------------------------------------
790 # Test cases sqllimits1-12.*: Test the SQLITE_MAX_ATTACHED limit.
792 # EVIDENCE-OF: R-41778-26203 SQLITE_LIMIT_ATTACHED The maximum number of
793 # attached databases.
796 do_test sqllimits1-12.1 {
797 set max $::SQLITE_MAX_ATTACHED
798 for {set i 0} {$i < ($max)} {incr i} {
799 forcedelete test${i}.db test${i}.db-journal
801 for {set i 0} {$i < ($max)} {incr i} {
802 execsql "ATTACH 'test${i}.db' AS aux${i}"
804 catchsql "ATTACH 'test${i}.db' AS aux${i}"
805 } "1 {too many attached databases - max $::SQLITE_MAX_ATTACHED}"
806 do_test sqllimits1-12.2 {
807 set max $::SQLITE_MAX_ATTACHED
808 for {set i 0} {$i < ($max)} {incr i} {
809 execsql "DETACH aux${i}"
814 #--------------------------------------------------------------------
815 # Test cases sqllimits1-13.*: Check that the SQLITE_MAX_VARIABLE_NUMBER
818 # EVIDENCE-OF: R-42363-29104 SQLITE_LIMIT_VARIABLE_NUMBER The maximum
819 # index number of any parameter in an SQL statement.
821 do_test sqllimits1-13.1 {
822 set max $::SQLITE_MAX_VARIABLE_NUMBER
823 catchsql "SELECT ?[expr {$max+1}] FROM t1"
824 } "1 {variable number must be between ?1 and ?$::SQLITE_MAX_VARIABLE_NUMBER}"
825 do_test sqllimits1-13.2 {
826 set max $::SQLITE_MAX_VARIABLE_NUMBER
828 for {set i 0} {$i < ($max+3)} {incr i} {
831 catchsql "SELECT [join $vals ,] FROM t1"
832 } "1 {too many SQL variables}"
835 #--------------------------------------------------------------------
836 # Test cases sqllimits1-15.* verify that the
837 # SQLITE_MAX_LIKE_PATTERN_LENGTH limit is enforced. This limit only
838 # applies to the built-in LIKE operator, supplying an external
839 # implementation by overriding the like() scalar function bypasses
842 # EVIDENCE-OF: R-12940-37052 SQLITE_LIMIT_LIKE_PATTERN_LENGTH The
843 # maximum length of the pattern argument to the LIKE or GLOB operators.
845 # These tests check that the limit is not incorrectly applied to
846 # the left-hand-side of the LIKE operator (the string being tested
847 # against the pattern).
849 set SQLITE_LIMIT_LIKE_PATTERN 1000
850 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH $SQLITE_LIMIT_LIKE_PATTERN
851 do_test sqllimits1-15.1 {
852 set max $::SQLITE_LIMIT_LIKE_PATTERN
853 set ::pattern [string repeat "A%" [expr $max/2]]
854 set ::string [string repeat "A" [expr {$max*2}]]
856 SELECT $::string LIKE $::pattern;
859 do_test sqllimits1-15.2 {
860 set max $::SQLITE_LIMIT_LIKE_PATTERN
861 set ::pattern [string repeat "A%" [expr {($max/2) + 1}]]
862 set ::string [string repeat "A" [expr {$max*2}]]
864 SELECT $::string LIKE $::pattern;
866 } {1 {LIKE or GLOB pattern too complex}}
868 #--------------------------------------------------------------------
869 # This test case doesn't really belong with the other limits tests.
870 # It is in this file because it is taxing to run, like the limits tests.
872 # Update for 3.37.0: strftime() used to allocate a large static buffer
873 # into which it would write its result. With that implementation, the
874 # following would trigger an SQLITE_TOOBIG error. But strftime() now
875 # uses the StrAccum functions, causing this test to fail.
877 #do_test sqllimits1-16.1 {
878 # set ::N [expr int(([expr pow(2,32)]/50) + 1)]
879 # expr (($::N*50) & 0xffffffff)<55
881 #do_test sqllimits1-16.2 {
882 # set ::format "[string repeat A 60][string repeat "%J" $::N]"
884 # SELECT strftime($::format, 1);
886 #} {1 {string or blob too big}}
888 do_catchsql_test sqllimits1.17.0 {
889 SELECT *,*,*,*,*,*,*,* FROM (
890 SELECT *,*,*,*,*,*,*,* FROM (
891 SELECT *,*,*,*,*,*,*,* FROM (
892 SELECT *,*,*,*,*,*,*,* FROM (
893 SELECT *,*,*,*,*,*,*,* FROM (
894 SELECT 1,2,3,4,5,6,7,8,9,10
897 } "1 {too many columns in result set}"
900 foreach {key value} [array get saved] {
901 catch {set $key $value}
904 #-------------------------------------------------------------------------
905 # At one point the following caused an assert() to fail.
907 sqlite3_limit db SQLITE_LIMIT_LENGTH 10000
908 set nm [string repeat x 10000]
909 do_catchsql_test sqllimits1-17.1 "
910 CREATE TABLE $nm (x PRIMARY KEY)
911 " {1 {string or blob too big}}