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 set ::str [string repeat %J 2100]
297 catchsql { SELECT strftime($::str, '2003-10-31') }
298 } {1 {string or blob too big}}
300 do_test sqllimits1-5.11 {
301 set ::str1 [string repeat A [expr {$SQLITE_LIMIT_LENGTH - 10}]]
302 set ::str2 [string repeat B [expr {$SQLITE_LIMIT_LENGTH - 10}]]
303 catchsql { SELECT $::str1 || $::str2 }
304 } {1 {string or blob too big}}
306 do_test sqllimits1-5.12 {
307 set ::str1 [string repeat ' [expr {$SQLITE_LIMIT_LENGTH - 10}]]
308 catchsql { SELECT quote($::str1) }
309 } {1 {string or blob too big}}
311 do_test sqllimits1-5.13 {
312 set ::str1 [string repeat ' [expr {$SQLITE_LIMIT_LENGTH - 10}]]
313 catchsql { SELECT hex($::str1) }
314 } {1 {string or blob too big}}
316 do_test sqllimits1-5.14.1 {
317 set ::STMT [sqlite3_prepare db "SELECT ?" -1 TAIL]
318 sqlite3_bind_zeroblob $::STMT 1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
320 do_test sqllimits1-5.14.2 {
323 do_test sqllimits1-5.14.3 {
324 sqlite3_reset $::STMT
326 do_test sqllimits1-5.14.4 {
327 set np1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
328 set ::str1 [string repeat A $np1]
329 catch {sqlite3_bind_text $::STMT 1 $::str1 -1} res
333 do_test sqllimits1-5.14.5 {
334 catch {sqlite3_bind_text16 $::STMT 1 $::str1 -1} res
338 do_test sqllimits1-5.14.6 {
339 catch {sqlite3_bind_text $::STMT 1 $::str1 $np1} res
343 do_test sqllimits1-5.14.7 {
344 catch {sqlite3_bind_text16 $::STMT 1 $::str1 $np1} res
348 do_test sqllimits1-5.14.8 {
349 set n [expr {$np1-1}]
350 catch {sqlite3_bind_text $::STMT 1 $::str1 $n} res
353 do_test sqllimits1-5.14.9 {
354 catch {sqlite3_bind_text16 $::STMT 1 $::str1 $n} res
357 sqlite3_finalize $::STMT
359 do_test sqllimits1-5.15 {
362 INSERT INTO t4 VALUES(1);
363 INSERT INTO t4 VALUES(2);
364 INSERT INTO t4 SELECT 2+x FROM t4;
367 SELECT group_concat(hex(randomblob(20000))) FROM t4;
369 } {1 {string or blob too big}}
370 db eval {DROP TABLE t4}
372 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 0x7fffffff
373 set strvalue [string repeat A $::SQLITE_LIMIT_LENGTH]
374 do_test sqllimits1-5.16 {
375 catchsql "SELECT '$strvalue'"
377 do_test sqllimits1-5.17.1 {
378 catchsql "SELECT 'A$strvalue'"
379 } [list 1 {string or blob too big}]
380 do_test sqllimits1-5.17.2 {
381 sqlite3_limit db SQLITE_LIMIT_LENGTH 0x7fffffff
382 catchsql {SELECT 'A' || $::strvalue}
383 } [list 0 A$strvalue]
384 do_test sqllimits1-5.17.3 {
385 sqlite3_limit db SQLITE_LIMIT_LENGTH $SQLITE_LIMIT_LENGTH
386 catchsql {SELECT 'A' || $::strvalue}
387 } [list 1 {string or blob too big}]
388 set blobvalue [string repeat 41 $::SQLITE_LIMIT_LENGTH]
389 do_test sqllimits1-5.18 {
390 catchsql "SELECT x'$blobvalue'"
392 do_test sqllimits1-5.19 {
393 catchsql "SELECT '41$blobvalue'"
394 } [list 1 {string or blob too big}]
398 set strvalue [string repeat D [expr {$SQLITE_LIMIT_LENGTH-12}]]
399 do_test sqllimits1-5.20 {
400 catchsql {SELECT strftime('%Y ' || $::strvalue, '2008-01-02')}
401 } [list 0 [list "2008 $strvalue"]]
402 do_test sqllimits1-5.21 {
403 catchsql {SELECT strftime('%Y-%m-%d ' || $::strvalue, '2008-01-02')}
404 } {1 {string or blob too big}}
408 #--------------------------------------------------------------------
409 # Test cases sqllimits1-6.* test that the SQLITE_MAX_SQL_LENGTH limit
412 # EVIDENCE-OF: R-09808-17554 SQLITE_LIMIT_SQL_LENGTH The maximum length
413 # of an SQL statement, in bytes.
415 do_test sqllimits1-6.1 {
416 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 50000
417 set sql "SELECT 1 WHERE 1==1"
418 set tail " /* A comment to take up space in order to make the string\
419 longer without increasing the expression depth */\
421 set N [expr {(50000 / [string length $tail])+1}]
422 append sql [string repeat $tail $N]
424 } {1 {string or blob too big}}
425 do_test sqllimits1-6.3 {
426 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 50000
427 set sql "SELECT 1 WHERE 1==1"
428 set tail " /* A comment to take up space in order to make the string\
429 longer without increasing the expression depth */\
431 set N [expr {(50000 / [string length $tail])+1}]
432 append sql [string repeat $tail $N]
433 set nbytes [string length $sql]
435 set rc [catch {sqlite3_prepare db $sql $nbytes TAIL} STMT]
437 } {1 {(18) statement too long}}
438 do_test sqllimits1-6.4 {
440 } {statement too long}
442 #--------------------------------------------------------------------
443 # Test cases sqllimits1-7.* test that the limit set using the
444 # max_page_count pragma.
446 do_test sqllimits1-7.1 {
448 PRAGMA max_page_count = 1000;
451 do_test sqllimits1-7.2 {
452 execsql { CREATE TABLE trig (a INTEGER, b INTEGER); }
454 # Set up a tree of triggers to fire when a row is inserted
457 # INSERT -> insert_b -> update_b -> insert_a -> update_a (chain 1)
458 # -> update_a -> insert_a -> update_b (chain 2)
459 # -> insert_a -> update_b -> insert_b -> update_a (chain 3)
460 # -> update_a -> insert_b -> update_b (chain 4)
462 # Table starts with N rows.
464 # Chain 1: insert_b (update N rows)
465 # -> update_b (insert 1 rows)
466 # -> insert_a (update N rows)
467 # -> update_a (insert 1 rows)
469 # chains 2, 3 and 4 are similar. Each inserts more than N^2 rows, where
470 # N is the number of rows at the conclusion of the previous chain.
472 # Therefore, a single insert adds (N^16 plus some) rows to the database.
473 # A really long loop...
476 CREATE TRIGGER update_b BEFORE UPDATE ON trig
478 INSERT INTO trig VALUES (65, 'update_b');
481 CREATE TRIGGER update_a AFTER UPDATE ON trig
483 INSERT INTO trig VALUES (65, 'update_a');
486 CREATE TRIGGER insert_b BEFORE INSERT ON trig
488 UPDATE trig SET a = 1;
491 CREATE TRIGGER insert_a AFTER INSERT ON trig
493 UPDATE trig SET a = 1;
498 do_test sqllimits1-7.3 {
500 INSERT INTO trig VALUES (1,1);
504 do_test sqllimits1-7.4 {
506 SELECT COUNT(*) FROM trig;
510 # This tries to insert so many rows it fills up the database (limited
511 # to 1MB, so not that noteworthy an achievement).
513 do_test sqllimits1-7.5 {
515 INSERT INTO trig VALUES (1,10);
517 } {1 {database or disk is full}}
519 do_test sqllimits1-7.6 {
521 SELECT COUNT(*) FROM trig;
525 # Now check the response of the library to opening a file larger than
526 # the current max_page_count value. The response is to change the
527 # internal max_page_count value to match the actual size of the file.
528 if {[db eval {PRAGMA auto_vacuum}]} {
533 do_test sqllimits1-7.7.1 {
535 PRAGMA max_page_count = 1000000;
536 CREATE TABLE abc(a, b, c);
537 INSERT INTO abc VALUES(1, 2, 3);
538 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
539 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
540 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
541 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
542 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
543 INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
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 FROM abc;
547 INSERT INTO abc SELECT b, a, c FROM abc;
548 INSERT INTO abc SELECT c, b, a FROM abc;
550 expr [file size test.db] / 1024
552 do_test sqllimits1-7.7.2 {
556 PRAGMA max_page_count = 1000;
559 SELECT count(*) FROM sqlite_master;
562 do_test sqllimits1-7.7.3 {
564 PRAGMA max_page_count;
567 do_test sqllimits1-7.7.4 {
573 #--------------------------------------------------------------------
574 # Test cases sqllimits1-8.* test the SQLITE_MAX_COLUMN limit.
576 # EVIDENCE-OF: R-43996-29471 SQLITE_LIMIT_COLUMN The maximum number of
577 # columns in a table definition or in the result set of a SELECT or the
578 # maximum number of columns in an index or in an ORDER BY or GROUP BY
581 set SQLITE_LIMIT_COLUMN 200
582 sqlite3_limit db SQLITE_LIMIT_COLUMN $SQLITE_LIMIT_COLUMN
583 do_test sqllimits1-8.1 {
584 # Columns in a table.
586 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
589 catchsql "CREATE TABLE t([join $cols ,])"
590 } {1 {too many columns on t}}
592 do_test sqllimits1-8.2 {
593 # Columns in the result-set of a SELECT.
595 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
596 lappend cols "sql AS sql$i"
598 catchsql "SELECT [join $cols ,] FROM sqlite_master"
599 } {1 {too many columns in result set}}
601 do_test sqllimits1-8.3 {
602 # Columns in the result-set of a sub-SELECT.
604 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
605 lappend cols "sql AS sql$i"
607 catchsql "SELECT sql4 FROM (SELECT [join $cols ,] FROM sqlite_master)"
608 } {1 {too many columns in result set}}
610 do_test sqllimits1-8.4 {
611 # Columns in an index.
613 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
616 set sql1 "CREATE TABLE t1(c);"
617 set sql2 "CREATE INDEX i1 ON t1([join $cols ,]);"
618 catchsql "$sql1 ; $sql2"
619 } {1 {too many columns in index}}
621 do_test sqllimits1-8.5 {
622 # Columns in a GROUP BY clause.
623 catchsql "SELECT * FROM t1 GROUP BY [join $cols ,]"
624 } {1 {too many terms in GROUP BY clause}}
626 do_test sqllimits1-8.6 {
627 # Columns in an ORDER BY clause.
628 catchsql "SELECT * FROM t1 ORDER BY [join $cols ,]"
629 } {1 {too many terms in ORDER BY clause}}
631 do_test sqllimits1-8.7 {
632 # Assignments in an UPDATE statement.
634 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
637 catchsql "UPDATE t1 SET [join $cols ,];"
638 } {1 {too many columns in set list}}
640 do_test sqllimits1-8.8 {
641 # Columns in a view definition:
643 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
646 execsql "CREATE VIEW v1 AS SELECT [join $cols ,] FROM t1;"
647 catchsql {SELECT * FROM v1}
648 } {1 {too many columns in result set}}
650 do_test sqllimits1-8.9 {
651 # Columns in a view definition (testing * expansion):
653 for {set i 0} {$i < $SQLITE_LIMIT_COLUMN} {incr i} {
656 execsql {DROP VIEW IF EXISTS v1}
657 catchsql "CREATE TABLE t2([join $cols ,])"
658 catchsql "CREATE VIEW v1 AS SELECT *, c1 AS o FROM t2;"
659 catchsql "SELECT * FROM v1"
660 } {1 {too many columns in result set}}
662 do_test sqllimits1-8.10 {
665 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
668 set sql "SELECT c FROM t1 ORDER BY [join $cols ,]"
670 } {1 {too many terms in ORDER BY clause}}
671 do_test sqllimits1-8.11 {
674 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
675 lappend cols [expr {$i%3 + 1}]
677 set sql "SELECT c, c+1, c+2 FROM t1 UNION SELECT c-1, c-2, c-3 FROM t1"
678 append sql " ORDER BY [join $cols ,]"
680 } {1 {too many terms in ORDER BY clause}}
683 #--------------------------------------------------------------------
684 # These tests - sqllimits1-9.* - test that the SQLITE_LIMIT_EXPR_DEPTH
685 # limit is enforced. The limit refers to the number of terms in
688 # EVIDENCE-OF: R-12723-08526 SQLITE_LIMIT_EXPR_DEPTH The maximum depth
689 # of the parse tree on any expression.
691 if {$SQLITE_MAX_EXPR_DEPTH==0} {
692 puts -nonewline stderr "WARNING: Compile with -DSQLITE_MAX_EXPR_DEPTH to run "
693 puts stderr "tests sqllimits1-9.X"
695 do_test sqllimits1-9.1 {
696 set max $::SQLITE_MAX_EXPR_DEPTH
697 set expr "(1 [string repeat {AND 1 } $max])"
701 } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
703 # Attempting to beat the expression depth limit using nested SELECT
704 # queries causes a parser stack overflow.
705 do_test sqllimits1-9.2 {
706 set max $::SQLITE_MAX_EXPR_DEPTH
708 for {set i 0} {$i <= $max} {incr i} {
709 set expr "SELECT ($expr)"
711 catchsql [subst { $expr }]
712 } "1 {parser stack overflow}"
715 do_test sqllimits1-9.3 {
717 PRAGMA max_page_count = 1000000; -- 1 GB
719 INSERT INTO v0 VALUES(1);
722 for {set i 1} {$i < 200} {incr i} {
723 set expr "(a [string repeat {AND 1 } 50]) AS a"
725 CREATE VIEW v${i} AS SELECT $expr FROM v[expr {$i-1}]
731 do_test sqllimits1-9.4 {
735 } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
739 #--------------------------------------------------------------------
740 # Test cases sqllimits1-10.* test that the SQLITE_MAX_VDBE_OP
741 # limit works as expected. The limit refers to the number of opcodes
742 # in a single VDBE program.
746 #--------------------------------------------------------------------
747 # Test the SQLITE_LIMIT_FUNCTION_ARG limit works. Test case names
748 # match the pattern "sqllimits1-11.*".
750 # EVIDENCE-OF: R-59001-45278 SQLITE_LIMIT_FUNCTION_ARG The maximum
751 # number of arguments on a function.
753 for {set max 5} {$max<=$SQLITE_MAX_FUNCTION_ARG} {incr max} {
754 do_test sqllimits1-11.$max.1 {
756 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG $::max
757 for {set i 0} {$i < $::max} {incr i} {
760 catchsql "SELECT max([join $vals ,])"
761 } "0 [expr {$::max - 1}]"
762 do_test sqllimits1-11.$max.2 {
764 for {set i 0} {$i <= $::max} {incr i} {
767 catchsql "SELECT max([join $vals ,])"
768 } {1 {too many arguments on function max}}
770 # Test that it is SQLite, and not the implementation of the
771 # user function that is throwing the error.
772 proc myfunc {args} {error "I don't like to be called!"}
773 do_test sqllimits1-11.$max.2 {
774 db function myfunc myfunc
776 for {set i 0} {$i <= $::max} {incr i} {
779 catchsql "SELECT myfunc([join $vals ,])"
780 } {1 {too many arguments on function myfunc}}
783 #--------------------------------------------------------------------
784 # Test cases sqllimits1-12.*: Test the SQLITE_MAX_ATTACHED limit.
786 # EVIDENCE-OF: R-41778-26203 SQLITE_LIMIT_ATTACHED The maximum number of
787 # attached databases.
790 do_test sqllimits1-12.1 {
791 set max $::SQLITE_MAX_ATTACHED
792 for {set i 0} {$i < ($max)} {incr i} {
793 forcedelete test${i}.db test${i}.db-journal
795 for {set i 0} {$i < ($max)} {incr i} {
796 execsql "ATTACH 'test${i}.db' AS aux${i}"
798 catchsql "ATTACH 'test${i}.db' AS aux${i}"
799 } "1 {too many attached databases - max $::SQLITE_MAX_ATTACHED}"
800 do_test sqllimits1-12.2 {
801 set max $::SQLITE_MAX_ATTACHED
802 for {set i 0} {$i < ($max)} {incr i} {
803 execsql "DETACH aux${i}"
808 #--------------------------------------------------------------------
809 # Test cases sqllimits1-13.*: Check that the SQLITE_MAX_VARIABLE_NUMBER
812 # EVIDENCE-OF: R-42363-29104 SQLITE_LIMIT_VARIABLE_NUMBER The maximum
813 # index number of any parameter in an SQL statement.
815 do_test sqllimits1-13.1 {
816 set max $::SQLITE_MAX_VARIABLE_NUMBER
817 catchsql "SELECT ?[expr {$max+1}] FROM t1"
818 } "1 {variable number must be between ?1 and ?$::SQLITE_MAX_VARIABLE_NUMBER}"
819 do_test sqllimits1-13.2 {
820 set max $::SQLITE_MAX_VARIABLE_NUMBER
822 for {set i 0} {$i < ($max+3)} {incr i} {
825 catchsql "SELECT [join $vals ,] FROM t1"
826 } "1 {too many SQL variables}"
829 #--------------------------------------------------------------------
830 # Test cases sqllimits1-15.* verify that the
831 # SQLITE_MAX_LIKE_PATTERN_LENGTH limit is enforced. This limit only
832 # applies to the built-in LIKE operator, supplying an external
833 # implementation by overriding the like() scalar function bypasses
836 # EVIDENCE-OF: R-12940-37052 SQLITE_LIMIT_LIKE_PATTERN_LENGTH The
837 # maximum length of the pattern argument to the LIKE or GLOB operators.
839 # These tests check that the limit is not incorrectly applied to
840 # the left-hand-side of the LIKE operator (the string being tested
841 # against the pattern).
843 set SQLITE_LIMIT_LIKE_PATTERN 1000
844 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH $SQLITE_LIMIT_LIKE_PATTERN
845 do_test sqllimits1-15.1 {
846 set max $::SQLITE_LIMIT_LIKE_PATTERN
847 set ::pattern [string repeat "A%" [expr $max/2]]
848 set ::string [string repeat "A" [expr {$max*2}]]
850 SELECT $::string LIKE $::pattern;
853 do_test sqllimits1-15.2 {
854 set max $::SQLITE_LIMIT_LIKE_PATTERN
855 set ::pattern [string repeat "A%" [expr {($max/2) + 1}]]
856 set ::string [string repeat "A" [expr {$max*2}]]
858 SELECT $::string LIKE $::pattern;
860 } {1 {LIKE or GLOB pattern too complex}}
862 #--------------------------------------------------------------------
863 # This test case doesn't really belong with the other limits tests.
864 # It is in this file because it is taxing to run, like the limits tests.
866 do_test sqllimits1-16.1 {
867 set ::N [expr int(([expr pow(2,32)]/50) + 1)]
868 expr (($::N*50) & 0xffffffff)<55
870 do_test sqllimits1-16.2 {
871 set ::format "[string repeat A 60][string repeat "%J" $::N]"
873 SELECT strftime($::format, 1);
875 } {1 {string or blob too big}}
877 do_catchsql_test sqllimits1.17.0 {
878 SELECT *,*,*,*,*,*,*,* FROM (
879 SELECT *,*,*,*,*,*,*,* FROM (
880 SELECT *,*,*,*,*,*,*,* FROM (
881 SELECT *,*,*,*,*,*,*,* FROM (
882 SELECT *,*,*,*,*,*,*,* FROM (
883 SELECT 1,2,3,4,5,6,7,8,9,10
886 } "1 {too many columns in result set}"
889 foreach {key value} [array get saved] {
890 catch {set $key $value}