diff options
author | drh <drh@noemail.net> | 2007-09-03 15:19:34 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2007-09-03 15:19:34 +0000 |
commit | 33f4e02af65cd4ab4292a09cbd9d3d304f4cb536 (patch) | |
tree | 6d6d5b6b06e1454dbf4add9450a3dbf9c11eb3a1 /src | |
parent | cd2543b6ae6a3ac7dff3232624c93a073824bf06 (diff) | |
download | sqlite-33f4e02af65cd4ab4292a09cbd9d3d304f4cb536.tar.gz sqlite-33f4e02af65cd4ab4292a09cbd9d3d304f4cb536.zip |
Honor the SQLITE_OPEN_ flags passed into sqlite3_open_v2(). Some
test cases added but more are needed. Ticket #2616. (CVS 4376)
FossilOrigin-Name: 020a2b10d408f51d4ef3211c5f701f5378fd4625
Diffstat (limited to 'src')
-rw-r--r-- | src/attach.c | 8 | ||||
-rw-r--r-- | src/btree.c | 8 | ||||
-rw-r--r-- | src/btree.h | 5 | ||||
-rw-r--r-- | src/build.c | 12 | ||||
-rw-r--r-- | src/journal.c | 4 | ||||
-rw-r--r-- | src/main.c | 18 | ||||
-rw-r--r-- | src/os_unix.c | 11 | ||||
-rw-r--r-- | src/pager.c | 44 | ||||
-rw-r--r-- | src/pager.h | 4 | ||||
-rw-r--r-- | src/sqlite.h.in | 12 | ||||
-rw-r--r-- | src/sqliteInt.h | 9 | ||||
-rw-r--r-- | src/tclsqlite.c | 6 | ||||
-rw-r--r-- | src/test2.c | 5 | ||||
-rw-r--r-- | src/test3.c | 5 | ||||
-rw-r--r-- | src/test_async.c | 4 | ||||
-rw-r--r-- | src/vdbe.c | 12 |
16 files changed, 105 insertions, 62 deletions
diff --git a/src/attach.c b/src/attach.c index 82377fbb3..3c2f6a63d 100644 --- a/src/attach.c +++ b/src/attach.c @@ -11,7 +11,7 @@ ************************************************************************* ** This file contains code used to implement the ATTACH and DETACH commands. ** -** $Id: attach.c,v 1.61 2007/08/16 04:30:39 drh Exp $ +** $Id: attach.c,v 1.62 2007/09/03 15:19:35 drh Exp $ */ #include "sqliteInt.h" @@ -73,8 +73,8 @@ static void attachFunc( const char *zName; const char *zFile; Db *aNew; - char zErr[128]; char *zErrDyn = 0; + char zErr[128]; zFile = (const char *)sqlite3_value_text(argv[0]); zName = (const char *)sqlite3_value_text(argv[1]); @@ -133,7 +133,9 @@ static void attachFunc( ** it to obtain the database schema. At this point the schema may ** or may not be initialised. */ - rc = sqlite3BtreeFactory(db, zFile, 0, SQLITE_DEFAULT_CACHE_SIZE, &aNew->pBt); + rc = sqlite3BtreeFactory(db, zFile, 0, SQLITE_DEFAULT_CACHE_SIZE, + db->openFlags | SQLITE_OPEN_MAIN_DB, + &aNew->pBt); if( rc==SQLITE_OK ){ aNew->pSchema = sqlite3SchemaGet(db, aNew->pBt); if( !aNew->pSchema ){ diff --git a/src/btree.c b/src/btree.c index bda46fbad..2f81d4115 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.420 2007/08/30 01:19:59 drh Exp $ +** $Id: btree.c,v 1.421 2007/09/03 15:19:35 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -1110,7 +1110,8 @@ int sqlite3BtreeOpen( const char *zFilename, /* Name of the file containing the BTree database */ sqlite3 *pSqlite, /* Associated database handle */ Btree **ppBtree, /* Pointer to new Btree object written here */ - int flags /* Options */ + int flags, /* Options */ + int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */ ){ sqlite3_vfs *pVfs; /* The VFS to use for this btree */ BtShared *pBt = 0; /* Shared part of btree structure */ @@ -1208,7 +1209,8 @@ int sqlite3BtreeOpen( rc = SQLITE_NOMEM; goto btree_open_out; } - rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename, EXTRA_SIZE, flags); + rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename, + EXTRA_SIZE, flags, vfsFlags); if( rc==SQLITE_OK ){ rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader); } diff --git a/src/btree.h b/src/btree.h index 26418990d..f7bc8e12d 100644 --- a/src/btree.h +++ b/src/btree.h @@ -13,7 +13,7 @@ ** subsystem. See comments in the source code for a detailed description ** of what each interface routine does. ** -** @(#) $Id: btree.h,v 1.92 2007/08/30 01:19:59 drh Exp $ +** @(#) $Id: btree.h,v 1.93 2007/09/03 15:19:35 drh Exp $ */ #ifndef _BTREE_H_ #define _BTREE_H_ @@ -59,7 +59,8 @@ int sqlite3BtreeOpen( const char *zFilename, /* Name of database file to open */ sqlite3 *db, /* Associated database connection */ Btree **, /* Return open Btree* here */ - int flags /* Flags */ + int flags, /* Flags */ + int vfsFlags /* Flags passed through to VFS open */ ); /* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the diff --git a/src/build.c b/src/build.c index c8f50e07b..f46d28ee1 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.443 2007/08/30 01:19:59 drh Exp $ +** $Id: build.c,v 1.444 2007/09/03 15:19:35 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -3138,7 +3138,15 @@ void sqlite3RollbackTransaction(Parse *pParse){ int sqlite3OpenTempDatabase(Parse *pParse){ sqlite3 *db = pParse->db; if( db->aDb[1].pBt==0 && !pParse->explain ){ - int rc = sqlite3BtreeFactory(db, 0, 0, SQLITE_DEFAULT_CACHE_SIZE, + int rc; + static const int flags = + SQLITE_OPEN_READWRITE | + SQLITE_OPEN_CREATE | + SQLITE_OPEN_EXCLUSIVE | + SQLITE_OPEN_DELETEONCLOSE | + SQLITE_OPEN_TEMP_DB; + + rc = sqlite3BtreeFactory(db, 0, 0, SQLITE_DEFAULT_CACHE_SIZE, flags, &db->aDb[1].pBt); if( rc!=SQLITE_OK ){ sqlite3ErrorMsg(pParse, "unable to open a temporary database " diff --git a/src/journal.c b/src/journal.c index 2b195dda6..33304f64b 100644 --- a/src/journal.c +++ b/src/journal.c @@ -10,7 +10,7 @@ ** ************************************************************************* ** -** @(#) $Id: journal.c,v 1.5 2007/09/01 18:24:55 danielk1977 Exp $ +** @(#) $Id: journal.c,v 1.6 2007/09/03 15:19:35 drh Exp $ */ #ifdef SQLITE_ENABLE_ATOMIC_WRITE @@ -93,7 +93,7 @@ static int jrnlRead( if( p->pReal ){ rc = sqlite3OsRead(p->pReal, zBuf, iAmt, iOfst); }else{ - assert( n+iOfst<=p->iSize ); + assert( iAmt+iOfst<=p->iSize ); memcpy(zBuf, &p->zBuf[iOfst], iAmt); } return rc; diff --git a/src/main.c b/src/main.c index 51ed40d99..0a4c721cd 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.403 2007/09/03 11:04:22 danielk1977 Exp $ +** $Id: main.c,v 1.404 2007/09/03 15:19:35 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -727,18 +727,19 @@ int sqlite3BtreeFactory( const char *zFilename, /* Name of the file containing the BTree database */ int omitJournal, /* if TRUE then do not journal this file */ int nCache, /* How many pages in the page cache */ + int vfsFlags, /* Flags passed through to vfsOpen */ Btree **ppBtree /* Pointer to new Btree object written here */ ){ - int btree_flags = 0; + int btFlags = 0; int rc; assert( sqlite3_mutex_held(db->mutex) ); assert( ppBtree != 0); if( omitJournal ){ - btree_flags |= BTREE_OMIT_JOURNAL; + btFlags |= BTREE_OMIT_JOURNAL; } if( db->flags & SQLITE_NoReadlock ){ - btree_flags |= BTREE_NO_READLOCK; + btFlags |= BTREE_NO_READLOCK; } if( zFilename==0 ){ #if TEMP_STORE==0 @@ -757,7 +758,10 @@ int sqlite3BtreeFactory( #endif /* SQLITE_OMIT_MEMORYDB */ } - rc = sqlite3BtreeOpen(zFilename, (sqlite3 *)db, ppBtree, btree_flags); + if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (zFilename==0 || *zFilename==0) ){ + vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB; + } + rc = sqlite3BtreeOpen(zFilename, (sqlite3 *)db, ppBtree, btFlags, vfsFlags); if( rc==SQLITE_OK ){ sqlite3BtreeSetBusyHandler(*ppBtree, (void*)&db->busyHandler); sqlite3BtreeSetCacheSize(*ppBtree, nCache); @@ -1005,7 +1009,9 @@ static int openDatabase( } /* Open the backend database driver */ - rc = sqlite3BtreeFactory(db, zFilename, 0, SQLITE_DEFAULT_CACHE_SIZE, + db->openFlags = flags; + rc = sqlite3BtreeFactory(db, zFilename, 0, SQLITE_DEFAULT_CACHE_SIZE, + flags | SQLITE_OPEN_MAIN_DB, &db->aDb[0].pBt); if( rc!=SQLITE_OK ){ sqlite3Error(db, rc, 0); diff --git a/src/os_unix.c b/src/os_unix.c index f4a9ffe15..02db7eab6 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -2368,15 +2368,26 @@ static int unixOpen( ** (a) Exactly one of the READWRITE and READONLY flags must be set, and ** (b) if CREATE is set, then READWRITE must also be set, and ** (c) if EXCLUSIVE is set, then CREATE must also be set. + ** (d) if DELETEONCLOSE is set, then CREATE must also be set. */ assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly)); assert(isCreate==0 || isReadWrite); assert(isExclusive==0 || isCreate); + assert(isDelete==0 || isCreate); + + + /* The main DB, main journal, and master journal are never automatically + ** deleted + */ + assert( eType!=SQLITE_OPEN_MAIN_DB || !isDelete ); + assert( eType!=SQLITE_OPEN_MAIN_JOURNAL || !isDelete ); + assert( eType!=SQLITE_OPEN_MASTER_JOURNAL || !isDelete ); /* Assert that the upper layer has set one of the "file-type" flags. */ assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL + || eType==SQLITE_OPEN_TRANSIENT_DB ); if( isReadonly ) oflags |= O_RDONLY; diff --git a/src/pager.c b/src/pager.c index 13fbd39c8..e3b10016f 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.384 2007/09/01 16:16:15 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.385 2007/09/03 15:19:35 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" @@ -353,6 +353,7 @@ struct Pager { u8 doNotSync; /* Boolean. While true, do not spill the cache */ u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */ u8 changeCountDone; /* Set after incrementing the change-counter */ + u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ int errCode; /* One of several kinds of errors */ int dbSize; /* Number of pages in the file */ int origDbSize; /* dbSize before the current change */ @@ -1979,21 +1980,17 @@ int sqlite3_opentemp_count = 0; ** file when it is closed. ** ** 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. +** generated automatically. ** -** If zFilename is not 0, SQLITE_OPEN_TEMP_DB is passed as the file type. +** The vfsFlags value should be SQLITE_OPEN_SUBJOURNAL or SQLITE_OPEN */ static int sqlite3PagerOpentemp( - sqlite3_vfs *pVfs, - sqlite3_file *pFile, - char *zFilename + sqlite3_vfs *pVfs, /* The virtual file system layer */ + 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; - int flags = ( - SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| - SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_DELETEONCLOSE - ); char *zFree = 0; if( zFilename==0 ){ @@ -2002,21 +1999,20 @@ static int sqlite3PagerOpentemp( return SQLITE_NOMEM; } 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 - rc = sqlite3OsOpen(pVfs, zFilename, pFile, flags, 0); + vfsFlags |= SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | + SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE; + rc = sqlite3OsOpen(pVfs, zFilename, pFile, vfsFlags, 0); assert( rc!=SQLITE_OK || pFile->pMethods ); sqlite3_free(zFree); return rc; @@ -2041,7 +2037,8 @@ int sqlite3PagerOpen( Pager **ppPager, /* Return the Pager structure here */ const char *zFilename, /* Name of the database file to open */ int nExtra, /* Extra bytes append to each in-memory page */ - int flags /* flags controlling this file */ + int flags, /* flags controlling this file */ + int vfsFlags /* flags passed through to sqlite3_vfs.xOpen() */ ){ u8 *pPtr; Pager *pPager = 0; @@ -2096,6 +2093,7 @@ int sqlite3PagerOpen( return SQLITE_NOMEM; } pPtr = (u8 *)&pPager[1]; + pPager->vfsFlags = vfsFlags; pPager->fd = (sqlite3_file*)&pPtr[pVfs->szOsFile*0]; pPager->stfd = (sqlite3_file*)&pPtr[pVfs->szOsFile*1]; pPager->jfd = (sqlite3_file*)&pPtr[pVfs->szOsFile*2]; @@ -2112,13 +2110,9 @@ int sqlite3PagerOpen( 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. -****/ - int oflag = - (SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_DB); int fout = 0; - rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, oflag, &fout); + rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, + pPager->vfsFlags, &fout); readOnly = (fout&SQLITE_OPEN_READONLY); /* If the file was successfully opened for read/write access, @@ -2919,7 +2913,8 @@ 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); + rc = sqlite3PagerOpentemp(pPager->pVfs, pPager->fd, pPager->zFilename, + pPager->vfsFlags); if( rc ) return rc; } @@ -4720,7 +4715,8 @@ static int pagerStmtBegin(Pager *pPager){ pPager->stmtHdrOff = 0; pPager->stmtCksum = pPager->cksumInit; if( !pPager->stmtOpen ){ - rc = sqlite3PagerOpentemp(pPager->pVfs, pPager->stfd, 0); + rc = sqlite3PagerOpentemp(pPager->pVfs, pPager->stfd, 0, + SQLITE_OPEN_SUBJOURNAL); if( rc ) goto stmt_begin_failed; pPager->stmtOpen = 1; pPager->stmtNRec = 0; diff --git a/src/pager.h b/src/pager.h index 72fc84f42..cf05b11be 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.66 2007/08/31 18:34:59 drh Exp $ +** @(#) $Id: pager.h,v 1.67 2007/09/03 15:19:35 drh Exp $ */ #ifndef _PAGER_H_ @@ -54,7 +54,7 @@ typedef struct PgHdr DbPage; ** See source code comments for a detailed description of the following ** routines: */ -int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char *, int, int); +int sqlite3PagerOpen(sqlite3_vfs *, Pager **ppPager, const char*, int,int,int); void sqlite3PagerSetBusyhandler(Pager*, BusyHandler *pBusyHandler); void sqlite3PagerSetDestructor(Pager*, void(*)(DbPage*,int)); void sqlite3PagerSetReiniter(Pager*, void(*)(DbPage*,int)); diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 907b2342a..a8fcf3a5e 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.254 2007/09/01 18:17:22 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.255 2007/09/03 15:19:35 drh Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -362,10 +362,11 @@ int sqlite3_exec( #define SQLITE_OPEN_EXCLUSIVE 0x00000010 #define SQLITE_OPEN_MAIN_DB 0x00000100 #define SQLITE_OPEN_TEMP_DB 0x00000200 -#define SQLITE_OPEN_MAIN_JOURNAL 0x00000400 -#define SQLITE_OPEN_TEMP_JOURNAL 0x00000800 -#define SQLITE_OPEN_SUBJOURNAL 0x00001000 -#define SQLITE_OPEN_MASTER_JOURNAL 0x00002000 +#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 +#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 +#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 +#define SQLITE_OPEN_SUBJOURNAL 0x00002000 +#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* ** CAPI3REF: Device Characteristics @@ -619,6 +620,7 @@ typedef struct sqlite3_mutex sqlite3_mutex; ** <li> [SQLITE_OPEN_MAIN_JOURNAL] ** <li> [SQLITE_OPEN_TEMP_DB] ** <li> [SQLITE_OPEN_TEMP_JOURNAL] +** <li> [SQLITE_OPEN_TRANSIENT_DB] ** <li> [SQLITE_OPEN_SUBJOURNAL] ** <li> [SQLITE_OPEN_MASTER_JOURNAL] ** </ul> diff --git a/src/sqliteInt.h b/src/sqliteInt.h index c8fc07cdc..e342c527b 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,12 +11,16 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.607 2007/08/31 17:42:48 danielk1977 Exp $ +** @(#) $Id: sqliteInt.h,v 1.608 2007/09/03 15:19:35 drh Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ #include "sqliteLimit.h" +/* +** For testing purposes, the various size limit constants are really +** variables that we can modify in the testfixture. +*/ #ifdef SQLITE_TEST #undef SQLITE_MAX_LENGTH #undef SQLITE_MAX_COLUMN @@ -433,6 +437,7 @@ struct sqlite3 { int nDb; /* Number of backends currently in use */ Db *aDb; /* All backends */ int flags; /* Miscellanous flags. See below */ + int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ int errCode; /* Most recent error code (SQLITE_*) */ int errMask; /* & result codes with this before returning */ u8 autoCommit; /* The auto-commit flag. */ @@ -1754,7 +1759,7 @@ void sqlite3DeferForeignKey(Parse*, int); void sqlite3Attach(Parse*, Expr*, Expr*, Expr*); void sqlite3Detach(Parse*, Expr*); int sqlite3BtreeFactory(const sqlite3 *db, const char *zFilename, - int omitJournal, int nCache, Btree **ppBtree); + int omitJournal, int nCache, int flags, Btree **ppBtree); int sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Token*); int sqlite3FixSrcList(DbFixer*, SrcList*); int sqlite3FixSelect(DbFixer*, Select*); diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 86cd06a9e..d2fcf50ec 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -12,7 +12,7 @@ ** A TCL Interface to SQLite. Append this file to sqlite3.c and ** compile the whole thing to build a TCL-enabled version of SQLite. ** -** $Id: tclsqlite.c,v 1.200 2007/08/31 14:31:45 drh Exp $ +** $Id: tclsqlite.c,v 1.201 2007/09/03 15:19:35 drh Exp $ */ #include "tcl.h" #include <errno.h> @@ -2306,7 +2306,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ int b; if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR; if( b ){ - flags &= ~SQLITE_OPEN_READWRITE; + flags &= ~(SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE); flags |= SQLITE_OPEN_READONLY; }else{ flags &= ~SQLITE_OPEN_READONLY; @@ -2315,7 +2315,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){ }else if( strcmp(zArg, "-create")==0 ){ int b; if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR; - if( b ){ + if( b && (flags & SQLITE_OPEN_READONLY)==0 ){ flags |= SQLITE_OPEN_CREATE; }else{ flags &= ~SQLITE_OPEN_CREATE; diff --git a/src/test2.c b/src/test2.c index ded9547ce..9b77ff382 100644 --- a/src/test2.c +++ b/src/test2.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test2.c,v 1.51 2007/08/29 12:31:28 danielk1977 Exp $ +** $Id: test2.c,v 1.52 2007/09/03 15:19:35 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -77,7 +77,8 @@ static int pager_open( return TCL_ERROR; } if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR; - rc = sqlite3PagerOpen(sqlite3_vfs_find(0), &pPager, argv[1], 0, 0); + rc = sqlite3PagerOpen(sqlite3_vfs_find(0), &pPager, argv[1], 0, 0, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; diff --git a/src/test3.c b/src/test3.c index d2a6071e4..a62cb8a0f 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.85 2007/08/30 08:27:40 danielk1977 Exp $ +** $Id: test3.c,v 1.86 2007/09/03 15:19:36 drh Exp $ */ #include "sqliteInt.h" #include "btreeInt.h" @@ -81,7 +81,8 @@ static int btree_open( sDb.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_RECURSIVE); sqlite3_mutex_enter(sDb.mutex); } - rc = sqlite3BtreeOpen(argv[1], &sDb, &pBt, flags); + rc = sqlite3BtreeOpen(argv[1], &sDb, &pBt, flags, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB); if( rc!=SQLITE_OK ){ Tcl_AppendResult(interp, errorName(rc), 0); return TCL_ERROR; diff --git a/src/test_async.c b/src/test_async.c index 74147f149..f3373f10c 100644 --- a/src/test_async.c +++ b/src/test_async.c @@ -1192,7 +1192,7 @@ static int testAsyncWait( ** of this module. */ int Sqlitetestasync_Init(Tcl_Interp *interp){ -#if OS_UNIX && SQLITE_THREADSAFE && defined(SQLITE_ENABLE_REDEF_IO) +#if OS_UNIX && SQLITE_THREADSAFE Tcl_CreateObjCommand(interp,"sqlite3async_enable",testAsyncEnable,0,0); Tcl_CreateObjCommand(interp,"sqlite3async_halt",testAsyncHalt,0,0); Tcl_CreateObjCommand(interp,"sqlite3async_delay",testAsyncDelay,0,0); @@ -1200,6 +1200,6 @@ int Sqlitetestasync_Init(Tcl_Interp *interp){ Tcl_CreateObjCommand(interp,"sqlite3async_wait",testAsyncWait,0,0); Tcl_LinkVar(interp, "sqlite3async_trace", (char*)&sqlite3async_trace, TCL_LINK_INT); -#endif /* OS_UNIX and SQLITE_THREADSAFE and defined(SQLITE_ENABLE_REDEF_IO) */ +#endif /* OS_UNIX and SQLITE_THREADSAFE */ return TCL_OK; } diff --git a/src/vdbe.c b/src/vdbe.c index b92bbcad4..654c17fde 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.649 2007/08/30 11:48:32 danielk1977 Exp $ +** $Id: vdbe.c,v 1.650 2007/09/03 15:19:36 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -2829,11 +2829,19 @@ case OP_OpenWrite: { /* no-push */ case OP_OpenEphemeral: { /* no-push */ int i = pOp->p1; Cursor *pCx; + static const int openFlags = + SQLITE_OPEN_READWRITE | + SQLITE_OPEN_CREATE | + SQLITE_OPEN_EXCLUSIVE | + SQLITE_OPEN_DELETEONCLOSE | + SQLITE_OPEN_TRANSIENT_DB; + assert( i>=0 ); pCx = allocateCursor(p, i, -1); if( pCx==0 ) goto no_mem; pCx->nullRow = 1; - rc = sqlite3BtreeFactory(db, 0, 1, SQLITE_DEFAULT_TEMP_CACHE_SIZE, &pCx->pBt); + rc = sqlite3BtreeFactory(db, 0, 1, SQLITE_DEFAULT_TEMP_CACHE_SIZE, openFlags, + &pCx->pBt); if( rc==SQLITE_OK ){ rc = sqlite3BtreeBeginTrans(pCx->pBt, 1); } |