From: dan Date: Tue, 11 Feb 2014 19:35:42 +0000 (+0000) Subject: Test case updates to account for the fact that database files are not created until... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e5c544e0ab7bdc85f9971ce7e51786f2f1169ca4;p=thirdparty%2Fsqlite.git Test case updates to account for the fact that database files are not created until they are first written. FossilOrigin-Name: 8ef97420b2614f50de6e6d7c758483b8b888f325 --- diff --git a/manifest b/manifest index 0c51f8c0d0..d7bc58d067 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\slatest\strunk\schanges. -D 2014-02-11T05:26:22.664 +C Test\scase\supdates\sto\saccount\sfor\sthe\sfact\sthat\sdatabase\sfiles\sare\snot\screated\suntil\sthey\sare\sfirst\swritten. +D 2014-02-11T19:35:42.768 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -205,7 +205,7 @@ F src/notify.c 976dd0f6171d4588e89e874fcc765e92914b6d30 F src/os.c 1b147e4cf7cc39e618115c14a086aed44bc91ace F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 -F src/os_unix.c a45a0d2fc8e0e78d018c4b25a705217212e990fa +F src/os_unix.c d75a3d63df53542d74fd8af2f76ef7ea639cfc71 F src/os_win.c d4284f003445054a26689f1264b1b9bf7261bd1b F src/pager.c 0ffa313a30ed6d061d9c6601b7b175cc50a1cab7 F src/pager.h ffd5607f7b3e4590b415b007a4382f693334d428 @@ -336,9 +336,9 @@ F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 F test/backcompat.test 5f8ad58b3eaebc78cd2c66c65476a42e6f32b2ad -F test/backup.test c9cdd23a495864b9edf75a9fa66f5cb7e10fcf62 +F test/backup.test cfac575288523288f0acfb6470b7e9cba6c16a52 F test/backup2.test 34986ef926ea522911a51dfdb2f8e99b7b75ebcf -F test/backup4.test 2a2e4a64388090b152de753fd9e123f28f6a3bd4 +F test/backup4.test 4e3a2f9d83cdfeb4efd5dddb0dfbd06116d50957 F test/backup_ioerr.test 4c3c7147cee85b024ecf6e150e090c32fdbb5135 F test/backup_malloc.test 7162d604ec2b4683c4b3799a48657fb8b5e2d450 F test/badutf.test d5360fc31f643d37a973ab0d8b4fb85799c3169f @@ -368,7 +368,7 @@ F test/capi3.test 6cdd49656bd62a296924f4d2fcfd05cd2a298369 F test/capi3b.test efb2b9cfd127efa84433cd7a2d72ce0454ae0dc4 F test/capi3c.test a21869e4d50d5dbb7e566e328fc0bc7c2efa6a32 F test/capi3d.test 6d0fc0a86d73f42dd19a7d8b7761ab9bc02277d0 -F test/capi3e.test ad90088b18b0367125ff2d4b5400153fd2f99aab +F test/capi3e.test 1ecb23b79a6f2a50ba336142e795d6e677d1d2d4 F test/cast.test 4c275cbdc8202d6f9c54a3596701719868ac7dc3 F test/check.test 5831ddb6f2c687782eaf2e1a07b6e17f24c4f763 F test/close.test 340bd24cc58b16c6bc01967402755027c37eb815 @@ -447,7 +447,7 @@ F test/e_resolve.test dcce9308fb13b934ce29591105d031d3e14fbba6 F test/e_select.test 52692ff3849541e828ad4661fe3773a9b8711763 F test/e_select2.test aceb80ab927d46fba5ce7586ebabf23e2bb0604f F test/e_update.test 312cb8f5ccfe41515a6bb092f8ea562a9bd54d52 -F test/e_uri.test a2c92d80093a7efdcfbb11093651cbea87097b6b +F test/e_uri.test bfa56d624d693a81bb29ac2a9a999e35c2c8d9bf F test/e_vacuum.test 5bfbdc21b65c0abf24398d0ba31dc88d93ca77a9 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea F test/enc2.test 83437a79ba1545a55fb549309175c683fb334473 @@ -457,7 +457,7 @@ F test/eqp.test 57c6c604c2807fb5531731c5323133453c24afac F test/errmsg.test f31592a594b44ee121371d25ddd5d63497bb3401 F test/eval.test bc269c365ba877554948441e91ad5373f9f91be3 F test/exclusive.test c7ebbc756eacf544c108b15eed64d7d4e5f86b75 -F test/exclusive2.test 32798111aae78a5deec980eee383213f189df308 +F test/exclusive2.test a3bfa5d21268d2d1f4dd1c094ad9cd583914ca73 F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7 F test/exists.test 8f7b27b61c2fbe5822f0a1f899c715d14e416e30 F test/expr.test 67c9fd6f8f829e239dc8b0f4a08a73c08b09196d @@ -987,7 +987,7 @@ F test/tkt3929.test cdf67acf5aa936ec4ffead81db87f8a71fe40e59 F test/tkt3935.test e15261fedb9e30a4305a311da614a5d8e693c767 F test/tkt3992.test f3e7d548ac26f763b47bc0f750da3d03c81071da F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd -F test/tkt4018.test 7c2c9ba4df489c676a0a7a0e809a1fb9b2185bd1 +F test/tkt4018.test 04115ae33ee39988a076bd78decef7cec820ebe0 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7 F test/tpch01.test 8f4ac52f62f3e9f6bce0889105aecdf0275e331b F test/trace.test 4b36a41a3e9c7842151af6da5998f5080cdad9e5 @@ -1152,7 +1152,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 95d0c58d2791d81b432e7d263f3fc2f26858d395 9367632dd7e4fec9197227e35b0627c2e81ebffc -R 0c738095590e8f126bb6f4bdc18129b2 +P 1f2e1b0c64934ec80f09d596d512f7c320e36f81 +R 49abc8d6d7ef4006e5cb557bcc20c7b2 U dan -Z ac41b2fb5d4eee0ab8c3239008c3f099 +Z 6ee8c9c2c8d267732a52bf0bb533fbfa diff --git a/manifest.uuid b/manifest.uuid index ab7a3b2749..a2b1e528e9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1f2e1b0c64934ec80f09d596d512f7c320e36f81 \ No newline at end of file +8ef97420b2614f50de6e6d7c758483b8b888f325 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index f043421458..75a567ac0b 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -1530,19 +1530,22 @@ static int unixLock(sqlite3_file *id, int eFileLock){ } if( pFile->ctrlFlags & UNIXFILE_DEFERRED ){ - int eOrigLock = pFile->eFileLock; - if( eFileLock==SHARED_LOCK ){ - int statrc; - struct stat sBuf; - memset(&sBuf, 0, sizeof(sBuf)); - statrc = osStat(pFile->zPath, &sBuf); - if( statrc && errno==ENOENT ){ - pFile->eFileLock = SHARED_LOCK; - return SQLITE_OK; - } + const char *zPath = pFile->zPath; /* Full-path to database file */ + int eOrigLock; /* Current lock held on pFile */ + + assert( pFile->eFileLock==SHARED_LOCK || pFile->eFileLock==NO_LOCK ); + + /* If SQLite is requesting a SHARED lock and the database file does + ** not exist, return early without opening the file. */ + if( eFileLock==SHARED_LOCK && osAccess(zPath, F_OK) && errno==ENOENT ){ + pFile->eFileLock = SHARED_LOCK; + return SQLITE_OK; } - rc = unixOpen(pFile->pVfs, pFile->zPath, id, pFile->openFlags, 0); + /* Or, if the database file has been created or a write lock is + ** requested, open the database file now. */ + eOrigLock = pFile->eFileLock; + rc = unixOpen(pFile->pVfs, zPath, id, pFile->openFlags, 0); if( rc==SQLITE_OK && eOrigLock ){ rc = unixLock(id, eOrigLock); } @@ -1552,7 +1555,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){ /* Make sure the locking sequence is correct. ** (1) We never move from unlocked to anything higher than shared lock. - ** (2) SQLite never explicitly requests a pendig lock. + ** (2) SQLite never explicitly requests a pending lock. ** (3) A shared lock is always held when a reserve lock is requested. */ assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); @@ -1960,8 +1963,8 @@ static int unixClose(sqlite3_file *id){ unixUnlock(id, NO_LOCK); unixEnterMutex(); - /* unixFile.pInode is always valid here. Otherwise, a different close - ** routine (e.g. nolockClose()) would be called instead. */ + /* unixFile.pInode may be NULL here if the file was never opened. + */ assert( pFile->pInode==0 || pFile->pInode->nLock>0 || pFile->pInode->bProcessLock==0 @@ -3207,12 +3210,9 @@ static int unixRead( if( pFile->ctrlFlags & UNIXFILE_DEFERRED ){ int rc; - struct stat sBuf; - memset(&sBuf, 0, sizeof(sBuf)); - rc = osStat(pFile->zPath, &sBuf); - if( rc!=0 ){ + if( osAccess(pFile->zPath, F_OK) && errno==ENOENT ){ memset(pBuf, 0, amt); - rc = (errno==ENOENT ? SQLITE_IOERR_SHORT_READ : SQLITE_IOERR_FSTAT); + rc = SQLITE_IOERR_SHORT_READ; }else{ rc = unixOpen(pFile->pVfs, pFile->zPath, id, pFile->openFlags, 0); } @@ -5237,10 +5237,6 @@ static int fillInUnixFile( #if SQLITE_MAX_MMAP_SIZE>0 pNew->mmapSizeMax = sqlite3GlobalConfig.szMmap; #endif - if( sqlite3_uri_boolean(((ctrlFlags & UNIXFILE_URI) ? zFilename : 0), - "psow", SQLITE_POWERSAFE_OVERWRITE) ){ - pNew->ctrlFlags |= UNIXFILE_PSOW; - } if( strcmp(pVfs->zName,"unix-excl")==0 ){ pNew->ctrlFlags |= UNIXFILE_EXCL; } @@ -5379,7 +5375,6 @@ static int fillInUnixFile( if( h>=0 ) robust_close(pNew, h, __LINE__); }else{ pNew->pMethod = pLockingStyle; - OpenCounter(+1); verifyDbFile(pNew); } return rc; @@ -5636,7 +5631,7 @@ static int unixOpen( int eType = flags&0xFFFFFF00; /* Type of file to open */ int noLock; /* True to omit locking primitives */ int rc = SQLITE_OK; /* Function Return Code */ - int ctrlFlags = 0; /* UNIXFILE_* flags */ + int ctrlFlags; /* UNIXFILE_* flags */ int isExclusive = (flags & SQLITE_OPEN_EXCLUSIVE); int isDelete = (flags & SQLITE_OPEN_DELETEONCLOSE); @@ -5666,6 +5661,11 @@ static int unixOpen( char zTmpname[MAX_PATHNAME+2]; const char *zName = zPath; + assert( p->pInode==0 && (p->h==-1 || p->h==0) ); + p->ctrlFlags &= ~UNIXFILE_DEFERRED; + p->eFileLock = NO_LOCK; + ctrlFlags = p->ctrlFlags; + /* Check the following statements are true: ** ** (a) Exactly one of the READWRITE and READONLY flags must be set, and @@ -5702,7 +5702,6 @@ static int unixOpen( sqlite3_randomness(0,0); } - memset(p, 0, sizeof(unixFile)); if( eType==SQLITE_OPEN_MAIN_DB ){ UnixUnusedFd *pUnused; @@ -5873,9 +5872,6 @@ static int unixOpen( rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); open_finished: - if( rc!=SQLITE_OK ){ - sqlite3_free(p->pUnused); - } return rc; } @@ -5891,10 +5887,21 @@ static int unixOpenDeferred( const int mask2 = SQLITE_OPEN_READONLY | SQLITE_OPEN_DELETEONCLOSE | SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_AUTOPROXY; + int rc; /* Return code */ + unixFile *p = (unixFile*)pFile; /* File object to populate */ + + /* Zero the file object */ + memset(p, 0, sizeof(unixFile)); + if( (flags & UNIXFILE_URI) + && sqlite3_uri_boolean(zPath, "psow", SQLITE_POWERSAFE_OVERWRITE) + ){ + p->ctrlFlags |= UNIXFILE_PSOW; + } + /* If all the flags in mask1 are set, and all the flags in mask2 are ** clear, the file does not exist but the directory does and is ** writable, then this is a deferred open. */ - if( 0 && zPath && (flags & (mask1 | mask2))==mask1 ){ + if( zPath && (flags & (mask1 | mask2))==mask1 ){ int posixrc; posixrc = osAccess(zPath, F_OK); if( posixrc && errno==ENOENT ){ @@ -5905,24 +5912,22 @@ static int unixOpenDeferred( zDirname[i] = '\0'; posixrc = osAccess(zDirname, W_OK); if( posixrc==0 ){ - unixFile *p = (unixFile*)pFile; - memset(p, 0, sizeof(unixFile)); p->pMethod = (**(finder_type*)pVfs->pAppData)(0, 0); p->pVfs = pVfs; p->h = -1; - p->ctrlFlags = UNIXFILE_DEFERRED; - if( sqlite3_uri_boolean(((flags & UNIXFILE_URI) ? zPath : 0), - "psow", SQLITE_POWERSAFE_OVERWRITE) ){ - p->ctrlFlags |= UNIXFILE_PSOW; - } + p->ctrlFlags |= UNIXFILE_DEFERRED; p->openFlags = flags; p->zPath = zPath; if( pOutFlags ) *pOutFlags = flags; + OpenCounter(+1); return SQLITE_OK; } } } - return unixOpen(pVfs, zPath, pFile, flags, pOutFlags); + + rc = unixOpen(pVfs, zPath, pFile, flags, pOutFlags); + OpenCounter( rc==SQLITE_OK ); + return rc; } /* diff --git a/test/backup.test b/test/backup.test index 444619c68c..42d2571563 100644 --- a/test/backup.test +++ b/test/backup.test @@ -325,6 +325,13 @@ foreach nDestPgsz {512 1024 2048 4096} { } } +proc file_size {zFile} { + if {[file exists $zFile]} { + return [file size $zFile] + } + return 0 +} + #-------------------------------------------------------------------- do_test backup-3.$iTest.1 { catch { forcedelete test.db } @@ -333,14 +340,14 @@ do_test backup-3.$iTest.1 { set iTab 1 db eval { PRAGMA page_size = 512 } - while {[file size test.db] <= $::sqlite_pending_byte} { + while {[file_size test.db] <= $::sqlite_pending_byte} { db eval "CREATE TABLE t${iTab}(a, b, c)" incr iTab } sqlite3 db2 test2.db db2 eval { PRAGMA page_size = 4096 } - while {[file size test2.db] < $::sqlite_pending_byte} { + while {[file_size test2.db] < $::sqlite_pending_byte} { db2 eval "CREATE TABLE t${iTab}(a, b, c)" incr iTab } diff --git a/test/backup4.test b/test/backup4.test index 417df80e55..bdfb21344e 100644 --- a/test/backup4.test +++ b/test/backup4.test @@ -23,6 +23,13 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl set testprefix backup4 +proc file_size {zFile} { + if {[file exists $zFile]} { + return [file size $zFile] + } + return 0 +} + #------------------------------------------------------------------------- # At one point this test was failing because [db] was using an out of # date schema in test case 1.2. @@ -72,7 +79,7 @@ do_test 2.3 { file size test.db } {1024} -do_test 2.4 { file size test.db2 } 0 +do_test 2.4 { file_size test.db2 } 0 db close forcedelete test.db @@ -98,6 +105,6 @@ do_test 3.3 { file size test.db } {1024} -do_test 3.4 { file size test.db2 } 0 +do_test 3.4 { file_size test.db2 } 0 finish_test diff --git a/test/capi3e.test b/test/capi3e.test index d7ab8d0bd4..04a9ba61dc 100644 --- a/test/capi3e.test +++ b/test/capi3e.test @@ -70,9 +70,12 @@ foreach name $names { sqlite3_errcode $db2 } {SQLITE_OK} do_test capi3e-1.2.$i { + sqlite3_exec $db2 { CREATE TABLE t1(x) } + } {0 {}} + do_test capi3e-1.3.$i { sqlite3_close $db2 } {SQLITE_OK} - do_test capi3e-1.3.$i { + do_test capi3e-1.4.$i { file isfile $name } {1} } diff --git a/test/e_uri.test b/test/e_uri.test index a8865cad28..cff7f4541c 100644 --- a/test/e_uri.test +++ b/test/e_uri.test @@ -64,6 +64,7 @@ if {$tcl_platform(platform) == "unix"} { do_test 1.1 { forcedelete file:test.db test.db set DB [sqlite3_open_v2 file:test.db [concat $flags SQLITE_OPEN_URI] ""] + sqlite3_exec $DB {CREATE TABLE t1(x)} list [file exists file:test.db] [file exists test.db] } {0 1} do_test 1.2 { @@ -71,12 +72,14 @@ if {$tcl_platform(platform) == "unix"} { set STMT [sqlite3_prepare $DB "ATTACH 'file:test.db2' AS aux" -1 dummy] sqlite3_step $STMT sqlite3_finalize $STMT + sqlite3_exec $DB {CREATE TABLE aux.t1(x)} list [file exists file:test.db2] [file exists test.db2] } {0 1} sqlite3_close $DB do_test 1.3 { forcedelete file:test.db test.db set DB [sqlite3_open_v2 file:test.db [concat $flags] ""] + sqlite3_exec $DB {CREATE TABLE t1(x)} list [file exists file:test.db] [file exists test.db] } {1 0} do_test 1.4 { @@ -84,6 +87,7 @@ if {$tcl_platform(platform) == "unix"} { set STMT [sqlite3_prepare $DB "ATTACH 'file:test.db2' AS aux" -1 dummy] sqlite3_step $STMT sqlite3_finalize $STMT + sqlite3_exec $DB {CREATE TABLE aux.t1(x)} list [file exists file:test.db2] [file exists test.db2] } {1 0} sqlite3_close $DB @@ -96,6 +100,7 @@ if {$tcl_platform(platform) == "unix"} { do_test 1.5 { forcedelete file:test.db test.db set DB [sqlite3_open_v2 file:test.db [concat $flags SQLITE_OPEN_URI] ""] + sqlite3_exec $DB {CREATE TABLE t1(x)} list [file exists file:test.db] [file exists test.db] } {0 1} do_test 1.6 { @@ -103,12 +108,14 @@ if {$tcl_platform(platform) == "unix"} { set STMT [sqlite3_prepare $DB "ATTACH 'file:test.db2' AS aux" -1 dummy] sqlite3_step $STMT sqlite3_finalize $STMT + sqlite3_exec $DB {CREATE TABLE aux.t1(x)} list [file exists file:test.db2] [file exists test.db2] } {0 1} sqlite3_close $DB do_test 1.7 { forcedelete file:test.db test.db set DB [sqlite3_open_v2 file:test.db [concat $flags] ""] + sqlite3_exec $DB {CREATE TABLE t1(x)} list [file exists file:test.db] [file exists test.db] } {0 1} do_test 1.8 { @@ -116,6 +123,7 @@ if {$tcl_platform(platform) == "unix"} { set STMT [sqlite3_prepare $DB "ATTACH 'file:test.db2' AS aux" -1 dummy] sqlite3_step $STMT sqlite3_finalize $STMT + sqlite3_exec $DB {CREATE TABLE aux.t1(x)} list [file exists file:test.db2] [file exists test.db2] } {0 1} sqlite3_close $DB @@ -314,6 +322,7 @@ foreach {tn uri read write create} { # forcedelete test.db sqlite3 db test.db +db eval {CREATE TABLE t1(x)} db close foreach {tn uri flags error} { 1 {file:test.db?mode=ro} ro {not an error} @@ -331,7 +340,7 @@ foreach {tn uri flags error} { set f(ro) [list SQLITE_OPEN_READONLY SQLITE_OPEN_URI] set f(rw) [list SQLITE_OPEN_READWRITE SQLITE_OPEN_URI] set f(rwc) [list SQLITE_OPEN_READWRITE SQLITE_OPEN_CREATE SQLITE_OPEN_URI] - +breakpoint set DB [sqlite3_open_v2 $uri $f($flags) ""] set e [sqlite3_errmsg $DB] sqlite3_close $DB diff --git a/test/exclusive2.test b/test/exclusive2.test index 712363e762..1644983d99 100644 --- a/test/exclusive2.test +++ b/test/exclusive2.test @@ -69,18 +69,20 @@ proc pagerChangeCounter {filename new {fd ""}} { } proc readPagerChangeCounter {filename} { - set fd [open $filename RDONLY] - fconfigure $fd -translation binary -encoding binary - - seek $fd 24 - foreach {a b c d} [list 0 0 0 0] {} - binary scan [read $fd 4] cccc a b c d - set ret [expr ($a&0x000000FF)<<24] - incr ret [expr ($b&0x000000FF)<<16] - incr ret [expr ($c&0x000000FF)<<8] - incr ret [expr ($d&0x000000FF)<<0] - - close $fd + if {[file exists $filename]} { + set fd [open $filename RDONLY] + fconfigure $fd -translation binary -encoding binary + seek $fd 24 + foreach {a b c d} [list 0 0 0 0] {} + binary scan [read $fd 4] cccc a b c d + set ret [expr ($a&0x000000FF)<<24] + incr ret [expr ($b&0x000000FF)<<16] + incr ret [expr ($c&0x000000FF)<<8] + incr ret [expr ($d&0x000000FF)<<0] + close $fd + } else { + set ret 0 + } return $ret } diff --git a/test/tkt4018.test b/test/tkt4018.test index 2bc41d47aa..b091937be4 100644 --- a/test/tkt4018.test +++ b/test/tkt4018.test @@ -46,6 +46,7 @@ do_test tkt4018-1.1 { # connection to test.db 10000 times. If file-descriptors are not being # reused, then the process will quickly exceed its maximum number of # file descriptors (1024 by default on linux). +breakpoint do_test tkt4018-1.2 { for {set i 0} {$i < 10000} {incr i} { sqlite3 db2 test.db