| | @@ -656,11 +656,11 @@ |
| 656 | 656 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 657 | 657 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 658 | 658 | */ |
| 659 | 659 | #define SQLITE_VERSION "3.8.0" |
| 660 | 660 | #define SQLITE_VERSION_NUMBER 3008000 |
| 661 | | -#define SQLITE_SOURCE_ID "2013-08-15 22:40:21 f2d175f975cd0be63425424ec322a98fb650019e" |
| 661 | +#define SQLITE_SOURCE_ID "2013-08-19 11:15:48 a0d9ca4f07f1dc3a189864f8ed9cdb0b1d791b1a" |
| 662 | 662 | |
| 663 | 663 | /* |
| 664 | 664 | ** CAPI3REF: Run-Time Library Version Numbers |
| 665 | 665 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 666 | 666 | ** |
| | @@ -8587,11 +8587,11 @@ |
| 8587 | 8587 | #define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */ |
| 8588 | 8588 | |
| 8589 | 8589 | SQLITE_PRIVATE int sqlite3BtreeClose(Btree*); |
| 8590 | 8590 | SQLITE_PRIVATE int sqlite3BtreeSetCacheSize(Btree*,int); |
| 8591 | 8591 | SQLITE_PRIVATE int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64); |
| 8592 | | -SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel(Btree*,int,int,int); |
| 8592 | +SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags(Btree*,unsigned); |
| 8593 | 8593 | SQLITE_PRIVATE int sqlite3BtreeSyncDisabled(Btree*); |
| 8594 | 8594 | SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix); |
| 8595 | 8595 | SQLITE_PRIVATE int sqlite3BtreeGetPageSize(Btree*); |
| 8596 | 8596 | SQLITE_PRIVATE int sqlite3BtreeMaxPageCount(Btree*,int); |
| 8597 | 8597 | SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree*); |
| | @@ -9291,10 +9291,22 @@ |
| 9291 | 9291 | ** Flags that make up the mask passed to sqlite3PagerAcquire(). |
| 9292 | 9292 | */ |
| 9293 | 9293 | #define PAGER_ACQUIRE_NOCONTENT 0x01 /* Do not load data from disk */ |
| 9294 | 9294 | #define PAGER_ACQUIRE_READONLY 0x02 /* Read-only page is acceptable */ |
| 9295 | 9295 | |
| 9296 | +/* |
| 9297 | +** Flags for sqlite3PagerSetFlags() |
| 9298 | +*/ |
| 9299 | +#define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */ |
| 9300 | +#define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */ |
| 9301 | +#define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */ |
| 9302 | +#define PAGER_SYNCHRONOUS_MASK 0x03 /* Mask for three values above */ |
| 9303 | +#define PAGER_FULLFSYNC 0x04 /* PRAGMA fullfsync=ON */ |
| 9304 | +#define PAGER_CKPT_FULLFSYNC 0x08 /* PRAGMA checkpoint_fullfsync=ON */ |
| 9305 | +#define PAGER_CACHESPILL 0x10 /* PRAGMA cache_spill=ON */ |
| 9306 | +#define PAGER_FLAGS_MASK 0x1c /* All above except SYNCHRONOUS */ |
| 9307 | + |
| 9296 | 9308 | /* |
| 9297 | 9309 | ** The remainder of this file contains the declarations of the functions |
| 9298 | 9310 | ** that make up the Pager sub-system API. See source code comments for |
| 9299 | 9311 | ** a detailed description of each routine. |
| 9300 | 9312 | */ |
| | @@ -9317,11 +9329,11 @@ |
| 9317 | 9329 | SQLITE_PRIVATE int sqlite3PagerSetPagesize(Pager*, u32*, int); |
| 9318 | 9330 | SQLITE_PRIVATE int sqlite3PagerMaxPageCount(Pager*, int); |
| 9319 | 9331 | SQLITE_PRIVATE void sqlite3PagerSetCachesize(Pager*, int); |
| 9320 | 9332 | SQLITE_PRIVATE void sqlite3PagerSetMmapLimit(Pager *, sqlite3_int64); |
| 9321 | 9333 | SQLITE_PRIVATE void sqlite3PagerShrink(Pager*); |
| 9322 | | -SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel(Pager*,int,int,int); |
| 9334 | +SQLITE_PRIVATE void sqlite3PagerSetFlags(Pager*,unsigned); |
| 9323 | 9335 | SQLITE_PRIVATE int sqlite3PagerLockingMode(Pager *, int); |
| 9324 | 9336 | SQLITE_PRIVATE int sqlite3PagerSetJournalMode(Pager *, int); |
| 9325 | 9337 | SQLITE_PRIVATE int sqlite3PagerGetJournalMode(Pager*); |
| 9326 | 9338 | SQLITE_PRIVATE int sqlite3PagerOkToChangeJournalMode(Pager*); |
| 9327 | 9339 | SQLITE_PRIVATE i64 sqlite3PagerJournalSizeLimit(Pager *, i64); |
| | @@ -10180,36 +10192,37 @@ |
| 10180 | 10192 | /* |
| 10181 | 10193 | ** Possible values for the sqlite3.flags. |
| 10182 | 10194 | */ |
| 10183 | 10195 | #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ |
| 10184 | 10196 | #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */ |
| 10185 | | -#define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */ |
| 10186 | | -#define SQLITE_ShortColNames 0x00000008 /* Show short columns names */ |
| 10187 | | -#define SQLITE_CountRows 0x00000010 /* Count rows changed by INSERT, */ |
| 10197 | +#define SQLITE_FullFSync 0x00000004 /* Use full fsync on the backend */ |
| 10198 | +#define SQLITE_CkptFullFSync 0x00000008 /* Use full fsync for checkpoint */ |
| 10199 | +#define SQLITE_CacheSpill 0x00000010 /* OK to spill pager cache */ |
| 10200 | +#define SQLITE_FullColNames 0x00000020 /* Show full column names on SELECT */ |
| 10201 | +#define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ |
| 10202 | +#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ |
| 10188 | 10203 | /* DELETE, or UPDATE and return */ |
| 10189 | 10204 | /* the count using a callback. */ |
| 10190 | | -#define SQLITE_NullCallback 0x00000020 /* Invoke the callback once if the */ |
| 10205 | +#define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ |
| 10191 | 10206 | /* result set is empty */ |
| 10192 | | -#define SQLITE_SqlTrace 0x00000040 /* Debug print SQL as it executes */ |
| 10193 | | -#define SQLITE_VdbeListing 0x00000080 /* Debug listings of VDBE programs */ |
| 10194 | | -#define SQLITE_WriteSchema 0x00000100 /* OK to update SQLITE_MASTER */ |
| 10195 | | -#define SQLITE_VdbeAddopTrace 0x00000200 /* Trace sqlite3VdbeAddOp() calls */ |
| 10196 | | -#define SQLITE_IgnoreChecks 0x00000400 /* Do not enforce check constraints */ |
| 10197 | | -#define SQLITE_ReadUncommitted 0x0000800 /* For shared-cache mode */ |
| 10198 | | -#define SQLITE_LegacyFileFmt 0x00001000 /* Create new databases in format 1 */ |
| 10199 | | -#define SQLITE_FullFSync 0x00002000 /* Use full fsync on the backend */ |
| 10200 | | -#define SQLITE_CkptFullFSync 0x00004000 /* Use full fsync for checkpoint */ |
| 10201 | | -#define SQLITE_RecoveryMode 0x00008000 /* Ignore schema errors */ |
| 10202 | | -#define SQLITE_ReverseOrder 0x00010000 /* Reverse unordered SELECTs */ |
| 10203 | | -#define SQLITE_RecTriggers 0x00020000 /* Enable recursive triggers */ |
| 10204 | | -#define SQLITE_ForeignKeys 0x00040000 /* Enforce foreign key constraints */ |
| 10205 | | -#define SQLITE_AutoIndex 0x00080000 /* Enable automatic indexes */ |
| 10206 | | -#define SQLITE_PreferBuiltin 0x00100000 /* Preference to built-in funcs */ |
| 10207 | | -#define SQLITE_LoadExtension 0x00200000 /* Enable load_extension */ |
| 10208 | | -#define SQLITE_EnableTrigger 0x00400000 /* True to enable triggers */ |
| 10209 | | -#define SQLITE_DeferFKs 0x00800000 /* Defer all FK constraints */ |
| 10210 | | -#define SQLITE_QueryOnly 0x01000000 /* Disable database changes */ |
| 10207 | +#define SQLITE_SqlTrace 0x00000200 /* Debug print SQL as it executes */ |
| 10208 | +#define SQLITE_VdbeListing 0x00000400 /* Debug listings of VDBE programs */ |
| 10209 | +#define SQLITE_WriteSchema 0x00000800 /* OK to update SQLITE_MASTER */ |
| 10210 | +#define SQLITE_VdbeAddopTrace 0x00001000 /* Trace sqlite3VdbeAddOp() calls */ |
| 10211 | +#define SQLITE_IgnoreChecks 0x00002000 /* Do not enforce check constraints */ |
| 10212 | +#define SQLITE_ReadUncommitted 0x0004000 /* For shared-cache mode */ |
| 10213 | +#define SQLITE_LegacyFileFmt 0x00008000 /* Create new databases in format 1 */ |
| 10214 | +#define SQLITE_RecoveryMode 0x00010000 /* Ignore schema errors */ |
| 10215 | +#define SQLITE_ReverseOrder 0x00020000 /* Reverse unordered SELECTs */ |
| 10216 | +#define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */ |
| 10217 | +#define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */ |
| 10218 | +#define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */ |
| 10219 | +#define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */ |
| 10220 | +#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ |
| 10221 | +#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */ |
| 10222 | +#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ |
| 10223 | +#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ |
| 10211 | 10224 | |
| 10212 | 10225 | |
| 10213 | 10226 | /* |
| 10214 | 10227 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 10215 | 10228 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| | @@ -38794,10 +38807,17 @@ |
| 38794 | 38807 | #ifndef SQLITE_OMIT_WAL |
| 38795 | 38808 | u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */ |
| 38796 | 38809 | #endif |
| 38797 | 38810 | }; |
| 38798 | 38811 | |
| 38812 | +/* |
| 38813 | +** Bits of the Pager.doNotSpill flag. See further description below. |
| 38814 | +*/ |
| 38815 | +#define SPILLFLAG_OFF 0x01 /* Never spill cache. Set via pragma */ |
| 38816 | +#define SPILLFLAG_ROLLBACK 0x02 /* Current rolling back, so do not spill */ |
| 38817 | +#define SPILLFLAG_NOSYNC 0x04 /* Spill is ok, but do not sync */ |
| 38818 | + |
| 38799 | 38819 | /* |
| 38800 | 38820 | ** A open page cache is an instance of struct Pager. A description of |
| 38801 | 38821 | ** some of the more important member variables follows: |
| 38802 | 38822 | ** |
| 38803 | 38823 | ** eState |
| | @@ -38860,23 +38880,25 @@ |
| 38860 | 38880 | ** The flag is cleared as soon as the journal file is finalized (either |
| 38861 | 38881 | ** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the |
| 38862 | 38882 | ** journal file from being successfully finalized, the setMaster flag |
| 38863 | 38883 | ** is cleared anyway (and the pager will move to ERROR state). |
| 38864 | 38884 | ** |
| 38865 | | -** doNotSpill, doNotSyncSpill |
| 38866 | | -** |
| 38867 | | -** These two boolean variables control the behavior of cache-spills |
| 38868 | | -** (calls made by the pcache module to the pagerStress() routine to |
| 38869 | | -** write cached data to the file-system in order to free up memory). |
| 38870 | | -** |
| 38871 | | -** When doNotSpill is non-zero, writing to the database from pagerStress() |
| 38872 | | -** is disabled altogether. This is done in a very obscure case that |
| 38885 | +** doNotSpill |
| 38886 | +** |
| 38887 | +** This variables control the behavior of cache-spills (calls made by |
| 38888 | +** the pcache module to the pagerStress() routine to write cached data |
| 38889 | +** to the file-system in order to free up memory). |
| 38890 | +** |
| 38891 | +** When bits SPILLFLAG_OFF or SPILLFLAG_ROLLBACK of doNotSpill are set, |
| 38892 | +** writing to the database from pagerStress() is disabled altogether. |
| 38893 | +** The SPILLFLAG_ROLLBACK case is done in a very obscure case that |
| 38873 | 38894 | ** comes up during savepoint rollback that requires the pcache module |
| 38874 | 38895 | ** to allocate a new page to prevent the journal file from being written |
| 38875 | | -** while it is being traversed by code in pager_playback(). |
| 38896 | +** while it is being traversed by code in pager_playback(). The SPILLFLAG_OFF |
| 38897 | +** case is a user preference. |
| 38876 | 38898 | ** |
| 38877 | | -** If doNotSyncSpill is non-zero, writing to the database from pagerStress() |
| 38899 | +** If the SPILLFLAG_NOSYNC bit is set, writing to the database from pagerStress() |
| 38878 | 38900 | ** is permitted, but syncing the journal file is not. This flag is set |
| 38879 | 38901 | ** by sqlite3PagerWrite() when the file-system sector-size is larger than |
| 38880 | 38902 | ** the database page-size in order to prevent a journal sync from happening |
| 38881 | 38903 | ** in between the journalling of two pages on the same sector. |
| 38882 | 38904 | ** |
| | @@ -38976,11 +38998,10 @@ |
| 38976 | 38998 | u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */ |
| 38977 | 38999 | u8 eLock; /* Current lock held on database file */ |
| 38978 | 39000 | u8 changeCountDone; /* Set after incrementing the change-counter */ |
| 38979 | 39001 | u8 setMaster; /* True if a m-j name has been written to jrnl */ |
| 38980 | 39002 | u8 doNotSpill; /* Do not spill the cache when non-zero */ |
| 38981 | | - u8 doNotSyncSpill; /* Do not do a spill that requires jrnl sync */ |
| 38982 | 39003 | u8 subjInMemory; /* True to use in-memory sub-journals */ |
| 38983 | 39004 | Pgno dbSize; /* Number of pages in the database */ |
| 38984 | 39005 | Pgno dbOrigSize; /* dbSize before the current transaction */ |
| 38985 | 39006 | Pgno dbFileSize; /* Number of pages in the database file */ |
| 38986 | 39007 | Pgno dbHintSize; /* Value passed to FCNTL_SIZE_HINT call */ |
| | @@ -40636,15 +40657,15 @@ |
| 40636 | 40657 | ** the data just read from the sub-journal. Mark the page as dirty |
| 40637 | 40658 | ** and if the pager requires a journal-sync, then mark the page as |
| 40638 | 40659 | ** requiring a journal-sync before it is written. |
| 40639 | 40660 | */ |
| 40640 | 40661 | assert( isSavepnt ); |
| 40641 | | - assert( pPager->doNotSpill==0 ); |
| 40642 | | - pPager->doNotSpill++; |
| 40662 | + assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)==0 ); |
| 40663 | + pPager->doNotSpill |= SPILLFLAG_ROLLBACK; |
| 40643 | 40664 | rc = sqlite3PagerAcquire(pPager, pgno, &pPg, 1); |
| 40644 | | - assert( pPager->doNotSpill==1 ); |
| 40645 | | - pPager->doNotSpill--; |
| 40665 | + assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 ); |
| 40666 | + pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK; |
| 40646 | 40667 | if( rc!=SQLITE_OK ) return rc; |
| 40647 | 40668 | pPg->flags &= ~PGHDR_NEED_READ; |
| 40648 | 40669 | sqlite3PcacheMakeDirty(pPg); |
| 40649 | 40670 | } |
| 40650 | 40671 | if( pPg ){ |
| | @@ -41745,13 +41766,16 @@ |
| 41745 | 41766 | SQLITE_PRIVATE void sqlite3PagerShrink(Pager *pPager){ |
| 41746 | 41767 | sqlite3PcacheShrink(pPager->pPCache); |
| 41747 | 41768 | } |
| 41748 | 41769 | |
| 41749 | 41770 | /* |
| 41750 | | -** Adjust the robustness of the database to damage due to OS crashes |
| 41751 | | -** or power failures by changing the number of syncs()s when writing |
| 41752 | | -** the rollback journal. There are three levels: |
| 41771 | +** Adjust settings of the pager to those specified in the pgFlags parameter. |
| 41772 | +** |
| 41773 | +** The "level" in pgFlags & PAGER_SYNCHRONOUS_MASK sets the robustness |
| 41774 | +** of the database to damage due to OS crashes or power failures by |
| 41775 | +** changing the number of syncs()s when writing the journals. |
| 41776 | +** There are three levels: |
| 41753 | 41777 | ** |
| 41754 | 41778 | ** OFF sqlite3OsSync() is never called. This is the default |
| 41755 | 41779 | ** for temporary and transient files. |
| 41756 | 41780 | ** |
| 41757 | 41781 | ** NORMAL The journal is synced once before writes begin on the |
| | @@ -41788,26 +41812,25 @@ |
| 41788 | 41812 | ** |
| 41789 | 41813 | ** Numeric values associated with these states are OFF==1, NORMAL=2, |
| 41790 | 41814 | ** and FULL=3. |
| 41791 | 41815 | */ |
| 41792 | 41816 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 41793 | | -SQLITE_PRIVATE void sqlite3PagerSetSafetyLevel( |
| 41817 | +SQLITE_PRIVATE void sqlite3PagerSetFlags( |
| 41794 | 41818 | Pager *pPager, /* The pager to set safety level for */ |
| 41795 | | - int level, /* PRAGMA synchronous. 1=OFF, 2=NORMAL, 3=FULL */ |
| 41796 | | - int bFullFsync, /* PRAGMA fullfsync */ |
| 41797 | | - int bCkptFullFsync /* PRAGMA checkpoint_fullfsync */ |
| 41819 | + unsigned pgFlags /* Various flags */ |
| 41798 | 41820 | ){ |
| 41821 | + unsigned level = pgFlags & PAGER_SYNCHRONOUS_MASK; |
| 41799 | 41822 | assert( level>=1 && level<=3 ); |
| 41800 | 41823 | pPager->noSync = (level==1 || pPager->tempFile) ?1:0; |
| 41801 | 41824 | pPager->fullSync = (level==3 && !pPager->tempFile) ?1:0; |
| 41802 | 41825 | if( pPager->noSync ){ |
| 41803 | 41826 | pPager->syncFlags = 0; |
| 41804 | 41827 | pPager->ckptSyncFlags = 0; |
| 41805 | | - }else if( bFullFsync ){ |
| 41828 | + }else if( pgFlags & PAGER_FULLFSYNC ){ |
| 41806 | 41829 | pPager->syncFlags = SQLITE_SYNC_FULL; |
| 41807 | 41830 | pPager->ckptSyncFlags = SQLITE_SYNC_FULL; |
| 41808 | | - }else if( bCkptFullFsync ){ |
| 41831 | + }else if( pgFlags & PAGER_CKPT_FULLFSYNC ){ |
| 41809 | 41832 | pPager->syncFlags = SQLITE_SYNC_NORMAL; |
| 41810 | 41833 | pPager->ckptSyncFlags = SQLITE_SYNC_FULL; |
| 41811 | 41834 | }else{ |
| 41812 | 41835 | pPager->syncFlags = SQLITE_SYNC_NORMAL; |
| 41813 | 41836 | pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL; |
| | @@ -41814,10 +41837,15 @@ |
| 41814 | 41837 | } |
| 41815 | 41838 | pPager->walSyncFlags = pPager->syncFlags; |
| 41816 | 41839 | if( pPager->fullSync ){ |
| 41817 | 41840 | pPager->walSyncFlags |= WAL_SYNC_TRANSACTIONS; |
| 41818 | 41841 | } |
| 41842 | + if( pgFlags & PAGER_CACHESPILL ){ |
| 41843 | + pPager->doNotSpill &= ~SPILLFLAG_OFF; |
| 41844 | + }else{ |
| 41845 | + pPager->doNotSpill |= SPILLFLAG_OFF; |
| 41846 | + } |
| 41819 | 41847 | } |
| 41820 | 41848 | #endif |
| 41821 | 41849 | |
| 41822 | 41850 | /* |
| 41823 | 41851 | ** The following global variable is incremented whenever the library |
| | @@ -42714,28 +42742,34 @@ |
| 42714 | 42742 | int rc = SQLITE_OK; |
| 42715 | 42743 | |
| 42716 | 42744 | assert( pPg->pPager==pPager ); |
| 42717 | 42745 | assert( pPg->flags&PGHDR_DIRTY ); |
| 42718 | 42746 | |
| 42719 | | - /* The doNotSyncSpill flag is set during times when doing a sync of |
| 42747 | + /* The doNotSpill NOSYNC bit is set during times when doing a sync of |
| 42720 | 42748 | ** journal (and adding a new header) is not allowed. This occurs |
| 42721 | 42749 | ** during calls to sqlite3PagerWrite() while trying to journal multiple |
| 42722 | 42750 | ** pages belonging to the same sector. |
| 42723 | 42751 | ** |
| 42724 | | - ** The doNotSpill flag inhibits all cache spilling regardless of whether |
| 42725 | | - ** or not a sync is required. This is set during a rollback. |
| 42752 | + ** The doNotSpill ROLLBACK and OFF bits inhibits all cache spilling |
| 42753 | + ** regardless of whether or not a sync is required. This is set during |
| 42754 | + ** a rollback or by user request, respectively. |
| 42726 | 42755 | ** |
| 42727 | 42756 | ** Spilling is also prohibited when in an error state since that could |
| 42728 | 42757 | ** lead to database corruption. In the current implementaton it |
| 42729 | 42758 | ** is impossible for sqlite3PcacheFetch() to be called with createFlag==1 |
| 42730 | 42759 | ** while in the error state, hence it is impossible for this routine to |
| 42731 | 42760 | ** be called in the error state. Nevertheless, we include a NEVER() |
| 42732 | 42761 | ** test for the error state as a safeguard against future changes. |
| 42733 | 42762 | */ |
| 42734 | 42763 | if( NEVER(pPager->errCode) ) return SQLITE_OK; |
| 42735 | | - if( pPager->doNotSpill ) return SQLITE_OK; |
| 42736 | | - if( pPager->doNotSyncSpill && (pPg->flags & PGHDR_NEED_SYNC)!=0 ){ |
| 42764 | + testcase( pPager->doNotSpill & SPILLFLAG_ROLLBACK ); |
| 42765 | + testcase( pPager->doNotSpill & SPILLFLAG_OFF ); |
| 42766 | + testcase( pPager->doNotSpill & SPILLFLAG_NOSYNC ); |
| 42767 | + if( pPager->doNotSpill |
| 42768 | + && ((pPager->doNotSpill & (SPILLFLAG_ROLLBACK|SPILLFLAG_OFF))!=0 |
| 42769 | + || (pPg->flags & PGHDR_NEED_SYNC)!=0) |
| 42770 | + ){ |
| 42737 | 42771 | return SQLITE_OK; |
| 42738 | 42772 | } |
| 42739 | 42773 | |
| 42740 | 42774 | pPg->pDirty = 0; |
| 42741 | 42775 | if( pagerUseWal(pPager) ){ |
| | @@ -44085,17 +44119,17 @@ |
| 44085 | 44119 | Pgno pg1; /* First page of the sector pPg is located on. */ |
| 44086 | 44120 | int nPage = 0; /* Number of pages starting at pg1 to journal */ |
| 44087 | 44121 | int ii; /* Loop counter */ |
| 44088 | 44122 | int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */ |
| 44089 | 44123 | |
| 44090 | | - /* Set the doNotSyncSpill flag to 1. This is because we cannot allow |
| 44124 | + /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow |
| 44091 | 44125 | ** a journal header to be written between the pages journaled by |
| 44092 | 44126 | ** this function. |
| 44093 | 44127 | */ |
| 44094 | 44128 | assert( !MEMDB ); |
| 44095 | | - assert( pPager->doNotSyncSpill==0 ); |
| 44096 | | - pPager->doNotSyncSpill++; |
| 44129 | + assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)==0 ); |
| 44130 | + pPager->doNotSpill |= SPILLFLAG_NOSYNC; |
| 44097 | 44131 | |
| 44098 | 44132 | /* This trick assumes that both the page-size and sector-size are |
| 44099 | 44133 | ** an integer power of 2. It sets variable pg1 to the identifier |
| 44100 | 44134 | ** of the first page of the sector pPg is located on. |
| 44101 | 44135 | */ |
| | @@ -44150,12 +44184,12 @@ |
| 44150 | 44184 | sqlite3PagerUnref(pPage); |
| 44151 | 44185 | } |
| 44152 | 44186 | } |
| 44153 | 44187 | } |
| 44154 | 44188 | |
| 44155 | | - assert( pPager->doNotSyncSpill==1 ); |
| 44156 | | - pPager->doNotSyncSpill--; |
| 44189 | + assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 ); |
| 44190 | + pPager->doNotSpill &= ~SPILLFLAG_NOSYNC; |
| 44157 | 44191 | }else{ |
| 44158 | 44192 | rc = pager_write(pDbPage); |
| 44159 | 44193 | } |
| 44160 | 44194 | return rc; |
| 44161 | 44195 | } |
| | @@ -51727,21 +51761,18 @@ |
| 51727 | 51761 | ** there is a high probability of damage) Level 2 is the default. There |
| 51728 | 51762 | ** is a very low but non-zero probability of damage. Level 3 reduces the |
| 51729 | 51763 | ** probability of damage to near zero but with a write performance reduction. |
| 51730 | 51764 | */ |
| 51731 | 51765 | #ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 51732 | | -SQLITE_PRIVATE int sqlite3BtreeSetSafetyLevel( |
| 51766 | +SQLITE_PRIVATE int sqlite3BtreeSetPagerFlags( |
| 51733 | 51767 | Btree *p, /* The btree to set the safety level on */ |
| 51734 | | - int level, /* PRAGMA synchronous. 1=OFF, 2=NORMAL, 3=FULL */ |
| 51735 | | - int fullSync, /* PRAGMA fullfsync. */ |
| 51736 | | - int ckptFullSync /* PRAGMA checkpoint_fullfync */ |
| 51768 | + unsigned pgFlags /* Various PAGER_* flags */ |
| 51737 | 51769 | ){ |
| 51738 | 51770 | BtShared *pBt = p->pBt; |
| 51739 | 51771 | assert( sqlite3_mutex_held(p->db->mutex) ); |
| 51740 | | - assert( level>=1 && level<=3 ); |
| 51741 | 51772 | sqlite3BtreeEnter(p); |
| 51742 | | - sqlite3PagerSetSafetyLevel(pBt->pPager, level, fullSync, ckptFullSync); |
| 51773 | + sqlite3PagerSetFlags(pBt->pPager, pgFlags); |
| 51743 | 51774 | sqlite3BtreeLeave(p); |
| 51744 | 51775 | return SQLITE_OK; |
| 51745 | 51776 | } |
| 51746 | 51777 | #endif |
| 51747 | 51778 | |
| | @@ -71760,10 +71791,11 @@ |
| 71760 | 71791 | /* This is the only way out of this procedure. We have to |
| 71761 | 71792 | ** release the mutexes on btrees that were acquired at the |
| 71762 | 71793 | ** top. */ |
| 71763 | 71794 | vdbe_return: |
| 71764 | 71795 | db->lastRowid = lastRowid; |
| 71796 | + testcase( nVmStep>0 ); |
| 71765 | 71797 | p->aCounter[SQLITE_STMTSTATUS_VM_STEP-1] += (int)nVmStep; |
| 71766 | 71798 | sqlite3VdbeLeave(p); |
| 71767 | 71799 | return rc; |
| 71768 | 71800 | |
| 71769 | 71801 | /* Jump to here if a string or blob larger than SQLITE_MAX_LENGTH |
| | @@ -81769,10 +81801,11 @@ |
| 81769 | 81801 | } |
| 81770 | 81802 | pPager = sqlite3BtreePager(aNew->pBt); |
| 81771 | 81803 | sqlite3PagerLockingMode(pPager, db->dfltLockMode); |
| 81772 | 81804 | sqlite3BtreeSecureDelete(aNew->pBt, |
| 81773 | 81805 | sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) ); |
| 81806 | + sqlite3BtreeSetPagerFlags(aNew->pBt, 3 | (db->flags & PAGER_FLAGS_MASK)); |
| 81774 | 81807 | } |
| 81775 | 81808 | aNew->safety_level = 3; |
| 81776 | 81809 | aNew->zName = sqlite3DbStrDup(db, zName); |
| 81777 | 81810 | if( rc==SQLITE_OK && aNew->zName==0 ){ |
| 81778 | 81811 | rc = SQLITE_NOMEM; |
| | @@ -85289,11 +85322,11 @@ |
| 85289 | 85322 | |
| 85290 | 85323 | /* Gather the complete text of the CREATE INDEX statement into |
| 85291 | 85324 | ** the zStmt variable |
| 85292 | 85325 | */ |
| 85293 | 85326 | if( pStart ){ |
| 85294 | | - int n = (pParse->sLastToken.z - pName->z) + pParse->sLastToken.n; |
| 85327 | + int n = (int)(pParse->sLastToken.z - pName->z) + pParse->sLastToken.n; |
| 85295 | 85328 | if( pName->z[n-1]==';' ) n--; |
| 85296 | 85329 | /* A named index with an explicit CREATE INDEX statement */ |
| 85297 | 85330 | zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s", |
| 85298 | 85331 | onError==OE_None ? "" : " UNIQUE", n, pName->z); |
| 85299 | 85332 | }else{ |
| | @@ -93834,10 +93867,38 @@ |
| 93834 | 93867 | sqlite3VdbeAddOp4(v, OP_Int64, 0, mem, 0, (char*)pI64, P4_INT64); |
| 93835 | 93868 | sqlite3VdbeSetNumCols(v, 1); |
| 93836 | 93869 | sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, SQLITE_STATIC); |
| 93837 | 93870 | sqlite3VdbeAddOp2(v, OP_ResultRow, mem, 1); |
| 93838 | 93871 | } |
| 93872 | + |
| 93873 | + |
| 93874 | +/* |
| 93875 | +** Set the safety_level and pager flags for pager iDb. Or if iDb<0 |
| 93876 | +** set these values for all pagers. |
| 93877 | +*/ |
| 93878 | +#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 93879 | +static void setAllPagerFlags(sqlite3 *db){ |
| 93880 | + if( db->autoCommit ){ |
| 93881 | + Db *pDb = db->aDb; |
| 93882 | + int n = db->nDb; |
| 93883 | + assert( SQLITE_FullFSync==PAGER_FULLFSYNC ); |
| 93884 | + assert( SQLITE_CkptFullFSync==PAGER_CKPT_FULLFSYNC ); |
| 93885 | + assert( SQLITE_CacheSpill==PAGER_CACHESPILL ); |
| 93886 | + assert( (PAGER_FULLFSYNC | PAGER_CKPT_FULLFSYNC | PAGER_CACHESPILL) |
| 93887 | + == PAGER_FLAGS_MASK ); |
| 93888 | + assert( (pDb->safety_level & PAGER_SYNCHRONOUS_MASK)==pDb->safety_level ); |
| 93889 | + while( (n--) > 0 ){ |
| 93890 | + if( pDb->pBt ){ |
| 93891 | + sqlite3BtreeSetPagerFlags(pDb->pBt, |
| 93892 | + pDb->safety_level | (db->flags & PAGER_FLAGS_MASK) ); |
| 93893 | + } |
| 93894 | + pDb++; |
| 93895 | + } |
| 93896 | + } |
| 93897 | +} |
| 93898 | +#endif |
| 93899 | + |
| 93839 | 93900 | |
| 93840 | 93901 | #ifndef SQLITE_OMIT_FLAG_PRAGMAS |
| 93841 | 93902 | /* |
| 93842 | 93903 | ** Check to see if zRight and zLeft refer to a pragma that queries |
| 93843 | 93904 | ** or changes one of the flags in db->flags. Return 1 if so and 0 if not. |
| | @@ -93853,10 +93914,11 @@ |
| 93853 | 93914 | { "count_changes", SQLITE_CountRows }, |
| 93854 | 93915 | { "empty_result_callbacks", SQLITE_NullCallback }, |
| 93855 | 93916 | { "legacy_file_format", SQLITE_LegacyFileFmt }, |
| 93856 | 93917 | { "fullfsync", SQLITE_FullFSync }, |
| 93857 | 93918 | { "checkpoint_fullfsync", SQLITE_CkptFullFSync }, |
| 93919 | + { "cache_spill", SQLITE_CacheSpill }, |
| 93858 | 93920 | { "reverse_unordered_selects", SQLITE_ReverseOrder }, |
| 93859 | 93921 | { "query_only", SQLITE_QueryOnly }, |
| 93860 | 93922 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 93861 | 93923 | { "automatic_index", SQLITE_AutoIndex }, |
| 93862 | 93924 | #endif |
| | @@ -94643,19 +94705,19 @@ |
| 94643 | 94705 | if( !db->autoCommit ){ |
| 94644 | 94706 | sqlite3ErrorMsg(pParse, |
| 94645 | 94707 | "Safety level may not be changed inside a transaction"); |
| 94646 | 94708 | }else{ |
| 94647 | 94709 | pDb->safety_level = getSafetyLevel(zRight,0,1)+1; |
| 94710 | + setAllPagerFlags(db); |
| 94648 | 94711 | } |
| 94649 | 94712 | } |
| 94650 | 94713 | }else |
| 94651 | 94714 | #endif /* SQLITE_OMIT_PAGER_PRAGMAS */ |
| 94652 | 94715 | |
| 94653 | 94716 | #ifndef SQLITE_OMIT_FLAG_PRAGMAS |
| 94654 | 94717 | if( flagPragma(pParse, zLeft, zRight) ){ |
| 94655 | | - /* The flagPragma() subroutine also generates any necessary code |
| 94656 | | - ** there is nothing more to do here */ |
| 94718 | + setAllPagerFlags(db); |
| 94657 | 94719 | }else |
| 94658 | 94720 | #endif /* SQLITE_OMIT_FLAG_PRAGMAS */ |
| 94659 | 94721 | |
| 94660 | 94722 | #ifndef SQLITE_OMIT_SCHEMA_PRAGMAS |
| 94661 | 94723 | /* |
| | @@ -95482,21 +95544,10 @@ |
| 95482 | 95544 | #endif |
| 95483 | 95545 | |
| 95484 | 95546 | |
| 95485 | 95547 | {/* Empty ELSE clause */} |
| 95486 | 95548 | |
| 95487 | | - /* |
| 95488 | | - ** Reset the safety level, in case the fullfsync flag or synchronous |
| 95489 | | - ** setting changed. |
| 95490 | | - */ |
| 95491 | | -#ifndef SQLITE_OMIT_PAGER_PRAGMAS |
| 95492 | | - if( db->autoCommit ){ |
| 95493 | | - sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level, |
| 95494 | | - (db->flags&SQLITE_FullFSync)!=0, |
| 95495 | | - (db->flags&SQLITE_CkptFullFSync)!=0); |
| 95496 | | - } |
| 95497 | | -#endif |
| 95498 | 95549 | pragma_out: |
| 95499 | 95550 | sqlite3DbFree(db, zLeft); |
| 95500 | 95551 | sqlite3DbFree(db, zRight); |
| 95501 | 95552 | } |
| 95502 | 95553 | |
| | @@ -109541,10 +109592,11 @@ |
| 109541 | 109592 | |
| 109542 | 109593 | pWC = pBuilder->pWC; |
| 109543 | 109594 | if( pWInfo->wctrlFlags & WHERE_AND_ONLY ) return SQLITE_OK; |
| 109544 | 109595 | pWCEnd = pWC->a + pWC->nTerm; |
| 109545 | 109596 | pNew = pBuilder->pNew; |
| 109597 | + memset(&sSum, 0, sizeof(sSum)); |
| 109546 | 109598 | |
| 109547 | 109599 | for(pTerm=pWC->a; pTerm<pWCEnd && rc==SQLITE_OK; pTerm++){ |
| 109548 | 109600 | if( (pTerm->eOperator & WO_OR)!=0 |
| 109549 | 109601 | && (pTerm->u.pOrInfo->indexable & pNew->maskSelf)!=0 |
| 109550 | 109602 | ){ |
| | @@ -117967,11 +118019,11 @@ |
| 117967 | 118019 | memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit)); |
| 117968 | 118020 | db->autoCommit = 1; |
| 117969 | 118021 | db->nextAutovac = -1; |
| 117970 | 118022 | db->szMmap = sqlite3GlobalConfig.szMmap; |
| 117971 | 118023 | db->nextPagesize = 0; |
| 117972 | | - db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger |
| 118024 | + db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger | SQLITE_CacheSpill |
| 117973 | 118025 | #if !defined(SQLITE_DEFAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX |
| 117974 | 118026 | | SQLITE_AutoIndex |
| 117975 | 118027 | #endif |
| 117976 | 118028 | #if SQLITE_DEFAULT_FILE_FORMAT<4 |
| 117977 | 118029 | | SQLITE_LegacyFileFmt |
| 117978 | 118030 | |