aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanielk1977 <danielk1977@noemail.net>2008-06-06 11:11:25 +0000
committerdanielk1977 <danielk1977@noemail.net>2008-06-06 11:11:25 +0000
commit17b90b5316d385494415d2f4826fafda772e82b5 (patch)
tree50b7f9967da6bf20afa154f76cccc97e7e3c9468 /src
parent4b5255ac3140226c4bf9dfdf8eb3c7515a40cb32 (diff)
downloadsqlite-17b90b5316d385494415d2f4826fafda772e82b5.tar.gz
sqlite-17b90b5316d385494415d2f4826fafda772e82b5.zip
Remove the xGetTempname() method from the vfs structure. Temp files are now opened by passing a NULL pointer as the filename to xOpen(). (CVS 5190)
FossilOrigin-Name: 5173b3e816c7eb711cd21a9068bbafb9ebb7cff1
Diffstat (limited to 'src')
-rw-r--r--src/os.c5
-rw-r--r--src/os_unix.c171
-rw-r--r--src/os_win.c122
-rw-r--r--src/pager.c83
-rw-r--r--src/pager.h3
-rw-r--r--src/sqlite.h.in5
-rw-r--r--src/test3.c32
-rw-r--r--src/test6.c7
-rw-r--r--src/test_async.c8
-rw-r--r--src/test_devsym.c13
-rw-r--r--src/test_onefile.c14
-rw-r--r--src/test_osinst.c15
-rw-r--r--src/vdbeaux.c8
13 files changed, 244 insertions, 242 deletions
diff --git a/src/os.c b/src/os.c
index 4abf630dd..834100f07 100644
--- a/src/os.c
+++ b/src/os.c
@@ -13,7 +13,7 @@
** This file contains OS interface code that is common to all
** architectures.
**
-** $Id: os.c,v 1.110 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: os.c,v 1.111 2008/06/06 11:11:26 danielk1977 Exp $
*/
#define _SQLITE_OS_C_ 1
#include "sqliteInt.h"
@@ -127,9 +127,6 @@ int sqlite3OsAccess(
DO_OS_MALLOC_TEST;
return pVfs->xAccess(pVfs, zPath, flags, pResOut);
}
-int sqlite3OsGetTempname(sqlite3_vfs *pVfs, int nBufOut, char *zBufOut){
- return pVfs->xGetTempname(pVfs, nBufOut, zBufOut);
-}
int sqlite3OsFullPathname(
sqlite3_vfs *pVfs,
const char *zPath,
diff --git a/src/os_unix.c b/src/os_unix.c
index ae634b75b..13c0ee257 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -12,7 +12,7 @@
**
** This file contains code that is specific to Unix systems.
**
-** $Id: os_unix.c,v 1.184 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: os_unix.c,v 1.185 2008/06/06 11:11:26 danielk1977 Exp $
*/
#include "sqliteInt.h"
#if OS_UNIX /* This file is used on unix only */
@@ -2185,7 +2185,7 @@ static int fillInUnixFile(
sqlite3_file *pId, /* Write to the unixFile structure here */
const char *zFilename /* Name of the file being opened */
){
- sqlite3LockingStyle lockingStyle;
+ sqlite3LockingStyle lockingStyle = noLockingStyle;
unixFile *pNew = (unixFile *)pId;
int rc;
@@ -2193,24 +2193,28 @@ static int fillInUnixFile(
fcntl(h, F_SETFD, fcntl(h, F_GETFD, 0) | FD_CLOEXEC);
#endif
- lockingStyle = sqlite3DetectLockingStyle(zFilename, h);
- if ( lockingStyle==posixLockingStyle ){
- enterMutex();
- rc = findLockInfo(h, &pNew->pLock, &pNew->pOpen);
- leaveMutex();
- if( rc ){
- if( dirfd>=0 ) close(dirfd);
- close(h);
- return rc;
+ assert( pNew->pLock==NULL );
+ assert( pNew->pOpen==NULL );
+ if( zFilename ){
+ /* If zFilename is NULL then this is a temporary file. Temporary files
+ ** are never locked or unlocked, so noLockingStyle is used for these.
+ ** The locking style used by other files is determined by
+ ** sqlite3DetectLockingStyle().
+ */
+ lockingStyle = sqlite3DetectLockingStyle(zFilename, h);
+ if ( lockingStyle==posixLockingStyle ){
+ enterMutex();
+ rc = findLockInfo(h, &pNew->pLock, &pNew->pOpen);
+ leaveMutex();
+ if( rc ){
+ if( dirfd>=0 ) close(dirfd);
+ close(h);
+ return rc;
+ }
}
- } else {
- /* pLock and pOpen are only used for posix advisory locking */
- pNew->pLock = NULL;
- pNew->pOpen = NULL;
}
OSTRACE3("OPEN %-3d %s\n", h, zFilename);
- pNew->dirfd = -1;
pNew->h = h;
pNew->dirfd = dirfd;
SET_THREADID(pNew);
@@ -2337,6 +2341,63 @@ static int openDirectory(const char *zFilename, int *pFd){
}
/*
+** Create a temporary file name in zBuf. zBuf must be allocated
+** by the calling process and must be big enough to hold at least
+** pVfs->mxPathname bytes.
+*/
+static int getTempname(int nBuf, char *zBuf){
+ static const char *azDirs[] = {
+ 0,
+ "/var/tmp",
+ "/usr/tmp",
+ "/tmp",
+ ".",
+ };
+ static const unsigned char zChars[] =
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789";
+ int i, j;
+ struct stat buf;
+ const char *zDir = ".";
+
+ /* It's odd to simulate an io-error here, but really this is just
+ ** using the io-error infrastructure to test that SQLite handles this
+ ** function failing.
+ */
+ SimulateIOError( return SQLITE_IOERR );
+
+ azDirs[0] = sqlite3_temp_directory;
+ for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); i++){
+ if( azDirs[i]==0 ) continue;
+ if( stat(azDirs[i], &buf) ) continue;
+ if( !S_ISDIR(buf.st_mode) ) continue;
+ if( access(azDirs[i], 07) ) continue;
+ zDir = azDirs[i];
+ break;
+ }
+
+ /* Check that the output buffer is large enough for the temporary file
+ ** name. If it is not, return SQLITE_ERROR.
+ */
+ if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 17) >= nBuf ){
+ return SQLITE_ERROR;
+ }
+
+ do{
+ sqlite3_snprintf(nBuf-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
+ j = strlen(zBuf);
+ sqlite3_randomness(15, &zBuf[j]);
+ for(i=0; i<15; i++, j++){
+ zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
+ }
+ zBuf[j] = 0;
+ }while( access(zBuf,0)==0 );
+ return SQLITE_OK;
+}
+
+
+/*
** Open the file zPath.
**
** Previously, the SQLite OS layer used three functions in place of this
@@ -2384,6 +2445,12 @@ static int unixOpen(
(eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL)
);
+ /* If argument zPath is a NULL pointer, this function is required to open
+ ** a temporary file. Use this buffer to store the file name in.
+ */
+ char zTmpname[MAX_PATHNAME+1];
+ const char *zName = zPath;
+
/* Check the following statements are true:
**
** (a) Exactly one of the READWRITE and READONLY flags must be set, and
@@ -2411,6 +2478,16 @@ static int unixOpen(
|| eType==SQLITE_OPEN_TRANSIENT_DB
);
+ if( !zName ){
+ int rc;
+ assert(isDelete && !isOpenDirectory);
+ rc = getTempname(MAX_PATHNAME+1, zTmpname);
+ if( rc!=SQLITE_OK ){
+ return rc;
+ }
+ zName = zTmpname;
+ }
+
if( isReadonly ) oflags |= O_RDONLY;
if( isReadWrite ) oflags |= O_RDWR;
if( isCreate ) oflags |= O_CREAT;
@@ -2418,7 +2495,7 @@ static int unixOpen(
oflags |= (O_LARGEFILE|O_BINARY);
memset(pFile, 0, sizeof(unixFile));
- fd = open(zPath, oflags, isDelete?0600:SQLITE_DEFAULT_FILE_PERMISSIONS);
+ fd = open(zName, oflags, isDelete?0600:SQLITE_DEFAULT_FILE_PERMISSIONS);
if( fd<0 && errno!=EISDIR && isReadWrite && !isExclusive ){
/* Failed to open the file for read/write access. Try read-only. */
flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
@@ -2429,7 +2506,7 @@ static int unixOpen(
return SQLITE_CANTOPEN;
}
if( isDelete ){
- unlink(zPath);
+ unlink(zName);
}
if( pOutFlags ){
*pOutFlags = flags;
@@ -2503,63 +2580,6 @@ static int unixAccess(
return SQLITE_OK;
}
-/*
-** Create a temporary file name in zBuf. zBuf must be allocated
-** by the calling process and must be big enough to hold at least
-** pVfs->mxPathname bytes.
-*/
-static int unixGetTempname(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
- static const char *azDirs[] = {
- 0,
- "/var/tmp",
- "/usr/tmp",
- "/tmp",
- ".",
- };
- static const unsigned char zChars[] =
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789";
- int i, j;
- struct stat buf;
- const char *zDir = ".";
-
- /* It's odd to simulate an io-error here, but really this is just
- ** using the io-error infrastructure to test that SQLite handles this
- ** function failing.
- */
- SimulateIOError( return SQLITE_ERROR );
-
- azDirs[0] = sqlite3_temp_directory;
- for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); i++){
- if( azDirs[i]==0 ) continue;
- if( stat(azDirs[i], &buf) ) continue;
- if( !S_ISDIR(buf.st_mode) ) continue;
- if( access(azDirs[i], 07) ) continue;
- zDir = azDirs[i];
- break;
- }
-
- /* Check that the output buffer is large enough for the temporary file
- ** name. If it is not, return SQLITE_ERROR.
- */
- if( (strlen(zDir) + strlen(SQLITE_TEMP_FILE_PREFIX) + 17) >= nBuf ){
- return SQLITE_ERROR;
- }
-
- do{
- assert( pVfs->mxPathname==MAX_PATHNAME );
- sqlite3_snprintf(nBuf-17, zBuf, "%s/"SQLITE_TEMP_FILE_PREFIX, zDir);
- j = strlen(zBuf);
- sqlite3_randomness(15, &zBuf[j]);
- for(i=0; i<15; i++, j++){
- zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
- }
- zBuf[j] = 0;
- }while( access(zBuf,0)==0 );
- return SQLITE_OK;
-}
-
/*
** Turn a relative pathname into a full pathname. The relative path
@@ -2773,7 +2793,6 @@ sqlite3_vfs *sqlite3OsDefaultVfs(void){
unixOpen, /* xOpen */
unixDelete, /* xDelete */
unixAccess, /* xAccess */
- unixGetTempname, /* xGetTempName */
unixFullPathname, /* xFullPathname */
unixDlOpen, /* xDlOpen */
unixDlError, /* xDlError */
diff --git a/src/os_win.c b/src/os_win.c
index b21f65705..9b13628bf 100644
--- a/src/os_win.c
+++ b/src/os_win.c
@@ -12,7 +12,7 @@
**
** This file contains code that is specific to windows.
**
-** $Id: os_win.c,v 1.124 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: os_win.c,v 1.125 2008/06/06 11:11:26 danielk1977 Exp $
*/
#include "sqliteInt.h"
#if OS_WIN /* This file is used for windows only */
@@ -1075,6 +1075,57 @@ static void *convertUtf8Filename(const char *zFilename){
}
/*
+** Create a temporary file name in zBuf. zBuf must be big enough to
+** hold at pVfs->mxPathname characters.
+*/
+static int getTempname(int nBuf, char *zBuf){
+ static char zChars[] =
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789";
+ int i, j;
+ char zTempPath[MAX_PATH+1];
+ if( sqlite3_temp_directory ){
+ sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
+ }else if( isNT() ){
+ char *zMulti;
+ WCHAR zWidePath[MAX_PATH];
+ GetTempPathW(MAX_PATH-30, zWidePath);
+ zMulti = unicodeToUtf8(zWidePath);
+ if( zMulti ){
+ sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
+ free(zMulti);
+ }else{
+ return SQLITE_NOMEM;
+ }
+ }else{
+ char *zUtf8;
+ char zMbcsPath[MAX_PATH];
+ GetTempPathA(MAX_PATH-30, zMbcsPath);
+ zUtf8 = mbcsToUtf8(zMbcsPath);
+ if( zUtf8 ){
+ sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
+ free(zUtf8);
+ }else{
+ return SQLITE_NOMEM;
+ }
+ }
+ for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
+ zTempPath[i] = 0;
+ sqlite3_snprintf(nBuf-30, zBuf,
+ "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
+ j = strlen(zBuf);
+ sqlite3_randomness(20, &zBuf[j]);
+ for(i=0; i<20; i++, j++){
+ zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
+ }
+ zBuf[j] = 0;
+ OSTRACE2("TEMP FILENAME: %s\n", zBuf);
+ return SQLITE_OK;
+}
+
+
+/*
** Open a file.
*/
static int winOpen(
@@ -1091,7 +1142,23 @@ static int winOpen(
DWORD dwFlagsAndAttributes = 0;
int isTemp;
winFile *pFile = (winFile*)id;
- void *zConverted = convertUtf8Filename(zName);
+ void *zConverted; /* Filename in OS encoding */
+ const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
+ char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
+
+ /* If the second argument to this function is NULL, generate a
+ ** temporary file name to use
+ */
+ if( !zUtf8Name ){
+ int rc = getTempname(MAX_PATH+1, zTmpname);
+ if( rc!=SQLITE_OK ){
+ return rc;
+ }
+ zUtf8Name = zTmpname;
+ }
+
+ /* Convert the filename to the system encoding. */
+ zConverted = convertUtf8Filename(zUtf8Name);
if( zConverted==0 ){
return SQLITE_NOMEM;
}
@@ -1276,56 +1343,6 @@ static int winAccess(
/*
-** Create a temporary file name in zBuf. zBuf must be big enough to
-** hold at pVfs->mxPathname characters.
-*/
-static int winGetTempname(sqlite3_vfs *pVfs, int nBuf, char *zBuf){
- static char zChars[] =
- "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789";
- int i, j;
- char zTempPath[MAX_PATH+1];
- if( sqlite3_temp_directory ){
- sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
- }else if( isNT() ){
- char *zMulti;
- WCHAR zWidePath[MAX_PATH];
- GetTempPathW(MAX_PATH-30, zWidePath);
- zMulti = unicodeToUtf8(zWidePath);
- if( zMulti ){
- sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zMulti);
- free(zMulti);
- }else{
- return SQLITE_NOMEM;
- }
- }else{
- char *zUtf8;
- char zMbcsPath[MAX_PATH];
- GetTempPathA(MAX_PATH-30, zMbcsPath);
- zUtf8 = mbcsToUtf8(zMbcsPath);
- if( zUtf8 ){
- sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", zUtf8);
- free(zUtf8);
- }else{
- return SQLITE_NOMEM;
- }
- }
- for(i=strlen(zTempPath); i>0 && zTempPath[i-1]=='\\'; i--){}
- zTempPath[i] = 0;
- sqlite3_snprintf(nBuf-30, zBuf,
- "%s\\"SQLITE_TEMP_FILE_PREFIX, zTempPath);
- j = strlen(zBuf);
- sqlite3_randomness(20, &zBuf[j]);
- for(i=0; i<20; i++, j++){
- zBuf[j] = (char)zChars[ ((unsigned char)zBuf[j])%(sizeof(zChars)-1) ];
- }
- zBuf[j] = 0;
- OSTRACE2("TEMP FILENAME: %s\n", zBuf);
- return SQLITE_OK;
-}
-
-/*
** Turn a relative pathname into a full pathname. Write the full
** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
** bytes in size.
@@ -1550,7 +1567,6 @@ sqlite3_vfs *sqlite3OsDefaultVfs(void){
winOpen, /* xOpen */
winDelete, /* xDelete */
winAccess, /* xAccess */
- winGetTempname, /* xGetTempName */
winFullPathname, /* xFullPathname */
winDlOpen, /* xDlOpen */
winDlError, /* xDlError */
diff --git a/src/pager.c b/src/pager.c
index 8cba4a37f..c37a75559 100644
--- a/src/pager.c
+++ b/src/pager.c
@@ -18,7 +18,7 @@
** file simultaneously, or one process from reading the database while
** another is writing.
**
-** @(#) $Id: pager.c,v 1.452 2008/06/05 11:39:11 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.453 2008/06/06 11:11:26 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_DISKIO
#include "sqliteInt.h"
@@ -372,7 +372,6 @@ struct Pager {
char *zFilename; /* Name of the database file */
char *zJournal; /* Name of the journal file */
char *zDirectory; /* Directory hold database and journal files */
- char *zStmtJrnl; /* Name of the statement journal file */
sqlite3_file *fd, *jfd; /* File descriptors for database and journal */
sqlite3_file *stfd; /* File descriptor for the statement subjournal*/
BusyHandler *pBusyHandler; /* Pointer to sqlite.busyHandler */
@@ -2132,13 +2131,11 @@ int sqlite3_opentemp_count = 0;
** file when it is closed.
*/
static int sqlite3PagerOpentemp(
- sqlite3_vfs *pVfs, /* The virtual file system layer */
+ Pager *pPager, /* The pager object */
sqlite3_file *pFile, /* Write the file descriptor here */
- char *zFilename, /* Name of the file. Might be NULL */
int vfsFlags /* Flags passed through to the VFS */
){
int rc;
- assert( zFilename!=0 );
#ifdef SQLITE_TEST
sqlite3_opentemp_count++; /* Used for testing and analysis only */
@@ -2146,7 +2143,7 @@ static int sqlite3PagerOpentemp(
vfsFlags |= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE;
- rc = sqlite3OsOpen(pVfs, zFilename, pFile, vfsFlags, 0);
+ rc = sqlite3OsOpen(pPager->pVfs, 0, pFile, vfsFlags, 0);
assert( rc!=SQLITE_OK || pFile->pMethods );
return rc;
}
@@ -2184,21 +2181,22 @@ int sqlite3PagerOpen(
int noReadlock = (flags & PAGER_NO_READLOCK)!=0;
int journalFileSize = sqlite3JournalSize(pVfs);
int nDefaultPage = SQLITE_DEFAULT_PAGE_SIZE;
- char *zPathname;
- int nPathname;
- char *zStmtJrnl;
- int nStmtJrnl;
+ char *zPathname = 0;
+ int nPathname = 0;
/* The default return is a NULL pointer */
*ppPager = 0;
- /* Compute the full pathname */
- nPathname = pVfs->mxPathname+1;
- zPathname = sqlite3_malloc(nPathname*2);
- if( zPathname==0 ){
- return SQLITE_NOMEM;
- }
+ /* Compute and store the full pathname in an allocated buffer pointed
+ ** to by zPathname, length nPathname. Or, if this is a temporary file,
+ ** leave both nPathname and zPathname set to 0.
+ */
if( zFilename && zFilename[0] ){
+ nPathname = pVfs->mxPathname+1;
+ zPathname = sqlite3_malloc(nPathname*2);
+ if( zPathname==0 ){
+ return SQLITE_NOMEM;
+ }
#ifndef SQLITE_OMIT_MEMORYDB
if( strcmp(zFilename,":memory:")==0 ){
memDb = 1;
@@ -2208,35 +2206,19 @@ int sqlite3PagerOpen(
{
rc = sqlite3OsFullPathname(pVfs, zFilename, nPathname, zPathname);
}
- }else{
- rc = sqlite3OsGetTempname(pVfs, nPathname, zPathname);
- }
- if( rc!=SQLITE_OK ){
- sqlite3_free(zPathname);
- return rc;
- }
- nPathname = strlen(zPathname);
-
- /* Put the statement journal in temporary disk space since this is
- ** sometimes RAM disk or other optimized storage. Unlikely the main
- ** main journal file, the statement journal does not need to be
- ** colocated with the database nor does it need to be persistent.
- */
- zStmtJrnl = &zPathname[nPathname+1];
- rc = sqlite3OsGetTempname(pVfs, pVfs->mxPathname+1, zStmtJrnl);
- if( rc!=SQLITE_OK ){
- sqlite3_free(zPathname);
- return rc;
+ if( rc!=SQLITE_OK ){
+ sqlite3_free(zPathname);
+ return rc;
+ }
+ nPathname = strlen(zPathname);
}
- nStmtJrnl = strlen(zStmtJrnl);
/* Allocate memory for the pager structure */
pPager = sqlite3MallocZero(
sizeof(*pPager) + /* Pager structure */
journalFileSize + /* The journal file structure */
pVfs->szOsFile * 3 + /* The main db and two journal files */
- 3*nPathname + 40 + /* zFilename, zDirectory, zJournal */
- nStmtJrnl /* zStmtJrnl */
+ 3*nPathname + 40 /* zFilename, zDirectory, zJournal */
);
if( !pPager ){
sqlite3_free(zPathname);
@@ -2250,11 +2232,11 @@ int sqlite3PagerOpen(
pPager->zFilename = (char*)&pPtr[pVfs->szOsFile*2+journalFileSize];
pPager->zDirectory = &pPager->zFilename[nPathname+1];
pPager->zJournal = &pPager->zDirectory[nPathname+1];
- pPager->zStmtJrnl = &pPager->zJournal[nPathname+10];
pPager->pVfs = pVfs;
- memcpy(pPager->zFilename, zPathname, nPathname+1);
- memcpy(pPager->zStmtJrnl, zStmtJrnl, nStmtJrnl+1);
- sqlite3_free(zPathname);
+ if( zPathname ){
+ memcpy(pPager->zFilename, zPathname, nPathname+1);
+ sqlite3_free(zPathname);
+ }
/* Open the pager file.
*/
@@ -2330,8 +2312,12 @@ int sqlite3PagerOpen(
if( i>0 ) pPager->zDirectory[i-1] = 0;
/* Fill in Pager.zJournal[] */
- memcpy(pPager->zJournal, pPager->zFilename, nPathname);
- memcpy(&pPager->zJournal[nPathname], "-journal", 9);
+ if( zPathname ){
+ memcpy(pPager->zJournal, pPager->zFilename, nPathname);
+ memcpy(&pPager->zJournal[nPathname], "-journal", 9);
+ }else{
+ pPager->zJournal = 0;
+ }
/* pPager->journalOpen = 0; */
pPager->useJournal = useJournal && !memDb;
@@ -3071,8 +3057,7 @@ static int pager_write_pagelist(PgHdr *pList){
/* If the file has not yet been opened, open it now. */
if( !pPager->fd->pMethods ){
assert(pPager->tempFile);
- rc = sqlite3PagerOpentemp(pPager->pVfs, pPager->fd, pPager->zFilename,
- pPager->vfsFlags);
+ rc = sqlite3PagerOpentemp(pPager, pPager->fd, pPager->vfsFlags);
if( rc ) return rc;
}
@@ -4961,6 +4946,9 @@ int *sqlite3PagerStats(Pager *pPager){
a[10] = pPager->nWrite;
return a;
}
+int sqlite3PagerIsMemdb(Pager *pPager){
+ return MEMDB;
+}
#endif
/*
@@ -4999,8 +4987,7 @@ static int pagerStmtBegin(Pager *pPager){
pPager->stmtHdrOff = 0;
pPager->stmtCksum = pPager->cksumInit;
if( !pPager->stmtOpen ){
- rc = sqlite3PagerOpentemp(pPager->pVfs, pPager->stfd, pPager->zStmtJrnl,
- SQLITE_OPEN_SUBJOURNAL);
+ rc = sqlite3PagerOpentemp(pPager, pPager->stfd, SQLITE_OPEN_SUBJOURNAL);
if( rc ){
goto stmt_begin_failed;
}
diff --git a/src/pager.h b/src/pager.h
index 2fefea8d5..224f55143 100644
--- a/src/pager.h
+++ b/src/pager.h
@@ -13,7 +13,7 @@
** subsystem. The page cache subsystem reads and writes a file a page
** at a time and provides a journal for rollback.
**
-** @(#) $Id: pager.h,v 1.74 2008/06/04 06:45:59 danielk1977 Exp $
+** @(#) $Id: pager.h,v 1.75 2008/06/06 11:11:26 danielk1977 Exp $
*/
#ifndef _PAGER_H_
@@ -130,6 +130,7 @@ int sqlite3PagerSync(Pager *pPager);
#ifdef SQLITE_TEST
int *sqlite3PagerStats(Pager*);
void sqlite3PagerRefdump(Pager*);
+ int sqlite3PagerIsMemdb(Pager*);
#endif
#ifdef SQLITE_TEST
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 610530a09..959e9569e 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
-** @(#) $Id: sqlite.h.in,v 1.320 2008/06/05 11:39:11 danielk1977 Exp $
+** @(#) $Id: sqlite.h.in,v 1.321 2008/06/06 11:11:26 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -781,7 +781,7 @@ typedef struct sqlite3_mutex sqlite3_mutex;
** directory.
**
** {F11150} SQLite will always allocate at least mxPathname+1 bytes for
-** the output buffers for xGetTempname and xFullPathname. {F11151} The exact
+** the output buffer xFullPathname. {F11151} The exact
** size of the output buffer is also passed as a parameter to both
** methods. {END} If the output buffer is not large enough, [SQLITE_CANTOPEN]
** should be returned. As this is handled as a fatal error by SQLite,
@@ -811,7 +811,6 @@ struct sqlite3_vfs {
int flags, int *pOutFlags);
int (*xDelete)(sqlite3_vfs*, const char *zName, int syncDir);
int (*xAccess)(sqlite3_vfs*, const char *zName, int flags, int *pResOut);
- int (*xGetTempname)(sqlite3_vfs*, int nOut, char *zOut);
int (*xFullPathname)(sqlite3_vfs*, const char *zName, int nOut, char *zOut);
void *(*xDlOpen)(sqlite3_vfs*, const char *zFilename);
void (*xDlError)(sqlite3_vfs*, int nByte, char *zErrMsg);
diff --git a/src/test3.c b/src/test3.c
index b94f4a1e1..f2381f41e 100644
--- a/src/test3.c
+++ b/src/test3.c
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test3.c,v 1.96 2008/05/27 20:17:01 shane Exp $
+** $Id: test3.c,v 1.97 2008/06/06 11:11:26 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "btreeInt.h"
@@ -1604,6 +1604,35 @@ static int btree_set_cache_size(
return TCL_OK;
}
+/*
+** Usage: btree_ismemdb ID
+**
+** Return true if the B-Tree is in-memory.
+*/
+static int btree_ismemdb(
+ void *NotUsed,
+ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
+ int argc, /* Number of arguments */
+ const char **argv /* Text of each argument */
+){
+ Btree *pBt;
+ int res;
+
+ if( argc!=2 ){
+ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
+ " ID\"", 0);
+ return TCL_ERROR;
+ }
+ pBt = sqlite3TextToPtr(argv[1]);
+ sqlite3_mutex_enter(pBt->db->mutex);
+ sqlite3BtreeEnter(pBt);
+ res = sqlite3PagerIsMemdb(sqlite3BtreePager(pBt));
+ sqlite3BtreeLeave(pBt);
+ sqlite3_mutex_leave(pBt->db->mutex);
+ Tcl_SetObjResult(interp, Tcl_NewBooleanObj(res));
+ return SQLITE_OK;
+}
+
/*
** Register commands with the TCL interpreter.
@@ -1654,6 +1683,7 @@ int Sqlitetest3_Init(Tcl_Interp *interp){
{ "btree_cursor_info", (Tcl_CmdProc*)btree_cursor_info },
{ "btree_ovfl_info", (Tcl_CmdProc*)btree_ovfl_info },
{ "btree_cursor_list", (Tcl_CmdProc*)btree_cursor_list },
+ { "btree_ismemdb", (Tcl_CmdProc*)btree_ismemdb },
};
int i;
diff --git a/src/test6.c b/src/test6.c
index 46b6ea76c..8805cb80f 100644
--- a/src/test6.c
+++ b/src/test6.c
@@ -14,7 +14,7 @@
** the effect on the database file of an OS crash or power failure. This
** is used to test the ability of SQLite to recover from those situations.
**
-** $Id: test6.c,v 1.38 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: test6.c,v 1.39 2008/06/06 11:11:26 danielk1977 Exp $
*/
#if SQLITE_TEST /* This file is used for testing only */
#include "sqliteInt.h"
@@ -589,10 +589,6 @@ static int cfAccess(
sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData;
return pVfs->xAccess(pVfs, zPath, flags, pResOut);
}
-static int cfGetTempname(sqlite3_vfs *pCfVfs, int nBufOut, char *zBufOut){
- sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs->pAppData;
- return pVfs->xGetTempname(pVfs, nBufOut, zBufOut);
-}
static int cfFullPathname(
sqlite3_vfs *pCfVfs,
const char *zPath,
@@ -747,7 +743,6 @@ static int crashEnableCmd(
cfOpen, /* xOpen */
cfDelete, /* xDelete */
cfAccess, /* xAccess */
- cfGetTempname, /* xGetTempName */
cfFullPathname, /* xFullPathname */
cfDlOpen, /* xDlOpen */
cfDlError, /* xDlError */
diff --git a/src/test_async.c b/src/test_async.c
index a2671fe68..5c02a9fe6 100644
--- a/src/test_async.c
+++ b/src/test_async.c
@@ -10,7 +10,7 @@
**
*************************************************************************
**
-** $Id: test_async.c,v 1.43 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: test_async.c,v 1.44 2008/06/06 11:11:26 danielk1977 Exp $
**
** This file contains an example implementation of an asynchronous IO
** backend for SQLite.
@@ -1167,11 +1167,6 @@ static int asyncAccess(
return rc;
}
-static int asyncGetTempname(sqlite3_vfs *pAsyncVfs, int nBufOut, char *zBufOut){
- sqlite3_vfs *pVfs = (sqlite3_vfs *)pAsyncVfs->pAppData;
- return pVfs->xGetTempname(pVfs, nBufOut, zBufOut);
-}
-
/*
** Fill in zPathOut with the full path to the file identified by zPath.
*/
@@ -1271,7 +1266,6 @@ static sqlite3_vfs async_vfs = {
asyncOpen, /* xOpen */
asyncDelete, /* xDelete */
asyncAccess, /* xAccess */
- asyncGetTempname, /* xGetTempName */
asyncFullPathname, /* xFullPathname */
asyncDlOpen, /* xDlOpen */
asyncDlError, /* xDlError */
diff --git a/src/test_devsym.c b/src/test_devsym.c
index b68994a15..0314804cd 100644
--- a/src/test_devsym.c
+++ b/src/test_devsym.c
@@ -14,7 +14,7 @@
** different device types (by overriding the return values of the
** xDeviceCharacteristics() and xSectorSize() methods).
**
-** $Id: test_devsym.c,v 1.6 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: test_devsym.c,v 1.7 2008/06/06 11:11:26 danielk1977 Exp $
*/
#if SQLITE_TEST /* This file is used for testing only */
@@ -59,7 +59,6 @@ static int devsymDeviceCharacteristics(sqlite3_file*);
static int devsymOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
static int devsymDelete(sqlite3_vfs*, const char *zName, int syncDir);
static int devsymAccess(sqlite3_vfs*, const char *zName, int flags, int *);
-static int devsymGetTempName(sqlite3_vfs*, int nOut, char *zOut);
static int devsymFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
#ifndef SQLITE_OMIT_LOAD_EXTENSION
static void *devsymDlOpen(sqlite3_vfs*, const char *zFilename);
@@ -81,7 +80,6 @@ static sqlite3_vfs devsym_vfs = {
devsymOpen, /* xOpen */
devsymDelete, /* xDelete */
devsymAccess, /* xAccess */
- devsymGetTempName, /* xGetTempName */
devsymFullPathname, /* xFullPathname */
#ifndef SQLITE_OMIT_LOAD_EXTENSION
devsymDlOpen, /* xDlOpen */
@@ -265,15 +263,6 @@ static int devsymAccess(
}
/*
-** Populate buffer zBufOut with a pathname suitable for use as a
-** temporary file. zBufOut is guaranteed to point to a buffer of
-** at least (DEVSYM_MAX_PATHNAME+1) bytes.
-*/
-static int devsymGetTempName(sqlite3_vfs *pVfs, int nOut, char *zBufOut){
- return sqlite3OsGetTempname(g.pVfs, nOut, zBufOut);
-}
-
-/*
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer
** of at least (DEVSYM_MAX_PATHNAME+1) bytes.
diff --git a/src/test_onefile.c b/src/test_onefile.c
index 594d1c303..f93192278 100644
--- a/src/test_onefile.c
+++ b/src/test_onefile.c
@@ -10,7 +10,7 @@
**
*************************************************************************
**
-** $Id: test_onefile.c,v 1.7 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: test_onefile.c,v 1.8 2008/06/06 11:11:26 danielk1977 Exp $
**
** OVERVIEW:
**
@@ -165,7 +165,6 @@ static int tmpDeviceCharacteristics(sqlite3_file*);
static int fsOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
static int fsDelete(sqlite3_vfs*, const char *zName, int syncDir);
static int fsAccess(sqlite3_vfs*, const char *zName, int flags, int *);
-static int fsGetTempname(sqlite3_vfs*, int nOut, char *zOut);
static int fsFullPathname(sqlite3_vfs*, const char *zName, int nOut,char *zOut);
static void *fsDlOpen(sqlite3_vfs*, const char *zFilename);
static void fsDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
@@ -194,7 +193,6 @@ static fs_vfs_t fs_vfs = {
fsOpen, /* xOpen */
fsDelete, /* xDelete */
fsAccess, /* xAccess */
- fsGetTempname, /* xGetTempName */
fsFullPathname, /* xFullPathname */
fsDlOpen, /* xDlOpen */
fsDlError, /* xDlError */
@@ -732,16 +730,6 @@ static int fsAccess(
}
/*
-** Populate buffer zBufOut with a pathname suitable for use as a
-** temporary file. zBufOut is guaranteed to point to a buffer of
-** at least (FS_MAX_PATHNAME+1) bytes.
-*/
-static int fsGetTempname(sqlite3_vfs *pVfs, int nBufOut, char *zBufOut){
- sqlite3_vfs *pParent = ((fs_vfs_t *)pVfs)->pParent;
- return pParent->xGetTempname(pParent, nBufOut, zBufOut);
-}
-
-/*
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer
** of at least (FS_MAX_PATHNAME+1) bytes.
diff --git a/src/test_osinst.c b/src/test_osinst.c
index 9daa52f1c..00029142b 100644
--- a/src/test_osinst.c
+++ b/src/test_osinst.c
@@ -14,7 +14,7 @@
** adds instrumentation to all vfs and file methods. C and Tcl interfaces
** are provided to control the instrumentation.
**
-** $Id: test_osinst.c,v 1.13 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: test_osinst.c,v 1.14 2008/06/06 11:11:26 danielk1977 Exp $
*/
/*
@@ -173,7 +173,6 @@ static int instDeviceCharacteristics(sqlite3_file*);
static int instOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
static int instDelete(sqlite3_vfs*, const char *zName, int syncDir);
static int instAccess(sqlite3_vfs*, const char *zName, int flags, int *);
-static int instGetTempName(sqlite3_vfs*, int nOut, char *zOut);
static int instFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
static void *instDlOpen(sqlite3_vfs*, const char *zFilename);
static void instDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
@@ -195,7 +194,6 @@ static sqlite3_vfs inst_vfs = {
instOpen, /* xOpen */
instDelete, /* xDelete */
instAccess, /* xAccess */
- instGetTempName, /* xGetTempName */
instFullPathname, /* xFullPathname */
instDlOpen, /* xDlOpen */
instDlError, /* xDlError */
@@ -419,17 +417,6 @@ static int instAccess(
}
/*
-** Populate buffer zBufOut with a pathname suitable for use as a
-** temporary file. zBufOut is guaranteed to point to a buffer of
-** at least (INST_MAX_PATHNAME+1) bytes.
-*/
-static int instGetTempName(sqlite3_vfs *pVfs, int nOut, char *zBufOut){
- OS_TIME_VFS( OS_GETTEMPNAME, 0, 0, 0, 0,
- REALVFS(pVfs)->xGetTempname(REALVFS(pVfs), nOut, zBufOut);
- );
-}
-
-/*
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer
** of at least (INST_MAX_PATHNAME+1) bytes.
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index 3e6c09d4d..5398ec180 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -14,7 +14,7 @@
** to version 2.8.7, all this code was combined into the vdbe.c source file.
** But that file was getting too big so this subroutines were split out.
**
-** $Id: vdbeaux.c,v 1.384 2008/06/05 11:39:11 danielk1977 Exp $
+** $Id: vdbeaux.c,v 1.385 2008/06/06 11:11:27 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -1246,9 +1246,9 @@ static int vdbeCommit(sqlite3 *db){
** master-journal.
**
** If the return value of sqlite3BtreeGetFilename() is a zero length
- ** string, it means the main database is :memory:. In that case we do
- ** not support atomic multi-file commits, so use the simple case then
- ** too.
+ ** string, it means the main database is :memory: or a temp file. In
+ ** that case we do not support atomic multi-file commits, so use the
+ ** simple case then too.
*/
if( 0==strlen(sqlite3BtreeGetFilename(db->aDb[0].pBt)) || nTrans<=1 ){
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){