Index: src/pcache.c ================================================================== --- src/pcache.c +++ src/pcache.c @@ -650,11 +650,11 @@ int sqlite3PcacheSetSpillsize(PCache *p, int mxPage){ int res; assert( p->pCache!=0 ); if( mxPage ){ if( mxPage<0 ){ - mxPage = (int)((-1024*(i64)p->szCache)/(p->szPage+p->szExtra)); + mxPage = (int)((-1024*(i64)mxPage)/(p->szPage+p->szExtra)); } p->szSpill = mxPage; } res = numberOfCachePages(p); if( resszSpill ) res = p->szSpill; Index: src/pragma.c ================================================================== --- src/pragma.c +++ src/pragma.c @@ -767,26 +767,27 @@ ** ** The cache_spill=BOOLEAN setting applies to all attached schemas, ** not just the schema specified. */ case PragTyp_CACHE_SPILL: { - int size; assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); if( !zRight ){ if( sqlite3ReadSchema(pParse) ) goto pragma_out; returnSingleInt(v, "cache_spill", (db->flags & SQLITE_CacheSpill)==0 ? 0 : sqlite3BtreeSetSpillSize(pDb->pBt,0)); }else{ + int size = 1; if( sqlite3GetInt32(zRight, &size) ){ sqlite3BtreeSetSpillSize(pDb->pBt, size); } - if( sqlite3GetBoolean(zRight, 0) ){ + if( sqlite3GetBoolean(zRight, size!=0) ){ db->flags |= SQLITE_CacheSpill; }else{ db->flags &= ~SQLITE_CacheSpill; } + setAllPagerFlags(db); } break; } /* Index: test/pragma2.test ================================================================== --- test/pragma2.test +++ test/pragma2.test @@ -195,20 +195,31 @@ PRAGMA cache_spill; BEGIN; UPDATE t1 SET c=c+1; PRAGMA lock_status; } -} {100000 main reserved temp unknown} ;# Large cache spill threshold +} {100000 main reserved temp unknown} ;# Big spill threshold -> no excl lock do_test pragma2-4.5.3 { db eval { ROLLBACK; PRAGMA cache_spill=25; + PRAGMA main.cache_spill; + BEGIN; + UPDATE t1 SET c=c+1; + PRAGMA lock_status; + } +} {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock +do_test pragma2-4.5.4 { + db eval { + ROLLBACK; + PRAGMA cache_spill(-25); + PRAGMA main.cache_spill; BEGIN; UPDATE t1 SET c=c+1; PRAGMA lock_status; } -} {main exclusive temp unknown} ;# Large cache spill, so no exclusive lock +} {50 main exclusive temp unknown} ;# Small cache spill -> exclusive lock # Verify that newly attached databases inherit the cache_spill=OFF # setting. # @@ -229,8 +240,28 @@ PRAGMA cache_spill=ON; -- Applies to all databases BEGIN; UPDATE t2 SET c=c-1; PRAGMA lock_status; } {main unlocked temp unknown aux1 exclusive} +db close +forcedelete test.db +sqlite3 db test.db + +breakpoint +do_execsql_test pragma2-5.1 { + PRAGMA page_size=16384; + CREATE TABLE t1(x); + PRAGMA cache_size=2; + PRAGMA cache_spill=YES; + PRAGMA cache_spill; +} {2} +do_execsql_test pragma2-5.2 { + PRAGMA cache_spill=NO; + PRAGMA cache_spill; +} {0} +do_execsql_test pragma2-5.3 { + PRAGMA cache_spill(-51); + PRAGMA cache_spill; +} {3} test_restore_config_pagecache finish_test