diff options
author | dan miller | 2007-10-20 02:49:29 +0000 |
---|---|---|
committer | dan miller | 2007-10-20 02:49:29 +0000 |
commit | e36d23a85ebff914d74bb541558c2b6082b78edb (patch) | |
tree | 54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/test/pragma.test | |
parent | * Fixed an issue whereby avatar chat distances were being calculated against ... (diff) | |
download | opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2 opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz |
sqlite source (unix build) added to libraries
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/pragma.test')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/test/pragma.test | 1037 |
1 files changed, 1037 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/pragma.test b/libraries/sqlite/unix/sqlite-3.5.1/test/pragma.test new file mode 100644 index 0000000..501c608 --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/test/pragma.test | |||
@@ -0,0 +1,1037 @@ | |||
1 | # 2002 March 6 | ||
2 | # | ||
3 | # The author disclaims copyright to this source code. In place of | ||
4 | # a legal notice, here is a blessing: | ||
5 | # | ||
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. | ||
9 | # | ||
10 | #*********************************************************************** | ||
11 | # This file implements regression tests for SQLite library. | ||
12 | # | ||
13 | # This file implements tests for the PRAGMA command. | ||
14 | # | ||
15 | # $Id: pragma.test,v 1.54 2007/05/17 16:38:30 danielk1977 Exp $ | ||
16 | |||
17 | set testdir [file dirname $argv0] | ||
18 | source $testdir/tester.tcl | ||
19 | |||
20 | # Test organization: | ||
21 | # | ||
22 | # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db. | ||
23 | # pragma-2.*: Test synchronous on attached db. | ||
24 | # pragma-3.*: Test detection of table/index inconsistency by integrity_check. | ||
25 | # pragma-4.*: Test cache_size and default_cache_size on attached db. | ||
26 | # pragma-5.*: Test that pragma synchronous may not be used inside of a | ||
27 | # transaction. | ||
28 | # pragma-6.*: Test schema-query pragmas. | ||
29 | # pragma-7.*: Miscellaneous tests. | ||
30 | # pragma-8.*: Test user_version and schema_version pragmas. | ||
31 | # pragma-9.*: Test temp_store and temp_store_directory. | ||
32 | # pragma-10.*: Test the count_changes pragma in the presence of triggers. | ||
33 | # pragma-11.*: Test the collation_list pragma. | ||
34 | # | ||
35 | |||
36 | ifcapable !pragma { | ||
37 | finish_test | ||
38 | return | ||
39 | } | ||
40 | |||
41 | # Delete the preexisting database to avoid the special setup | ||
42 | # that the "all.test" script does. | ||
43 | # | ||
44 | db close | ||
45 | file delete test.db test.db-journal | ||
46 | file delete test3.db test3.db-journal | ||
47 | sqlite3 db test.db; set DB [sqlite3_connection_pointer db] | ||
48 | |||
49 | |||
50 | ifcapable pager_pragmas { | ||
51 | set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}] | ||
52 | set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}] | ||
53 | do_test pragma-1.1 { | ||
54 | execsql { | ||
55 | PRAGMA cache_size; | ||
56 | PRAGMA default_cache_size; | ||
57 | PRAGMA synchronous; | ||
58 | } | ||
59 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] | ||
60 | do_test pragma-1.2 { | ||
61 | execsql { | ||
62 | PRAGMA synchronous=OFF; | ||
63 | PRAGMA cache_size=1234; | ||
64 | PRAGMA cache_size; | ||
65 | PRAGMA default_cache_size; | ||
66 | PRAGMA synchronous; | ||
67 | } | ||
68 | } [list 1234 $DFLT_CACHE_SZ 0] | ||
69 | do_test pragma-1.3 { | ||
70 | db close | ||
71 | sqlite3 db test.db | ||
72 | execsql { | ||
73 | PRAGMA cache_size; | ||
74 | PRAGMA default_cache_size; | ||
75 | PRAGMA synchronous; | ||
76 | } | ||
77 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] | ||
78 | do_test pragma-1.4 { | ||
79 | execsql { | ||
80 | PRAGMA synchronous=OFF; | ||
81 | PRAGMA cache_size; | ||
82 | PRAGMA default_cache_size; | ||
83 | PRAGMA synchronous; | ||
84 | } | ||
85 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0] | ||
86 | do_test pragma-1.5 { | ||
87 | execsql { | ||
88 | PRAGMA cache_size=4321; | ||
89 | PRAGMA cache_size; | ||
90 | PRAGMA default_cache_size; | ||
91 | PRAGMA synchronous; | ||
92 | } | ||
93 | } [list 4321 $DFLT_CACHE_SZ 0] | ||
94 | do_test pragma-1.6 { | ||
95 | execsql { | ||
96 | PRAGMA synchronous=ON; | ||
97 | PRAGMA cache_size; | ||
98 | PRAGMA default_cache_size; | ||
99 | PRAGMA synchronous; | ||
100 | } | ||
101 | } [list 4321 $DFLT_CACHE_SZ 1] | ||
102 | do_test pragma-1.7 { | ||
103 | db close | ||
104 | sqlite3 db test.db | ||
105 | execsql { | ||
106 | PRAGMA cache_size; | ||
107 | PRAGMA default_cache_size; | ||
108 | PRAGMA synchronous; | ||
109 | } | ||
110 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] | ||
111 | do_test pragma-1.8 { | ||
112 | execsql { | ||
113 | PRAGMA default_cache_size=123; | ||
114 | PRAGMA cache_size; | ||
115 | PRAGMA default_cache_size; | ||
116 | PRAGMA synchronous; | ||
117 | } | ||
118 | } {123 123 2} | ||
119 | do_test pragma-1.9.1 { | ||
120 | db close | ||
121 | sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] | ||
122 | execsql { | ||
123 | PRAGMA cache_size; | ||
124 | PRAGMA default_cache_size; | ||
125 | PRAGMA synchronous; | ||
126 | } | ||
127 | } {123 123 2} | ||
128 | ifcapable vacuum { | ||
129 | do_test pragma-1.9.2 { | ||
130 | execsql { | ||
131 | VACUUM; | ||
132 | PRAGMA cache_size; | ||
133 | PRAGMA default_cache_size; | ||
134 | PRAGMA synchronous; | ||
135 | } | ||
136 | } {123 123 2} | ||
137 | } | ||
138 | do_test pragma-1.10 { | ||
139 | execsql { | ||
140 | PRAGMA synchronous=NORMAL; | ||
141 | PRAGMA cache_size; | ||
142 | PRAGMA default_cache_size; | ||
143 | PRAGMA synchronous; | ||
144 | } | ||
145 | } {123 123 1} | ||
146 | do_test pragma-1.11 { | ||
147 | execsql { | ||
148 | PRAGMA synchronous=FULL; | ||
149 | PRAGMA cache_size; | ||
150 | PRAGMA default_cache_size; | ||
151 | PRAGMA synchronous; | ||
152 | } | ||
153 | } {123 123 2} | ||
154 | do_test pragma-1.12 { | ||
155 | db close | ||
156 | sqlite3 db test.db; set ::DB [sqlite3_connection_pointer db] | ||
157 | execsql { | ||
158 | PRAGMA cache_size; | ||
159 | PRAGMA default_cache_size; | ||
160 | PRAGMA synchronous; | ||
161 | } | ||
162 | } {123 123 2} | ||
163 | |||
164 | # Make sure the pragma handler understands numeric values in addition | ||
165 | # to keywords like "off" and "full". | ||
166 | # | ||
167 | do_test pragma-1.13 { | ||
168 | execsql { | ||
169 | PRAGMA synchronous=0; | ||
170 | PRAGMA synchronous; | ||
171 | } | ||
172 | } {0} | ||
173 | do_test pragma-1.14 { | ||
174 | execsql { | ||
175 | PRAGMA synchronous=2; | ||
176 | PRAGMA synchronous; | ||
177 | } | ||
178 | } {2} | ||
179 | } ;# ifcapable pager_pragmas | ||
180 | |||
181 | # Test turning "flag" pragmas on and off. | ||
182 | # | ||
183 | ifcapable debug { | ||
184 | # Pragma "vdbe_listing" is only available if compiled with SQLITE_DEBUG | ||
185 | # | ||
186 | do_test pragma-1.15 { | ||
187 | execsql { | ||
188 | PRAGMA vdbe_listing=YES; | ||
189 | PRAGMA vdbe_listing; | ||
190 | } | ||
191 | } {1} | ||
192 | do_test pragma-1.16 { | ||
193 | execsql { | ||
194 | PRAGMA vdbe_listing=NO; | ||
195 | PRAGMA vdbe_listing; | ||
196 | } | ||
197 | } {0} | ||
198 | } | ||
199 | |||
200 | do_test pragma-1.17 { | ||
201 | execsql { | ||
202 | PRAGMA parser_trace=ON; | ||
203 | PRAGMA parser_trace=OFF; | ||
204 | } | ||
205 | } {} | ||
206 | do_test pragma-1.18 { | ||
207 | execsql { | ||
208 | PRAGMA bogus = -1234; -- Parsing of negative values | ||
209 | } | ||
210 | } {} | ||
211 | |||
212 | # Test modifying the safety_level of an attached database. | ||
213 | do_test pragma-2.1 { | ||
214 | file delete -force test2.db | ||
215 | file delete -force test2.db-journal | ||
216 | execsql { | ||
217 | ATTACH 'test2.db' AS aux; | ||
218 | } | ||
219 | } {} | ||
220 | ifcapable pager_pragmas { | ||
221 | do_test pragma-2.2 { | ||
222 | execsql { | ||
223 | pragma aux.synchronous; | ||
224 | } | ||
225 | } {2} | ||
226 | do_test pragma-2.3 { | ||
227 | execsql { | ||
228 | pragma aux.synchronous = OFF; | ||
229 | pragma aux.synchronous; | ||
230 | pragma synchronous; | ||
231 | } | ||
232 | } {0 2} | ||
233 | do_test pragma-2.4 { | ||
234 | execsql { | ||
235 | pragma aux.synchronous = ON; | ||
236 | pragma synchronous; | ||
237 | pragma aux.synchronous; | ||
238 | } | ||
239 | } {2 1} | ||
240 | } ;# ifcapable pager_pragmas | ||
241 | |||
242 | # Construct a corrupted index and make sure the integrity_check | ||
243 | # pragma finds it. | ||
244 | # | ||
245 | # These tests won't work if the database is encrypted | ||
246 | # | ||
247 | do_test pragma-3.1 { | ||
248 | db close | ||
249 | file delete -force test.db test.db-journal | ||
250 | sqlite3 db test.db | ||
251 | execsql { | ||
252 | PRAGMA auto_vacuum=OFF; | ||
253 | BEGIN; | ||
254 | CREATE TABLE t2(a,b,c); | ||
255 | CREATE INDEX i2 ON t2(a); | ||
256 | INSERT INTO t2 VALUES(11,2,3); | ||
257 | INSERT INTO t2 VALUES(22,3,4); | ||
258 | COMMIT; | ||
259 | SELECT rowid, * from t2; | ||
260 | } | ||
261 | } {1 11 2 3 2 22 3 4} | ||
262 | if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { | ||
263 | do_test pragma-3.2 { | ||
264 | set rootpage [execsql {SELECT rootpage FROM sqlite_master WHERE name='i2'}] | ||
265 | set db [btree_open test.db 100 0] | ||
266 | btree_begin_transaction $db | ||
267 | set c [btree_cursor $db $rootpage 1] | ||
268 | btree_first $c | ||
269 | btree_delete $c | ||
270 | btree_commit $db | ||
271 | btree_close $db | ||
272 | execsql {PRAGMA integrity_check} | ||
273 | } {{rowid 1 missing from index i2} {wrong # of entries in index i2}} | ||
274 | do_test pragma-3.3 { | ||
275 | execsql {PRAGMA integrity_check=1} | ||
276 | } {{rowid 1 missing from index i2}} | ||
277 | do_test pragma-3.4 { | ||
278 | execsql { | ||
279 | ATTACH DATABASE 'test.db' AS t2; | ||
280 | PRAGMA integrity_check | ||
281 | } | ||
282 | } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}} | ||
283 | do_test pragma-3.5 { | ||
284 | execsql { | ||
285 | PRAGMA integrity_check=3 | ||
286 | } | ||
287 | } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}} | ||
288 | do_test pragma-3.6 { | ||
289 | execsql { | ||
290 | PRAGMA integrity_check=xyz | ||
291 | } | ||
292 | } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}} | ||
293 | do_test pragma-3.7 { | ||
294 | execsql { | ||
295 | PRAGMA integrity_check=0 | ||
296 | } | ||
297 | } {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}} | ||
298 | |||
299 | # Add additional corruption by appending unused pages to the end of | ||
300 | # the database file testerr.db | ||
301 | # | ||
302 | do_test pragma-3.8 { | ||
303 | execsql {DETACH t2} | ||
304 | file delete -force testerr.db testerr.db-journal | ||
305 | set out [open testerr.db w] | ||
306 | fconfigure $out -translation binary | ||
307 | set in [open test.db r] | ||
308 | fconfigure $in -translation binary | ||
309 | puts -nonewline $out [read $in] | ||
310 | seek $in 0 | ||
311 | puts -nonewline $out [read $in] | ||
312 | close $in | ||
313 | close $out | ||
314 | execsql {REINDEX t2} | ||
315 | execsql {PRAGMA integrity_check} | ||
316 | } {ok} | ||
317 | do_test pragma-3.9 { | ||
318 | execsql { | ||
319 | ATTACH 'testerr.db' AS t2; | ||
320 | PRAGMA integrity_check | ||
321 | } | ||
322 | } {{*** in database t2 *** | ||
323 | Page 4 is never used | ||
324 | Page 5 is never used | ||
325 | Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}} | ||
326 | do_test pragma-3.10 { | ||
327 | execsql { | ||
328 | PRAGMA integrity_check=1 | ||
329 | } | ||
330 | } {{*** in database t2 *** | ||
331 | Page 4 is never used}} | ||
332 | do_test pragma-3.11 { | ||
333 | execsql { | ||
334 | PRAGMA integrity_check=5 | ||
335 | } | ||
336 | } {{*** in database t2 *** | ||
337 | Page 4 is never used | ||
338 | Page 5 is never used | ||
339 | Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}} | ||
340 | do_test pragma-3.12 { | ||
341 | execsql { | ||
342 | PRAGMA integrity_check=4 | ||
343 | } | ||
344 | } {{*** in database t2 *** | ||
345 | Page 4 is never used | ||
346 | Page 5 is never used | ||
347 | Page 6 is never used} {rowid 1 missing from index i2}} | ||
348 | do_test pragma-3.13 { | ||
349 | execsql { | ||
350 | PRAGMA integrity_check=3 | ||
351 | } | ||
352 | } {{*** in database t2 *** | ||
353 | Page 4 is never used | ||
354 | Page 5 is never used | ||
355 | Page 6 is never used}} | ||
356 | do_test pragma-3.14 { | ||
357 | execsql { | ||
358 | PRAGMA integrity_check(2) | ||
359 | } | ||
360 | } {{*** in database t2 *** | ||
361 | Page 4 is never used | ||
362 | Page 5 is never used}} | ||
363 | do_test pragma-3.15 { | ||
364 | execsql { | ||
365 | ATTACH 'testerr.db' AS t3; | ||
366 | PRAGMA integrity_check | ||
367 | } | ||
368 | } {{*** in database t2 *** | ||
369 | Page 4 is never used | ||
370 | Page 5 is never used | ||
371 | Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** | ||
372 | Page 4 is never used | ||
373 | Page 5 is never used | ||
374 | Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}} | ||
375 | do_test pragma-3.16 { | ||
376 | execsql { | ||
377 | PRAGMA integrity_check(9) | ||
378 | } | ||
379 | } {{*** in database t2 *** | ||
380 | Page 4 is never used | ||
381 | Page 5 is never used | ||
382 | Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** | ||
383 | Page 4 is never used | ||
384 | Page 5 is never used | ||
385 | Page 6 is never used} {rowid 1 missing from index i2}} | ||
386 | do_test pragma-3.17 { | ||
387 | execsql { | ||
388 | PRAGMA integrity_check=7 | ||
389 | } | ||
390 | } {{*** in database t2 *** | ||
391 | Page 4 is never used | ||
392 | Page 5 is never used | ||
393 | Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 *** | ||
394 | Page 4 is never used | ||
395 | Page 5 is never used}} | ||
396 | do_test pragma-3.18 { | ||
397 | execsql { | ||
398 | PRAGMA integrity_check=4 | ||
399 | } | ||
400 | } {{*** in database t2 *** | ||
401 | Page 4 is never used | ||
402 | Page 5 is never used | ||
403 | Page 6 is never used} {rowid 1 missing from index i2}} | ||
404 | } | ||
405 | do_test pragma-3.99 { | ||
406 | catchsql {DETACH t3} | ||
407 | catchsql {DETACH t2} | ||
408 | file delete -force testerr.db testerr.db-journal | ||
409 | catchsql {DROP INDEX i2} | ||
410 | } {0 {}} | ||
411 | |||
412 | # Test modifying the cache_size of an attached database. | ||
413 | ifcapable pager_pragmas { | ||
414 | do_test pragma-4.1 { | ||
415 | execsql { | ||
416 | ATTACH 'test2.db' AS aux; | ||
417 | pragma aux.cache_size; | ||
418 | pragma aux.default_cache_size; | ||
419 | } | ||
420 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] | ||
421 | do_test pragma-4.2 { | ||
422 | execsql { | ||
423 | pragma aux.cache_size = 50; | ||
424 | pragma aux.cache_size; | ||
425 | pragma aux.default_cache_size; | ||
426 | } | ||
427 | } [list 50 $DFLT_CACHE_SZ] | ||
428 | do_test pragma-4.3 { | ||
429 | execsql { | ||
430 | pragma aux.default_cache_size = 456; | ||
431 | pragma aux.cache_size; | ||
432 | pragma aux.default_cache_size; | ||
433 | } | ||
434 | } {456 456} | ||
435 | do_test pragma-4.4 { | ||
436 | execsql { | ||
437 | pragma cache_size; | ||
438 | pragma default_cache_size; | ||
439 | } | ||
440 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] | ||
441 | do_test pragma-4.5 { | ||
442 | execsql { | ||
443 | DETACH aux; | ||
444 | ATTACH 'test3.db' AS aux; | ||
445 | pragma aux.cache_size; | ||
446 | pragma aux.default_cache_size; | ||
447 | } | ||
448 | } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] | ||
449 | do_test pragma-4.6 { | ||
450 | execsql { | ||
451 | DETACH aux; | ||
452 | ATTACH 'test2.db' AS aux; | ||
453 | pragma aux.cache_size; | ||
454 | pragma aux.default_cache_size; | ||
455 | } | ||
456 | } {456 456} | ||
457 | } ;# ifcapable pager_pragmas | ||
458 | |||
459 | # Test that modifying the sync-level in the middle of a transaction is | ||
460 | # disallowed. | ||
461 | ifcapable pager_pragmas { | ||
462 | do_test pragma-5.0 { | ||
463 | execsql { | ||
464 | pragma synchronous; | ||
465 | } | ||
466 | } {2} | ||
467 | do_test pragma-5.1 { | ||
468 | catchsql { | ||
469 | BEGIN; | ||
470 | pragma synchronous = OFF; | ||
471 | } | ||
472 | } {1 {Safety level may not be changed inside a transaction}} | ||
473 | do_test pragma-5.2 { | ||
474 | execsql { | ||
475 | pragma synchronous; | ||
476 | } | ||
477 | } {2} | ||
478 | catchsql {COMMIT;} | ||
479 | } ;# ifcapable pager_pragmas | ||
480 | |||
481 | # Test schema-query pragmas | ||
482 | # | ||
483 | ifcapable schema_pragmas { | ||
484 | ifcapable tempdb { | ||
485 | do_test pragma-6.1 { | ||
486 | set res {} | ||
487 | execsql {SELECT * FROM sqlite_temp_master} | ||
488 | foreach {idx name file} [execsql {pragma database_list}] { | ||
489 | lappend res $idx $name | ||
490 | } | ||
491 | set res | ||
492 | } {0 main 1 temp 2 aux} | ||
493 | } | ||
494 | do_test pragma-6.2 { | ||
495 | execsql { | ||
496 | pragma table_info(t2) | ||
497 | } | ||
498 | } {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0} | ||
499 | db nullvalue <<NULL>> | ||
500 | do_test pragma-6.2.2 { | ||
501 | execsql { | ||
502 | CREATE TABLE t5( | ||
503 | a TEXT DEFAULT CURRENT_TIMESTAMP, | ||
504 | b DEFAULT (5+3), | ||
505 | c TEXT, | ||
506 | d INTEGER DEFAULT NULL, | ||
507 | e TEXT DEFAULT '' | ||
508 | ); | ||
509 | PRAGMA table_info(t5); | ||
510 | } | ||
511 | } {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 0} | ||
512 | db nullvalue {} | ||
513 | ifcapable {foreignkey} { | ||
514 | do_test pragma-6.3 { | ||
515 | execsql { | ||
516 | CREATE TABLE t3(a int references t2(b), b UNIQUE); | ||
517 | pragma foreign_key_list(t3); | ||
518 | } | ||
519 | } {0 0 t2 a b} | ||
520 | do_test pragma-6.4 { | ||
521 | execsql { | ||
522 | pragma index_list(t3); | ||
523 | } | ||
524 | } {0 sqlite_autoindex_t3_1 1} | ||
525 | } | ||
526 | ifcapable {!foreignkey} { | ||
527 | execsql {CREATE TABLE t3(a,b UNIQUE)} | ||
528 | } | ||
529 | do_test pragma-6.5 { | ||
530 | execsql { | ||
531 | CREATE INDEX t3i1 ON t3(a,b); | ||
532 | pragma index_info(t3i1); | ||
533 | } | ||
534 | } {0 0 a 1 1 b} | ||
535 | } ;# ifcapable schema_pragmas | ||
536 | # Miscellaneous tests | ||
537 | # | ||
538 | ifcapable schema_pragmas { | ||
539 | do_test pragma-7.1 { | ||
540 | # Make sure a pragma knows to read the schema if it needs to | ||
541 | db close | ||
542 | sqlite3 db test.db | ||
543 | execsql { | ||
544 | pragma index_list(t3); | ||
545 | } | ||
546 | } {0 t3i1 0 1 sqlite_autoindex_t3_1 1} | ||
547 | } ;# ifcapable schema_pragmas | ||
548 | ifcapable {utf16} { | ||
549 | do_test pragma-7.2 { | ||
550 | db close | ||
551 | sqlite3 db test.db | ||
552 | catchsql { | ||
553 | pragma encoding=bogus; | ||
554 | } | ||
555 | } {1 {unsupported encoding: bogus}} | ||
556 | } | ||
557 | ifcapable tempdb { | ||
558 | do_test pragma-7.3 { | ||
559 | db close | ||
560 | sqlite3 db test.db | ||
561 | execsql { | ||
562 | pragma lock_status; | ||
563 | } | ||
564 | } {main unlocked temp closed} | ||
565 | } else { | ||
566 | do_test pragma-7.3 { | ||
567 | db close | ||
568 | sqlite3 db test.db | ||
569 | execsql { | ||
570 | pragma lock_status; | ||
571 | } | ||
572 | } {main unlocked} | ||
573 | } | ||
574 | |||
575 | |||
576 | #---------------------------------------------------------------------- | ||
577 | # Test cases pragma-8.* test the "PRAGMA schema_version" and "PRAGMA | ||
578 | # user_version" statements. | ||
579 | # | ||
580 | # pragma-8.1: PRAGMA schema_version | ||
581 | # pragma-8.2: PRAGMA user_version | ||
582 | # | ||
583 | |||
584 | ifcapable schema_version { | ||
585 | |||
586 | # First check that we can set the schema version and then retrieve the | ||
587 | # same value. | ||
588 | do_test pragma-8.1.1 { | ||
589 | execsql { | ||
590 | PRAGMA schema_version = 105; | ||
591 | } | ||
592 | } {} | ||
593 | do_test pragma-8.1.2 { | ||
594 | execsql2 { | ||
595 | PRAGMA schema_version; | ||
596 | } | ||
597 | } {schema_version 105} | ||
598 | do_test pragma-8.1.3 { | ||
599 | execsql { | ||
600 | PRAGMA schema_version = 106; | ||
601 | } | ||
602 | } {} | ||
603 | do_test pragma-8.1.4 { | ||
604 | execsql { | ||
605 | PRAGMA schema_version; | ||
606 | } | ||
607 | } 106 | ||
608 | |||
609 | # Check that creating a table modifies the schema-version (this is really | ||
610 | # to verify that the value being read is in fact the schema version). | ||
611 | do_test pragma-8.1.5 { | ||
612 | execsql { | ||
613 | CREATE TABLE t4(a, b, c); | ||
614 | INSERT INTO t4 VALUES(1, 2, 3); | ||
615 | SELECT * FROM t4; | ||
616 | } | ||
617 | } {1 2 3} | ||
618 | do_test pragma-8.1.6 { | ||
619 | execsql { | ||
620 | PRAGMA schema_version; | ||
621 | } | ||
622 | } 107 | ||
623 | |||
624 | # Now open a second connection to the database. Ensure that changing the | ||
625 | # schema-version using the first connection forces the second connection | ||
626 | # to reload the schema. This has to be done using the C-API test functions, | ||
627 | # because the TCL API accounts for SCHEMA_ERROR and retries the query. | ||
628 | do_test pragma-8.1.7 { | ||
629 | sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] | ||
630 | execsql { | ||
631 | SELECT * FROM t4; | ||
632 | } db2 | ||
633 | } {1 2 3} | ||
634 | do_test pragma-8.1.8 { | ||
635 | execsql { | ||
636 | PRAGMA schema_version = 108; | ||
637 | } | ||
638 | } {} | ||
639 | do_test pragma-8.1.9 { | ||
640 | set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] | ||
641 | sqlite3_step $::STMT | ||
642 | } SQLITE_ERROR | ||
643 | do_test pragma-8.1.10 { | ||
644 | sqlite3_finalize $::STMT | ||
645 | } SQLITE_SCHEMA | ||
646 | |||
647 | # Make sure the schema-version can be manipulated in an attached database. | ||
648 | file delete -force test2.db | ||
649 | file delete -force test2.db-journal | ||
650 | do_test pragma-8.1.11 { | ||
651 | execsql { | ||
652 | ATTACH 'test2.db' AS aux; | ||
653 | CREATE TABLE aux.t1(a, b, c); | ||
654 | PRAGMA aux.schema_version = 205; | ||
655 | } | ||
656 | } {} | ||
657 | do_test pragma-8.1.12 { | ||
658 | execsql { | ||
659 | PRAGMA aux.schema_version; | ||
660 | } | ||
661 | } 205 | ||
662 | do_test pragma-8.1.13 { | ||
663 | execsql { | ||
664 | PRAGMA schema_version; | ||
665 | } | ||
666 | } 108 | ||
667 | |||
668 | # And check that modifying the schema-version in an attached database | ||
669 | # forces the second connection to reload the schema. | ||
670 | do_test pragma-8.1.14 { | ||
671 | sqlite3 db2 test.db; set ::DB2 [sqlite3_connection_pointer db2] | ||
672 | execsql { | ||
673 | ATTACH 'test2.db' AS aux; | ||
674 | SELECT * FROM aux.t1; | ||
675 | } db2 | ||
676 | } {} | ||
677 | do_test pragma-8.1.15 { | ||
678 | execsql { | ||
679 | PRAGMA aux.schema_version = 206; | ||
680 | } | ||
681 | } {} | ||
682 | do_test pragma-8.1.16 { | ||
683 | set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM aux.t1" -1 DUMMY] | ||
684 | sqlite3_step $::STMT | ||
685 | } SQLITE_ERROR | ||
686 | do_test pragma-8.1.17 { | ||
687 | sqlite3_finalize $::STMT | ||
688 | } SQLITE_SCHEMA | ||
689 | do_test pragma-8.1.18 { | ||
690 | db2 close | ||
691 | } {} | ||
692 | |||
693 | # Now test that the user-version can be read and written (and that we aren't | ||
694 | # accidentally manipulating the schema-version instead). | ||
695 | do_test pragma-8.2.1 { | ||
696 | execsql2 { | ||
697 | PRAGMA user_version; | ||
698 | } | ||
699 | } {user_version 0} | ||
700 | do_test pragma-8.2.2 { | ||
701 | execsql { | ||
702 | PRAGMA user_version = 2; | ||
703 | } | ||
704 | } {} | ||
705 | do_test pragma-8.2.3.1 { | ||
706 | execsql2 { | ||
707 | PRAGMA user_version; | ||
708 | } | ||
709 | } {user_version 2} | ||
710 | do_test pragma-8.2.3.2 { | ||
711 | db close | ||
712 | sqlite3 db test.db | ||
713 | execsql { | ||
714 | PRAGMA user_version; | ||
715 | } | ||
716 | } {2} | ||
717 | do_test pragma-8.2.4.1 { | ||
718 | execsql { | ||
719 | PRAGMA schema_version; | ||
720 | } | ||
721 | } {108} | ||
722 | ifcapable vacuum { | ||
723 | do_test pragma-8.2.4.2 { | ||
724 | execsql { | ||
725 | VACUUM; | ||
726 | PRAGMA user_version; | ||
727 | } | ||
728 | } {2} | ||
729 | do_test pragma-8.2.4.3 { | ||
730 | execsql { | ||
731 | PRAGMA schema_version; | ||
732 | } | ||
733 | } {109} | ||
734 | } | ||
735 | db eval {ATTACH 'test2.db' AS aux} | ||
736 | |||
737 | # Check that the user-version in the auxilary database can be manipulated ( | ||
738 | # and that we aren't accidentally manipulating the same in the main db). | ||
739 | do_test pragma-8.2.5 { | ||
740 | execsql { | ||
741 | PRAGMA aux.user_version; | ||
742 | } | ||
743 | } {0} | ||
744 | do_test pragma-8.2.6 { | ||
745 | execsql { | ||
746 | PRAGMA aux.user_version = 3; | ||
747 | } | ||
748 | } {} | ||
749 | do_test pragma-8.2.7 { | ||
750 | execsql { | ||
751 | PRAGMA aux.user_version; | ||
752 | } | ||
753 | } {3} | ||
754 | do_test pragma-8.2.8 { | ||
755 | execsql { | ||
756 | PRAGMA main.user_version; | ||
757 | } | ||
758 | } {2} | ||
759 | |||
760 | # Now check that a ROLLBACK resets the user-version if it has been modified | ||
761 | # within a transaction. | ||
762 | do_test pragma-8.2.9 { | ||
763 | execsql { | ||
764 | BEGIN; | ||
765 | PRAGMA aux.user_version = 10; | ||
766 | PRAGMA user_version = 11; | ||
767 | } | ||
768 | } {} | ||
769 | do_test pragma-8.2.10 { | ||
770 | execsql { | ||
771 | PRAGMA aux.user_version; | ||
772 | } | ||
773 | } {10} | ||
774 | do_test pragma-8.2.11 { | ||
775 | execsql { | ||
776 | PRAGMA main.user_version; | ||
777 | } | ||
778 | } {11} | ||
779 | do_test pragma-8.2.12 { | ||
780 | execsql { | ||
781 | ROLLBACK; | ||
782 | PRAGMA aux.user_version; | ||
783 | } | ||
784 | } {3} | ||
785 | do_test pragma-8.2.13 { | ||
786 | execsql { | ||
787 | PRAGMA main.user_version; | ||
788 | } | ||
789 | } {2} | ||
790 | |||
791 | # Try a negative value for the user-version | ||
792 | do_test pragma-8.2.14 { | ||
793 | execsql { | ||
794 | PRAGMA user_version = -450; | ||
795 | } | ||
796 | } {} | ||
797 | do_test pragma-8.2.15 { | ||
798 | execsql { | ||
799 | PRAGMA user_version; | ||
800 | } | ||
801 | } {-450} | ||
802 | } ; # ifcapable schema_version | ||
803 | |||
804 | |||
805 | # Test temp_store and temp_store_directory pragmas | ||
806 | # | ||
807 | ifcapable pager_pragmas { | ||
808 | do_test pragma-9.1 { | ||
809 | db close | ||
810 | sqlite3 db test.db | ||
811 | execsql { | ||
812 | PRAGMA temp_store; | ||
813 | } | ||
814 | } {0} | ||
815 | do_test pragma-9.2 { | ||
816 | execsql { | ||
817 | PRAGMA temp_store=file; | ||
818 | PRAGMA temp_store; | ||
819 | } | ||
820 | } {1} | ||
821 | do_test pragma-9.3 { | ||
822 | execsql { | ||
823 | PRAGMA temp_store=memory; | ||
824 | PRAGMA temp_store; | ||
825 | } | ||
826 | } {2} | ||
827 | do_test pragma-9.4 { | ||
828 | execsql { | ||
829 | PRAGMA temp_store_directory; | ||
830 | } | ||
831 | } {} | ||
832 | do_test pragma-9.5 { | ||
833 | set pwd [string map {' ''} [pwd]] | ||
834 | execsql " | ||
835 | PRAGMA temp_store_directory='$pwd'; | ||
836 | " | ||
837 | } {} | ||
838 | do_test pragma-9.6 { | ||
839 | execsql { | ||
840 | PRAGMA temp_store_directory; | ||
841 | } | ||
842 | } [list [pwd]] | ||
843 | do_test pragma-9.7 { | ||
844 | catchsql { | ||
845 | PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; | ||
846 | } | ||
847 | } {1 {not a writable directory}} | ||
848 | do_test pragma-9.8 { | ||
849 | execsql { | ||
850 | PRAGMA temp_store_directory=''; | ||
851 | } | ||
852 | } {} | ||
853 | if {![info exists TEMP_STORE] || $TEMP_STORE<=1} { | ||
854 | ifcapable tempdb { | ||
855 | do_test pragma-9.9 { | ||
856 | execsql { | ||
857 | PRAGMA temp_store_directory; | ||
858 | PRAGMA temp_store=FILE; | ||
859 | CREATE TEMP TABLE temp_store_directory_test(a integer); | ||
860 | INSERT INTO temp_store_directory_test values (2); | ||
861 | SELECT * FROM temp_store_directory_test; | ||
862 | } | ||
863 | } {2} | ||
864 | do_test pragma-9.10 { | ||
865 | catchsql " | ||
866 | PRAGMA temp_store_directory='$pwd'; | ||
867 | SELECT * FROM temp_store_directory_test; | ||
868 | " | ||
869 | } {1 {no such table: temp_store_directory_test}} | ||
870 | } | ||
871 | } | ||
872 | do_test pragma-9.11 { | ||
873 | execsql { | ||
874 | PRAGMA temp_store = 0; | ||
875 | PRAGMA temp_store; | ||
876 | } | ||
877 | } {0} | ||
878 | do_test pragma-9.12 { | ||
879 | execsql { | ||
880 | PRAGMA temp_store = 1; | ||
881 | PRAGMA temp_store; | ||
882 | } | ||
883 | } {1} | ||
884 | do_test pragma-9.13 { | ||
885 | execsql { | ||
886 | PRAGMA temp_store = 2; | ||
887 | PRAGMA temp_store; | ||
888 | } | ||
889 | } {2} | ||
890 | do_test pragma-9.14 { | ||
891 | execsql { | ||
892 | PRAGMA temp_store = 3; | ||
893 | PRAGMA temp_store; | ||
894 | } | ||
895 | } {0} | ||
896 | breakpoint | ||
897 | do_test pragma-9.15 { | ||
898 | catchsql { | ||
899 | BEGIN EXCLUSIVE; | ||
900 | CREATE TEMP TABLE temp_table(t); | ||
901 | INSERT INTO temp_table VALUES('valuable data'); | ||
902 | PRAGMA temp_store = 1; | ||
903 | } | ||
904 | } {1 {temporary storage cannot be changed from within a transaction}} | ||
905 | do_test pragma-9.16 { | ||
906 | execsql { | ||
907 | SELECT * FROM temp_table; | ||
908 | COMMIT; | ||
909 | } | ||
910 | } {{valuable data}} | ||
911 | } ;# ifcapable pager_pragmas | ||
912 | |||
913 | ifcapable trigger { | ||
914 | |||
915 | do_test pragma-10.0 { | ||
916 | catchsql { | ||
917 | DROP TABLE main.t1; | ||
918 | } | ||
919 | execsql { | ||
920 | PRAGMA count_changes = 1; | ||
921 | |||
922 | CREATE TABLE t1(a PRIMARY KEY); | ||
923 | CREATE TABLE t1_mirror(a); | ||
924 | CREATE TABLE t1_mirror2(a); | ||
925 | CREATE TRIGGER t1_bi BEFORE INSERT ON t1 BEGIN | ||
926 | INSERT INTO t1_mirror VALUES(new.a); | ||
927 | END; | ||
928 | CREATE TRIGGER t1_ai AFTER INSERT ON t1 BEGIN | ||
929 | INSERT INTO t1_mirror2 VALUES(new.a); | ||
930 | END; | ||
931 | CREATE TRIGGER t1_bu BEFORE UPDATE ON t1 BEGIN | ||
932 | UPDATE t1_mirror SET a = new.a WHERE a = old.a; | ||
933 | END; | ||
934 | CREATE TRIGGER t1_au AFTER UPDATE ON t1 BEGIN | ||
935 | UPDATE t1_mirror2 SET a = new.a WHERE a = old.a; | ||
936 | END; | ||
937 | CREATE TRIGGER t1_bd BEFORE DELETE ON t1 BEGIN | ||
938 | DELETE FROM t1_mirror WHERE a = old.a; | ||
939 | END; | ||
940 | CREATE TRIGGER t1_ad AFTER DELETE ON t1 BEGIN | ||
941 | DELETE FROM t1_mirror2 WHERE a = old.a; | ||
942 | END; | ||
943 | } | ||
944 | } {} | ||
945 | |||
946 | do_test pragma-10.1 { | ||
947 | execsql { | ||
948 | INSERT INTO t1 VALUES(randstr(10,10)); | ||
949 | } | ||
950 | } {1} | ||
951 | do_test pragma-10.2 { | ||
952 | execsql { | ||
953 | UPDATE t1 SET a = randstr(10,10); | ||
954 | } | ||
955 | } {1} | ||
956 | do_test pragma-10.3 { | ||
957 | execsql { | ||
958 | DELETE FROM t1; | ||
959 | } | ||
960 | } {1} | ||
961 | |||
962 | } ;# ifcapable trigger | ||
963 | |||
964 | ifcapable schema_pragmas { | ||
965 | do_test pragma-11.1 { | ||
966 | execsql2 { | ||
967 | pragma collation_list; | ||
968 | } | ||
969 | } {seq 0 name NOCASE seq 1 name BINARY} | ||
970 | do_test pragma-11.2 { | ||
971 | db collate New_Collation blah... | ||
972 | execsql { | ||
973 | pragma collation_list; | ||
974 | } | ||
975 | } {0 New_Collation 1 NOCASE 2 BINARY} | ||
976 | } | ||
977 | |||
978 | ifcapable schema_pragmas&&tempdb { | ||
979 | do_test pragma-12.1 { | ||
980 | sqlite3 db2 test.db | ||
981 | execsql { | ||
982 | PRAGMA temp.table_info('abc'); | ||
983 | } db2 | ||
984 | } {} | ||
985 | db2 close | ||
986 | |||
987 | do_test pragma-12.2 { | ||
988 | sqlite3 db2 test.db | ||
989 | execsql { | ||
990 | PRAGMA temp.default_cache_size = 200; | ||
991 | PRAGMA temp.default_cache_size; | ||
992 | } db2 | ||
993 | } {200} | ||
994 | db2 close | ||
995 | |||
996 | do_test pragma-12.3 { | ||
997 | sqlite3 db2 test.db | ||
998 | execsql { | ||
999 | PRAGMA temp.cache_size = 400; | ||
1000 | PRAGMA temp.cache_size; | ||
1001 | } db2 | ||
1002 | } {400} | ||
1003 | db2 close | ||
1004 | } | ||
1005 | |||
1006 | ifcapable bloblit { | ||
1007 | |||
1008 | do_test pragma-13.1 { | ||
1009 | execsql { | ||
1010 | DROP TABLE IF EXISTS t4; | ||
1011 | PRAGMA vdbe_trace=on; | ||
1012 | PRAGMA vdbe_listing=on; | ||
1013 | PRAGMA sql_trace=on; | ||
1014 | CREATE TABLE t4(a INTEGER PRIMARY KEY,b); | ||
1015 | INSERT INTO t4(b) VALUES(x'0123456789abcdef0123456789abcdef0123456789'); | ||
1016 | INSERT INTO t4(b) VALUES(randstr(30,30)); | ||
1017 | INSERT INTO t4(b) VALUES(1.23456); | ||
1018 | INSERT INTO t4(b) VALUES(NULL); | ||
1019 | INSERT INTO t4(b) VALUES(0); | ||
1020 | INSERT INTO t4(b) SELECT b||b||b||b FROM t4; | ||
1021 | SELECT * FROM t4; | ||
1022 | } | ||
1023 | execsql { | ||
1024 | PRAGMA vdbe_trace=off; | ||
1025 | PRAGMA vdbe_listing=off; | ||
1026 | PRAGMA sql_trace=off; | ||
1027 | } | ||
1028 | } {} | ||
1029 | |||
1030 | } ;# ifcapable bloblit | ||
1031 | |||
1032 | # Reset the sqlite3_temp_directory variable for the next run of tests: | ||
1033 | sqlite3 dbX :memory: | ||
1034 | dbX eval {PRAGMA temp_store_directory = ""} | ||
1035 | dbX close | ||
1036 | |||
1037 | finish_test | ||