Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -3481,13 +3481,12 @@ */ int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){ if( mxPage>0 ){ pPager->mxPgno = mxPage; } - if( pPager->eState!=PAGER_OPEN && pPager->mxPgnodbSize ){ - pPager->mxPgno = pPager->dbSize; - } + assert( pPager->eState!=PAGER_OPEN ); /* Called only by OP_MaxPgcnt */ + assert( pPager->mxPgno>=pPager->dbSize ); /* OP_MaxPgcnt enforces this */ return pPager->mxPgno; } /* ** The following set of routines are used to disable the simulated Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -5791,20 +5791,26 @@ #ifndef SQLITE_OMIT_PAGER_PRAGMAS /* Opcode: MaxPgcnt P1 P2 P3 * * ** ** Try to set the maximum page count for database P1 to the value in P3. -** Do not let the maximum page count fall below the current page count. +** Do not let the maximum page count fall below the current page count and +** do not change the maximum page count value if P3==0. +** ** Store the maximum page count after the change in register P2. */ case OP_MaxPgcnt: { /* out2-prerelease */ - unsigned int pgcnt; + unsigned int newMax; Btree *pBt; pBt = db->aDb[pOp->p1].pBt; - pgcnt = sqlite3BtreeLastPage(pBt); - pOut->u.i = sqlite3BtreeMaxPageCount(pBt, pOp->p3p3); + newMax = 0; + if( pOp->p3 ){ + newMax = sqlite3BtreeLastPage(pBt); + if( pOp->p3>newMax ) newMax = pOp->p3; + } + pOut->u.i = sqlite3BtreeMaxPageCount(pBt, newMax); break; } #endif