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

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

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 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
OLDNEW
1 # 2006 September 4 1 # 2006 September 4
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 # $Id: misc7.test,v 1.29 2009/07/16 18:21:18 drh Exp $ 13 # $Id: misc7.test,v 1.29 2009/07/16 18:21:18 drh Exp $
14 14
15 set testdir [file dirname $argv0] 15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl 16 source $testdir/tester.tcl
17 17
18 do_test misc7-1-misuse { 18 if {[clang_sanitize_address]==0} {
19 c_misuse_test 19 do_test misc7-1-misuse {
20 } {} 20 c_misuse_test
21 } {}
22 }
21 23
22 do_test misc7-2 { 24 do_test misc7-2 {
23 c_realloc_test 25 c_realloc_test
24 } {} 26 } {}
25 27
26 do_test misc7-3 { 28 do_test misc7-3 {
27 c_collation_test 29 c_collation_test
28 } {} 30 } {}
29 31
30 # Try to open a directory: 32 # Try to open a directory:
31 # 33 #
32 do_test misc7-4 { 34 do_test misc7-4 {
33 file delete mydir 35 delete_file mydir
34 file mkdir mydir 36 file mkdir mydir
35 set rc [catch { 37 set rc [catch {
36 sqlite3 db2 ./mydir 38 sqlite3 db2 ./mydir
37 } msg] 39 } msg]
38 list $rc $msg 40 list $rc $msg
39 } {1 {unable to open database file}} 41 } {1 {unable to open database file}}
40 42
41 # Try to open a file with a directory where its journal file should be. 43 # Try to open a file with a directory where its journal file should be.
42 # 44 #
43 do_test misc7-5 { 45 do_test misc7-5 {
44 file delete mydir 46 delete_file mydir
45 file mkdir mydir-journal 47 file mkdir mydir-journal
46 sqlite3 db2 ./mydir 48 sqlite3 db2 ./mydir
47 catchsql { 49 catchsql {
48 CREATE TABLE abc(a, b, c); 50 CREATE TABLE abc(a, b, c);
49 } db2 51 } db2
50 } {1 {unable to open database file}} 52 } {1 {unable to open database file}}
51 db2 close 53 db2 close
52 54
53 #-------------------------------------------------------------------- 55 #--------------------------------------------------------------------
54 # The following tests, misc7-6.* test the libraries behaviour when 56 # The following tests, misc7-6.* test the libraries behaviour when
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 }] 146 }]
145 set delay [lindex $tm 0] ;# In microseconds 147 set delay [lindex $tm 0] ;# In microseconds
146 lappend result [expr {$delay>1500000 && $delay<4000000}] 148 lappend result [expr {$delay>1500000 && $delay<4000000}]
147 } {1 {database is locked} 1} 149 } {1 {database is locked} 1}
148 db2 close 150 db2 close
149 151
150 #-------------------------------------------------------------------- 152 #--------------------------------------------------------------------
151 # Test that nothing goes horribly wrong when attaching a database 153 # Test that nothing goes horribly wrong when attaching a database
152 # after the omit_readlock pragma has been exercised. 154 # after the omit_readlock pragma has been exercised.
153 # 155 #
156 # Note: The PRAGMA omit_readlock was an early hack to disable the
157 # fcntl() calls for read-only databases so that read-only databases could
158 # be read on broken NFS systems. That pragma has now been removed.
159 # (Use the unix-none VFS as a replacement, if needed.) But these tests
160 # do not really depend on omit_readlock, so we left them in place.
161 #
154 do_test misc7-7.1 { 162 do_test misc7-7.1 {
155 file delete -force test2.db 163 forcedelete test2.db
156 file delete -force test2.db-journal 164 forcedelete test2.db-journal
157 execsql { 165 execsql {
158 PRAGMA omit_readlock = 1; 166 PRAGMA omit_readlock = 1;
159 ATTACH 'test2.db' AS aux; 167 ATTACH 'test2.db' AS aux;
160 CREATE TABLE aux.hello(world); 168 CREATE TABLE aux.hello(world);
161 SELECT name FROM aux.sqlite_master; 169 SELECT name FROM aux.sqlite_master;
162 } 170 }
163 } {hello} 171 } {hello}
164 do_test misc7-7.2 { 172 do_test misc7-7.2 {
165 execsql { 173 execsql {
166 DETACH aux; 174 DETACH aux;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 do_test misc7-13 { 255 do_test misc7-13 {
248 sqlite3 db test.db 256 sqlite3 db test.db
249 register_echo_module [sqlite3_connection_pointer db] 257 register_echo_module [sqlite3_connection_pointer db]
250 set ::echo_module_cost 2.0e+99 258 set ::echo_module_cost 2.0e+99
251 execsql {SELECT * FROM t1 WHERE a = 1;} 259 execsql {SELECT * FROM t1 WHERE a = 1;}
252 } {1 2 3} 260 } {1 2 3}
253 unset ::echo_module_cost 261 unset ::echo_module_cost
254 } 262 }
255 263
256 db close 264 db close
257 file delete -force test.db 265 forcedelete test.db
258 file delete -force test.db-journal 266 forcedelete test.db-journal
259 sqlite3 db test.db 267 sqlite3 db test.db
260 268
261 ifcapable explain { 269 ifcapable explain {
262 do_execsql_test misc7-14.1 { 270 do_execsql_test misc7-14.1 {
263 CREATE TABLE abc(a PRIMARY KEY, b, c); 271 CREATE TABLE abc(a PRIMARY KEY, b, c);
264 EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE rowid = 1; 272 EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE rowid = 1;
265 } { 273 } {
266 0 0 0 {SEARCH TABLE abc AS t2 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)} 274 0 0 0 {SEARCH TABLE abc AS t2 USING INTEGER PRIMARY KEY (rowid=?)}
267 } 275 }
268 do_execsql_test misc7-14.2 { 276 do_execsql_test misc7-14.2 {
269 EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE a = 1; 277 EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE a = 1;
270 } {0 0 0 278 } {0 0 0
271 {SEARCH TABLE abc AS t2 USING INDEX sqlite_autoindex_abc_1 (a=?) (~1 rows)} 279 {SEARCH TABLE abc AS t2 USING INDEX sqlite_autoindex_abc_1 (a=?)}
272 } 280 }
273 do_execsql_test misc7-14.3 { 281 do_execsql_test misc7-14.3 {
274 EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 ORDER BY a; 282 EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 ORDER BY a;
275 } {0 0 0 283 } {0 0 0
276 {SCAN TABLE abc AS t2 USING INDEX sqlite_autoindex_abc_1 (~1000000 rows)} 284 {SCAN TABLE abc AS t2 USING INDEX sqlite_autoindex_abc_1}
277 } 285 }
278 } 286 }
279 287
280 db close 288 db close
281 file delete -force test.db 289 forcedelete test.db
282 file delete -force test.db-journal 290 forcedelete test.db-journal
283 sqlite3 db test.db 291 sqlite3 db test.db
284 292
285 #-------------------------------------------------------------------- 293 #--------------------------------------------------------------------
286 # This is all to force the pager_remove_from_stmt_list() function 294 # This is all to force the pager_remove_from_stmt_list() function
287 # (inside pager.c) to remove a pager from the middle of the 295 # (inside pager.c) to remove a pager from the middle of the
288 # statement-list. 296 # statement-list.
289 # 297 #
290 do_test misc7-15.1 { 298 do_test misc7-15.1 {
291 execsql { 299 execsql {
292 PRAGMA cache_size = 10; 300 PRAGMA cache_size = 10;
(...skipping 23 matching lines...) Expand all
316 } {1} 324 } {1}
317 do_test misc7-15.2 { 325 do_test misc7-15.2 {
318 execsql { 326 execsql {
319 DELETE FROM abc WHERE rowid > 12; 327 DELETE FROM abc WHERE rowid > 12;
320 INSERT INTO abc SELECT 328 INSERT INTO abc SELECT
321 randstr(100,100), randstr(100,100), randstr(100,100) FROM abc; 329 randstr(100,100), randstr(100,100), randstr(100,100) FROM abc;
322 } 330 }
323 } {} 331 } {}
324 332
325 db close 333 db close
326 file delete -force test.db 334 forcedelete test.db
327 file delete -force test.db-journal 335 forcedelete test.db-journal
328 sqlite3 db test.db 336 sqlite3 db test.db
329 337
330 do_ioerr_test misc7-16 -sqlprep { 338 do_ioerr_test misc7-16 -sqlprep {
331 PRAGMA cache_size = 10; 339 PRAGMA cache_size = 10;
332 PRAGMA default_cache_size = 10; 340 PRAGMA default_cache_size = 10;
333 CREATE TABLE t3(a, b, UNIQUE(a, b)); 341 CREATE TABLE t3(a, b, UNIQUE(a, b));
334 INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) ); 342 INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
335 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; 343 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
336 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; 344 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
337 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; 345 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
338 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; 346 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
339 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; 347 INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
340 UPDATE t3 348 UPDATE t3
341 SET b = 'hello world' 349 SET b = 'hello world'
342 WHERE rowid >= (SELECT max(rowid)-1 FROM t3); 350 WHERE rowid >= (SELECT max(rowid)-1 FROM t3);
343 } -tclbody { 351 } -tclbody {
344 set rc [catch {db eval { 352 set rc [catch {db eval {
345 BEGIN; 353 BEGIN;
346 PRAGMA cache_size = 10; 354 PRAGMA cache_size = 10;
347 INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) ); 355 INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
348 UPDATE t3 SET a = b; 356 UPDATE t3 SET a = b;
349 COMMIT; 357 COMMIT;
350 }} msg] 358 }} msg]
351 359
352 if {!$rc || ($rc && [string first "columns" $msg]==0)} { 360 if {!$rc || ($rc && [string first "UNIQUE" $msg]==0)} {
353 set msg 361 set msg
354 } else { 362 } else {
355 error $msg 363 error $msg
356 } 364 }
357 } 365 }
358 366
359 sqlite3 db test.db 367 sqlite3 db test.db
360 368
361 do_test misc7-16.X { 369 do_test misc7-16.X {
362 execsql { 370 execsql {
363 SELECT count(*) FROM t3; 371 SELECT count(*) FROM t3;
364 } 372 }
365 } {32} 373 } {32}
366 374
367 #---------------------------------------------------------------------- 375 #----------------------------------------------------------------------
368 # Test the situation where a hot-journal is discovered but write-access 376 # Test the situation where a hot-journal is discovered but write-access
369 # to it is denied. This should return SQLITE_BUSY. 377 # to it is denied. This should return SQLITE_BUSY.
370 # 378 #
371 # These tests do not work on windows due to restrictions in the 379 # These tests do not work on windows due to restrictions in the
372 # windows file system. 380 # windows file system.
373 # 381 #
374 if {$tcl_platform(platform)!="windows" && $tcl_platform(platform)!="os2"} { 382 if {$tcl_platform(platform)!="windows"} {
375 383
376 # Some network filesystems (ex: AFP) do not support setting read-only 384 # Some network filesystems (ex: AFP) do not support setting read-only
377 # permissions. Only run these tests if full unix permission setting 385 # permissions. Only run these tests if full unix permission setting
378 # capabilities are supported. 386 # capabilities are supported.
379 # 387 #
380 file attributes test.db -permissions rw-r--r-- 388 file attributes test.db -permissions rw-r--r--
381 if {[file attributes test.db -permissions]==0644} { 389 if {[file attributes test.db -permissions]==0644} {
382 390
383 do_test misc7-17.1 { 391 do_test misc7-17.1 {
384 execsql { 392 execsql {
385 BEGIN; 393 BEGIN;
386 DELETE FROM t3 WHERE (oid%3)==0; 394 DELETE FROM t3 WHERE (oid%3)==0;
387 } 395 }
388 copy_file test.db bak.db 396 forcecopy test.db bak.db
389 copy_file test.db-journal bak.db-journal 397 forcecopy test.db-journal bak.db-journal
390 execsql { 398 execsql {
391 COMMIT; 399 COMMIT;
392 } 400 }
393 401
394 db close 402 db close
395 copy_file bak.db test.db 403 forcecopy bak.db test.db
396 copy_file bak.db-journal test.db-journal 404 forcecopy bak.db-journal test.db-journal
397 sqlite3 db test.db 405 sqlite3 db test.db
398 406
399 catch {file attributes test.db-journal -permissions r--------} 407 catch {file attributes test.db-journal -permissions r--------}
400 catch {file attributes test.db-journal -readonly 1} 408 catch {file attributes test.db-journal -readonly 1}
401 catchsql { 409 catchsql {
402 SELECT count(*) FROM t3; 410 SELECT count(*) FROM t3;
403 } 411 }
404 } {1 {unable to open database file}} 412 } {1 {unable to open database file}}
405 do_test misc7-17.2 { 413 do_test misc7-17.2 {
406 # Note that the -readonly flag must be cleared before the -permissions 414 # Note that the -readonly flag must be cleared before the -permissions
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 # sqlite3_global_recover() is a no-op. But we might as well test it 478 # sqlite3_global_recover() is a no-op. But we might as well test it
471 # if only to get the test coverage. 479 # if only to get the test coverage.
472 # 480 #
473 do_test misc7-20.1 { 481 do_test misc7-20.1 {
474 sqlite3_global_recover 482 sqlite3_global_recover
475 } {SQLITE_OK} 483 } {SQLITE_OK}
476 484
477 # Try to open a really long file name. 485 # Try to open a really long file name.
478 # 486 #
479 do_test misc7-21.1 { 487 do_test misc7-21.1 {
480 set zFile [file join [pwd] "[string repeat abcde 104].db"] 488 set zFile [file join [get_pwd] "[string repeat abcde 104].db"]
481 set rc [catch {sqlite3 db2 $zFile} msg] 489 set rc [catch {sqlite3 db2 $zFile} msg]
482 list $rc $msg 490 list $rc $msg
483 } {1 {unable to open database file}} 491 } {1 {unable to open database file}}
484 492
493 # Try to do hot-journal rollback with a read-only connection. The
494 # error code should be SQLITE_READONLY_ROLLBACK.
495 #
496 do_test misc7-22.1 {
497 db close
498 forcedelete test.db copy.db-journal
499 sqlite3 db test.db
500 execsql {
501 CREATE TABLE t1(a, b);
502 INSERT INTO t1 VALUES(1, 2);
503 INSERT INTO t1 VALUES(3, 4);
504 }
505 db close
506 sqlite3 db test.db -readonly 1
507 catchsql {
508 INSERT INTO t1 VALUES(5, 6);
509 }
510 } {1 {attempt to write a readonly database}}
511 do_test misc7-22.2 { execsql { SELECT * FROM t1 } } {1 2 3 4}
512 do_test misc7-22.3 {
513 set fd [open test.db-journal w]
514 puts $fd [string repeat abc 1000]
515 close $fd
516 catchsql { SELECT * FROM t1 }
517 } {1 {attempt to write a readonly database}}
518 do_test misc7-22.4 {
519 sqlite3_extended_errcode db
520 } SQLITE_READONLY_ROLLBACK
485 521
486 db close 522 db close
487 file delete -force test.db 523 forcedelete test.db
488 524
489 finish_test 525 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698