Index: src/pager.c ================================================================== --- src/pager.c +++ src/pager.c @@ -16,11 +16,11 @@ ** is separate from the database file. The pager also implements file ** locking to prevent two processes from writing the same database ** file simultaneously, or one process from reading the database while ** another is writing. ** -** @(#) $Id: pager.c,v 1.480 2008/08/26 18:05:48 danielk1977 Exp $ +** @(#) $Id: pager.c,v 1.481 2008/08/26 21:07:27 drh Exp $ */ #ifndef SQLITE_OMIT_DISKIO #include "sqliteInt.h" /* @@ -1943,19 +1943,20 @@ int sqlite3PagerSetPagesize(Pager *pPager, u16 *pPageSize){ int rc = SQLITE_OK; u16 pageSize = *pPageSize; assert( pageSize==0 || (pageSize>=512 && pageSize<=SQLITE_MAX_PAGE_SIZE) ); if( pageSize && pageSize!=pPager->pageSize - && !pPager->memDb && sqlite3PcacheRefCount(pPager->pPCache)==0 + && (pPager->memDb==0 || pPager->dbSize==0) + && sqlite3PcacheRefCount(pPager->pPCache)==0 ){ char *pNew = (char *)sqlite3PageMalloc(pageSize); if( !pNew ){ rc = SQLITE_NOMEM; }else{ pager_reset(pPager); pPager->pageSize = pageSize; - setSectorSize(pPager); + if( !pPager->memDb ) setSectorSize(pPager); sqlite3PageFree(pPager->pTmpSpace); pPager->pTmpSpace = pNew; sqlite3PcacheSetPageSize(pPager->pPCache, pageSize); } } @@ -3570,11 +3571,15 @@ /* ** Sync the pager file to disk. */ int sqlite3PagerSync(Pager *pPager){ int rc; - rc = sqlite3OsSync(pPager->fd, pPager->sync_flags); + if( MEMDB ){ + rc = SQLITE_OK; + }else{ + rc = sqlite3OsSync(pPager->fd, pPager->sync_flags); + } return rc; } /* ** Sync the database file for the pager pPager. zMaster points to the name Index: src/vacuum.c ================================================================== --- src/vacuum.c +++ src/vacuum.c @@ -12,11 +12,11 @@ ** This file contains code used to implement the VACUUM command. ** ** Most of the code in this file may be omitted by defining the ** SQLITE_OMIT_VACUUM macro. ** -** $Id: vacuum.c,v 1.82 2008/08/23 16:17:56 danielk1977 Exp $ +** $Id: vacuum.c,v 1.83 2008/08/26 21:07:27 drh Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" #if !defined(SQLITE_OMIT_VACUUM) && !defined(SQLITE_OMIT_ATTACH) @@ -79,16 +79,18 @@ ** This routine implements the OP_Vacuum opcode of the VDBE. */ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){ int rc = SQLITE_OK; /* Return code from service routines */ Btree *pMain; /* The database being vacuumed */ + Pager *pMainPager; /* Pager for database being vacuumed */ Btree *pTemp; /* The temporary database we vacuum into */ char *zSql = 0; /* SQL statements */ int saved_flags; /* Saved value of the db->flags */ int saved_nChange; /* Saved value of db->nChange */ int saved_nTotalChange; /* Saved value of db->nTotalChange */ Db *pDb = 0; /* Database to detach at end of vacuum */ + int isMemDb; /* True is vacuuming a :memory: database */ int nRes; /* Save the current value of the write-schema flag before setting it. */ saved_flags = db->flags; saved_nChange = db->nChange; @@ -99,10 +101,12 @@ sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction"); rc = SQLITE_ERROR; goto end_of_vacuum; } pMain = db->aDb[0].pBt; + pMainPager = sqlite3BtreePager(pMain); + isMemDb = sqlite3PagerFile(pMainPager)->pMethods==0; /* Attach the temporary database as 'vacuum_db'. The synchronous pragma ** can be set to 'off' for this file, as it is not recovered if a crash ** occurs anyway. The integrity of the database is maintained by a ** (possibly synchronous) transaction opened on the main database before @@ -135,11 +139,11 @@ if( nKey ) db->nextPagesize = 0; } #endif if( sqlite3BtreeSetPageSize(pTemp, sqlite3BtreeGetPageSize(pMain), nRes) - || sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes) + || (!isMemDb && sqlite3BtreeSetPageSize(pTemp, db->nextPagesize, nRes)) || db->mallocFailed ){ rc = SQLITE_NOMEM; goto end_of_vacuum; } Index: test/pagesize.test ================================================================== --- test/pagesize.test +++ test/pagesize.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. # This file implements tests for the page_size PRAGMA. # -# $Id: pagesize.test,v 1.12 2007/04/06 21:42:22 drh Exp $ +# $Id: pagesize.test,v 1.13 2008/08/26 21:07:27 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -77,16 +77,27 @@ } foreach PGSZ {512 2048 4096 8192} { if {[info exists SQLITE_MAX_PAGE_SIZE] && $SQLITE_MAX_PAGE_SIZE<$PGSZ} continue ifcapable memorydb { - do_test pagesize-2.$PGSZ.0 { + do_test pagesize-2.$PGSZ.0.1 { db close sqlite3 db :memory: execsql "PRAGMA page_size=$PGSZ;" execsql {PRAGMA page_size} - } 1024 + } $PGSZ + do_test pagesize-2.$PGSZ.0.2 { + execsql {CREATE TABLE t1(x UNIQUE, y UNIQUE, z UNIQUE)} + execsql {PRAGMA page_size} + } $PGSZ + do_test pagesize-2.$PGSZ.0.3 { + execsql { + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(2,3,4); + SELECT * FROM t1; + } + } {1 2 3 2 3 4} } do_test pagesize-2.$PGSZ.1 { db close file delete -force test.db sqlite3 db test.db Index: test/vacuum3.test ================================================================== --- test/vacuum3.test +++ test/vacuum3.test @@ -10,11 +10,11 @@ #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is changing the database page size using a # VACUUM statement. # -# $Id: vacuum3.test,v 1.8 2008/08/23 16:17:56 danielk1977 Exp $ +# $Id: vacuum3.test,v 1.9 2008/08/26 21:07:27 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # If the VACUUM statement is disabled in the current build, skip all @@ -233,11 +233,27 @@ VACUUM; } execsql { SELECT * FROM abc } db2 } {1 2 3 4 5 6} +# Unable to change the page-size of an in-memory using vacuum. db2 close +sqlite3 db2 :memory: +do_test vacuum3-5.1 { + db2 eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1234); + PRAGMA page_size=4096; + VACUUM; + SELECT * FROM t1; + } +} {1234} +do_test vacuum3-5.2 { + db2 eval { + PRAGMA page_size + } +} {1024} set create_database_sql { BEGIN; CREATE TABLE t1(a, b, c); INSERT INTO t1 VALUES(1, randstr(50,50), randstr(50,50));