From 0baa035a1e3339d8bb0aea2205a2dee4f56fcc9e Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 25 Feb 2014 21:55:16 +0000 Subject: [PATCH 1/6] Do not allow temporary registers to be in use across an OP_Yield within a co-routine. Fix for ticket [8c63ff0eca81a9132d8]. FossilOrigin-Name: 97a8c9733cba97c78e979dfd5c66610c23e90288 --- manifest | 15 +++++++------ manifest.uuid | 2 +- src/sqliteInt.h | 1 - src/where.c | 8 +++---- test/tkt-8c63ff0ec.test | 48 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 test/tkt-8c63ff0ec.test diff --git a/manifest b/manifest index f25d3185ff..e66acbb7e2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Also\sadjust\sthe\sorder\sof\sfiles\sin\sthe\samalgamation\sto\sensure\sthat\n_FILE_OFFSET_BITS\sis\sdefined\sbefore\sany\s#include,\sfor\sQNX. -D 2014-02-25T18:12:58.878 +C Do\snot\sallow\stemporary\sregisters\sto\sbe\sin\suse\sacross\san\sOP_Yield\swithin\sa\nco-routine.\s\sFix\sfor\sticket\s[8c63ff0eca81a9132d8]. +D 2014-02-25T21:55:16.402 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -221,7 +221,7 @@ F src/shell.c 3dd86bf73ccd079f0e32ef5069600586085e8239 F src/sqlite.h.in a2ef671f92747a5a1c8a47bad5c585a8dd9eca80 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h 6725dc99b3985a97bad315910e59c3f7f5058916 +F src/sqliteInt.h 46dfbe0b58282421188a6c25b6c0c0fae18e0134 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -290,7 +290,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c d622974f30d3347c7b71bfe49ce1f1e9b6570980 +F src/where.c 0b5a4d45fdf05ad541893d986abd2f660f6e0094 F src/whereInt.h 921f935af8b684ffb49705610bda7284db1db138 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -881,6 +881,7 @@ F test/tkt-80ba201079.test 105a721e6aad0ae3c5946d7615d1e4d03f6145b8 F test/tkt-80e031a00f.test 9a154173461a4dbe2de49cda73963e04842d52f7 F test/tkt-8454a207b9.test c583a9f814a82a2b5ba95207f55001c9f0cd816c F test/tkt-868145d012.test a5f941107ece6a64410ca4755c6329b7eb57a356 +F test/tkt-8c63ff0ec.test 258b7fc8d7e4e1cb5362c7d65c143528b9c4cbed F test/tkt-91e2e8ba6f.test 08c4f94ae07696b05c9b822da0b4e5337a2f54c5 F test/tkt-94c04eaadb.test f738c57c7f68ab8be1c054415af7774617cb6223 F test/tkt-9d68c883.test 458f7d82a523d7644b54b497c986378a7d8c8b67 @@ -1151,7 +1152,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 953cdd6adadfd46b51ad61d7939cecca154a02cb -R d169e5164f16cb0355a3972eba04326c +P 23001a85cd334090cf6c70d4d7e722a01f4f6899 +R 53d871612a374a058c13125cf02ae108 U drh -Z 6c6f89e1dd41d2a146386cfa06ae53d9 +Z 196bbfe69fc9298304e0610559f3cd1e diff --git a/manifest.uuid b/manifest.uuid index a069c374c5..a96614dc89 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -23001a85cd334090cf6c70d4d7e722a01f4f6899 \ No newline at end of file +97a8c9733cba97c78e979dfd5c66610c23e90288 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 72fe47be5a..c7f2941d5d 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2358,7 +2358,6 @@ struct Parse { u8 checkSchema; /* Causes schema cookie check after an error */ u8 nested; /* Number of nested calls to the parser/code generator */ u8 nTempReg; /* Number of temporary registers in aTempReg[] */ - u8 nTempInUse; /* Number of aTempReg[] currently checked out */ u8 nColCache; /* Number of entries in aColCache[] */ u8 iColCache; /* Next entry in aColCache[] to replace */ u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ diff --git a/src/where.c b/src/where.c index d606ba4c18..f5d44a3877 100644 --- a/src/where.c +++ b/src/where.c @@ -2853,13 +2853,14 @@ static Bitmask codeOneLoopStart( ** construct. */ assert( pLoop->u.btree.nEq==1 ); - iReleaseReg = sqlite3GetTempReg(pParse); pTerm = pLoop->aLTerm[0]; assert( pTerm!=0 ); assert( pTerm->pExpr!=0 ); assert( omitTable==0 ); testcase( pTerm->wtFlags & TERM_VIRTUAL ); + iReleaseReg = ++pParse->nMem; iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg); + if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg); addrNxt = pLevel->addrNxt; sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); VdbeCoverage(v); sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg); @@ -2948,7 +2949,7 @@ static Bitmask codeOneLoopStart( pLevel->p2 = start; assert( pLevel->p5==0 ); if( testOp!=OP_Noop ){ - iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse); + iRowidReg = ++pParse->nMem; sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg); sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg); @@ -3181,7 +3182,7 @@ static Bitmask codeOneLoopStart( if( omitTable ){ /* pIdx is a covering index. No need to access the main table. */ }else if( HasRowid(pIdx->pTable) ){ - iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse); + iRowidReg = ++pParse->nMem; sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */ @@ -3529,7 +3530,6 @@ static Bitmask codeOneLoopStart( pTerm->wtFlags |= TERM_CODED; } } - sqlite3ReleaseTempReg(pParse, iReleaseReg); return pLevel->notReady; } diff --git a/test/tkt-8c63ff0ec.test b/test/tkt-8c63ff0ec.test new file mode 100644 index 0000000000..d4aaefd74a --- /dev/null +++ b/test/tkt-8c63ff0ec.test @@ -0,0 +1,48 @@ +# 2014-02-25 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Test cases to show that ticket [8c63ff0eca81a9132d8d67b31cd6ae9712a2cc6f] +# "Incorrect query result on a UNION ALL" which was caused by using the same +# temporary register in concurrent co-routines, as been fixed. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix tkt-8c63ff0ec + +do_execsql_test 1.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d, e); + INSERT INTO t1 VALUES(1,20,30,40,50),(3,60,70,80,90); + CREATE TABLE t2(x INTEGER PRIMARY KEY); + INSERT INTO t2 VALUES(2); + CREATE TABLE t3(z); + INSERT INTO t3 VALUES(2),(2),(2),(2); + + SELECT a, b+c FROM t1 + UNION ALL + SELECT x, 5 FROM t2 JOIN t3 ON z=x WHERE x=2 + ORDER BY a; +} {1 50 2 5 2 5 2 5 2 5 3 130} +do_execsql_test 1.2 { + SELECT a, b+c+d FROM t1 + UNION ALL + SELECT x, 5 FROM t2 JOIN t3 ON z=x WHERE x=2 + ORDER BY a; +} {1 90 2 5 2 5 2 5 2 5 3 210} +do_execsql_test 1.3 { + SELECT a, b+c+d+e FROM t1 + UNION ALL + SELECT x, 5 FROM t2 JOIN t3 ON z=x WHERE x=2 + ORDER BY a; +} {1 140 2 5 2 5 2 5 2 5 3 300} + +finish_test From 434a93147cfa23b7a9bd49fef8f1f1b59c9da4d3 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 26 Feb 2014 02:26:09 +0000 Subject: [PATCH 2/6] Improved handling of constants and especially constant functions in the ORDER BY clause of a query. Do not optimize out "ORDER BY random()". Fix for ticket [65bdeb9739605cc2296]. FossilOrigin-Name: dca1945aeb3fb005263f9be00ee8e72b966ae303 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 21 ++++----------------- test/where2.test | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index e66acbb7e2..1acd1fc253 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\sallow\stemporary\sregisters\sto\sbe\sin\suse\sacross\san\sOP_Yield\swithin\sa\nco-routine.\s\sFix\sfor\sticket\s[8c63ff0eca81a9132d8]. -D 2014-02-25T21:55:16.402 +C Improved\shandling\sof\sconstants\sand\sespecially\sconstant\sfunctions\sin\sthe\nORDER\sBY\sclause\sof\sa\squery.\s\sDo\snot\soptimize\sout\s"ORDER\sBY\srandom()".\nFix\sfor\sticket\s[65bdeb9739605cc2296]. +D 2014-02-26T02:26:09.921 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -290,7 +290,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 76e7fc6de229bea8b30bb2539110f03a494dc3a8 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45 -F src/where.c 0b5a4d45fdf05ad541893d986abd2f660f6e0094 +F src/where.c 6042e1a377cf7dc72c10493269ed75e276275cd8 F src/whereInt.h 921f935af8b684ffb49705610bda7284db1db138 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1070,7 +1070,7 @@ F test/walshared.test 0befc811dcf0b287efae21612304d15576e35417 F test/walslow.test e7be6d9888f83aa5d3d3c7c08aa9b5c28b93609a F test/walthread.test de8dbaf6d9e41481c460ba31ca61e163d7348f8e F test/where.test 28b64e93428961b07b0d486778d63fd672948f6b -F test/where2.test ed6baa9420a109d8be683dbef5d153d186f3690b +F test/where2.test 455a2eb2666e66c1e84e2cb5815173a85e6237db F test/where3.test d28c51f257e60be30f74308fa385ceeddfb54a6e F test/where4.test d8420ceeb8323a41ceff1f1841fc528e824e1ecf F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 @@ -1152,7 +1152,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 23001a85cd334090cf6c70d4d7e722a01f4f6899 -R 53d871612a374a058c13125cf02ae108 +P 97a8c9733cba97c78e979dfd5c66610c23e90288 +R a3177866e2afe2abf843086af2a9a3a2 U drh -Z 196bbfe69fc9298304e0610559f3cd1e +Z c50f86b62c93dcd00c53d2ca75883787 diff --git a/manifest.uuid b/manifest.uuid index a96614dc89..68c025b08a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -97a8c9733cba97c78e979dfd5c66610c23e90288 \ No newline at end of file +dca1945aeb3fb005263f9be00ee8e72b966ae303 \ No newline at end of file diff --git a/src/where.c b/src/where.c index f5d44a3877..a5dd7b59e7 100644 --- a/src/where.c +++ b/src/where.c @@ -4901,9 +4901,12 @@ static int wherePathSatisfiesOrderBy( orderDistinctMask |= pLoop->maskSelf; for(i=0; ia[i].pExpr; - if( (exprTableUsage(&pWInfo->sMaskSet, p)&~orderDistinctMask)==0 ){ + mTerm = exprTableUsage(&pWInfo->sMaskSet,p); + if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue; + if( (mTerm&~orderDistinctMask)==0 ){ obSat |= MASKBIT(i); } } @@ -5526,22 +5529,6 @@ WhereInfo *sqlite3WhereBegin( goto whereBeginError; } - /* If the ORDER BY (or GROUP BY) clause contains references to general - ** expressions, then we won't be able to satisfy it using indices, so - ** go ahead and disable it now. - */ - if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){ - for(ii=0; iinExpr; ii++){ - Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr); - if( pExpr->op!=TK_COLUMN ){ - pWInfo->pOrderBy = pOrderBy = 0; - break; - }else if( pExpr->iColumn<0 ){ - break; - } - } - } - if( wctrlFlags & WHERE_WANT_DISTINCT ){ if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ /* The DISTINCT marking is pointless. Ignore it. */ diff --git a/test/where2.test b/test/where2.test index 45ea486d95..d9b2b23de9 100644 --- a/test/where2.test +++ b/test/where2.test @@ -121,6 +121,42 @@ do_test where2-2.3 { } } {85 6 7396 7402 nosort t1 *} +# Ticket [65bdeb9739605cc22966f49208452996ff29a640] 2014-02-26 +# Make sure "ORDER BY random" does not gets optimized out. +# +do_test where2-2.4 { + db eval { + CREATE TABLE x1(a INTEGER PRIMARY KEY, b DEFAULT 1); + WITH RECURSIVE + cnt(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM cnt WHERE x<50) + INSERT INTO x1 SELECT x, 1 FROM cnt; + CREATE TABLE x2(x INTEGER PRIMARY KEY); + INSERT INTO x2 VALUES(1); + } + set sql {SELECT * FROM x1, x2 WHERE x=1 ORDER BY random()} + set out1 [db eval $sql] + set out2 [db eval $sql] + set out3 [db eval $sql] + expr {$out1!=$out2 && $out2!=$out3} +} {1} +do_execsql_test where2-2.5 { + -- random() is not optimized out + EXPLAIN SELECT * FROM x1, x2 WHERE x=1 ORDER BY random(); +} {/ random/} +do_execsql_test where2-2.5b { + -- random() is not optimized out + EXPLAIN SELECT * FROM x1, x2 WHERE x=1 ORDER BY random(); +} {/ SorterOpen /} +do_execsql_test where2-2.6 { + -- other constant functions are optimized out + EXPLAIN SELECT * FROM x1, x2 WHERE x=1 ORDER BY abs(5); +} {~/ abs/} +do_execsql_test where2-2.6b { + -- other constant functions are optimized out + EXPLAIN SELECT * FROM x1, x2 WHERE x=1 ORDER BY abs(5); +} {~/ SorterOpen /} + + # Efficient handling of forward and reverse table scans. # From 3852b68edd2d378f9f4a4b2377654ecbb6d423c1 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 26 Feb 2014 13:53:34 +0000 Subject: [PATCH 3/6] In the command-line shell for CSV import, if the lines are \r\n terminated and the last field is blank, make sure an empty string and not a "\r" string is imported. FossilOrigin-Name: 9c2e7612cd137895e13ee872e668ce1216719d85 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/shell.c | 2 +- test/shell5.test | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 1acd1fc253..b398e0004c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\shandling\sof\sconstants\sand\sespecially\sconstant\sfunctions\sin\sthe\nORDER\sBY\sclause\sof\sa\squery.\s\sDo\snot\soptimize\sout\s"ORDER\sBY\srandom()".\nFix\sfor\sticket\s[65bdeb9739605cc2296]. -D 2014-02-26T02:26:09.921 +C In\sthe\scommand-line\sshell\sfor\sCSV\simport,\sif\sthe\slines\sare\s\\r\\n\sterminated\nand\sthe\slast\sfield\sis\sblank,\smake\ssure\san\sempty\sstring\sand\snot\sa\s"\\r"\sstring\nis\simported. +D 2014-02-26T13:53:34.384 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -217,7 +217,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c ca8b99d894164435f5c55cb304c1b8121705c51e F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 28bff39f9bc5ec618b0719fe3f7b4be9f88b6f02 -F src/shell.c 3dd86bf73ccd079f0e32ef5069600586085e8239 +F src/shell.c ca2b066ab31793532530e0c2fcf79e99628f3b2b F src/sqlite.h.in a2ef671f92747a5a1c8a47bad5c585a8dd9eca80 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -804,7 +804,7 @@ F test/shell1.test f2a1d471e5cd2b42f7a65b166dc1ace2b8d11583 F test/shell2.test c57da3a381c099b02c813ba156298d5c2f5c93a3 F test/shell3.test 5e8545ec72c4413a0e8d4c6be56496e3c257ca29 F test/shell4.test aa4eef8118b412d1a01477a53426ece169ea86a9 -F test/shell5.test cee83b4385f842fec1f2a0bec9ea811f35386edf +F test/shell5.test bb755ea9144b8078a752fc56223582627070b5f1 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868 F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329 @@ -1152,7 +1152,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 97a8c9733cba97c78e979dfd5c66610c23e90288 -R a3177866e2afe2abf843086af2a9a3a2 +P dca1945aeb3fb005263f9be00ee8e72b966ae303 +R 4bbcd8ca02f23a972c97ceb5ec0d3c0c U drh -Z c50f86b62c93dcd00c53d2ca75883787 +Z 998297c355a76316139497aa81dafb02 diff --git a/manifest.uuid b/manifest.uuid index 68c025b08a..b18a32bd5f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dca1945aeb3fb005263f9be00ee8e72b966ae303 \ No newline at end of file +9c2e7612cd137895e13ee872e668ce1216719d85 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 266bb8f90f..7bb8da3e0f 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1893,7 +1893,7 @@ static char *csv_read_one_field(CSVReader *p){ } if( c=='\n' ){ p->nLine++; - if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--; + if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--; } p->cTerm = c; } diff --git a/test/shell5.test b/test/shell5.test index ce05a303ca..4c38b75e6f 100644 --- a/test/shell5.test +++ b/test/shell5.test @@ -285,6 +285,25 @@ do_test shell5-1.10 { db eval {SELECT hex(c) FROM t1 ORDER BY rowid} } {636F6C756D6E33 783320220D0A64617461222033 783320220A64617461222033} +# Blank last column with \r\n line endings. +do_test shell5-1.11 { + set out [open shell5.csv w] + fconfigure $out -translation binary + puts $out "column1,column2,column3\r" + puts $out "a,b, \r" + puts $out "x,y,\r" + puts $out "p,q,r\r" + close $out + catch {db close} + forcedelete test.db + catchcmd test.db {.mode csv +.import shell5.csv t1 + } + sqlite3 db test.db + db eval {SELECT *, '|' FROM t1} +} {a b { } | x y {} | p q r |} + + db close finish_test From 7e4efaecad8b403574647d08d2f47f0cc60679ef Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 26 Feb 2014 21:35:31 +0000 Subject: [PATCH 4/6] More efficient removal of duplicates in recursive queries using the UNION compound operator. FossilOrigin-Name: 06c2db875e6cabd81c2a153b2fa4aba03eaed268 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 10 ++++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index b398e0004c..9c72c3971c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\sthe\scommand-line\sshell\sfor\sCSV\simport,\sif\sthe\slines\sare\s\\r\\n\sterminated\nand\sthe\slast\sfield\sis\sblank,\smake\ssure\san\sempty\sstring\sand\snot\sa\s"\\r"\sstring\nis\simported. -D 2014-02-26T13:53:34.384 +C More\sefficient\sremoval\sof\sduplicates\sin\srecursive\squeries\susing\sthe\sUNION\ncompound\soperator. +D 2014-02-26T21:35:31.484 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -216,7 +216,7 @@ F src/printf.c 85d07756e45d7496d19439dcae3e6e9e0090f269 F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c ca8b99d894164435f5c55cb304c1b8121705c51e F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 -F src/select.c 28bff39f9bc5ec618b0719fe3f7b4be9f88b6f02 +F src/select.c 35b07a47fdee9a98e03c4ffb3801026c72114cb7 F src/shell.c ca2b066ab31793532530e0c2fcf79e99628f3b2b F src/sqlite.h.in a2ef671f92747a5a1c8a47bad5c585a8dd9eca80 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e @@ -1152,7 +1152,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P dca1945aeb3fb005263f9be00ee8e72b966ae303 -R 4bbcd8ca02f23a972c97ceb5ec0d3c0c +P 9c2e7612cd137895e13ee872e668ce1216719d85 +R 8af1befb78d550449f6afe7ccc2f524b U drh -Z 998297c355a76316139497aa81dafb02 +Z 54acbfe19bff5d9f12c833489ea306bb diff --git a/manifest.uuid b/manifest.uuid index b18a32bd5f..b0059e4d9c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9c2e7612cd137895e13ee872e668ce1216719d85 \ No newline at end of file +06c2db875e6cabd81c2a153b2fa4aba03eaed268 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 93947d56b2..a8cb341c65 100644 --- a/src/select.c +++ b/src/select.c @@ -818,14 +818,16 @@ static void selectInnerLoop( r1 = sqlite3GetTempReg(pParse); r2 = sqlite3GetTempRange(pParse, nKey+2); r3 = r2+nKey+1; - sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3); if( eDest==SRT_DistQueue ){ /* If the destination is DistQueue, then cursor (iParm+1) is open ** on a second ephemeral index that holds all values every previously - ** added to the queue. Only add this new value if it has never before - ** been added */ - addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0); + ** added to the queue. */ + addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, + regResult, nResultCol); VdbeCoverage(v); + } + sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3); + if( eDest==SRT_DistQueue ){ sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3); sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); } From c7181907688fa0d2a2bcabff7f392757e6efab96 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 27 Feb 2014 15:04:13 +0000 Subject: [PATCH 5/6] Add #defines to the command-line shell source code (shell.c) so that it can be imported directly into other projects (ex: Fossil) and used without editing. FossilOrigin-Name: a6690400235705ecc0d1a60dacff6ad5fb1f944a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 9c72c3971c..7ec2f4b525 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\sefficient\sremoval\sof\sduplicates\sin\srecursive\squeries\susing\sthe\sUNION\ncompound\soperator. -D 2014-02-26T21:35:31.484 +C Add\s#defines\sto\sthe\scommand-line\sshell\ssource\scode\s(shell.c)\sso\sthat\sit\ncan\sbe\simported\sdirectly\sinto\sother\sprojects\s(ex:\sFossil)\sand\sused\swithout\s\nediting. +D 2014-02-27T15:04:13.436 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -217,7 +217,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c ca8b99d894164435f5c55cb304c1b8121705c51e F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 35b07a47fdee9a98e03c4ffb3801026c72114cb7 -F src/shell.c ca2b066ab31793532530e0c2fcf79e99628f3b2b +F src/shell.c 720e79facdae4787e7bfa577dae6b37a685244b0 F src/sqlite.h.in a2ef671f92747a5a1c8a47bad5c585a8dd9eca80 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1152,7 +1152,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 9c2e7612cd137895e13ee872e668ce1216719d85 -R 8af1befb78d550449f6afe7ccc2f524b +P 06c2db875e6cabd81c2a153b2fa4aba03eaed268 +R b72dc063fb220f3231791c5c73300f82 U drh -Z 54acbfe19bff5d9f12c833489ea306bb +Z d3f85704b6a67858d1c2e6d5e8f9f735 diff --git a/manifest.uuid b/manifest.uuid index b0059e4d9c..03c67c2593 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -06c2db875e6cabd81c2a153b2fa4aba03eaed268 \ No newline at end of file +a6690400235705ecc0d1a60dacff6ad5fb1f944a \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 7bb8da3e0f..3cd7aaf892 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1008,7 +1008,7 @@ static int run_table_dump_query( int nResult; int i; const char *z; - rc = sqlite3_prepare(p->db, zSelect, -1, &pSelect, 0); + rc = sqlite3_prepare_v2(p->db, zSelect, -1, &pSelect, 0); if( rc!=SQLITE_OK || !pSelect ){ fprintf(p->out, "/**** ERROR: (%d) %s *****/\n", rc, sqlite3_errmsg(p->db)); if( (rc&0xff)!=SQLITE_CORRUPT ) p->nErr++; @@ -1456,7 +1456,7 @@ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ zTableInfo = appendText(zTableInfo, zTable, '"'); zTableInfo = appendText(zTableInfo, ");", 0); - rc = sqlite3_prepare(p->db, zTableInfo, -1, &pTableInfo, 0); + rc = sqlite3_prepare_v2(p->db, zTableInfo, -1, &pTableInfo, 0); free(zTableInfo); if( rc!=SQLITE_OK || !pTableInfo ){ return 1; @@ -2399,7 +2399,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ return 1; } nByte = strlen30(zSql); - rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0); + rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){ char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable); char cSep = '('; @@ -2425,7 +2425,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ xCloser(sCsv.in); return 1; } - rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0); + rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); } sqlite3_free(zSql); if( rc ){ @@ -2452,7 +2452,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ } zSql[j++] = ')'; zSql[j] = 0; - rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0); + rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); sqlite3_free(zSql); if( rc ){ fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db)); @@ -3548,11 +3548,13 @@ int main(int argc, char **argv){ int rc = 0; int warnInmemoryDb = 0; +#if !defined(USE_SYSTEM_SQLITE) || USE_SYSTEM_SQLITE!=1 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){ fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n", sqlite3_sourceid(), SQLITE_SOURCE_ID); exit(1); } +#endif Argv0 = argv[0]; main_init(&data); stdin_is_interactive = isatty(0); @@ -3645,6 +3647,11 @@ int main(int argc, char **argv){ #else fprintf(stderr,"%s: Error: no database filename specified\n", Argv0); return 1; +#endif +#ifdef SQLITE_SHELL_DBNAME_PROC + { extern void SQLITE_SHELL_DBNAME_PROC(const char**); + SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename); + warnInmemoryDb = 0; } #endif } data.out = stdout; From 69b30abd598ed827cddeede9d133c83e579517c3 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 27 Feb 2014 15:11:52 +0000 Subject: [PATCH 6/6] A better way of handling the USE_SYSTEM_SQLITE #define in shell.c. FossilOrigin-Name: 51ce713c6ee91bdf0126155334dcc800b3daa509 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 7ec2f4b525..6892cecea2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\s#defines\sto\sthe\scommand-line\sshell\ssource\scode\s(shell.c)\sso\sthat\sit\ncan\sbe\simported\sdirectly\sinto\sother\sprojects\s(ex:\sFossil)\sand\sused\swithout\s\nediting. -D 2014-02-27T15:04:13.436 +C A\sbetter\sway\sof\shandling\sthe\sUSE_SYSTEM_SQLITE\s#define\sin\sshell.c. +D 2014-02-27T15:11:52.919 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -217,7 +217,7 @@ F src/random.c d10c1f85b6709ca97278428fd5db5bbb9c74eece F src/resolve.c ca8b99d894164435f5c55cb304c1b8121705c51e F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 35b07a47fdee9a98e03c4ffb3801026c72114cb7 -F src/shell.c 720e79facdae4787e7bfa577dae6b37a685244b0 +F src/shell.c bf75ce6bea4c8f56c1b46bee201c25acddffb675 F src/sqlite.h.in a2ef671f92747a5a1c8a47bad5c585a8dd9eca80 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1152,7 +1152,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 06c2db875e6cabd81c2a153b2fa4aba03eaed268 -R b72dc063fb220f3231791c5c73300f82 +P a6690400235705ecc0d1a60dacff6ad5fb1f944a +R d9e4cc8c2428822c2a58511d3bd2892d U drh -Z d3f85704b6a67858d1c2e6d5e8f9f735 +Z 2ca6d024109a270000c3879d5e05ce0a diff --git a/manifest.uuid b/manifest.uuid index 03c67c2593..5a0d8578c1 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a6690400235705ecc0d1a60dacff6ad5fb1f944a \ No newline at end of file +51ce713c6ee91bdf0126155334dcc800b3daa509 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 3cd7aaf892..6815c489e6 100644 --- a/src/shell.c +++ b/src/shell.c @@ -3548,7 +3548,7 @@ int main(int argc, char **argv){ int rc = 0; int warnInmemoryDb = 0; -#if !defined(USE_SYSTEM_SQLITE) || USE_SYSTEM_SQLITE!=1 +#if USE_SYSTEM_SQLITE+0!=1 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){ fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n", sqlite3_sourceid(), SQLITE_SOURCE_ID);