Updates to ensure the values of PRAGMA settings like "page_size", "auto_vacuum", "user_version" and "application_id" are not lost when a database is RBU vacuumed.

FossilOrigin-Name: 74ffea76b8c9ddd7699ce6ca77dce005bd7922ac
This commit is contained in:
dan 2016-04-19 19:27:09 +00:00
parent 46f0035b48
commit 1aea63032a
4 changed files with 125 additions and 16 deletions

View File

@ -174,6 +174,73 @@ foreach step {0 1} {
SELECT * FROM t4 ORDER BY b
} {a b c d e f j k l}
reset_db
do_execsql_test 1.7.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
INSERT INTO t1 VALUES(NULL, 'one');
INSERT INTO t1 VALUES(NULL, 'two');
DELETE FROM t1 WHERE a=2;
INSERT INTO t1 VALUES(NULL, 'three');
INSERT INTO t1 VALUES(NULL, 'four');
DELETE FROM t1 WHERE a=4;
INSERT INTO t1 VALUES(NULL, 'five');
INSERT INTO t1 VALUES(NULL, 'six');
DELETE FROM t1 WHERE a=6;
SELECT * FROM t1;
} {1 one 3 three 5 five}
do_rbu_vacuum_test 1.7.1 $step
do_execsql_test 1.7.2 {
INSERT INTO t1 VALUES(NULL, 'seven');
SELECT * FROM t1;
} {1 one 3 three 5 five 7 seven}
reset_db
do_execsql_test 1.8.0 {
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
CREATE INDEX i1 ON t1(b);
INSERT INTO t1 VALUES(NULL, 'one');
INSERT INTO t1 VALUES(NULL, 'two');
INSERT INTO t1 VALUES(NULL, 'three');
INSERT INTO t1 VALUES(NULL, 'four');
INSERT INTO t1 VALUES(NULL, 'five');
INSERT INTO t1 VALUES(NULL, 'six');
ANALYZE;
SELECT * FROM sqlite_stat1;
} {t1 i1 {6 1}}
do_rbu_vacuum_test 1.8.1 $step
do_execsql_test 1.7.2 {
SELECT * FROM sqlite_stat1;
} {t1 i1 {6 1}}
reset_db
do_execsql_test 1.9.0 {
PRAGMA page_size = 8192;
PRAGMA auto_vacuum = 2;
PRAGMA user_version = 412;
PRAGMA application_id = 413;
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b);
CREATE INDEX i1 ON t1(b);
INSERT INTO t1 VALUES(NULL, 'one');
INSERT INTO t1 VALUES(NULL, 'two');
INSERT INTO t1 VALUES(NULL, 'three');
INSERT INTO t1 VALUES(NULL, 'four');
INSERT INTO t1 VALUES(NULL, 'five');
INSERT INTO t1 VALUES(NULL, 'six');
PRAGMA main.page_size;
PRAGMA main.auto_vacuum;
PRAGMA main.user_version;
PRAGMA main.application_id;
} {8192 2 412 413}
do_rbu_vacuum_test 1.9.1 $step
do_execsql_test 1.9.2 {
PRAGMA main.page_size;
PRAGMA main.auto_vacuum;
PRAGMA main.user_version;
PRAGMA main.application_id;
} {8192 2 412 413}
}
#-------------------------------------------------------------------------
@ -229,7 +296,6 @@ for {set i 1} 1 {incr i} {
do_test 2.2.$i.2 {
list [catch { rbu close } msg] $msg
} {1 {SQLITE_BUSY - database modified during rbu vacuum}}
}
catch { db close }

View File

@ -3333,6 +3333,38 @@ static void rbuInitPhaseOneSteps(sqlite3rbu *p){
}
}
/*
** The second argument passed to this function is the name of a PRAGMA
** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
** This function executes the following on sqlite3rbu.dbRbu:
**
** "PRAGMA main.$zPragma"
**
** where $zPragma is the string passed as the second argument, then
** on sqlite3rbu.dbMain:
**
** "PRAGMA main.$zPragma = $val"
**
** where $val is the value returned by the first PRAGMA invocation.
**
** In short, it copies the value of the specified PRAGMA setting from
** dbRbu to dbMain.
*/
static void rbuCopyPragma(sqlite3rbu *p, const char *zPragma){
if( p->rc==SQLITE_OK ){
sqlite3_stmt *pPragma = 0;
p->rc = prepareFreeAndCollectError(p->dbRbu, &pPragma, &p->zErrmsg,
sqlite3_mprintf("PRAGMA main.%s", zPragma)
);
if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pPragma) ){
p->rc = rbuMPrintfExec(p, p->dbMain, "PRAGMA main.%s = %d",
zPragma, sqlite3_column_int(pPragma, 0)
);
}
rbuFinalize(p, pPragma);
}
}
/*
** The RBU handle passed as the only argument has just been opened and
** the state database is empty. If this RBU handle was opened for an
@ -3343,11 +3375,15 @@ static void rbuCreateTargetSchema(sqlite3rbu *p){
sqlite3_stmt *pInsert = 0;
assert( rbuIsVacuum(p) );
p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
if( p->rc==SQLITE_OK ){
p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
"SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0"
" AND name!='sqlite_sequence' "
" ORDER BY type DESC"
);
}
p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
"SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0"
" ORDER BY type DESC"
);
while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
@ -3355,8 +3391,6 @@ static void rbuCreateTargetSchema(sqlite3rbu *p){
rbuFinalize(p, pSql);
if( p->rc!=SQLITE_OK ) return;
p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
if( p->rc==SQLITE_OK ){
p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
"SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL"
@ -3470,6 +3504,11 @@ static sqlite3rbu *openRbuHandle(
if( p->eStage==RBU_STAGE_OAL ){
sqlite3 *db = p->dbMain;
if( pState->eStage==0 && rbuIsVacuum(p) ){
rbuCopyPragma(p, "page_size");
rbuCopyPragma(p, "auto_vacuum");
}
/* Open transactions both databases. The *-oal file is opened or
** created at this point. */
p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
@ -3491,6 +3530,8 @@ static sqlite3rbu *openRbuHandle(
** when this handle was opened, create the target database schema. */
if( pState->eStage==0 && rbuIsVacuum(p) ){
rbuCreateTargetSchema(p);
rbuCopyPragma(p, "user_version");
rbuCopyPragma(p, "application_id");
}
/* Point the object iterator at the first object */
@ -3854,12 +3895,14 @@ static int rbuVfsRead(
if( pRbu && rbuIsVacuum(pRbu)
&& rc==SQLITE_IOERR_SHORT_READ && iOfst==0
&& (p->openFlags & SQLITE_OPEN_MAIN_DB)
&& pRbu->pRbuFd->base.pMethods
){
sqlite3_file *pFd = (sqlite3_file*)pRbu->pRbuFd;
rc = pFd->pMethods->xRead(pFd, zBuf, iAmt, iOfst);
if( rc==SQLITE_OK ){
u8 *aBuf = (u8*)zBuf;
rbuPutU32(&aBuf[52], 0); /* largest root page number */
u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0;
rbuPutU32(&aBuf[52], iRoot); /* largest root page number */
rbuPutU32(&aBuf[36], 0); /* number of free pages */
rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
rbuPutU32(&aBuf[28], 1); /* size of db file in pages */

View File

@ -1,5 +1,5 @@
C When\san\sRBU\svacuum\sis\sstarted\son\sa\sdb\sidentified\susing\sa\sURI\sfilename,\spass\sthe\ssame\sURI\sparameters\swhen\screating\sthe\snew\sversion\sof\sthe\sdb.\sThis\sensures\sthat\sRBU\svacuum\sworks\swith\spassword\sprotected\sdatabases.
D 2016-04-19T17:11:05.418
C Updates\sto\sensure\sthe\svalues\sof\sPRAGMA\ssettings\slike\s"page_size",\s"auto_vacuum",\s"user_version"\sand\s"application_id"\sare\snot\slost\swhen\sa\sdatabase\sis\sRBU\svacuumed.
D 2016-04-19T19:27:09.289
F Makefile.in eba680121821b8a60940a81454316f47a341487a
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 71b8b16cf9393f68e2e2035486ca104872558836
@ -246,8 +246,8 @@ F ext/rbu/rbufault2.test 9a7f19edd6ea35c4c9f807d8a3db0a03a5670c06
F ext/rbu/rbufts.test 828cd689da825f0a7b7c53ffc1f6f7fdb6fa5bda
F ext/rbu/rbuprogress.test 2023a7df2c523e3df1cb532eff811cda385a789a
F ext/rbu/rbusave.test 0f43b6686084f426ddd040b878426452fd2c2f48
F ext/rbu/rbuvacuum.test b7194617c22f69e2015082a5414585aae2827a29
F ext/rbu/sqlite3rbu.c 0447a8a306411e585d8595465abbed7709f1feb7
F ext/rbu/rbuvacuum.test ecd7ce1cd8528d6230b56f4840bbb7188cee6946
F ext/rbu/sqlite3rbu.c a6c02a67834f9e6c2adb18a9191aa0ae65057cfb
F ext/rbu/sqlite3rbu.h 1342ab6121e715b8da59ec35c5b5c16060be7a6b
F ext/rbu/test_rbu.c 430b8b9520c233505371d564d3561e0b554355f4
F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
@ -1483,7 +1483,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 00b2f4b09ffca5156e43c4db2bfe0b2c979c49b0
R e7445097e6cb895f2eea40503c71f11e
P ca021ba88106500f347ed65199a4832bc9eb5ef8
R 8122ed3aabc11f4475527c60a5badfa5
U dan
Z 90c42b90d6761cf98f1c67d89391cb68
Z 8cbed13b6f72dec5a4cc65417abbee63

View File

@ -1 +1 @@
ca021ba88106500f347ed65199a4832bc9eb5ef8
74ffea76b8c9ddd7699ce6ca77dce005bd7922ac