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
19 set testprefix sqllimits1
21 # Verify that the default per-connection limits are the same as
22 # the compile-time hard limits.
25 do_test sqllimits1-1.1 {
26 sqlite3_limit db SQLITE_LIMIT_LENGTH -1
28 do_test sqllimits1-1.2 {
29 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
30 } $SQLITE_MAX_SQL_LENGTH
31 do_test sqllimits1-1.3 {
32 sqlite3_limit db SQLITE_LIMIT_COLUMN -1
34 do_test sqllimits1-1.4 {
35 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
36 } $SQLITE_MAX_EXPR_DEPTH
37 do_test sqllimits1-1.5 {
38 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
39 } $SQLITE_MAX_COMPOUND_SELECT
40 do_test sqllimits1-1.6 {
41 sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
43 do_test sqllimits1-1.7 {
44 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
45 } $SQLITE_MAX_FUNCTION_ARG
46 do_test sqllimits1-1.8 {
47 sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
48 } $SQLITE_MAX_ATTACHED
49 do_test sqllimits1-1.9 {
50 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
51 } $SQLITE_MAX_LIKE_PATTERN_LENGTH
52 do_test sqllimits1-1.10 {
53 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
54 } $SQLITE_MAX_VARIABLE_NUMBER
55 do_test sqllimits1-1.11 {
56 sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH -1
57 } $SQLITE_MAX_TRIGGER_DEPTH
58 do_test sqllimits1-1.12 {
59 sqlite3_limit db SQLITE_LIMIT_WORKER_THREADS 99999
60 sqlite3_limit db SQLITE_LIMIT_WORKER_THREADS -1
61 } $SQLITE_MAX_WORKER_THREADS
63 # Limit parameters out of range.
65 do_test sqllimits1-1.20 {
66 sqlite3_limit db SQLITE_LIMIT_TOOSMALL 123
68 do_test sqllimits1-1.21 {
69 sqlite3_limit db SQLITE_LIMIT_TOOSMALL 123
71 do_test sqllimits1-1.22 {
72 sqlite3_limit db SQLITE_LIMIT_TOOBIG 123
74 do_test sqllimits1-1.23 {
75 sqlite3_limit db SQLITE_LIMIT_TOOBIG 123
79 # Decrease all limits by half. Verify that the new limits take.
81 if {$SQLITE_MAX_LENGTH>=2} {
82 do_test sqllimits1-2.1.1 {
83 sqlite3_limit db SQLITE_LIMIT_LENGTH \
84 [expr {$::SQLITE_MAX_LENGTH/2}]
86 do_test sqllimits1-2.1.2 {
87 sqlite3_limit db SQLITE_LIMIT_LENGTH -1
88 } [expr {$SQLITE_MAX_LENGTH/2}]
90 if {$SQLITE_MAX_SQL_LENGTH>=2} {
91 do_test sqllimits1-2.2.1 {
92 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH \
93 [expr {$::SQLITE_MAX_SQL_LENGTH/2}]
94 } $SQLITE_MAX_SQL_LENGTH
95 do_test sqllimits1-2.2.2 {
96 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
97 } [expr {$SQLITE_MAX_SQL_LENGTH/2}]
99 if {$SQLITE_MAX_COLUMN>=2} {
100 do_test sqllimits1-2.3.1 {
101 sqlite3_limit db SQLITE_LIMIT_COLUMN \
102 [expr {$::SQLITE_MAX_COLUMN/2}]
104 do_test sqllimits1-2.3.2 {
105 sqlite3_limit db SQLITE_LIMIT_COLUMN -1
106 } [expr {$SQLITE_MAX_COLUMN/2}]
108 if {$SQLITE_MAX_EXPR_DEPTH>=2} {
109 do_test sqllimits1-2.4.1 {
110 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH \
111 [expr {$::SQLITE_MAX_EXPR_DEPTH/2}]
112 } $SQLITE_MAX_EXPR_DEPTH
113 do_test sqllimits1-2.4.2 {
114 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
115 } [expr {$SQLITE_MAX_EXPR_DEPTH/2}]
117 if {$SQLITE_MAX_COMPOUND_SELECT>=2} {
118 do_test sqllimits1-2.5.1 {
119 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT \
120 [expr {$::SQLITE_MAX_COMPOUND_SELECT/2}]
121 } $SQLITE_MAX_COMPOUND_SELECT
122 do_test sqllimits1-2.5.2 {
123 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
124 } [expr {$SQLITE_MAX_COMPOUND_SELECT/2}]
126 if {$SQLITE_MAX_VDBE_OP>=2} {
127 do_test sqllimits1-2.6.1 {
128 sqlite3_limit db SQLITE_LIMIT_VDBE_OP \
129 [expr {$::SQLITE_MAX_VDBE_OP/2}]
130 } $SQLITE_MAX_VDBE_OP
131 do_test sqllimits1-2.6.2 {
132 sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
133 } [expr {$SQLITE_MAX_VDBE_OP/2}]
135 if {$SQLITE_MAX_FUNCTION_ARG>=2} {
136 do_test sqllimits1-2.7.1 {
137 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG \
138 [expr {$::SQLITE_MAX_FUNCTION_ARG/2}]
139 } $SQLITE_MAX_FUNCTION_ARG
140 do_test sqllimits1-2.7.2 {
141 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
142 } [expr {$SQLITE_MAX_FUNCTION_ARG/2}]
144 if {$SQLITE_MAX_ATTACHED>=2} {
145 do_test sqllimits1-2.8.1 {
146 sqlite3_limit db SQLITE_LIMIT_ATTACHED \
147 [expr {$::SQLITE_MAX_ATTACHED/2}]
148 } $SQLITE_MAX_ATTACHED
149 do_test sqllimits1-2.8.2 {
150 sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
151 } [expr {$SQLITE_MAX_ATTACHED/2}]
153 if {$SQLITE_MAX_LIKE_PATTERN_LENGTH>=2} {
154 do_test sqllimits1-2.9.1 {
155 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH \
156 [expr {$::SQLITE_MAX_LIKE_PATTERN_LENGTH/2}]
157 } $SQLITE_MAX_LIKE_PATTERN_LENGTH
158 do_test sqllimits1-2.9.2 {
159 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
160 } [expr {$SQLITE_MAX_LIKE_PATTERN_LENGTH/2}]
162 if {$SQLITE_MAX_VARIABLE_NUMBER>=2} {
163 do_test sqllimits1-2.10.1 {
164 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER \
165 [expr {$::SQLITE_MAX_VARIABLE_NUMBER/2}]
166 } $SQLITE_MAX_VARIABLE_NUMBER
167 do_test sqllimits1-2.10.2 {
168 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
169 } [expr {$SQLITE_MAX_VARIABLE_NUMBER/2}]
172 # In a separate database connection, verify that the limits are unchanged.
174 do_test sqllimits1-3.1 {
175 sqlite3_limit db2 SQLITE_LIMIT_LENGTH -1
177 do_test sqllimits1-3.2 {
178 sqlite3_limit db2 SQLITE_LIMIT_SQL_LENGTH -1
179 } $SQLITE_MAX_SQL_LENGTH
180 do_test sqllimits1-3.3 {
181 sqlite3_limit db2 SQLITE_LIMIT_COLUMN -1
183 do_test sqllimits1-3.4 {
184 sqlite3_limit db2 SQLITE_LIMIT_EXPR_DEPTH -1
185 } $SQLITE_MAX_EXPR_DEPTH
186 do_test sqllimits1-3.5 {
187 sqlite3_limit db2 SQLITE_LIMIT_COMPOUND_SELECT -1
188 } $SQLITE_MAX_COMPOUND_SELECT
189 do_test sqllimits1-3.6 {
190 sqlite3_limit db2 SQLITE_LIMIT_VDBE_OP -1
191 } $SQLITE_MAX_VDBE_OP
192 do_test sqllimits1-3.7 {
193 sqlite3_limit db2 SQLITE_LIMIT_FUNCTION_ARG -1
194 } $SQLITE_MAX_FUNCTION_ARG
195 do_test sqllimits1-3.8 {
196 sqlite3_limit db2 SQLITE_LIMIT_ATTACHED -1
197 } $SQLITE_MAX_ATTACHED
198 do_test sqllimits1-3.9 {
199 sqlite3_limit db2 SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
200 } $SQLITE_MAX_LIKE_PATTERN_LENGTH
201 do_test sqllimits1-3.10 {
202 sqlite3_limit db2 SQLITE_LIMIT_VARIABLE_NUMBER -1
203 } $SQLITE_MAX_VARIABLE_NUMBER
206 # Attempt to set all limits to the maximum 32-bit integer. Verify
207 # that the limit does not exceed the compile-time upper bound.
209 do_test sqllimits1-4.1.1 {
210 sqlite3_limit db SQLITE_LIMIT_LENGTH 0x7fffffff
211 sqlite3_limit db SQLITE_LIMIT_LENGTH -1
213 do_test sqllimits1-4.2.1 {
214 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 0x7fffffff
215 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
216 } $SQLITE_MAX_SQL_LENGTH
217 do_test sqllimits1-4.3.1 {
218 sqlite3_limit db SQLITE_LIMIT_COLUMN 0x7fffffff
219 sqlite3_limit db SQLITE_LIMIT_COLUMN -1
221 do_test sqllimits1-4.4.1 {
222 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH 0x7fffffff
223 sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
224 } $SQLITE_MAX_EXPR_DEPTH
225 do_test sqllimits1-4.5.1 {
226 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 0x7fffffff
227 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
228 } $SQLITE_MAX_COMPOUND_SELECT
229 do_test sqllimits1-4.6.1 {
230 sqlite3_limit db SQLITE_LIMIT_VDBE_OP 0x7fffffff
231 sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
232 } $SQLITE_MAX_VDBE_OP
233 do_test sqllimits1-4.7.1 {
234 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG 0x7fffffff
235 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
236 } $SQLITE_MAX_FUNCTION_ARG
237 do_test sqllimits1-4.8.1 {
238 sqlite3_limit db SQLITE_LIMIT_ATTACHED 0x7fffffff
239 sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
240 } $SQLITE_MAX_ATTACHED
241 do_test sqllimits1-4.9.1 {
242 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH 0x7fffffff
243 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
244 } $SQLITE_MAX_LIKE_PATTERN_LENGTH
245 do_test sqllimits1-4.10.1 {
246 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER 0x7fffffff
247 sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
248 } $SQLITE_MAX_VARIABLE_NUMBER
250 #--------------------------------------------------------------------
251 # Test cases sqllimits1-5.* test that the SQLITE_MAX_LENGTH limit
254 # EVIDENCE-OF: R-61987-00541 SQLITE_LIMIT_LENGTH The maximum size of any
255 # string or BLOB or table row, in bytes.
260 set SQLITE_LIMIT_LENGTH 100000
261 sqlite3_limit db SQLITE_LIMIT_LENGTH $SQLITE_LIMIT_LENGTH
263 do_test sqllimits1-5.1.1 {
264 catchsql { SELECT randomblob(2147483647) }
265 } {1 {string or blob too big}}
266 do_test sqllimits1-5.1.2 {
267 catchsql { SELECT zeroblob(2147483647) }
268 } {1 {string or blob too big}}
270 do_test sqllimits1-5.2 {
271 catchsql { SELECT LENGTH(randomblob($::LARGESIZE)) }
272 } [list 0 $LARGESIZE]
274 do_test sqllimits1-5.3 {
275 catchsql { SELECT quote(randomblob($::LARGESIZE)) }
276 } {1 {string or blob too big}}
278 do_test sqllimits1-5.4 {
279 catchsql { SELECT LENGTH(zeroblob($::LARGESIZE)) }
280 } [list 0 $LARGESIZE]
282 do_test sqllimits1-5.5 {
283 catchsql { SELECT quote(zeroblob($::LARGESIZE)) }
284 } {1 {string or blob too big}}
286 do_test sqllimits1-5.6 {
287 catchsql { SELECT zeroblob(-1) }
290 do_test sqllimits1-5.9 {
291 set ::str [string repeat A 65537]
292 set ::rep [string repeat B 65537]
293 catchsql { SELECT replace($::str, 'A', $::rep) }
294 } {1 {string or blob too big}}
296 do_test sqllimits1-5.10 {
297 # Prior to 3.37.0 strftime() allocated a large static buffer into
298 # which to format its output. Using that strategy, 2100 repeats was
299 # enough to exceed 100KiB and provoke the error. As of 3.37.0 strftime()
300 # uses the StrAccum functions, so it requires 12100 to fail.
302 # set ::str [string repeat %J 2100]
303 set ::str [string repeat %J 12100]
304 catchsql { SELECT length(strftime($::str, '2003-10-31')) }
305 } {1 {string or blob too big}}
307 do_test sqllimits1-5.11 {
308 set ::str1 [string repeat A [expr {$SQLITE_LIMIT_LENGTH - 10}]]
309 set ::str2 [string repeat B [expr {$SQLITE_LIMIT_LENGTH - 10}]]
310 catchsql { SELECT $::str1 || $::str2 }
311 } {1 {string or blob too big}}
313 do_test sqllimits1-5.12 {
314 set ::str1 [string repeat ' [expr {$SQLITE_LIMIT_LENGTH - 10}]]
315 catchsql { SELECT quote($::str1) }
316 } {1 {string or blob too big}}
318 do_test sqllimits1-5.13 {
319 set ::str1 [string repeat ' [expr {$SQLITE_LIMIT_LENGTH - 10}]]
320 catchsql { SELECT hex($::str1) }
321 } {1 {string or blob too big}}
323 do_test sqllimits1-5.14.1 {
324 set ::STMT [sqlite3_prepare db "SELECT ?" -1 TAIL]
325 sqlite3_bind_zeroblob $::STMT 1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
327 do_test sqllimits1-5.14.2 {
330 do_test sqllimits1-5.14.3 {
331 sqlite3_reset $::STMT
333 do_test sqllimits1-5.14.4 {
334 set np1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
335 set ::str1 [string repeat A $np1]
336 catch {sqlite3_bind_text $::STMT 1 $::str1 -1} res
340 do_test sqllimits1-5.14.5 {
341 catch {sqlite3_bind_text16 $::STMT 1 $::str1 -1} res
345 do_test sqllimits1-5.14.6 {
346 catch {sqlite3_bind_text $::STMT 1 $::str1 $np1} res
350 do_test sqllimits1-5.14.7 {
351 catch {sqlite3_bind_text16 $::STMT 1 $::str1 [expr $np1+1]} res
355 do_test sqllimits1-5.14.8 {
356 set n [expr {$np1-1}]
357 catch {sqlite3_bind_text $::STMT 1 $::str1 $n} res
360 do_test sqllimits1-5.14.9 {
361 catch {sqlite3_bind_text16 $::STMT 1 $::str1 $n} res
364 sqlite3_finalize $::STMT
366 do_test sqllimits1-5.15 {
369 INSERT INTO t4 VALUES(1);
370 INSERT INTO t4 VALUES(2);
371 INSERT INTO t4 SELECT 2+x FROM t4;
374 SELECT group_concat(hex(randomblob(20000))) FROM t4;
376 } {1 {string or blob too big}}
377 db eval {DROP TABLE t4}
379 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 0x7fffffff
380 set strvalue [string repeat A $::SQLITE_LIMIT_LENGTH]
381 do_test sqllimits1-5.16 {
382 catchsql "SELECT '$strvalue' AS x"
384 do_test sqllimits1-5.17.1 {
385 catchsql "SELECT 'A$strvalue'"
386 } [list 1 {string or blob too big}]
387 do_test sqllimits1-5.17.2 {
388 sqlite3_limit db SQLITE_LIMIT_LENGTH 0x7fffffff
389 catchsql {SELECT 'A' || $::strvalue}
390 } [list 0 A$strvalue]
391 do_test sqllimits1-5.17.3 {
392 sqlite3_limit db SQLITE_LIMIT_LENGTH $SQLITE_LIMIT_LENGTH
393 catchsql {SELECT 'A' || $::strvalue}
394 } [list 1 {string or blob too big}]
395 set blobvalue [string repeat 41 $::SQLITE_LIMIT_LENGTH]
396 do_test sqllimits1-5.18 {
397 catchsql "SELECT x'$blobvalue' AS x"
399 do_test sqllimits1-5.19 {
400 catchsql "SELECT '41$blobvalue'"
401 } [list 1 {string or blob too big}]
405 set strvalue [string repeat D [expr {$SQLITE_LIMIT_LENGTH-11}]]
406 do_test sqllimits1-5.20 {
407 catchsql {SELECT strftime('%Y ' || $::strvalue, '2008-01-02')}
408 } [list 0 [list "2008 $strvalue"]]
409 do_test sqllimits1-5.21 {
410 catchsql {SELECT strftime('%Y-%m-%d ' || $::strvalue, '2008-01-02')}
411 } {1 {string or blob too big}}
415 #--------------------------------------------------------------------
416 # Test cases sqllimits1-6.* test that the SQLITE_MAX_SQL_LENGTH limit
419 # EVIDENCE-OF: R-09808-17554 SQLITE_LIMIT_SQL_LENGTH The maximum length
420 # of an SQL statement, in bytes.
422 do_test sqllimits1-6.1 {
423 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 50000
424 set sql "SELECT 1 WHERE 1==1"
425 set tail " /* A comment to take up space in order to make the string\
426 longer without increasing the expression depth */\
428 set N [expr {(50000 / [string length $tail])+1}]
429 append sql [string repeat $tail $N]
431 } {1 {string or blob too big}}
432 do_test sqllimits1-6.3 {
433 sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 50000
434 set sql "SELECT 1 WHERE 1==1"
435 set tail " /* A comment to take up space in order to make the string\
436 longer without increasing the expression depth */\
438 set N [expr {(50000 / [string length $tail])+1}]
439 append sql [string repeat $tail $N]
440 set nbytes [string length $sql]
442 set rc [catch {sqlite3_prepare db $sql $nbytes TAIL} STMT]
444 } {1 {(18) statement too long}}
445 do_test sqllimits1-6.4 {
447 } {statement too long}
449 #--------------------------------------------------------------------
450 # Test cases sqllimits1-7.* test that the limit set using the
451 # max_page_count pragma.
453 do_test sqllimits1-7.1 {
455 PRAGMA max_page_count = 1000;
458 do_test sqllimits1-7.2 {
459 execsql { CREATE TABLE trig (a INTEGER, b INTEGER); }
461 # Set up a tree of triggers to fire when a row is inserted
464 # INSERT -> insert_b -> update_b -> insert_a -> update_a (chain 1)
465 # -> update_a -> insert_a -> update_b (chain 2)
466 # -> insert_a -> update_b -> insert_b -> update_a (chain 3)
467 # -> update_a -> insert_b -> update_b (chain 4)
469 # Table starts with N rows.
471 # Chain 1: insert_b (update N rows)
472 # -> update_b (insert 1 rows)
473 # -> insert_a (update N rows)
474 # -> update_a (insert 1 rows)
476 # chains 2, 3 and 4 are similar. Each inserts more than N^2 rows, where
477 # N is the number of rows at the conclusion of the previous chain.
479 # Therefore, a single insert adds (N^16 plus some) rows to the database.
480 # A really long loop...
483 CREATE TRIGGER update_b BEFORE UPDATE ON trig
485 INSERT INTO trig VALUES (65, 'update_b');
488 CREATE TRIGGER update_a AFTER UPDATE ON trig
490 INSERT INTO trig VALUES (65, 'update_a');
493 CREATE TRIGGER insert_b BEFORE INSERT ON trig
495 UPDATE trig SET a = 1;
498 CREATE TRIGGER insert_a AFTER INSERT ON trig
500 UPDATE trig SET a = 1;
505 do_test sqllimits1-7.3 {
507 INSERT INTO trig VALUES (1,1);
511 do_test sqllimits1-7.4 {
513 SELECT COUNT(*) FROM trig;
517 # This tries to insert so many rows it fills up the database (limited
518 # to 1MB, so not that noteworthy an achievement).
520 do_test sqllimits1-7.5 {
522 INSERT INTO trig VALUES (1,10);
524 } {1 {database or disk is full}}
526 do_test sqllimits1-7.6 {
528 SELECT COUNT(*) FROM trig;
532 # Now check the response of the library to opening a file larger than
533 # the current max_page_count value. The response is to change the
534 # internal max_page_count value to match the actual size of the file.
535 if {[db eval {PRAGMA auto_vacuum}]} {
540 do_test sqllimits1-7.7.1 {
542 PRAGMA max_page_count = 1000000;
543 CREATE TABLE abc(a, b, c);
544 INSERT INTO abc VALUES(1, 2, 3);
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, b||c||a, c||a||b FROM abc;
553 INSERT INTO abc SELECT a, b, c FROM abc;
554 INSERT INTO abc SELECT b, a, c FROM abc;
555 INSERT INTO abc SELECT c, b, a FROM abc;
557 expr [file size test.db] / 1024
559 do_test sqllimits1-7.7.2 {
563 PRAGMA max_page_count = 1000;
566 SELECT count(*) FROM sqlite_master;
569 do_test sqllimits1-7.7.3 {
571 PRAGMA max_page_count;
574 do_test sqllimits1-7.7.4 {
580 #--------------------------------------------------------------------
581 # Test cases sqllimits1-8.* test the SQLITE_MAX_COLUMN limit.
583 # EVIDENCE-OF: R-43996-29471 SQLITE_LIMIT_COLUMN The maximum number of
584 # columns in a table definition or in the result set of a SELECT or the
585 # maximum number of columns in an index or in an ORDER BY or GROUP BY
588 set SQLITE_LIMIT_COLUMN 200
589 sqlite3_limit db SQLITE_LIMIT_COLUMN $SQLITE_LIMIT_COLUMN
590 do_test sqllimits1-8.1 {
591 # Columns in a table.
593 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
596 catchsql "CREATE TABLE t([join $cols ,])"
597 } {1 {too many columns on t}}
599 do_test sqllimits1-8.2 {
600 # Columns in the result-set of a SELECT.
602 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
603 lappend cols "sql AS sql$i"
605 catchsql "SELECT [join $cols ,] FROM sqlite_master"
606 } {1 {too many columns in result set}}
608 do_test sqllimits1-8.3 {
609 # Columns in the result-set of a sub-SELECT.
611 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
612 lappend cols "sql AS sql$i"
614 catchsql "SELECT sql4 FROM (SELECT [join $cols ,] FROM sqlite_master)"
615 } {1 {too many columns in result set}}
617 do_test sqllimits1-8.4 {
618 # Columns in an index.
620 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
623 set sql1 "CREATE TABLE t1(c);"
624 set sql2 "CREATE INDEX i1 ON t1([join $cols ,]);"
625 catchsql "$sql1 ; $sql2"
626 } {1 {too many columns in index}}
628 do_test sqllimits1-8.5 {
629 # Columns in a GROUP BY clause.
630 catchsql "SELECT * FROM t1 GROUP BY [join $cols ,]"
631 } {1 {too many terms in GROUP BY clause}}
633 do_test sqllimits1-8.6 {
634 # Columns in an ORDER BY clause.
635 catchsql "SELECT * FROM t1 ORDER BY [join $cols ,]"
636 } {1 {too many terms in ORDER BY clause}}
638 do_test sqllimits1-8.7 {
639 # Assignments in an UPDATE statement.
641 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
644 catchsql "UPDATE t1 SET [join $cols ,];"
645 } {1 {too many columns in set list}}
647 do_test sqllimits1-8.8 {
648 # Columns in a view definition:
650 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
653 execsql "CREATE VIEW v1 AS SELECT [join $cols ,] FROM t1;"
654 catchsql {SELECT * FROM v1}
655 } {1 {too many columns in result set}}
657 do_test sqllimits1-8.9 {
658 # Columns in a view definition (testing * expansion):
660 for {set i 0} {$i < $SQLITE_LIMIT_COLUMN} {incr i} {
663 execsql {DROP VIEW IF EXISTS v1}
664 catchsql "CREATE TABLE t2([join $cols ,])"
665 catchsql "CREATE VIEW v1 AS SELECT *, c1 AS o FROM t2;"
666 catchsql "SELECT * FROM v1"
667 } {1 {too many columns in result set}}
669 do_test sqllimits1-8.10 {
672 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
675 set sql "SELECT c FROM t1 ORDER BY [join $cols ,]"
677 } {1 {too many terms in ORDER BY clause}}
678 do_test sqllimits1-8.11 {
681 for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
682 lappend cols [expr {$i%3 + 1}]
684 set sql "SELECT c, c+1, c+2 FROM t1 UNION SELECT c-1, c-2, c-3 FROM t1"
685 append sql " ORDER BY [join $cols ,]"
687 } {1 {too many terms in ORDER BY clause}}
690 #--------------------------------------------------------------------
691 # These tests - sqllimits1-9.* - test that the SQLITE_LIMIT_EXPR_DEPTH
692 # limit is enforced. The limit refers to the number of terms in
695 # EVIDENCE-OF: R-12723-08526 SQLITE_LIMIT_EXPR_DEPTH The maximum depth
696 # of the parse tree on any expression.
698 if {$SQLITE_MAX_EXPR_DEPTH==0} {
699 puts -nonewline stderr "WARNING: Compile with -DSQLITE_MAX_EXPR_DEPTH to run "
700 puts stderr "tests sqllimits1-9.X"
702 do_test sqllimits1-9.1 {
703 set max $::SQLITE_MAX_EXPR_DEPTH
704 set expr "(1 [string repeat {AND 1 } $max])"
708 } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
710 # Attempting to beat the expression depth limit using nested SELECT
711 # queries causes a parser stack overflow.
712 do_test sqllimits1-9.2 {
713 set max $::SQLITE_MAX_EXPR_DEPTH
715 for {set i 0} {$i <= $max} {incr i} {
716 set expr "SELECT ($expr)"
718 catchsql [subst { $expr }]
719 } "1 {parser stack overflow}"
722 do_test sqllimits1-9.3 {
724 PRAGMA max_page_count = 1000000; -- 1 GB
726 INSERT INTO v0 VALUES(1);
729 for {set i 1} {$i < 200} {incr i} {
730 set expr "(a [string repeat {AND 1 } 50]) AS a"
732 CREATE VIEW v${i} AS SELECT $expr FROM v[expr {$i-1}]
738 do_test sqllimits1-9.4 {
742 } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
746 #--------------------------------------------------------------------
747 # Test cases sqllimits1-10.* test that the SQLITE_MAX_VDBE_OP
748 # limit works as expected. The limit refers to the number of opcodes
749 # in a single VDBE program.
753 #--------------------------------------------------------------------
754 # Test the SQLITE_LIMIT_FUNCTION_ARG limit works. Test case names
755 # match the pattern "sqllimits1-11.*".
757 # EVIDENCE-OF: R-59001-45278 SQLITE_LIMIT_FUNCTION_ARG The maximum
758 # number of arguments on a function.
760 for {set max 5} {$max<=$SQLITE_MAX_FUNCTION_ARG} {incr max} {
761 do_test sqllimits1-11.$max.1 {
763 sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG $::max
764 for {set i 0} {$i < $::max} {incr i} {
767 catchsql "SELECT max([join $vals ,])"
768 } "0 [expr {$::max - 1}]"
769 do_test sqllimits1-11.$max.2 {
771 for {set i 0} {$i <= $::max} {incr i} {
774 catchsql "SELECT max([join $vals ,])"
775 } {1 {too many arguments on function max}}
777 # Test that it is SQLite, and not the implementation of the
778 # user function that is throwing the error.
779 proc myfunc {args} {error "I don't like to be called!"}
780 do_test sqllimits1-11.$max.2 {
781 db function myfunc myfunc
783 for {set i 0} {$i <= $::max} {incr i} {
786 catchsql "SELECT myfunc([join $vals ,])"
787 } {1 {too many arguments on function myfunc}}
790 #--------------------------------------------------------------------
791 # Test cases sqllimits1-12.*: Test the SQLITE_MAX_ATTACHED limit.
793 # EVIDENCE-OF: R-41778-26203 SQLITE_LIMIT_ATTACHED The maximum number of
794 # attached databases.
797 do_test sqllimits1-12.1 {
798 set max $::SQLITE_MAX_ATTACHED
799 for {set i 0} {$i < ($max)} {incr i} {
800 forcedelete test${i}.db test${i}.db-journal
802 for {set i 0} {$i < ($max)} {incr i} {
803 execsql "ATTACH 'test${i}.db' AS aux${i}"
805 catchsql "ATTACH 'test${i}.db' AS aux${i}"
806 } "1 {too many attached databases - max $::SQLITE_MAX_ATTACHED}"
807 do_test sqllimits1-12.2 {
808 set max $::SQLITE_MAX_ATTACHED
809 for {set i 0} {$i < ($max)} {incr i} {
810 execsql "DETACH aux${i}"
815 #--------------------------------------------------------------------
816 # Test cases sqllimits1-13.*: Check that the SQLITE_MAX_VARIABLE_NUMBER
819 # EVIDENCE-OF: R-42363-29104 SQLITE_LIMIT_VARIABLE_NUMBER The maximum
820 # index number of any parameter in an SQL statement.
822 do_test sqllimits1-13.1 {
823 set max $::SQLITE_MAX_VARIABLE_NUMBER
824 catchsql "SELECT ?[expr {$max+1}] FROM t1"
825 } "1 {variable number must be between ?1 and ?$::SQLITE_MAX_VARIABLE_NUMBER}"
826 do_test sqllimits1-13.2 {
827 set max $::SQLITE_MAX_VARIABLE_NUMBER
829 for {set i 0} {$i < ($max+3)} {incr i} {
832 catchsql "SELECT [join $vals ,] FROM t1"
833 } "1 {too many SQL variables}"
836 #--------------------------------------------------------------------
837 # Test cases sqllimits1-15.* verify that the
838 # SQLITE_MAX_LIKE_PATTERN_LENGTH limit is enforced. This limit only
839 # applies to the built-in LIKE operator, supplying an external
840 # implementation by overriding the like() scalar function bypasses
843 # EVIDENCE-OF: R-12940-37052 SQLITE_LIMIT_LIKE_PATTERN_LENGTH The
844 # maximum length of the pattern argument to the LIKE or GLOB operators.
846 # These tests check that the limit is not incorrectly applied to
847 # the left-hand-side of the LIKE operator (the string being tested
848 # against the pattern).
850 set SQLITE_LIMIT_LIKE_PATTERN 1000
851 sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH $SQLITE_LIMIT_LIKE_PATTERN
852 do_test sqllimits1-15.1 {
853 set max $::SQLITE_LIMIT_LIKE_PATTERN
854 set ::pattern [string repeat "A%" [expr $max/2]]
855 set ::string [string repeat "A" [expr {$max*2}]]
857 SELECT $::string LIKE $::pattern;
860 do_test sqllimits1-15.2 {
861 set max $::SQLITE_LIMIT_LIKE_PATTERN
862 set ::pattern [string repeat "A%" [expr {($max/2) + 1}]]
863 set ::string [string repeat "A" [expr {$max*2}]]
865 SELECT $::string LIKE $::pattern;
867 } {1 {LIKE or GLOB pattern too complex}}
869 #--------------------------------------------------------------------
870 # This test case doesn't really belong with the other limits tests.
871 # It is in this file because it is taxing to run, like the limits tests.
873 # Update for 3.37.0: strftime() used to allocate a large static buffer
874 # into which it would write its result. With that implementation, the
875 # following would trigger an SQLITE_TOOBIG error. But strftime() now
876 # uses the StrAccum functions, causing this test to fail.
878 #do_test sqllimits1-16.1 {
879 # set ::N [expr int(([expr pow(2,32)]/50) + 1)]
880 # expr (($::N*50) & 0xffffffff)<55
882 #do_test sqllimits1-16.2 {
883 # set ::format "[string repeat A 60][string repeat "%J" $::N]"
885 # SELECT strftime($::format, 1);
887 #} {1 {string or blob too big}}
889 do_catchsql_test sqllimits1.17.0 {
890 SELECT *,*,*,*,*,*,*,* FROM (
891 SELECT *,*,*,*,*,*,*,* FROM (
892 SELECT *,*,*,*,*,*,*,* FROM (
893 SELECT *,*,*,*,*,*,*,* FROM (
894 SELECT *,*,*,*,*,*,*,* FROM (
895 SELECT 1,2,3,4,5,6,7,8,9,10
898 } "1 {too many columns in result set}"
901 foreach {key value} [array get saved] {
902 catch {set $key $value}
905 #-------------------------------------------------------------------------
906 # At one point the following caused an assert() to fail.
908 sqlite3_limit db SQLITE_LIMIT_LENGTH 10000
909 set nm [string repeat x 10000]
910 do_catchsql_test sqllimits1-17.1 "
911 CREATE TABLE $nm (x PRIMARY KEY)
912 " {1 {string or blob too big}}
914 #-------------------------------------------------------------------------
916 sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 10
917 do_catchsql_test sqllimits1-18.1 {
919 INSERT INTO b1 VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
922 do_catchsql_test sqllimits1-18.2 {
923 INSERT INTO b1 VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9), (10)
925 } {1 {too many terms in compound SELECT}}
927 #-------------------------------------------------------------------------
931 do_execsql_test 19.0 {
932 PRAGMA encoding = 'utf16';
934 set bigstr [string repeat abcdefghij 5000]
935 set bigstr16 [encoding convertto unicode $bigstr]
938 string length $bigstr16
942 set ::stmt [sqlite3_prepare db "SELECT length( ? )" -1 TAIL]
943 sqlite3_bind_text16 $::stmt 1 $bigstr16 100000
945 set val [sqlite3_column_int $::stmt 0]
946 sqlite3_finalize $::stmt
950 sqlite3_limit db SQLITE_LIMIT_LENGTH 100000
953 set ::stmt [sqlite3_prepare db "SELECT length( ? )" -1 TAIL]
954 sqlite3_bind_text16 $::stmt 1 $bigstr16 100000
956 set val [sqlite3_column_int $::stmt 0]
957 sqlite3_finalize $::stmt
961 sqlite3_limit db SQLITE_LIMIT_LENGTH 99999
964 set ::stmt [sqlite3_prepare db "SELECT length( ? )" -1 TAIL]
965 list [catch { sqlite3_bind_text16 $::stmt 1 $bigstr16 100000 } msg] $msg
967 sqlite3_finalize $::stmt
969 sqlite3_limit db SQLITE_LIMIT_LENGTH 100000
972 set ::stmt [sqlite3_prepare db "SELECT length( ? )" -1 TAIL]
973 list [catch { sqlite3_bind_text16 $::stmt 1 $bigstr16 100002 } msg] $msg
975 sqlite3_finalize $::stmt