From: drh Date: Wed, 8 Jun 2016 13:49:28 +0000 (+0000) Subject: Fix the dbhash utility so that it ignores the root page number when hashing X-Git-Tag: version-3.14.0~102^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7c4942cb1a3900231ef2f2e47bc368a3e278ecb5;p=thirdparty%2Fsqlite.git Fix the dbhash utility so that it ignores the root page number when hashing the sqlite_master table. Add new command-line options. Add the ability to hash multiple databases with a single command. FossilOrigin-Name: 44f157e0f0d5a76ef9002b2592164c4fdae89e34 --- diff --git a/manifest b/manifest index 7d7f2a3501..efda9daef2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C An\sinitial\sattempt\sat\sa\s"dbhash"\scommand-line\sutility. -D 2016-06-08T01:03:05.100 +C Fix\sthe\sdbhash\sutility\sso\sthat\sit\signores\sthe\sroot\spage\snumber\swhen\shashing\nthe\ssqlite_master\stable.\s\sAdd\snew\scommand-line\soptions.\s\sAdd\sthe\sability\sto\nhash\smultiple\sdatabases\swith\sa\ssingle\scommand. +D 2016-06-08T13:49:28.865 F Makefile.in f3f7d2060ce03af4584e711ef3a626ef0b1d6340 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 50149765ef72f4e652b9a0f1f6462c4784bb9423 @@ -1420,7 +1420,7 @@ F tool/build-all-msvc.bat 3e4e4043b53f1aede4308e0d2567bbd773614630 x F tool/build-shell.sh 950f47c6174f1eea171319438b93ba67ff5bf367 F tool/cg_anno.tcl 692ce4b8693d59e3a3de77ca97f4139ecfa641b0 x F tool/checkSpacing.c 810e51703529a204fc4e1eb060e9ab663e3c06d2 -F tool/dbhash.c 11ae59057c1ebbd54ac10bdc59c8fc7e0a43a156 +F tool/dbhash.c 3e7a97ebdaff842f99ee1eab3787717582d665b8 F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 @@ -1501,10 +1501,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 2091a4c9231c7871f27661adc27dd7df26500f6c -R 2cb484710443ce45b289f472a9c90e73 -T *branch * dbhash -T *sym-dbhash * -T -sym-trunk * +P 2247649ca215c06205b33b2250eb809baf39263a +R 8393151ede059e20b861d67944f07343 U drh -Z 1329a111dd8194eb5ec209c8b1ad3288 +Z e6c66d0412cbc063d2ea74dc380f683a diff --git a/manifest.uuid b/manifest.uuid index ca0df0561c..8a0b15bbb6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2247649ca215c06205b33b2250eb809baf39263a \ No newline at end of file +44f157e0f0d5a76ef9002b2592164c4fdae89e34 \ No newline at end of file diff --git a/tool/dbhash.c b/tool/dbhash.c index 0e1b02b673..8873c39c2a 100644 --- a/tool/dbhash.c +++ b/tool/dbhash.c @@ -10,7 +10,7 @@ ** ************************************************************************* ** -** This is a utility program that computes a hash on the content +** This is a utility program that computes an SHA1 hash on the content ** of an SQLite database. ** ** The hash is computed over just the content of the database. Free @@ -40,12 +40,16 @@ struct SHA1Context { */ struct GlobalVars { const char *zArgv0; /* Name of program */ - int bSchemaPK; /* Use the schema-defined PK, not the true PK */ unsigned fDebug; /* Debug flags */ sqlite3 *db; /* The database connection */ SHA1Context cx; /* SHA1 hash context */ } g; +/* +** Debugging flags +*/ +#define DEBUG_FULLTRACE 0x00000001 /* Trace hash to stderr */ + /****************************************************************************** ** The Hash Engine ** @@ -200,7 +204,7 @@ static void hash_step(const unsigned char *data, unsigned int len){ /* Add padding and compute and output the message digest. */ -static void hash_finish(void){ +static void hash_finish(const char *zName){ unsigned int i; unsigned char finalcount[8]; unsigned char digest[20]; @@ -224,7 +228,7 @@ static void hash_finish(void){ zOut[i*2+1] = zEncode[digest[i] & 0xf]; } zOut[i*2]= 0; - printf("%s\n", zOut); + printf("%s %s\n", zOut, zName); } /* End of the hashing logic *******************************************************************************/ @@ -286,19 +290,28 @@ static sqlite3_stmt *db_prepare(const char *zFormat, ...){ } /* -** Compute the hash for a single table named zTab +** Compute the hash for all rows of the query formed from the printf-style +** zFormat and its argument. */ -static void hash_one_table(const char *zTab){ - sqlite3_stmt *pStmt; - int nCol; - int i; - pStmt = db_prepare("SELECT * FROM \"%w\";", zTab); +static void hash_one_query(const char *zFormat, ...){ + va_list ap; + sqlite3_stmt *pStmt; /* The query defined by zFormat and "..." */ + int nCol; /* Number of columns in the result set */ + int i; /* Loop counter */ + + /* Prepare the query defined by zFormat and "..." */ + va_start(ap, zFormat); + pStmt = db_vprepare(zFormat, ap); + va_end(ap); nCol = sqlite3_column_count(pStmt); + + /* Compute a hash over the result of the query */ while( SQLITE_ROW==sqlite3_step(pStmt) ){ for(i=0; i