Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -16,11 +16,11 @@ ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.375 2007/08/24 16:08:29 drh Exp $ +** @(#) $Id: pager.c,v 1.376 2007/08/24 16:29:24 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" #include #include @@ -1806,48 +1806,50 @@ ** ** Write the file descriptor into *fd. Return SQLITE_OK on success or some ** other error code if we fail. The OS will automatically delete the temporary ** file when it is closed. ** -** If zNameOut is 0, then SQLITE_OPEN_SUBJOURNAL is passed to the OS layer. -** If zNameOut is not 0, SQLITE_OPEN_TEMP_DB is passed. +** If zFilename is 0, then an appropriate temporary filename is +** generated automatically and SQLITE_OPEN_SUBJOURNAL is passed to +** the OS layer as the file type. +** +** If zFilename is not 0, SQLITE_OPEN_TEMP_DB is passed as the file type. */ static int sqlite3PagerOpentemp( sqlite3_vfs *pVfs, sqlite3_file *pFile, - char *zNameOut + char *zFilename ){ - int cnt = 8; int rc; int flags = ( SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_DELETEONCLOSE ); char *zFree = 0; - if( zNameOut==0 ){ + if( zFilename==0 ){ zFree = (char *)sqlite3_malloc(pVfs->mxPathname); if( !zFree ){ return SQLITE_NOMEM; } - zNameOut = zFree; + zFilename = zFree; flags |= SQLITE_OPEN_SUBJOURNAL; + rc = sqlite3OsGetTempName(pVfs, zFilename); + if( rc!=SQLITE_OK ){ + sqlite3_free(zFree); + return rc; + } }else{ flags |= SQLITE_OPEN_TEMP_DB; } #ifdef SQLITE_TEST sqlite3_opentemp_count++; /* Used for testing and analysis only */ #endif - do{ - cnt--; - sqlite3OsGetTempName(pVfs, zNameOut); - rc = sqlite3OsOpen(pVfs, zNameOut, pFile, flags, 0); - assert( rc!=SQLITE_OK || pFile->pMethods ); - }while( cnt>0 && rc!=SQLITE_OK && rc!=SQLITE_NOMEM ); - + rc = sqlite3OsOpen(pVfs, zFilename, pFile, flags, 0); + assert( rc!=SQLITE_OK || pFile->pMethods ); sqlite3_free(zFree); return rc; } /* @@ -1900,17 +1902,17 @@ zPathname[0] = 0; }else #endif { rc = sqlite3OsFullPathname(pVfs, zFilename, zPathname); - if( rc!=SQLITE_OK ){ - sqlite3_free(zPathname); - return rc; - } } }else{ - zPathname[0] = 0; + rc = sqlite3OsGetTempName(pVfs, zPathname); + } + if( rc!=SQLITE_OK ){ + sqlite3_free(zPathname); + return rc; } nPathname = strlen(zPathname); /* Allocate memory for the pager structure */ pPager = sqlite3MallocZero( @@ -1934,11 +1936,11 @@ memcpy(pPager->zFilename, zPathname, nPathname+1); sqlite3_free(zPathname); /* Open the pager file. */ - if( pPager->zFilename[0] ){ + if( zFilename && zFilename[0] && !memDb ){ if( nPathname>(pVfs->mxPathname - sizeof("-journal")) ){ rc = SQLITE_CANTOPEN; }else{ /*** FIXME: Might need to be SQLITE_OPEN_TEMP_DB. Need to pass in **** a flag from higher up. Index: test/pager.test ================================================================== --- test/pager.test +++ test/pager.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is page cache subsystem. # -# $Id: pager.test,v 1.29 2007/08/24 16:08:29 drh Exp $ +# $Id: pager.test,v 1.30 2007/08/24 16:29:24 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -407,11 +407,10 @@ } {} # Test truncate on an in-memory database is Ok. ifcapable memorydb { do_test pager-4.6.2 { -btree_breakpoint set ::p2 [pager_open :memory: 10] pager_truncate $::p2 5 } {} do_test pager-4.6.3 { for {set i 1} {$i<5} {incr i} {