Fix a problem with VACUUM that can lead to database corruption. (CVS 2323)
FossilOrigin-Name: 63894baf1b37156fd0b84eba4c9c5e8f43cee3f3
This commit is contained in:
parent
c30f9e7356
commit
8cbd373ca7
16
manifest
16
manifest
@ -1,5 +1,5 @@
|
|||||||
C Return\sSQLITE_BUSY\sif\sthe\sdatabase\sis\slocked\sreading\sthe\sschema\swithin\r\nsqlite_prepare().\sTicket\s#1106.\s(CVS\s2322)
|
C Fix\sa\sproblem\swith\sVACUUM\sthat\scan\slead\sto\sdatabase\scorruption.\s(CVS\s2323)
|
||||||
D 2005-02-09T07:05:46
|
D 2005-02-12T00:19:30
|
||||||
F Makefile.in d928187101fa3d78426cf48ca30e39d0fb714e57
|
F Makefile.in d928187101fa3d78426cf48ca30e39d0fb714e57
|
||||||
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
|
||||||
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
|
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
|
||||||
@ -73,7 +73,7 @@ F src/trigger.c 038c8e128d4551cd016426cd11bbf5c478816481
|
|||||||
F src/update.c b6f4668c11059f86b71581187d09197fa28ec4be
|
F src/update.c b6f4668c11059f86b71581187d09197fa28ec4be
|
||||||
F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
|
F src/utf.c bda5eb85039ef16f2d17004c1e18c96e1ab0a80c
|
||||||
F src/util.c 1b7b9a127b66743ab6cba8d44597aeb570723c99
|
F src/util.c 1b7b9a127b66743ab6cba8d44597aeb570723c99
|
||||||
F src/vacuum.c 4dbe45a5c41674a04ac45a7586031583386ab119
|
F src/vacuum.c ccb34e92fd662b2d975e3c8d8cfd229c9081cb78
|
||||||
F src/vdbe.c d9ec62c9f63768b4d4f8513b25aded8faf2de17b
|
F src/vdbe.c d9ec62c9f63768b4d4f8513b25aded8faf2de17b
|
||||||
F src/vdbe.h bb9186484f749a839c6c43953e79a6530253f7cd
|
F src/vdbe.h bb9186484f749a839c6c43953e79a6530253f7cd
|
||||||
F src/vdbeInt.h e80721cd8ff611789e20743eec43363a9fb5a48e
|
F src/vdbeInt.h e80721cd8ff611789e20743eec43363a9fb5a48e
|
||||||
@ -204,7 +204,7 @@ F test/types2.test 81dd1897be8ef4b5b73d0006e6076abe40610de3
|
|||||||
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
|
F test/unique.test 0e38d4cc7affeef2527720d1dafd1f6870f02f2b
|
||||||
F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf
|
F test/update.test 7669ca789d62c258b678e8aa7a22a57eac10f2cf
|
||||||
F test/utf16.test 459c2f5ab80c60092c603630a348c32d6e59c558
|
F test/utf16.test 459c2f5ab80c60092c603630a348c32d6e59c558
|
||||||
F test/vacuum.test 10204524354ff5947e056419fa6b4f4b5067a541
|
F test/vacuum.test 76c4bc4589353d071e81c003a25338d02560474d
|
||||||
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
|
F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102
|
||||||
F test/view.test 306cc4342eb03c28de1a92c681836189e03e5af9
|
F test/view.test 306cc4342eb03c28de1a92c681836189e03e5af9
|
||||||
F test/where.test ffb790dfda75d977bae7a1f5830351623f76861b
|
F test/where.test ffb790dfda75d977bae7a1f5830351623f76861b
|
||||||
@ -270,7 +270,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
|
|||||||
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
|
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
|
||||||
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
|
||||||
F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd
|
F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd
|
||||||
P f73a8aa34afd39e0b7df8f22b5c5d2c8d8979a1b
|
P c33c02d6069b90f295698a9f35f4aa99dee5f5e9
|
||||||
R f830539fd533897542bbb8d2a19a23a0
|
R 8e61ab153be1dc618b065882d6b2d1a5
|
||||||
U danielk1977
|
U drh
|
||||||
Z 0245bb834a1cf0f9358bd0fb2bd64ab5
|
Z ed61c7e978da07a018272bafaa9d7f6b
|
||||||
|
@ -1 +1 @@
|
|||||||
c33c02d6069b90f295698a9f35f4aa99dee5f5e9
|
63894baf1b37156fd0b84eba4c9c5e8f43cee3f3
|
33
src/vacuum.c
33
src/vacuum.c
@ -14,7 +14,7 @@
|
|||||||
** Most of the code in this file may be omitted by defining the
|
** Most of the code in this file may be omitted by defining the
|
||||||
** SQLITE_OMIT_VACUUM macro.
|
** SQLITE_OMIT_VACUUM macro.
|
||||||
**
|
**
|
||||||
** $Id: vacuum.c,v 1.38 2005/02/05 12:48:48 danielk1977 Exp $
|
** $Id: vacuum.c,v 1.39 2005/02/12 00:19:30 drh Exp $
|
||||||
*/
|
*/
|
||||||
#include "sqliteInt.h"
|
#include "sqliteInt.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
@ -244,22 +244,31 @@ int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db){
|
|||||||
*/
|
*/
|
||||||
if( sqlite3BtreeIsInTrans(pTemp) ){
|
if( sqlite3BtreeIsInTrans(pTemp) ){
|
||||||
u32 meta;
|
u32 meta;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* This array determines which meta meta values are preserved in the
|
||||||
|
** vacuum. Even entries are the meta value number and odd entries
|
||||||
|
** are an increment to apply to the meta value after the vacuum.
|
||||||
|
** The increment is used to increase the schema cookie so that other
|
||||||
|
** connections to the same database will know to reread the schema.
|
||||||
|
*/
|
||||||
|
static const unsigned char aCopy[] = {
|
||||||
|
1, 1, /* Add one to the old schema cookie */
|
||||||
|
3, 0, /* Preserve the default page cache size */
|
||||||
|
5, 0, /* Preserve the default text encoding */
|
||||||
|
6, 0, /* Preserve the user version */
|
||||||
|
};
|
||||||
|
|
||||||
assert( 0==sqlite3BtreeIsInTrans(pMain) );
|
assert( 0==sqlite3BtreeIsInTrans(pMain) );
|
||||||
rc = sqlite3BtreeBeginTrans(pMain, 1);
|
rc = sqlite3BtreeBeginTrans(pMain, 1);
|
||||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||||
|
|
||||||
/* Copy Btree meta values 3 and 4. These correspond to SQL layer meta
|
/* Copy Btree meta values */
|
||||||
** values 2 and 3, the default values of a couple of pragmas.
|
for(i=0; i<sizeof(aCopy)/sizeof(aCopy[0]); i+=2){
|
||||||
*/
|
rc = sqlite3BtreeGetMeta(pMain, aCopy[i], &meta);
|
||||||
rc = sqlite3BtreeGetMeta(pMain, 3, &meta);
|
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
rc = sqlite3BtreeUpdateMeta(pTemp, aCopy[i], meta+aCopy[i+1]);
|
||||||
rc = sqlite3BtreeUpdateMeta(pTemp, 3, meta);
|
}
|
||||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
|
||||||
rc = sqlite3BtreeGetMeta(pMain, 4, &meta);
|
|
||||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
|
||||||
rc = sqlite3BtreeUpdateMeta(pTemp, 4, meta);
|
|
||||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
|
||||||
|
|
||||||
rc = sqlite3BtreeCopyFile(pMain, pTemp);
|
rc = sqlite3BtreeCopyFile(pMain, pTemp);
|
||||||
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
if( rc!=SQLITE_OK ) goto end_of_vacuum;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# This file implements regression tests for SQLite library. The
|
# This file implements regression tests for SQLite library. The
|
||||||
# focus of this file is testing the VACUUM statement.
|
# focus of this file is testing the VACUUM statement.
|
||||||
#
|
#
|
||||||
# $Id: vacuum.test,v 1.33 2005/02/03 01:08:20 drh Exp $
|
# $Id: vacuum.test,v 1.34 2005/02/12 00:19:30 drh Exp $
|
||||||
|
|
||||||
set testdir [file dirname $argv0]
|
set testdir [file dirname $argv0]
|
||||||
source $testdir/tester.tcl
|
source $testdir/tester.tcl
|
||||||
@ -153,6 +153,52 @@ do_test vacuum-2.4 {
|
|||||||
cksum db2
|
cksum db2
|
||||||
} $cksum
|
} $cksum
|
||||||
|
|
||||||
|
# Make sure the schema cookie is incremented by vacuum.
|
||||||
|
#
|
||||||
|
do_test vacuum-2.5 {
|
||||||
|
execsql {
|
||||||
|
BEGIN;
|
||||||
|
CREATE TABLE t6 AS SELECT * FROM t1;
|
||||||
|
CREATE TABLE t7 AS SELECT * FROM t1;
|
||||||
|
COMMIT;
|
||||||
|
}
|
||||||
|
sqlite3 db3 test.db
|
||||||
|
execsql {
|
||||||
|
SELECT * FROM t7 LIMIT 1
|
||||||
|
} db3
|
||||||
|
execsql {
|
||||||
|
VACUUM;
|
||||||
|
}
|
||||||
|
execsql {
|
||||||
|
INSERT INTO t7 VALUES(1234567890,'hello','world');
|
||||||
|
} db3
|
||||||
|
execsql {
|
||||||
|
SELECT * FROM t7 WHERE a=1234567890
|
||||||
|
}
|
||||||
|
} {1234567890 hello world}
|
||||||
|
integrity_check vacuum-2.6
|
||||||
|
do_test vacuum-2.7 {
|
||||||
|
execsql {
|
||||||
|
SELECT * FROM t7 WHERE a=1234567890
|
||||||
|
} db3
|
||||||
|
} {1234567890 hello world}
|
||||||
|
do_test vacuum-2.8 {
|
||||||
|
execsql {
|
||||||
|
INSERT INTO t7 SELECT * FROM t6;
|
||||||
|
SELECT count(*) FROM t7;
|
||||||
|
}
|
||||||
|
} 513
|
||||||
|
integrity_check vacuum-2.9
|
||||||
|
do_test vacuum-2.10 {
|
||||||
|
execsql {
|
||||||
|
DELETE FROM t7;
|
||||||
|
SELECT count(*) FROM t7;
|
||||||
|
} db3
|
||||||
|
} 0
|
||||||
|
integrity_check vacuum-2.11
|
||||||
|
db3 close
|
||||||
|
|
||||||
|
|
||||||
# Ticket #427. Make sure VACUUM works when the EMPTY_RESULT_CALLBACKS
|
# Ticket #427. Make sure VACUUM works when the EMPTY_RESULT_CALLBACKS
|
||||||
# pragma is turned on.
|
# pragma is turned on.
|
||||||
#
|
#
|
||||||
@ -302,4 +348,5 @@ ifcapable {autoinc} {
|
|||||||
} $::cksum
|
} $::cksum
|
||||||
}
|
}
|
||||||
|
|
||||||
# finish_test
|
|
||||||
|
finish_test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user