Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -4727,11 +4727,11 @@ #ifdef SQLITE_ENABLE_DESERIALIZE int memJM = 0; /* Memory journal mode */ #else # define memJM 0 #endif - int readOnly = 0; /* True if this is a read-only file */ + int readOnly = PAGER_READWRITE; /* True if this is a read-only file */ int journalFileSize; /* Bytes to allocate for each journal fd */ char *zPathname = 0; /* Full path to database file */ int nPathname = 0; /* Number of bytes in zPathname */ int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */ int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */ @@ -4858,10 +4858,11 @@ assert( !memDb ); #ifdef SQLITE_ENABLE_DESERIALIZE memJM = (fout&SQLITE_OPEN_MEMORY)!=0; #endif readOnly = (fout&SQLITE_OPEN_READONLY)!=0; + assert( readOnly==PAGER_READWRITE || readOnly==PAGER_READONLY ); /* If the file was successfully opened for read/write access, ** choose a default page size in case we have to create the ** database file. The default page size is the maximum of: ** @@ -4897,10 +4898,11 @@ } pPager->noLock = sqlite3_uri_boolean(zFilename, "nolock", 0); if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0 || sqlite3_uri_boolean(zFilename, "immutable", 0) ){ vfsFlags |= SQLITE_OPEN_READONLY; + readOnly = PAGER_IMMUTABLE; goto act_like_temp_file; } } }else{ /* If a temporary file is requested, it is not opened immediately. @@ -4916,11 +4918,13 @@ act_like_temp_file: tempFile = 1; pPager->eState = PAGER_READER; /* Pretend we already have a lock */ pPager->eLock = EXCLUSIVE_LOCK; /* Pretend we are in EXCLUSIVE mode */ pPager->noLock = 1; /* Do no locking */ - readOnly = (vfsFlags&SQLITE_OPEN_READONLY); + if( (vfsFlags & SQLITE_OPEN_READONLY)!=0 && readOnly==PAGER_READWRITE ){ + readOnly = PAGER_READONLY; + } } /* The following call to PagerSetPagesize() serves to set the value of ** Pager.pageSize and to allocate the Pager.pTmpSpace buffer. */ @@ -6694,10 +6698,16 @@ } /* ** Return TRUE if the database file is opened read-only. Return FALSE ** if the database is (in theory) writable. +** +** Actually, the return value is one of: +** +** PAGER_READWRITE (value 0 - false) +** PAGER_READONLY (value 1 - true) +** PAGER_IMMUTABLE (value 2 - also true) */ u8 sqlite3PagerIsreadonly(Pager *pPager){ return pPager->readOnly; } Index: src/pager.h ================================================================== --- src/pager.h +++ src/pager.h @@ -197,10 +197,14 @@ int sqlite3PagerWalFramesize(Pager *pPager); #endif /* Functions used to query pager state and configuration. */ u8 sqlite3PagerIsreadonly(Pager*); +/* Return values from sqlite3PagerIsreadonly() */ +#define PAGER_READWRITE 0 /* Read/write database */ +#define PAGER_READONLY 1 /* Read only but might change by outside forces */ +#define PAGER_IMMUTABLE 2 /* Guaranteed to never change */ u32 sqlite3PagerDataVersion(Pager*); #ifdef SQLITE_DEBUG int sqlite3PagerRefcount(Pager*); #endif int sqlite3PagerMemUsed(Pager*);