From: drh Date: Wed, 24 Jun 2015 12:44:42 +0000 (+0000) Subject: Add the --rebuild object to fuzzcheck. X-Git-Tag: version-3.8.11~137 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9a645868641fb183eaf8a806e4002afd422a3a9e;p=thirdparty%2Fsqlite.git Add the --rebuild object to fuzzcheck. FossilOrigin-Name: db87664a224f44e01b85570a3f3b6ec1c81d6e0a --- diff --git a/manifest b/manifest index 115cde3d11..1f6e0c4992 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Prevent\san\sinfinite\sloop\swhile\ssearching\sa\scorrupt\sfreelist. -D 2015-06-24T12:24:03.684 +C Add\sthe\s--rebuild\sobject\sto\sfuzzcheck. +D 2015-06-24T12:44:42.961 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 1063c58075b7400d93326b0eb332b48a54f53025 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -657,7 +657,7 @@ F test/fuzz2.test 76dc35b32b6d6f965259508508abce75a6c4d7e1 F test/fuzz3.test efd384b896c647b61a2c1848ba70d42aad60a7b3 F test/fuzz_common.tcl a87dfbb88c2a6b08a38e9a070dabd129e617b45b F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 -F test/fuzzcheck.c 5805b2236292f8643d56e727a3a6e4d88e0856a5 +F test/fuzzcheck.c 40f9db60546bef5a3b47858387f158f25b33dca9 F test/fuzzdata1.db 7ee3227bad0e7ccdeb08a9e6822916777073c664 F test/fuzzdata2.db f03a420d3b822cc82e4f894ca957618fbe9c4973 F test/fuzzdata3.db ab36b87c73d97e046edc931d07210caba0eee3ce @@ -1286,7 +1286,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 5ba983432069714afebbb2f0ef22d41be52f7a4c -R fe400a5b514399d4ba64d3ad8d7504b9 +P 4e5424fe89eed346f6cf26a05c72694d1eb9f58f +R 408d47278af1389986b4d5a1a26ee4ab U drh -Z 86686a0d10808f274a0105773f11c508 +Z 58722377525bd9539d5add410a8de869 diff --git a/manifest.uuid b/manifest.uuid index c4ae3ad4ed..9433eda3c3 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4e5424fe89eed346f6cf26a05c72694d1eb9f58f \ No newline at end of file +db87664a224f44e01b85570a3f3b6ec1c81d6e0a \ No newline at end of file diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c index f637e6463c..34c21adec3 100644 --- a/test/fuzzcheck.c +++ b/test/fuzzcheck.c @@ -615,6 +615,31 @@ static void runSql(sqlite3 *db, const char *zSql, unsigned runFlags){ } } +/* +** Rebuild the database file. +** +** (1) Remove duplicate entries +** (2) Put all entries in order +** (3) Vacuum +*/ +static void rebuild_database(sqlite3 *db){ + int rc; + rc = sqlite3_exec(db, + "BEGIN;\n" + "CREATE TEMP TABLE dbx AS SELECT DISTINCT dbcontent FROM db;\n" + "DELETE FROM db;\n" + "INSERT INTO db(dbid, dbcontent) SELECT NULL, dbcontent FROM dbx ORDER BY 2;\n" + "DROP TABLE dbx;\n" + "CREATE TEMP TABLE sx AS SELECT DISTINCT sqltext FROM xsql;\n" + "DELETE FROM xsql;\n" + "INSERT INTO xsql(sqlid,sqltext) SELECT NULL, sqltext FROM sx ORDER BY 2;\n" + "DROP TABLE sx;\n" + "COMMIT;\n" + "PRAGMA page_size=1024;\n" + "VACUUM;\n", 0, 0, 0); + if( rc ) fatalError("cannot rebuild: %s", sqlite3_errmsg(db)); +} + /* ** Print sketchy documentation for this utility program */ @@ -633,6 +658,7 @@ static void showHelp(void){ " --load-db ARGS... Load template databases from files into SOURCE_DB\n" " -m TEXT Add a description to the database\n" " --native-vfs Use the native VFS for initially empty database files\n" +" --rebuild Rebuild and vacuum the database file\n" " --result-trace Show the results of each SQL command\n" " --sqlid N Use only SQL where sqlid=N\n" " -v Increased output\n" @@ -655,6 +681,7 @@ int main(int argc, char **argv){ int onlySqlid = -1; /* --sqlid */ int onlyDbid = -1; /* --dbid */ int nativeFlag = 0; /* --native-vfs */ + int rebuildFlag = 0; /* --rebuild */ int runFlags = 0; /* Flags sent to runSql() */ char *zMsg = 0; /* Add this message */ int nSrcDb = 0; /* Number of source databases */ @@ -705,6 +732,9 @@ int main(int argc, char **argv){ quietFlag = 1; verboseFlag = 0; }else + if( strcmp(z,"rebuild")==0 ){ + rebuildFlag = 1; + }else if( strcmp(z,"result-trace")==0 ){ runFlags |= SQL_OUTPUT; }else @@ -743,7 +773,7 @@ int main(int argc, char **argv){ fatalError("cannot open source database %s - %s", azSrcDb[iSrcDb], sqlite3_errmsg(db)); } - rc = sqlite3_exec(db, + rc = sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS db(\n" " dbid INTEGER PRIMARY KEY, -- database id\n" " dbcontent BLOB -- database disk file image\n" @@ -781,6 +811,7 @@ int main(int argc, char **argv){ sqlite3_finalize(pStmt); rc = sqlite3_exec(db, "COMMIT", 0, 0, 0); if( rc ) fatalError("cannot commit the transaction: %s", sqlite3_errmsg(db)); + rebuild_database(db); sqlite3_close(db); return 0; } @@ -814,6 +845,16 @@ int main(int argc, char **argv){ } sqlite3_finalize(pStmt); } + + /* Rebuild the database, if requested */ + if( rebuildFlag ){ + if( !quietFlag ){ + printf("%s: rebuilding... ", zDbName); + fflush(stdout); + } + rebuild_database(db); + if( !quietFlag ) printf("done\n"); + } /* Close the source database. Verify that no SQLite memory allocations are ** outstanding.