From: drh Date: Fri, 15 Nov 2013 13:12:30 +0000 (+0000) Subject: Add the --query option to the wordcount test program. X-Git-Tag: version-3.8.2~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=776f3a2fa9dd7134755e72c7cf1583f4fdcbfd9a;p=thirdparty%2Fsqlite.git Add the --query option to the wordcount test program. FossilOrigin-Name: 5960d11eba4fc6ca136331279689424d03bd6e76 --- diff --git a/manifest b/manifest index f194ea4c79..79187a0a85 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\stypo\sin\sthe\s"synopsis"\sfor\sthe\sOP_Lt\sopcode\sthat\scauses\san\s\nincorrect\scomment\sto\sbe\sadded\sto\sEXPLAIN\soutput. -D 2013-11-15T03:21:43.898 +C Add\sthe\s--query\soption\sto\sthe\swordcount\stest\sprogram. +D 2013-11-15T13:12:30.792 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 8a07bebafbfda0eb67728f4bd15a36201662d1a1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1087,7 +1087,7 @@ F test/without_rowid1.test aaa26da19d543cd8d3d2d0e686dfa255556c15c8 F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99 F test/without_rowid3.test eac3d5c8a1924725b58503a368f2cbd24fd6c8a0 F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a -F test/wordcount.c 2c2cc1119de42e6730ca8bd149666f0e0095108a +F test/wordcount.c b8872ec44e8085bb671048a49cb696bed1100fe3 F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test 209d7ed441f44cc5299e4ebffbef06fd5aabfefd F tool/build-all-msvc.bat 1bac6adc3fdb4d9204f21d17b14be25778370e48 x @@ -1139,7 +1139,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P cbe85cc2a991d89a6cca391ffa1be0582a684e49 -R 0c746aa4efd05e48b97b713c68a5a0db +P d99a30a25d6102c389f1fb5ec389c137168615e9 +R 0d314918704a2d9deceec12d1b561362 U drh -Z 51d93302282dc3095ac1b627e9f3a079 +Z 4de182ff7f969e11fcd8166760e38fe1 diff --git a/manifest.uuid b/manifest.uuid index cbca5b1319..d03acca621 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d99a30a25d6102c389f1fb5ec389c137168615e9 \ No newline at end of file +5960d11eba4fc6ca136331279689424d03bd6e76 \ No newline at end of file diff --git a/test/wordcount.c b/test/wordcount.c index 2161c07174..f8bac4deb6 100644 --- a/test/wordcount.c +++ b/test/wordcount.c @@ -19,6 +19,7 @@ ** --select Use SELECT mode ** --update Use UPDATE mode ** --delete Use DELETE mode +** --query Use QUERY mode ** --nocase Add the NOCASE collating sequence to the words. ** --trace Enable sqlite3_trace() output. ** --summary Show summary information on the collected data. @@ -51,11 +52,15 @@ ** Delete mode means: ** (1) DELETE FROM wordcount WHERE word=$new ** -** Note that delete mode is only useful for preexisting databases. The -** wordcount table is created using IF NOT EXISTS so this utility can be -** run multiple times on the same database file. The --without-rowid, -** --nocase, and --pagesize parameters are only effective when creating -** a new database and are harmless no-ops on preexisting databases. +** Query mode means: +** (1) SELECT cnt FROM wordcount WHERE word=$new +** +** Note that delete mode and query mode are only useful for preexisting +** databases. The wordcount table is created using IF NOT EXISTS so this +** utility can be run multiple times on the same database file. The +** --without-rowid, --nocase, and --pagesize parameters are only effective +** when creating a new database and are harmless no-ops on preexisting +** databases. ** ****************************************************************************** ** @@ -170,6 +175,7 @@ static void checksumFinalize(sqlite3_context *context){ #define MODE_SELECT 2 #define MODE_UPDATE 3 #define MODE_DELETE 4 +#define MODE_QUERY 5 int main(int argc, char **argv){ const char *zFileToRead = 0; /* Input file. NULL for stdin */ @@ -196,6 +202,7 @@ int main(int argc, char **argv){ FILE *in; /* The open input file */ int rc; /* Return code from an SQLite interface */ int iCur, iHiwtr; /* Statistics values, current and "highwater" */ + sqlite3_int64 sumCnt = 0; /* Sum in QUERY mode */ char zInput[2000]; /* A single line of input */ /* Process command-line arguments */ @@ -215,6 +222,8 @@ int main(int argc, char **argv){ iMode = MODE_UPDATE; }else if( strcmp(z,"delete")==0 ){ iMode = MODE_DELETE; + }else if( strcmp(z,"query")==0 ){ + iMode = MODE_QUERY; }else if( strcmp(z,"nocase")==0 ){ useNocase = 1; }else if( strcmp(z,"trace")==0 ){ @@ -303,6 +312,13 @@ int main(int argc, char **argv){ sqlite3_free(zSql); /* Prepare SQL statements that will be needed */ + if( iMode==MODE_QUERY ){ + rc = sqlite3_prepare_v2(db, + "SELECT cnt FROM wordcount WHERE word=?1", + -1, &pSelect, 0); + if( rc ) fatal_error("Could not prepare the SELECT statement: %s\n", + sqlite3_errmsg(db)); + } if( iMode==MODE_SELECT ){ rc = sqlite3_prepare_v2(db, "SELECT 1 FROM wordcount WHERE word=?1", @@ -385,6 +401,12 @@ int main(int argc, char **argv){ }else{ fatal_error("SELECT failed: %s\n", sqlite3_errmsg(db)); } + }else if( iMode==MODE_QUERY ){ + sqlite3_bind_text(pSelect, 1, zInput+i, j-i, SQLITE_STATIC); + if( sqlite3_step(pSelect)==SQLITE_ROW ){ + sumCnt += sqlite3_column_int64(pSelect, 0); + } + sqlite3_reset(pSelect); }else{ sqlite3_bind_text(pInsert, 1, zInput+i, j-i, SQLITE_STATIC); if( sqlite3_step(pInsert)!=SQLITE_DONE ){ @@ -417,6 +439,16 @@ int main(int argc, char **argv){ sqlite3_finalize(pSelect); sqlite3_finalize(pDelete); + if( iMode==MODE_QUERY ){ + printf("sum of cnt: %lld\n", sumCnt); + rc = sqlite3_prepare_v2(db,"SELECT sum(cnt*cnt) FROM wordcount", -1, + &pSelect, 0); + if( rc==SQLITE_OK && sqlite3_step(pSelect)==SQLITE_ROW ){ + printf("double-check: %lld\n", sqlite3_column_int64(pSelect, 0)); + } + sqlite3_finalize(pSelect); + } + if( showSummary ){ sqlite3_create_function(db, "checksum", -1, SQLITE_UTF8, 0, 0, checksumStep, checksumFinalize);