diff --git a/manifest b/manifest index 68cc015425..0075862162 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sin\shash.c\swhen\sreplacing\sentries\sin\stables\sconfigured\swith\scopyKey==0.\s(CVS\s4375) -D 2007-09-03T15:03:21 +C Honor\sthe\sSQLITE_OPEN_\sflags\spassed\sinto\ssqlite3_open_v2().\s\sSome\ntest\scases\sadded\sbut\smore\sare\sneeded.\s\sTicket\s#2616.\s(CVS\s4376) +D 2007-09-03T15:19:35 F Makefile.in bfcc303429a5d9dcd552d807ee016c77427418c3 F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -78,13 +78,13 @@ F sqlite3.def a96c1d0d39362b763d2ddba220a32da41a15c4b4 F sqlite3.pc.in 985b9bf34192a549d7d370e0f0b6b34a4f61369a F src/alter.c c9f30b4d6fbf7eff7c5518b002a217d4ecd13bcf F src/analyze.c 49b4bd45eb286d833793ed6bf72355a5c1974865 -F src/attach.c a52225c75b107be8c5bc144a2b6d20201be3f8f8 +F src/attach.c 02fd8779270b1df1c63e7ba6e6655b960fa0f3d5 F src/auth.c d41c34f3150b3b8248d364770ef922bbcefbff82 F src/btmutex.c 442be6f068d77ca9ffd69899cf0a3943c244548c -F src/btree.c f22955f6d04f045d72882c10f70f1a2fb9d21f54 -F src/btree.h 32fad0f06a280e007c31b089a0e1c63e858084ce +F src/btree.c bc7d856505b12f903966d1fd87165588ac7a961b +F src/btree.h d0736ebca4b6eafbdd823c46a8de574cea078211 F src/btreeInt.h 4330c19b8314545fdb209cc77e2a57f6a5290e9c -F src/build.c f8eeec5c71e8bab41b6cfcac79d56c9103a26a91 +F src/build.c 94d0d6dfd1e706c480903fbdda2e77466f21b898 F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0 F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131 F src/date.c af235f38f50809abd0a96da3bb3e0cc32be6226e @@ -95,11 +95,11 @@ F src/func.c 9d88141c4cffb3a04719e5a0fda65cde34bfa1e5 F src/hash.c 06c69a3a038b713c43353c79023372bcfe7f5180 F src/hash.h 3ad3da76bfb954978d227bf495568b0e6da2c19e F src/insert.c b11e5ca0d68bf2a7a56f47a052a0ee67dd4e2f89 -F src/journal.c 63f8a40827e871997272eb2598f5cd9e66aa0947 +F src/journal.c a45147d798f4d8dbdeed200ca7f740579bd8591b F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66 F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35 F src/loadext.c 6894dbbf1666577d957922811620375d6c2f058d -F src/main.c 04191005169375a45a8ef2afe9596d3bda8194b2 +F src/main.c e69df8c9e56e06f54ef894481e56b26ba807d253 F src/malloc.c de4e77fe70a9a0ac47a1c3a874422b107231bf31 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/mem1.c 1f85902b98b38bd8a8b0c24012933957256db13e @@ -116,12 +116,12 @@ F src/os_os2.c 8769301bff502de642ad2634cedcb77d967ce199 F src/os_os2.h c3f7d0af7e3453d1d7aa81b06c0a56f5a226530b F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3 -F src/os_unix.c 3b1b9c6d1b09b9cddd19287e6f842d712bf07602 +F src/os_unix.c 75521336c950555fae26288b61a3091fd6b0c367 F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e F src/os_win.c 57f9b96e78b98e135c41b985613a448d704f23f0 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b -F src/pager.c ac52bb1e22f7ce203e1eec8fa666be2cdd695ee9 -F src/pager.h f204c1a9fe0574953fba89c56d9d9bd1ddfa604a +F src/pager.c 0ce52a22ebfae0c085b68e00e30e9bf9ea462d0d +F src/pager.h d783e7f184afdc33adff37ba58d4e029bd8793b3 F src/parse.y 2d2ce439dc6184621fb0b86f4fc5aca7f391a590 F src/pragma.c 363e548dafb52327face8d99757ab56a7b1c1b26 F src/prepare.c 1506fd279824b1f4bac97514966d0370101f9a6b @@ -130,22 +130,22 @@ F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da F src/select.c 4706a6115da1bdc09a2be5991168a6cc2c0df267 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/shell.c ac29402b538515fa4697282387be9c1205e6e9eb -F src/sqlite.h.in aa6d84a8ed4fb83bfe266bdf7b1f9924a287746f +F src/sqlite.h.in fb4c95cd6995379741b46ffb6f38c5ed87bc26a9 F src/sqlite3ext.h a93f59cdee3638dc0c9c086f80df743a4e68c3cb -F src/sqliteInt.h adc8a20e80ccf9eef24cc32f241a3427915a136e +F src/sqliteInt.h bb126b074352ef0ee20399883172161baf5eead2 F src/sqliteLimit.h 1bcbbdfa856f8b71b561abb31edb864b0eca1d12 F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4 -F src/tclsqlite.c 8db035768623779c97d0509eb88ecbb49c51abca +F src/tclsqlite.c 8c970b4cdc615dfc0726abb470a06d285ed336fb F src/test1.c 6103787d839c2056a42b88082b53d0b79f62285d -F src/test2.c 4ab230fbdc0decfa7422f6a052b609ba54f4dfac -F src/test3.c 199a440ba2b38b26251393b609451a3484a15907 +F src/test2.c 77b34303883b9d722c65a6879bb0163a400e3789 +F src/test3.c 63e49781476f95e6167b441bf98b93392938a850 F src/test4.c c2c0f5dc907f1346f5d4b65eb5799f11eb9e4071 F src/test5.c 3a6a5717a149d7ca2e6d14f5be72cf7555d54dc4 F src/test6.c 0513982dfef4da2a4154b538d2bf538b84ca21d3 F src/test7.c a9d509d0e9ad214b4772696f49f6e61be26213d1 F src/test8.c f113aa3723a52113d0fa7c28155ecd37e7e04077 F src/test9.c b46c8fe02ac7cca1a7316436d8d38d50c66f4b2f -F src/test_async.c 8b6aa6a5701bf3cf52708db178379ee608b44b0c +F src/test_async.c 98c6efe1397ac467dadaadc29c009f9da43ee5a6 F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436 F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c F src/test_config.c 3f50b4060c360d33d069e64ce5684eac43fbf4db @@ -162,7 +162,7 @@ F src/update.c e89b980b443d44b68bfc0b1746cdb6308e049ac9 F src/utf.c 3cb3e9a460fee5634e08501a037d2e768bb2047b F src/util.c 49263637e0f228411201501ddfd1138338d6322c F src/vacuum.c 38745037c63246d1b0669038257890cf89fc4578 -F src/vdbe.c d2f156bbb6b636e9b4a3648c38454bf472668a86 +F src/vdbe.c b6c53921512496ef4d7c4f571feb73b7a495db35 F src/vdbe.h 03a0fa17f6753a24d6cb585d7a362944a2c115aa F src/vdbeInt.h 630145b9bfaa19190ab491f52658a7db550f2247 F src/vdbeapi.c 9c2d681b75e4b90c28b9dd01a3f2e5905267f884 @@ -374,6 +374,7 @@ F test/misc7.test a67af9620a510ce19f96ba69f3848228b7c62a73 F test/misuse.test 30b3a458e5a70c31e74c291937b6c82204c59f33 F test/notnull.test 44d600f916b770def8b095a9962dbe3be5a70d82 F test/null.test 9503e1f63e959544c006d9f01709c5b5eab67d54 +F test/openv2.test f5dd6b23e4dce828eb211649b600763c42a668df F test/pager.test 60303481b22b240c18d6dd1b64edcecc2f4b5a97 F test/pager2.test c025f91b75fe65e85febda64d9416428b8a5cab5 F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4 @@ -568,7 +569,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 91b50f31e35652a40d51f5d9bf22efce36d515e4 -R 1f20fef17ef49080f07da6476975a4c8 -U danielk1977 -Z a985adb5f326fdf3ef20c1c9a11c8b46 +P a19d3a73a91f2040ec35d913f11743ff4913ffb7 +R f918a019bdebc011e42f66cdd6fa0f1c +U drh +Z 5605eb020cc0a3c4f4681fb39456c028 diff --git a/manifest.uuid b/manifest.uuid index 3c33bb48af..488b40980f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a19d3a73a91f2040ec35d913f11743ff4913ffb7 \ No newline at end of file +020a2b10d408f51d4ef3211c5f701f5378fd4625 \ No newline at end of file diff --git a/src/attach.c b/src/attach.c index 82377fbb37..3c2f6a63d6 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 bda46fbadc..2f81d41154 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 26418990db..f7bc8e12d9 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 c8f50e07b7..f46d28ee1e 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 @@ -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 2b195dda6a..33304f64bd 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 51ed40d998..0a4c721cd1 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 @@ -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 f4a9ffe158..02db7eab67 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 13fbd39c85..e3b10016f5 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 72fc84f42c..cf05b11bee 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 907b2342a0..a8fcf3a5e3 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; **
  • [SQLITE_OPEN_MAIN_JOURNAL] **
  • [SQLITE_OPEN_TEMP_DB] **
  • [SQLITE_OPEN_TEMP_JOURNAL] +**
  • [SQLITE_OPEN_TRANSIENT_DB] **
  • [SQLITE_OPEN_SUBJOURNAL] **
  • [SQLITE_OPEN_MASTER_JOURNAL] ** diff --git a/src/sqliteInt.h b/src/sqliteInt.h index c8fc07cdca..e342c527b2 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 86cd06a9e9..d2fcf50ec9 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 @@ -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 ded9547cea..9b77ff3826 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 d2a6071e47..a62cb8a0fa 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 74147f149e..f3373f10c7 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 b92bbcad46..654c17fde7 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 @@ -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); } diff --git a/test/openv2.test b/test/openv2.test new file mode 100644 index 0000000000..637edc6aa3 --- /dev/null +++ b/test/openv2.test @@ -0,0 +1,41 @@ +# 2007 Sep 3 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Tests on the sqlite3_open_v2() interface. +# +# $Id: openv2.test,v 1.1 2007/09/03 15:19:36 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +db close +file delete -force test.db test.db-journal +do_test openv2-1.1 { + set rc [catch {sqlite3 db test.db -create 0} msg] + lappend rc $msg +} {1 {unable to open database file}} +do_test openv2-1.2 { + info commands db +} {} +do_test openv2-1.3 { + sqlite3 db test.db + db eval {CREATE TABLE t1(x)} + db close + sqlite3 db test.db -readonly 1 + db eval {SELECT name FROM sqlite_master} +} {t1} +do_test openv2-1.4 { + catchsql { + INSERT INTO t1 VALUES(123) + } +} {1 {attempt to write a readonly database}} + +finish_test