From 776f3a2fa9dd7134755e72c7cf1583f4fdcbfd9a Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 15 Nov 2013 13:12:30 +0000 Subject: [PATCH 1/2] Add the --query option to the wordcount test program. FossilOrigin-Name: 5960d11eba4fc6ca136331279689424d03bd6e76 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/wordcount.c | 42 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 12 deletions(-) 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); From 40864a14017f2fa8a323040fcbefd35407a3f48d Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 15 Nov 2013 18:58:37 +0000 Subject: [PATCH 2/2] Fix comments on the OP_Divide and OP_Remainder operators, especially the "Synopsis:" comment, so that they agree with the actual implementation. FossilOrigin-Name: cc17f1f05f15e9c62659a49c0656ff2b667bf701 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 79187a0a85..a346bf8ac2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--query\soption\sto\sthe\swordcount\stest\sprogram. -D 2013-11-15T13:12:30.792 +C Fix\scomments\son\sthe\sOP_Divide\sand\sOP_Remainder\soperators,\sespecially\sthe\n"Synopsis:"\scomment,\sso\sthat\sthey\sagree\swith\sthe\sactual\simplementation. +D 2013-11-15T18:58:37.334 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 8a07bebafbfda0eb67728f4bd15a36201662d1a1 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -280,7 +280,7 @@ F src/update.c 3de7e657b98ac67338d775c114a4068faf732402 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c 2fa6c821d28bbdbeec1b2a7b091a281c9ef8f918 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c d53b6b7e721b18c42754f10d68e75845e387f2ba +F src/vdbe.c 5573893423aec2d64871e8d504fadbcdaad39fed F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644 F src/vdbeInt.h 62eb680327011f3a4b0336642b0ca9d6ecc6eb91 F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed @@ -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 d99a30a25d6102c389f1fb5ec389c137168615e9 -R 0d314918704a2d9deceec12d1b561362 +P 5960d11eba4fc6ca136331279689424d03bd6e76 +R eeac4cc42ec89642fb7c3d8492dc346d U drh -Z 4de182ff7f969e11fcd8166760e38fe1 +Z cf9b95755a71f68840dd49a0488c3357 diff --git a/manifest.uuid b/manifest.uuid index d03acca621..479ceb1e91 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5960d11eba4fc6ca136331279689424d03bd6e76 \ No newline at end of file +cc17f1f05f15e9c62659a49c0656ff2b667bf701 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index c67a347b4c..1cd7be94ea 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1322,7 +1322,7 @@ case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */ ** If either input is NULL, the result is NULL. */ /* Opcode: Divide P1 P2 P3 * * -** Synopsis: r[P3]=r[P1]/r[P2] +** Synopsis: r[P3]=r[P2]/r[P1] ** ** Divide the value in register P1 by the value in register P2 ** and store the result in register P3 (P3=P2/P1). If the value in @@ -1330,11 +1330,11 @@ case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */ ** NULL, the result is NULL. */ /* Opcode: Remainder P1 P2 P3 * * -** Synopsis: r[P3]=r[P1]%r[P2] +** Synopsis: r[P3]=r[P2]%r[P1] ** -** Compute the remainder after integer division of the value in -** register P1 by the value in register P2 and store the result in P3. -** If the value in register P2 is zero the result is NULL. +** Compute the remainder after integer register P2 is divided by +** register P1 and store the result in register P3. +** If the value in register P1 is zero the result is NULL. ** If either operand is NULL, the result is NULL. */ case OP_Add: /* same as TK_PLUS, in1, in2, out3 */