Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: third_party/sqlite/src/test/pragma.test

Issue 949043002: Add //third_party/sqlite to dirs_to_snapshot, remove net_sql.patch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/test/permutations.test ('k') | third_party/sqlite/src/test/pragma2.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 2002 March 6 1 # 2002 March 6
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
11 # This file implements regression tests for SQLite library. 11 # This file implements regression tests for SQLite library.
12 # 12 #
13 # This file implements tests for the PRAGMA command. 13 # This file implements tests for the PRAGMA command.
14 # 14 #
15 # $Id: pragma.test,v 1.73 2009/01/12 14:01:45 danielk1977 Exp $ 15 # $Id: pragma.test,v 1.73 2009/01/12 14:01:45 danielk1977 Exp $
16 16
17 set testdir [file dirname $argv0] 17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl 18 source $testdir/tester.tcl
19 set testprefix pragma
19 20
20 # Do not use a codec for tests in this file, as the database file is 21 # Do not use a codec for tests in this file, as the database file is
21 # manipulated directly using tcl scripts (using the [hexio_write] command). 22 # manipulated directly using tcl scripts (using the [hexio_write] command).
22 # 23 #
23 do_not_use_codec 24 do_not_use_codec
24 25
25 # Test organization: 26 # Test organization:
26 # 27 #
27 # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db. 28 # pragma-1.*: Test cache_size, default_cache_size and synchronous on main db.
28 # pragma-2.*: Test synchronous on attached db. 29 # pragma-2.*: Test synchronous on attached db.
29 # pragma-3.*: Test detection of table/index inconsistency by integrity_check. 30 # pragma-3.*: Test detection of table/index inconsistency by integrity_check.
30 # pragma-4.*: Test cache_size and default_cache_size on attached db. 31 # pragma-4.*: Test cache_size and default_cache_size on attached db.
31 # pragma-5.*: Test that pragma synchronous may not be used inside of a 32 # pragma-5.*: Test that pragma synchronous may not be used inside of a
32 # transaction. 33 # transaction.
33 # pragma-6.*: Test schema-query pragmas. 34 # pragma-6.*: Test schema-query pragmas.
34 # pragma-7.*: Miscellaneous tests. 35 # pragma-7.*: Miscellaneous tests.
35 # pragma-8.*: Test user_version and schema_version pragmas. 36 # pragma-8.*: Test user_version and schema_version pragmas.
36 # pragma-9.*: Test temp_store and temp_store_directory. 37 # pragma-9.*: Test temp_store and temp_store_directory.
37 # pragma-10.*: Test the count_changes pragma in the presence of triggers. 38 # pragma-10.*: Test the count_changes pragma in the presence of triggers.
38 # pragma-11.*: Test the collation_list pragma. 39 # pragma-11.*: Test the collation_list pragma.
39 # pragma-14.*: Test the page_count pragma. 40 # pragma-14.*: Test the page_count pragma.
40 # pragma-15.*: Test that the value set using the cache_size pragma is not 41 # pragma-15.*: Test that the value set using the cache_size pragma is not
41 # reset when the schema is reloaded. 42 # reset when the schema is reloaded.
42 # pragma-16.*: Test proxy locking 43 # pragma-16.*: Test proxy locking
44 # pragma-20.*: Test data_store_directory.
45 # pragma-22.*: Test that "PRAGMA [db].integrity_check" respects the "db"
46 # directive - if it is present.
43 # 47 #
44 48
45 ifcapable !pragma { 49 ifcapable !pragma {
46 finish_test 50 finish_test
47 return 51 return
48 } 52 }
49 53
50 # Delete the preexisting database to avoid the special setup 54 # Delete the preexisting database to avoid the special setup
51 # that the "all.test" script does. 55 # that the "all.test" script does.
52 # 56 #
53 db close 57 db close
54 file delete test.db test.db-journal 58 delete_file test.db test.db-journal
55 file delete test3.db test3.db-journal 59 delete_file test3.db test3.db-journal
56 sqlite3 db test.db; set DB [sqlite3_connection_pointer db] 60 sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
57 61
58 62
59 ifcapable pager_pragmas { 63 ifcapable pager_pragmas {
60 set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}] 64 set DFLT_CACHE_SZ [db one {PRAGMA default_cache_size}]
61 set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}] 65 set TEMP_CACHE_SZ [db one {PRAGMA temp.default_cache_size}]
62 do_test pragma-1.1 { 66 do_test pragma-1.1 {
63 execsql { 67 execsql {
64 PRAGMA cache_size; 68 PRAGMA cache_size;
65 PRAGMA default_cache_size; 69 PRAGMA default_cache_size;
(...skipping 26 matching lines...) Expand all
92 PRAGMA synchronous; 96 PRAGMA synchronous;
93 } 97 }
94 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0] 98 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 0]
95 do_test pragma-1.5 { 99 do_test pragma-1.5 {
96 execsql { 100 execsql {
97 PRAGMA cache_size=-4321; 101 PRAGMA cache_size=-4321;
98 PRAGMA cache_size; 102 PRAGMA cache_size;
99 PRAGMA default_cache_size; 103 PRAGMA default_cache_size;
100 PRAGMA synchronous; 104 PRAGMA synchronous;
101 } 105 }
102 } [list 4321 $DFLT_CACHE_SZ 0] 106 } [list -4321 $DFLT_CACHE_SZ 0]
103 do_test pragma-1.6 { 107 do_test pragma-1.6 {
104 execsql { 108 execsql {
105 PRAGMA synchronous=ON; 109 PRAGMA synchronous=ON;
106 PRAGMA cache_size; 110 PRAGMA cache_size;
107 PRAGMA default_cache_size; 111 PRAGMA default_cache_size;
108 PRAGMA synchronous; 112 PRAGMA synchronous;
109 } 113 }
110 } [list 4321 $DFLT_CACHE_SZ 1] 114 } [list -4321 $DFLT_CACHE_SZ 1]
111 do_test pragma-1.7 { 115 do_test pragma-1.7 {
112 db close 116 db close
113 sqlite3 db test.db 117 sqlite3 db test.db
114 execsql { 118 execsql {
115 PRAGMA cache_size; 119 PRAGMA cache_size;
116 PRAGMA default_cache_size; 120 PRAGMA default_cache_size;
117 PRAGMA synchronous; 121 PRAGMA synchronous;
118 } 122 }
119 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2] 123 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ 2]
120 do_test pragma-1.8 { 124 do_test pragma-1.8 {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } {} 218 } {}
215 do_test pragma-1.18 { 219 do_test pragma-1.18 {
216 execsql { 220 execsql {
217 PRAGMA bogus = -1234; -- Parsing of negative values 221 PRAGMA bogus = -1234; -- Parsing of negative values
218 } 222 }
219 } {} 223 } {}
220 224
221 # Test modifying the safety_level of an attached database. 225 # Test modifying the safety_level of an attached database.
222 ifcapable pager_pragmas&&attach { 226 ifcapable pager_pragmas&&attach {
223 do_test pragma-2.1 { 227 do_test pragma-2.1 {
224 file delete -force test2.db 228 forcedelete test2.db
225 file delete -force test2.db-journal 229 forcedelete test2.db-journal
226 execsql { 230 execsql {
227 ATTACH 'test2.db' AS aux; 231 ATTACH 'test2.db' AS aux;
228 } 232 }
229 } {} 233 } {}
230 do_test pragma-2.2 { 234 do_test pragma-2.2 {
231 execsql { 235 execsql {
232 pragma aux.synchronous; 236 pragma aux.synchronous;
233 } 237 }
234 } {2} 238 } {2}
235 do_test pragma-2.3 { 239 do_test pragma-2.3 {
(...skipping 12 matching lines...) Expand all
248 } {2 1} 252 } {2 1}
249 } ;# ifcapable pager_pragmas 253 } ;# ifcapable pager_pragmas
250 254
251 # Construct a corrupted index and make sure the integrity_check 255 # Construct a corrupted index and make sure the integrity_check
252 # pragma finds it. 256 # pragma finds it.
253 # 257 #
254 # These tests won't work if the database is encrypted 258 # These tests won't work if the database is encrypted
255 # 259 #
256 do_test pragma-3.1 { 260 do_test pragma-3.1 {
257 db close 261 db close
258 file delete -force test.db test.db-journal 262 forcedelete test.db test.db-journal
259 sqlite3 db test.db 263 sqlite3 db test.db
260 execsql { 264 execsql {
261 PRAGMA auto_vacuum=OFF; 265 PRAGMA auto_vacuum=OFF;
262 BEGIN; 266 BEGIN;
263 CREATE TABLE t2(a,b,c); 267 CREATE TABLE t2(a,b,c);
264 CREATE INDEX i2 ON t2(a); 268 CREATE INDEX i2 ON t2(a);
265 INSERT INTO t2 VALUES(11,2,3); 269 INSERT INTO t2 VALUES(11,2,3);
266 INSERT INTO t2 VALUES(22,3,4); 270 INSERT INTO t2 VALUES(22,3,4);
267 COMMIT; 271 COMMIT;
268 SELECT rowid, * from t2; 272 SELECT rowid, * from t2;
269 } 273 }
270 } {1 11 2 3 2 22 3 4} 274 } {1 11 2 3 2 22 3 4}
271 ifcapable attach { 275 ifcapable attach {
272 if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} { 276 if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
273 do_test pragma-3.2 { 277 do_test pragma-3.2 {
274 db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break 278 db eval {SELECT rootpage FROM sqlite_master WHERE name='i2'} break
275 set pgsz [db eval {PRAGMA page_size}] 279 set pgsz [db eval {PRAGMA page_size}]
276 # overwrite the header on the rootpage of the index in order to 280 # overwrite the header on the rootpage of the index in order to
277 # make the index appear to be empty. 281 # make the index appear to be empty.
278 # 282 #
279 set offset [expr {$pgsz*($rootpage-1)}] 283 set offset [expr {$pgsz*($rootpage-1)}]
280 hexio_write test.db $offset 0a00000000040000000000 284 hexio_write test.db $offset 0a00000000040000000000
281 db close 285 db close
282 sqlite3 db test.db 286 sqlite3 db test.db
283 execsql {PRAGMA integrity_check} 287 execsql {PRAGMA integrity_check}
284 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2}} 288 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of e ntries in index i2}}
285 do_test pragma-3.3 { 289 do_test pragma-3.3 {
286 execsql {PRAGMA integrity_check=1} 290 execsql {PRAGMA integrity_check=1}
287 } {{rowid 1 missing from index i2}} 291 } {{row 1 missing from index i2}}
288 do_test pragma-3.4 { 292 do_test pragma-3.4 {
289 execsql { 293 execsql {
290 ATTACH DATABASE 'test.db' AS t2; 294 ATTACH DATABASE 'test.db' AS t2;
291 PRAGMA integrity_check 295 PRAGMA integrity_check
292 } 296 }
293 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from in dex i2} {wrong # of entries in index i2}} 297 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of e ntries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
294 do_test pragma-3.5 { 298 do_test pragma-3.5 {
295 execsql { 299 execsql {
296 PRAGMA integrity_check=4 300 PRAGMA integrity_check=4
297 } 301 }
298 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}} 302 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of e ntries in index i2} {row 1 missing from index i2}}
299 do_test pragma-3.6 { 303 do_test pragma-3.6 {
300 execsql { 304 execsql {
301 PRAGMA integrity_check=xyz 305 PRAGMA integrity_check=xyz
302 } 306 }
303 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from in dex i2} {wrong # of entries in index i2}} 307 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of e ntries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
304 do_test pragma-3.7 { 308 do_test pragma-3.7 {
305 execsql { 309 execsql {
306 PRAGMA integrity_check=0 310 PRAGMA integrity_check=0
307 } 311 }
308 } {{rowid 1 missing from index i2} {rowid 2 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {rowid 2 missing from in dex i2} {wrong # of entries in index i2}} 312 } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of e ntries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
309 313
310 # Add additional corruption by appending unused pages to the end of 314 # Add additional corruption by appending unused pages to the end of
311 # the database file testerr.db 315 # the database file testerr.db
312 # 316 #
313 do_test pragma-3.8 { 317 do_test pragma-3.8 {
314 execsql {DETACH t2} 318 execsql {DETACH t2}
315 file delete -force testerr.db testerr.db-journal 319 forcedelete testerr.db testerr.db-journal
316 set out [open testerr.db w] 320 set out [open testerr.db w]
317 fconfigure $out -translation binary 321 fconfigure $out -translation binary
318 set in [open test.db r] 322 set in [open test.db r]
319 fconfigure $in -translation binary 323 fconfigure $in -translation binary
320 puts -nonewline $out [read $in] 324 puts -nonewline $out [read $in]
321 seek $in 0 325 seek $in 0
322 puts -nonewline $out [read $in] 326 puts -nonewline $out [read $in]
323 close $in 327 close $in
324 close $out 328 close $out
325 hexio_write testerr.db 28 00000000 329 hexio_write testerr.db 28 00000000
326 execsql {REINDEX t2} 330 execsql {REINDEX t2}
327 execsql {PRAGMA integrity_check} 331 execsql {PRAGMA integrity_check}
328 } {ok} 332 } {ok}
329 do_test pragma-3.8.1 { 333 do_test pragma-3.8.1 {
330 execsql {PRAGMA quick_check} 334 execsql {PRAGMA quick_check}
331 } {ok} 335 } {ok}
336 do_test pragma-3.8.2 {
337 execsql {PRAGMA QUICK_CHECK}
338 } {ok}
332 do_test pragma-3.9 { 339 do_test pragma-3.9 {
333 execsql { 340 execsql {
334 ATTACH 'testerr.db' AS t2; 341 ATTACH 'testerr.db' AS t2;
335 PRAGMA integrity_check 342 PRAGMA integrity_check
336 } 343 }
337 } {{*** in database t2 *** 344 } {{*** in database t2 ***
338 Page 4 is never used 345 Page 4 is never used
339 Page 5 is never used 346 Page 5 is never used
340 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from inde x i2} {wrong # of entries in index i2}} 347 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2 } {wrong # of entries in index i2}}
341 do_test pragma-3.10 { 348 do_test pragma-3.10 {
342 execsql { 349 execsql {
343 PRAGMA integrity_check=1 350 PRAGMA integrity_check=1
344 } 351 }
345 } {{*** in database t2 *** 352 } {{*** in database t2 ***
346 Page 4 is never used}} 353 Page 4 is never used}}
347 do_test pragma-3.11 { 354 do_test pragma-3.11 {
348 execsql { 355 execsql {
349 PRAGMA integrity_check=5 356 PRAGMA integrity_check=5
350 } 357 }
351 } {{*** in database t2 *** 358 } {{*** in database t2 ***
352 Page 4 is never used 359 Page 4 is never used
353 Page 5 is never used 360 Page 5 is never used
354 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from inde x i2}} 361 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2 }}
355 do_test pragma-3.12 { 362 do_test pragma-3.12 {
356 execsql { 363 execsql {
357 PRAGMA integrity_check=4 364 PRAGMA integrity_check=4
358 } 365 }
359 } {{*** in database t2 *** 366 } {{*** in database t2 ***
360 Page 4 is never used 367 Page 4 is never used
361 Page 5 is never used 368 Page 5 is never used
362 Page 6 is never used} {rowid 1 missing from index i2}} 369 Page 6 is never used} {row 1 missing from index i2}}
363 do_test pragma-3.13 { 370 do_test pragma-3.13 {
364 execsql { 371 execsql {
365 PRAGMA integrity_check=3 372 PRAGMA integrity_check=3
366 } 373 }
367 } {{*** in database t2 *** 374 } {{*** in database t2 ***
368 Page 4 is never used 375 Page 4 is never used
369 Page 5 is never used 376 Page 5 is never used
370 Page 6 is never used}} 377 Page 6 is never used}}
371 do_test pragma-3.14 { 378 do_test pragma-3.14 {
372 execsql { 379 execsql {
373 PRAGMA integrity_check(2) 380 PRAGMA integrity_check(2)
374 } 381 }
375 } {{*** in database t2 *** 382 } {{*** in database t2 ***
376 Page 4 is never used 383 Page 4 is never used
377 Page 5 is never used}} 384 Page 5 is never used}}
378 do_test pragma-3.15 { 385 do_test pragma-3.15 {
379 execsql { 386 execsql {
380 ATTACH 'testerr.db' AS t3; 387 ATTACH 'testerr.db' AS t3;
381 PRAGMA integrity_check 388 PRAGMA integrity_check
382 } 389 }
383 } {{*** in database t2 *** 390 } {{*** in database t2 ***
384 Page 4 is never used 391 Page 4 is never used
385 Page 5 is never used 392 Page 5 is never used
386 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from inde x i2} {wrong # of entries in index i2} {*** in database t3 *** 393 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2 } {wrong # of entries in index i2} {*** in database t3 ***
387 Page 4 is never used 394 Page 4 is never used
388 Page 5 is never used 395 Page 5 is never used
389 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from inde x i2} {wrong # of entries in index i2}} 396 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2 } {wrong # of entries in index i2}}
390 do_test pragma-3.16 { 397 do_test pragma-3.16 {
391 execsql { 398 execsql {
392 PRAGMA integrity_check(10) 399 PRAGMA integrity_check(10)
393 } 400 }
394 } {{*** in database t2 *** 401 } {{*** in database t2 ***
395 Page 4 is never used 402 Page 4 is never used
396 Page 5 is never used 403 Page 5 is never used
397 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from inde x i2} {wrong # of entries in index i2} {*** in database t3 *** 404 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2 } {wrong # of entries in index i2} {*** in database t3 ***
398 Page 4 is never used 405 Page 4 is never used
399 Page 5 is never used 406 Page 5 is never used
400 Page 6 is never used} {rowid 1 missing from index i2}} 407 Page 6 is never used} {row 1 missing from index i2}}
401 do_test pragma-3.17 { 408 do_test pragma-3.17 {
402 execsql { 409 execsql {
403 PRAGMA integrity_check=8 410 PRAGMA integrity_check=8
404 } 411 }
405 } {{*** in database t2 *** 412 } {{*** in database t2 ***
406 Page 4 is never used 413 Page 4 is never used
407 Page 5 is never used 414 Page 5 is never used
408 Page 6 is never used} {rowid 1 missing from index i2} {rowid 2 missing from inde x i2} {wrong # of entries in index i2} {*** in database t3 *** 415 Page 6 is never used} {row 1 missing from index i2} {row 2 missing from index i2 } {wrong # of entries in index i2} {*** in database t3 ***
409 Page 4 is never used 416 Page 4 is never used
410 Page 5 is never used}} 417 Page 5 is never used}}
411 do_test pragma-3.18 { 418 do_test pragma-3.18 {
412 execsql { 419 execsql {
413 PRAGMA integrity_check=4 420 PRAGMA integrity_check=4
414 } 421 }
415 } {{*** in database t2 *** 422 } {{*** in database t2 ***
416 Page 4 is never used 423 Page 4 is never used
417 Page 5 is never used 424 Page 5 is never used
418 Page 6 is never used} {rowid 1 missing from index i2}} 425 Page 6 is never used} {row 1 missing from index i2}}
419 } 426 }
420 do_test pragma-3.19 { 427 do_test pragma-3.19 {
421 catch {db close} 428 catch {db close}
422 file delete -force test.db test.db-journal 429 forcedelete test.db test.db-journal
423 sqlite3 db test.db 430 sqlite3 db test.db
424 db eval {PRAGMA integrity_check} 431 db eval {PRAGMA integrity_check}
425 } {ok} 432 } {ok}
426 } 433 }
427 #exit 434
435 # Verify that PRAGMA integrity_check catches UNIQUE and NOT NULL
436 # constraint violations.
437 #
438 do_execsql_test pragma-3.20 {
439 CREATE TABLE t1(a,b);
440 CREATE INDEX t1a ON t1(a);
441 INSERT INTO t1 VALUES(1,1),(2,2),(3,3),(2,4),(NULL,5),(NULL,6);
442 PRAGMA writable_schema=ON;
443 UPDATE sqlite_master SET sql='CREATE UNIQUE INDEX t1a ON t1(a)'
444 WHERE name='t1a';
445 UPDATE sqlite_master SET sql='CREATE TABLE t1(a NOT NULL,b)'
446 WHERE name='t1';
447 PRAGMA writable_schema=OFF;
448 ALTER TABLE t1 RENAME TO t1x;
449 PRAGMA integrity_check;
450 } {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in in dex t1a} {NULL value in t1x.a}}
451 do_execsql_test pragma-3.21 {
452 PRAGMA integrity_check(3);
453 } {{non-unique entry in index t1a} {NULL value in t1x.a} {non-unique entry in in dex t1a}}
454 do_execsql_test pragma-3.22 {
455 PRAGMA integrity_check(2);
456 } {{non-unique entry in index t1a} {NULL value in t1x.a}}
457 do_execsql_test pragma-3.21 {
458 PRAGMA integrity_check(1);
459 } {{non-unique entry in index t1a}}
428 460
429 # Test modifying the cache_size of an attached database. 461 # Test modifying the cache_size of an attached database.
430 ifcapable pager_pragmas&&attach { 462 ifcapable pager_pragmas&&attach {
431 do_test pragma-4.1 { 463 do_test pragma-4.1 {
432 execsql { 464 execsql {
433 ATTACH 'test2.db' AS aux; 465 ATTACH 'test2.db' AS aux;
434 pragma aux.cache_size; 466 pragma aux.cache_size;
435 pragma aux.default_cache_size; 467 pragma aux.default_cache_size;
436 } 468 }
437 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ] 469 } [list $DFLT_CACHE_SZ $DFLT_CACHE_SZ]
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 } 552 }
521 } {} 553 } {}
522 db nullvalue <<NULL>> 554 db nullvalue <<NULL>>
523 do_test pragma-6.2.2 { 555 do_test pragma-6.2.2 {
524 execsql { 556 execsql {
525 CREATE TABLE t5( 557 CREATE TABLE t5(
526 a TEXT DEFAULT CURRENT_TIMESTAMP, 558 a TEXT DEFAULT CURRENT_TIMESTAMP,
527 b DEFAULT (5+3), 559 b DEFAULT (5+3),
528 c TEXT, 560 c TEXT,
529 d INTEGER DEFAULT NULL, 561 d INTEGER DEFAULT NULL,
530 e TEXT DEFAULT '' 562 e TEXT DEFAULT '',
563 UNIQUE(b,c,d),
564 PRIMARY KEY(e,b,c)
531 ); 565 );
532 PRAGMA table_info(t5); 566 PRAGMA table_info(t5);
533 } 567 }
534 } {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEG ER 0 NULL 0 4 e TEXT 0 '' 0} 568 } {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 2 2 c TEXT 0 <<NULL>> 3 3 d INTEG ER 0 NULL 0 4 e TEXT 0 '' 1}
535 db nullvalue {} 569 db nullvalue {}
570 do_test pragma-6.2.3 {
571 execsql {
572 CREATE TABLE t2_3(a,b INTEGER PRIMARY KEY,c);
573 pragma table_info(t2_3)
574 }
575 } {0 a {} 0 {} 0 1 b INTEGER 0 {} 1 2 c {} 0 {} 0}
536 ifcapable {foreignkey} { 576 ifcapable {foreignkey} {
537 do_test pragma-6.3.1 { 577 do_test pragma-6.3.1 {
538 execsql { 578 execsql {
539 CREATE TABLE t3(a int references t2(b), b UNIQUE); 579 CREATE TABLE t3(a int references t2(b), b UNIQUE);
540 pragma foreign_key_list(t3); 580 pragma foreign_key_list(t3);
541 } 581 }
542 } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE} 582 } {0 0 t2 a b {NO ACTION} {NO ACTION} NONE}
543 do_test pragma-6.3.2 { 583 do_test pragma-6.3.2 {
544 execsql { 584 execsql {
545 pragma foreign_key_list; 585 pragma foreign_key_list;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 } {} 774 } {}
735 do_test pragma-8.1.9 { 775 do_test pragma-8.1.9 {
736 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY] 776 set ::STMT [sqlite3_prepare $::DB2 "SELECT * FROM t4" -1 DUMMY]
737 sqlite3_step $::STMT 777 sqlite3_step $::STMT
738 } SQLITE_ERROR 778 } SQLITE_ERROR
739 do_test pragma-8.1.10 { 779 do_test pragma-8.1.10 {
740 sqlite3_finalize $::STMT 780 sqlite3_finalize $::STMT
741 } SQLITE_SCHEMA 781 } SQLITE_SCHEMA
742 782
743 # Make sure the schema-version can be manipulated in an attached database. 783 # Make sure the schema-version can be manipulated in an attached database.
744 file delete -force test2.db 784 forcedelete test2.db
745 file delete -force test2.db-journal 785 forcedelete test2.db-journal
746 ifcapable attach { 786 ifcapable attach {
747 do_test pragma-8.1.11 { 787 do_test pragma-8.1.11 {
748 execsql { 788 execsql {
749 ATTACH 'test2.db' AS aux; 789 ATTACH 'test2.db' AS aux;
750 CREATE TABLE aux.t1(a, b, c); 790 CREATE TABLE aux.t1(a, b, c);
751 PRAGMA aux.schema_version = 205; 791 PRAGMA aux.schema_version = 205;
752 } 792 }
753 } {} 793 } {}
754 do_test pragma-8.1.12 { 794 do_test pragma-8.1.12 {
755 execsql { 795 execsql {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 set bt [btree_from_db db 1] 954 set bt [btree_from_db db 1]
915 if {[btree_ismemdb $bt]} { 955 if {[btree_ismemdb $bt]} {
916 return "memory" 956 return "memory"
917 } 957 }
918 return "disk" 958 return "disk"
919 } 959 }
920 } 960 }
921 return "unknown" 961 return "unknown"
922 } 962 }
923 963
964 # Application_ID
965 #
966 do_test pragma-8.3.1 {
967 execsql {
968 PRAGMA application_id;
969 }
970 } {0}
971 do_test pragma-8.3.2 {
972 execsql {PRAGMA Application_ID(12345); PRAGMA application_id;}
973 } {12345}
924 974
925 # Test temp_store and temp_store_directory pragmas 975 # Test temp_store and temp_store_directory pragmas
926 # 976 #
927 ifcapable pager_pragmas { 977 ifcapable pager_pragmas {
928 do_test pragma-9.1 { 978 do_test pragma-9.1 {
929 db close 979 db close
930 sqlite3 db test.db 980 sqlite3 db test.db
931 execsql { 981 execsql {
932 PRAGMA temp_store; 982 PRAGMA temp_store;
933 } 983 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } {memory} 1030 } {memory}
981 } 1031 }
982 1032
983 do_test pragma-9.4 { 1033 do_test pragma-9.4 {
984 execsql { 1034 execsql {
985 PRAGMA temp_store_directory; 1035 PRAGMA temp_store_directory;
986 } 1036 }
987 } {} 1037 } {}
988 ifcapable wsd { 1038 ifcapable wsd {
989 do_test pragma-9.5 { 1039 do_test pragma-9.5 {
990 set pwd [string map {' ''} [file nativename [pwd]]] 1040 set pwd [string map {' ''} [file nativename [get_pwd]]]
991 execsql " 1041 execsql "
992 PRAGMA temp_store_directory='$pwd'; 1042 PRAGMA temp_store_directory='$pwd';
993 " 1043 "
994 } {} 1044 } {}
995 do_test pragma-9.6 { 1045 do_test pragma-9.6 {
996 execsql { 1046 execsql {
997 PRAGMA temp_store_directory; 1047 PRAGMA temp_store_directory;
998 } 1048 }
999 } [list [file nativename [pwd]]] 1049 } [list [file nativename [get_pwd]]]
1000 do_test pragma-9.7 { 1050 do_test pragma-9.7 {
1001 catchsql { 1051 catchsql {
1002 PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR'; 1052 PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
1003 } 1053 }
1004 } {1 {not a writable directory}} 1054 } {1 {not a writable directory}}
1005 do_test pragma-9.8 { 1055 do_test pragma-9.8 {
1006 execsql { 1056 execsql {
1007 PRAGMA temp_store_directory=''; 1057 PRAGMA temp_store_directory='';
1008 } 1058 }
1009 } {} 1059 } {}
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 PRAGMA vdbe_trace=off; 1248 PRAGMA vdbe_trace=off;
1199 PRAGMA vdbe_listing=off; 1249 PRAGMA vdbe_listing=off;
1200 PRAGMA sql_trace=off; 1250 PRAGMA sql_trace=off;
1201 } 1251 }
1202 } {} 1252 } {}
1203 1253
1204 } ;# ifcapable bloblit 1254 } ;# ifcapable bloblit
1205 1255
1206 ifcapable pager_pragmas { 1256 ifcapable pager_pragmas {
1207 db close 1257 db close
1208 file delete -force test.db 1258 forcedelete test.db
1209 sqlite3 db test.db 1259 sqlite3 db test.db
1210 1260
1211 do_test pragma-14.1 { 1261 do_test pragma-14.1 {
1212 execsql { pragma auto_vacuum = 0 } 1262 execsql { pragma auto_vacuum = 0 }
1213 execsql { pragma page_count } 1263 execsql { pragma page_count }
1214 } {0} 1264 } {0}
1215 1265
1216 do_test pragma-14.2 { 1266 do_test pragma-14.2 {
1217 execsql { 1267 execsql {
1218 CREATE TABLE abc(a, b, c); 1268 CREATE TABLE abc(a, b, c);
1219 PRAGMA page_count; 1269 PRAGMA page_count;
1220 } 1270 }
1221 } {2} 1271 } {2}
1272 do_test pragma-14.2uc {
1273 execsql {pragma PAGE_COUNT}
1274 } {2}
1222 1275
1223 do_test pragma-14.3 { 1276 do_test pragma-14.3 {
1224 execsql { 1277 execsql {
1225 BEGIN; 1278 BEGIN;
1226 CREATE TABLE def(a, b, c); 1279 CREATE TABLE def(a, b, c);
1227 PRAGMA page_count; 1280 PRAGMA page_count;
1228 } 1281 }
1229 } {3} 1282 } {3}
1283 do_test pragma-14.3uc {
1284 execsql {pragma PAGE_COUNT}
1285 } {3}
1230 1286
1231 do_test pragma-14.4 { 1287 do_test pragma-14.4 {
1232 set page_size [db one {pragma page_size}] 1288 set page_size [db one {pragma page_size}]
1233 expr [file size test.db] / $page_size 1289 expr [file size test.db] / $page_size
1234 } {2} 1290 } {2}
1235 1291
1236 do_test pragma-14.5 { 1292 do_test pragma-14.5 {
1237 execsql { 1293 execsql {
1238 ROLLBACK; 1294 ROLLBACK;
1239 PRAGMA page_count; 1295 PRAGMA page_count;
1240 } 1296 }
1241 } {2} 1297 } {2}
1242 1298
1243 do_test pragma-14.6 { 1299 do_test pragma-14.6 {
1244 file delete -force test2.db 1300 forcedelete test2.db
1245 sqlite3 db2 test2.db 1301 sqlite3 db2 test2.db
1246 execsql { 1302 execsql {
1247 PRAGMA auto_vacuum = 0; 1303 PRAGMA auto_vacuum = 0;
1248 CREATE TABLE t1(a, b, c); 1304 CREATE TABLE t1(a, b, c);
1249 CREATE TABLE t2(a, b, c); 1305 CREATE TABLE t2(a, b, c);
1250 CREATE TABLE t3(a, b, c); 1306 CREATE TABLE t3(a, b, c);
1251 CREATE TABLE t4(a, b, c); 1307 CREATE TABLE t4(a, b, c);
1252 } db2 1308 } db2
1253 db2 close 1309 db2 close
1254 execsql { 1310 execsql {
1255 ATTACH 'test2.db' AS aux; 1311 ATTACH 'test2.db' AS aux;
1256 PRAGMA aux.page_count; 1312 PRAGMA aux.page_count;
1257 } 1313 }
1258 } {5} 1314 } {5}
1315 do_test pragma-14.6uc {
1316 execsql {pragma AUX.PAGE_COUNT}
1317 } {5}
1259 } 1318 }
1260 1319
1261 # Test that the value set using the cache_size pragma is not reset when the 1320 # Test that the value set using the cache_size pragma is not reset when the
1262 # schema is reloaded. 1321 # schema is reloaded.
1263 # 1322 #
1264 ifcapable pager_pragmas { 1323 ifcapable pager_pragmas {
1265 db close 1324 db close
1266 sqlite3 db test.db 1325 sqlite3 db test.db
1267 do_test pragma-15.1 { 1326 do_test pragma-15.1 {
1268 execsql { 1327 execsql {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 catch {db close} 1529 catch {db close}
1471 sqlite3 db :memory: 1530 sqlite3 db :memory:
1472 execsql " 1531 execsql "
1473 PRAGMA temp_store=$::temp_setting; 1532 PRAGMA temp_store=$::temp_setting;
1474 PRAGMA temp_store=$::temp_setting; 1533 PRAGMA temp_store=$::temp_setting;
1475 PRAGMA temp_store; 1534 PRAGMA temp_store;
1476 " 1535 "
1477 } $val 1536 } $val
1478 } 1537 }
1479 1538
1539 # The SQLITE_FCNTL_PRAGMA logic, with error handling.
1540 #
1541 db close
1542 testvfs tvfs
1543 sqlite3 db test.db -vfs tvfs
1544 do_test pragma-19.1 {
1545 catchsql {PRAGMA error}
1546 } {1 {SQL logic error or missing database}}
1547 do_test pragma-19.2 {
1548 catchsql {PRAGMA error='This is the error message'}
1549 } {1 {This is the error message}}
1550 do_test pragma-19.3 {
1551 catchsql {PRAGMA error='7 This is the error message'}
1552 } {1 {This is the error message}}
1553 do_test pragma-19.4 {
1554 catchsql {PRAGMA error=7}
1555 } {1 {out of memory}}
1556 do_test pragma-19.5 {
1557 file tail [lindex [execsql {PRAGMA filename}] 0]
1558 } {test.db}
1559
1560 if {$tcl_platform(platform)=="windows"} {
1561 # Test data_store_directory pragma
1562 #
1563 db close
1564 sqlite3 db test.db
1565 file mkdir data_dir
1566 do_test pragma-20.1 {
1567 catchsql {PRAGMA data_store_directory}
1568 } {0 {}}
1569 do_test pragma-20.2 {
1570 set pwd [string map {' ''} [file nativename [get_pwd]]]
1571 catchsql "PRAGMA data_store_directory='$pwd';"
1572 } {0 {}}
1573 do_test pragma-20.3 {
1574 catchsql {PRAGMA data_store_directory}
1575 } [list 0 [list [file nativename [get_pwd]]]]
1576 do_test pragma-20.4 {
1577 set pwd [string map {' ''} [file nativename \
1578 [file join [get_pwd] data_dir]]]
1579 catchsql "PRAGMA data_store_directory='$pwd';"
1580 } {0 {}}
1581 do_test pragma-20.5 {
1582 sqlite3 db2 test2.db
1583 catchsql "PRAGMA database_list;" db2
1584 } [list 0 [list 0 main [file nativename \
1585 [file join [get_pwd] data_dir test2.db]]]]
1586 catch {db2 close}
1587 do_test pragma-20.6 {
1588 sqlite3 db2 [file join [get_pwd] test2.db]
1589 catchsql "PRAGMA database_list;" db2
1590 } [list 0 [list 0 main [file nativename \
1591 [file join [get_pwd] test2.db]]]]
1592 catch {db2 close}
1593 do_test pragma-20.7 {
1594 catchsql "PRAGMA data_store_directory='';"
1595 } {0 {}}
1596 do_test pragma-20.8 {
1597 catchsql {PRAGMA data_store_directory}
1598 } {0 {}}
1599
1600 forcedelete data_dir
1601 } ;# endif windows
1602
1603 database_may_be_corrupt
1604
1605 do_test 21.1 {
1606 # Create a corrupt database in testerr.db. And a non-corrupt at test.db.
1607 #
1608 db close
1609 forcedelete test.db
1610 sqlite3 db test.db
1611 execsql {
1612 PRAGMA page_size = 1024;
1613 PRAGMA auto_vacuum = 0;
1614 CREATE TABLE t1(a PRIMARY KEY, b);
1615 INSERT INTO t1 VALUES(1, 1);
1616 }
1617 for {set i 0} {$i < 10} {incr i} {
1618 execsql { INSERT INTO t1 SELECT a + (1 << $i), b + (1 << $i) FROM t1 }
1619 }
1620 db close
1621 forcecopy test.db testerr.db
1622 hexio_write testerr.db 15000 [string repeat 55 100]
1623 } {100}
1624
1625 set mainerr {*** in database main ***
1626 Multiple uses for byte 672 of page 15}
1627 set auxerr {*** in database aux ***
1628 Multiple uses for byte 672 of page 15}
1629
1630 set mainerr {/{\*\*\* in database main \*\*\*
1631 Multiple uses for byte 672 of page 15}.*/}
1632 set auxerr {/{\*\*\* in database aux \*\*\*
1633 Multiple uses for byte 672 of page 15}.*/}
1634
1635 do_test 22.2 {
1636 catch { db close }
1637 sqlite3 db testerr.db
1638 execsql { PRAGMA integrity_check }
1639 } $mainerr
1640
1641 do_test 22.3.1 {
1642 catch { db close }
1643 sqlite3 db test.db
1644 execsql {
1645 ATTACH 'testerr.db' AS 'aux';
1646 PRAGMA integrity_check;
1647 }
1648 } $auxerr
1649 do_test 22.3.2 {
1650 execsql { PRAGMA main.integrity_check; }
1651 } {ok}
1652 do_test 22.3.3 {
1653 execsql { PRAGMA aux.integrity_check; }
1654 } $auxerr
1655
1656 do_test 22.4.1 {
1657 catch { db close }
1658 sqlite3 db testerr.db
1659 execsql {
1660 ATTACH 'test.db' AS 'aux';
1661 PRAGMA integrity_check;
1662 }
1663 } $mainerr
1664 do_test 22.4.2 {
1665 execsql { PRAGMA main.integrity_check; }
1666 } $mainerr
1667 do_test 22.4.3 {
1668 execsql { PRAGMA aux.integrity_check; }
1669 } {ok}
1670
1671 db close
1672 forcedelete test.db test.db-wal test.db-journal
1673 sqlite3 db test.db
1674 sqlite3 db2 test.db
1675 do_test 23.1 {
1676 db eval {
1677 CREATE TABLE t1(a INTEGER PRIMARY KEY,b,c,d);
1678 CREATE INDEX i1 ON t1(b,c);
1679 CREATE INDEX i2 ON t1(c,d);
1680 CREATE TABLE t2(x INTEGER REFERENCES t1);
1681 }
1682 db2 eval {SELECT name FROM sqlite_master}
1683 } {t1 i1 i2 t2}
1684 do_test 23.2 {
1685 db eval {
1686 DROP INDEX i2;
1687 CREATE INDEX i2 ON t1(c,d,b);
1688 }
1689 db2 eval {PRAGMA index_info(i2)}
1690 } {0 2 c 1 3 d 2 1 b}
1691 do_test 23.3 {
1692 db eval {
1693 CREATE INDEX i3 ON t1(d,b,c);
1694 }
1695 db2 eval {PRAGMA index_list(t1)}
1696 } {0 i3 0 1 i2 0 2 i1 0}
1697 do_test 23.4 {
1698 db eval {
1699 ALTER TABLE t1 ADD COLUMN e;
1700 }
1701 db2 eval {
1702 PRAGMA table_info(t1);
1703 }
1704 } {/4 e {} 0 {} 0/}
1705 do_test 23.5 {
1706 db eval {
1707 DROP TABLE t2;
1708 CREATE TABLE t2(x, y INTEGER REFERENCES t1);
1709 }
1710 db2 eval {
1711 PRAGMA foreign_key_list(t2);
1712 }
1713 } {0 0 t1 y {} {NO ACTION} {NO ACTION} NONE}
1714
1715 database_never_corrupt
1480 finish_test 1716 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/permutations.test ('k') | third_party/sqlite/src/test/pragma2.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698