From 7f0cd09cdd83c29cad832cd219a3fb2642d48d3d Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 19 May 2015 23:56:07 +0000 Subject: [PATCH 01/14] Enhance the selecttrace display by showing Select.selFlags. FossilOrigin-Name: 45d3893c6142ee1dfed48e26a13cf547da12468a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index b7c9b4f43e..33442b2035 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sMSVC\smakefile\sso\sthat\sit\sworks\swith\sOTA.\s\sFix\sa\sharmless\scompiler\nwarning\sin\sFTS3. -D 2015-05-19T22:56:45.390 +C Enhance\sthe\sselecttrace\sdisplay\sby\sshowing\sSelect.selFlags. +D 2015-05-19T23:56:07.009 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -250,7 +250,7 @@ F src/printf.c 13ce37e5574f9b0682fa86dbcf9faf76b9d82a15 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 99eabf7eff0bfa65b75939b46caa82e2b2133f28 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 6d9d6ae899acb9bf148862e8cccdf16085514b26 +F src/select.c 95e728e1bdbca2ee45016308e3eb6d19095155cc F src/shell.c 07dda7cd692911d2f22269953418d049f2e2c0ee F src/sqlite.h.in 0127e418883c2b41f7fbc056bc1033fa56fbd2a5 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b271ed56532a78323accc8a7cb348d55f95c350e -R 90be3dacb0448d45e67c9b3d977b8761 +P c7b16645307d6e46c4153693d6806269de64955f +R ea3eb1f6139bdf0dd5e3dd418a160ce1 U drh -Z 153c06778c9f21378fccc520e3f4d229 +Z 134fe99ba84c8d22f546034f7884244d diff --git a/manifest.uuid b/manifest.uuid index 35751a8d88..605cc6bbcb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c7b16645307d6e46c4153693d6806269de64955f \ No newline at end of file +45d3893c6142ee1dfed48e26a13cf547da12468a \ No newline at end of file diff --git a/src/select.c b/src/select.c index e8d9fdd5ca..fff0cd9a28 100644 --- a/src/select.c +++ b/src/select.c @@ -5523,9 +5523,9 @@ select_end: void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ int n = 0; pView = sqlite3TreeViewPush(pView, moreToFollow); - sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p)", + sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x", ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""), - ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p + ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags ); if( p->pSrc && p->pSrc->nSrc ) n++; if( p->pWhere ) n++; From 00d5ab74051f5ffd075327ebd4ef4eb92fc1e9d9 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 May 2015 00:15:27 +0000 Subject: [PATCH 02/14] Fix handling of queries with VALUES on the left and UNION ALL SELECT on the right and a LIMIT clause. FossilOrigin-Name: c403502cdce8b82e570e6fc49ab7f5144800c189 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/parse.y | 6 ++++-- test/select4.test | 6 ++++++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 33442b2035..10bfc3621f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Enhance\sthe\sselecttrace\sdisplay\sby\sshowing\sSelect.selFlags. -D 2015-05-19T23:56:07.009 +C Fix\shandling\sof\squeries\swith\sVALUES\son\sthe\sleft\sand\sUNION\sALL\sSELECT\son\sthe\nright\sand\sa\sLIMIT\sclause. +D 2015-05-20T00:15:27.101 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -239,7 +239,7 @@ F src/os_win.c 97f7828a9554d753665b6fcf7540e31c2b3d6a6e F src/os_win.h eb7a47aa17b26b77eb97e4823f20a00b8bda12ca F src/pager.c 97110085b1321298412f1e5c37bddb95b36d9208 F src/pager.h c3476e7c89cdf1c6914e50a11f3714e30b4e0a77 -F src/parse.y c4e0387bc88c8e21e5ba653e2578959a1f3cdbc7 +F src/parse.y af55d4fb5e588705112e9788364ca3af09651fcf F src/pcache.c 10539fb959849ad6efff80050541cab3d25089d4 F src/pcache.h b44658c9c932d203510279439d891a2a83e12ba8 F src/pcache1.c 69d137620a305f814398bd29a0c998038c0695e9 @@ -864,7 +864,7 @@ F test/securedel2.test 2d54c28e46eb1fd6902089958b20b1b056c6f1c5 F test/select1.test be62204d2bd9a5a8a149e9974cfddce893d8f686 F test/select2.test 352480e0e9c66eda9c3044e412abdf5be0215b56 F test/select3.test 2ce595f8fb8e2ac10071d3b4e424cadd4634a054 -F test/select4.test 824342f382f16b4afe42d0887ef82b3d6abb6075 +F test/select4.test 6d5bc6d178a367e8b48fa1c1d3ea12cae9c2d650 F test/select5.test e758b8ef94f69b111df4cb819008856655dcd535 F test/select6.test 39eac4a5c03650b2b473c532882273283ee8b7a0 F test/select7.test 7fd2ef598cfabb6b9ff6ac13973b91d0527df49d @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c7b16645307d6e46c4153693d6806269de64955f -R ea3eb1f6139bdf0dd5e3dd418a160ce1 +P 45d3893c6142ee1dfed48e26a13cf547da12468a +R d2f9de9f0b0e2d9149961be12bc360a3 U drh -Z 134fe99ba84c8d22f546034f7884244d +Z dfad787f317538afb4e1ced0974df5c8 diff --git a/manifest.uuid b/manifest.uuid index 605cc6bbcb..8f7a7be3d9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -45d3893c6142ee1dfed48e26a13cf547da12468a \ No newline at end of file +c403502cdce8b82e570e6fc49ab7f5144800c189 \ No newline at end of file diff --git a/src/parse.y b/src/parse.y index 6a64206ac0..72a0a6d222 100644 --- a/src/parse.y +++ b/src/parse.y @@ -448,6 +448,7 @@ selectnowith(A) ::= oneselect(X). {A = X;} %ifndef SQLITE_OMIT_COMPOUND_SELECT selectnowith(A) ::= selectnowith(X) multiselect_op(Y) oneselect(Z). { Select *pRhs = Z; + Select *pLhs = X; if( pRhs && pRhs->pPrior ){ SrcList *pFrom; Token x; @@ -458,11 +459,12 @@ selectnowith(A) ::= selectnowith(X) multiselect_op(Y) oneselect(Z). { } if( pRhs ){ pRhs->op = (u8)Y; - pRhs->pPrior = X; + pRhs->pPrior = pLhs; + if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue; pRhs->selFlags &= ~SF_MultiValue; if( Y!=TK_ALL ) pParse->hasCompound = 1; }else{ - sqlite3SelectDelete(pParse->db, X); + sqlite3SelectDelete(pParse->db, pLhs); } A = pRhs; } diff --git a/test/select4.test b/test/select4.test index c0f88a1507..a7b1af20a5 100644 --- a/test/select4.test +++ b/test/select4.test @@ -909,5 +909,11 @@ do_execsql_test select4-14.14 { do_execsql_test select4-14.15 { SELECT * FROM (SELECT 123), (SELECT 456) ON likely(0 OR 1) OR 0; } {123 456} +do_execsql_test select4-14.16 { + VALUES(1),(2),(3),(4) UNION ALL SELECT 5 LIMIT 99; +} {1 2 3 4 5} +do_execsql_test select4-14.17 { + VALUES(1),(2),(3),(4) UNION ALL SELECT 5 LIMIT 3; +} {1 2 3} finish_test From 9df25c4736ed39426a3133d4a200c0aec7938d13 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 May 2015 15:51:09 +0000 Subject: [PATCH 03/14] A proposed fix for the problem of CREATE TABLE AS generating a table that has INTEGER values in a TEXT column. Ticket [f2ad7de056ab1dc92]. FossilOrigin-Name: d5e2c1fc7625130a3cbacc95c28bb553a0119cb8 --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/build.c | 22 ++++++++++++++++++++-- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 10bfc3621f..081a393c43 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\shandling\sof\squeries\swith\sVALUES\son\sthe\sleft\sand\sUNION\sALL\sSELECT\son\sthe\nright\sand\sa\sLIMIT\sclause. -D 2015-05-20T00:15:27.101 +C A\sproposed\sfix\sfor\sthe\sproblem\sof\sCREATE\sTABLE\sAS\sgenerating\sa\stable\sthat\nhas\sINTEGER\svalues\sin\sa\sTEXT\scolumn.\s\sTicket\s[f2ad7de056ab1dc92]. +D 2015-05-20T15:51:09.466 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 30a80340481098d699398cba3536c895373b2e2c F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c 61b47073f79f31e80a05db9ce13c5ca81bf8f74e +F src/build.c 857606eac00ffdcc35267e2b78aaebb5c4a4bd06 F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 5a0b735dc95604766f5dac73973658eef782ee8b @@ -1278,7 +1278,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 45d3893c6142ee1dfed48e26a13cf547da12468a -R d2f9de9f0b0e2d9149961be12bc360a3 +P c403502cdce8b82e570e6fc49ab7f5144800c189 +R 50de0e4641ea4d7735e732fb73d3af44 +T *branch * create-table-as-type-fix +T *sym-create-table-as-type-fix * +T -sym-trunk * U drh -Z dfad787f317538afb4e1ced0974df5c8 +Z 78e916760aff70e5689a89cd2eb362da diff --git a/manifest.uuid b/manifest.uuid index 8f7a7be3d9..e81f5435d7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c403502cdce8b82e570e6fc49ab7f5144800c189 \ No newline at end of file +d5e2c1fc7625130a3cbacc95c28bb553a0119cb8 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 7990561393..8003a2cb13 100644 --- a/src/build.c +++ b/src/build.c @@ -1915,15 +1915,24 @@ void sqlite3EndTable( if( pSelect ){ SelectDest dest; Table *pSelTab; + int regYield; /* Register holding co-routine entry-point */ + int addrTop; /* Top of the co-routine */ + regYield = ++pParse->nMem; assert(pParse->nTab==1); sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb); sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG); pParse->nTab = 2; - sqlite3SelectDestInit(&dest, SRT_Table, 1); + addrTop = sqlite3VdbeCurrentAddr(v) + 1; + sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop); + sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield); sqlite3Select(pParse, pSelect, &dest); - sqlite3VdbeAddOp1(v, OP_Close, 1); + sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield); + sqlite3VdbeJumpHere(v, addrTop - 1); if( pParse->nErr==0 ){ + int regRec = ++pParse->nMem; + int regRowid = ++pParse->nMem; + int addrInsLoop; pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect); if( pSelTab==0 ) return; assert( p->aCol==0 ); @@ -1932,6 +1941,15 @@ void sqlite3EndTable( pSelTab->nCol = 0; pSelTab->aCol = 0; sqlite3DeleteTable(db, pSelTab); + addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); + VdbeCoverage(v); + sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec); + sqlite3TableAffinity(v, p, 0); + sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid); + sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid); + sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInsLoop); + sqlite3VdbeJumpHere(v, addrInsLoop); + sqlite3VdbeAddOp1(v, OP_Close, 1); } } From 92632204879b8e6575e9abecb842a03b6baf3af7 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 May 2015 17:18:29 +0000 Subject: [PATCH 04/14] Simplification of the initialization code for CREATE TABLE AS. FossilOrigin-Name: 937f659e8933011c44e822328a97cb5f0607c04d --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/build.c | 49 +++++++++++++++++++++++++------------------------ 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/manifest b/manifest index 081a393c43..46fe211584 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C A\sproposed\sfix\sfor\sthe\sproblem\sof\sCREATE\sTABLE\sAS\sgenerating\sa\stable\sthat\nhas\sINTEGER\svalues\sin\sa\sTEXT\scolumn.\s\sTicket\s[f2ad7de056ab1dc92]. -D 2015-05-20T15:51:09.466 +C Simplification\sof\sthe\sinitialization\scode\sfor\sCREATE\sTABLE\sAS. +D 2015-05-20T17:18:29.382 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -195,7 +195,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 F src/btree.c 30a80340481098d699398cba3536c895373b2e2c F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 -F src/build.c 857606eac00ffdcc35267e2b78aaebb5c4a4bd06 +F src/build.c d5d9090788118178190c5724c19f93953b8c7a4e F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c a5cf5b4b56390cfb7b8636e8f7ddef90258dd575 F src/ctime.c 5a0b735dc95604766f5dac73973658eef782ee8b @@ -1278,10 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c403502cdce8b82e570e6fc49ab7f5144800c189 -R 50de0e4641ea4d7735e732fb73d3af44 -T *branch * create-table-as-type-fix -T *sym-create-table-as-type-fix * -T -sym-trunk * +P d5e2c1fc7625130a3cbacc95c28bb553a0119cb8 +R 6555861550de93cc52d9bfcbb7f3a817 U drh -Z 78e916760aff70e5689a89cd2eb362da +Z 1fd362c4cfc736e2f31eca469b4265bd diff --git a/manifest.uuid b/manifest.uuid index e81f5435d7..4fdbda1f64 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d5e2c1fc7625130a3cbacc95c28bb553a0119cb8 \ No newline at end of file +937f659e8933011c44e822328a97cb5f0607c04d \ No newline at end of file diff --git a/src/build.c b/src/build.c index 8003a2cb13..44d75e9557 100644 --- a/src/build.c +++ b/src/build.c @@ -1913,12 +1913,17 @@ void sqlite3EndTable( ** be redundant. */ if( pSelect ){ - SelectDest dest; - Table *pSelTab; + SelectDest dest; /* Where the SELECT should store results */ int regYield; /* Register holding co-routine entry-point */ int addrTop; /* Top of the co-routine */ + int regRec; /* A record to be insert into the new table */ + int regRowid; /* Rowid of the next row to insert */ + int addrInsLoop; /* Top of the loop for inserting rows */ + Table *pSelTab; /* A table that describes the SELECT results */ regYield = ++pParse->nMem; + regRec = ++pParse->nMem; + regRowid = ++pParse->nMem; assert(pParse->nTab==1); sqlite3VdbeAddOp3(v, OP_OpenWrite, 1, pParse->regRoot, iDb); sqlite3VdbeChangeP5(v, OPFLAG_P2ISREG); @@ -1929,28 +1934,24 @@ void sqlite3EndTable( sqlite3Select(pParse, pSelect, &dest); sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield); sqlite3VdbeJumpHere(v, addrTop - 1); - if( pParse->nErr==0 ){ - int regRec = ++pParse->nMem; - int regRowid = ++pParse->nMem; - int addrInsLoop; - pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect); - if( pSelTab==0 ) return; - assert( p->aCol==0 ); - p->nCol = pSelTab->nCol; - p->aCol = pSelTab->aCol; - pSelTab->nCol = 0; - pSelTab->aCol = 0; - sqlite3DeleteTable(db, pSelTab); - addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); - VdbeCoverage(v); - sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec); - sqlite3TableAffinity(v, p, 0); - sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid); - sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid); - sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInsLoop); - sqlite3VdbeJumpHere(v, addrInsLoop); - sqlite3VdbeAddOp1(v, OP_Close, 1); - } + if( pParse->nErr ) return; + pSelTab = sqlite3ResultSetOfSelect(pParse, pSelect); + if( pSelTab==0 ) return; + assert( p->aCol==0 ); + p->nCol = pSelTab->nCol; + p->aCol = pSelTab->aCol; + pSelTab->nCol = 0; + pSelTab->aCol = 0; + sqlite3DeleteTable(db, pSelTab); + addrInsLoop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); + VdbeCoverage(v); + sqlite3VdbeAddOp3(v, OP_MakeRecord, dest.iSdst, dest.nSdst, regRec); + sqlite3TableAffinity(v, p, 0); + sqlite3VdbeAddOp2(v, OP_NewRowid, 1, regRowid); + sqlite3VdbeAddOp3(v, OP_Insert, 1, regRec, regRowid); + sqlite3VdbeAddOp2(v, OP_Goto, 0, addrInsLoop); + sqlite3VdbeJumpHere(v, addrInsLoop); + sqlite3VdbeAddOp1(v, OP_Close, 1); } /* Compute the complete text of the CREATE statement */ From f058b9c472c5992c9176d4835b4f5953eaf5b8ee Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 May 2015 17:25:44 +0000 Subject: [PATCH 05/14] Add a test case to verify that CREATE TABLE AS does not store INT values in TEXT columns. Ticket [f2ad7de056ab1dc92]. FossilOrigin-Name: 0e45e8f1574ef19a43dbd118440ddbc5cec80ce7 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/misc1.test | 9 +++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 46fe211584..40287ea2dd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplification\sof\sthe\sinitialization\scode\sfor\sCREATE\sTABLE\sAS. -D 2015-05-20T17:18:29.382 +C Add\sa\stest\scase\sto\sverify\sthat\sCREATE\sTABLE\sAS\sdoes\snot\sstore\sINT\svalues\nin\sTEXT\scolumns.\s\sTicket\s[f2ad7de056ab1dc92]. +D 2015-05-20T17:25:44.766 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -766,7 +766,7 @@ F test/minmax.test 42fbad0e81afaa6e0de41c960329f2b2c3526efd F test/minmax2.test b44bae787fc7b227597b01b0ca5575c7cb54d3bc F test/minmax3.test cc1e8b010136db0d01a6f2a29ba5a9f321034354 F test/minmax4.test 936941484ebdceb8adec7c86b6cd9b6e5e897c1f -F test/misc1.test 783ba75743b2cf71e0f646bf540a6cef57264811 +F test/misc1.test 2bb46a3656e97f80c82880a94ea10d76a3b60cb0 F test/misc2.test 00d7de54eda90e237fc9a38b9e5ccc769ebf6d4d F test/misc3.test cf3dda47d5dda3e53fc5804a100d3c82be736c9d F test/misc4.test 0d8be3466adf123a7791a66ba2bc8e8d229e87f3 @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P d5e2c1fc7625130a3cbacc95c28bb553a0119cb8 -R 6555861550de93cc52d9bfcbb7f3a817 +P 937f659e8933011c44e822328a97cb5f0607c04d +R a7c7024ecc6e55965138342c00704c17 U drh -Z 1fd362c4cfc736e2f31eca469b4265bd +Z 8a4264223b9336427c1887f1ad564ff3 diff --git a/manifest.uuid b/manifest.uuid index 4fdbda1f64..d5a52b27d6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -937f659e8933011c44e822328a97cb5f0607c04d \ No newline at end of file +0e45e8f1574ef19a43dbd118440ddbc5cec80ce7 \ No newline at end of file diff --git a/test/misc1.test b/test/misc1.test index 7ae50e4fe0..93f417721d 100644 --- a/test/misc1.test +++ b/test/misc1.test @@ -603,6 +603,15 @@ do_execsql_test misc1-19.2 { SELECT * FROM t19b; } {4 5 6} +# 2015-05-20: CREATE TABLE AS should not store INT value is a TEXT +# column. +# +do_execsql_test misc1-19.3 { + CREATE TABLE t19c(x TEXT); + CREATE TABLE t19d AS SELECT * FROM t19c UNION ALL SELECT 1234; + SELECT x, typeof(x) FROM t19d; +} {1234 text} + # 2014-05-16: Tests for the SQLITE_TESTCTRL_FAULT_INSTALL feature. # unset -nocomplain fault_callbacks From 4f03f413bce373957e3219d7a0f5245932e180c0 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 20 May 2015 21:28:32 +0000 Subject: [PATCH 06/14] Add the sqlite3_value_dup() and sqlite3_value_free() interfaces. Use these interfaces to enhance R-Tree to add the sqlite3_rtree_query_info.apSqlParam field. FossilOrigin-Name: a7ee40c4fc62843ac5b96ba47ca14a66e8cd6961 --- ext/rtree/rtree.c | 40 ++++++++++++++++++++++++--------- ext/rtree/rtreeE.test | 7 ++++-- ext/rtree/sqlite3rtree.h | 2 ++ manifest | 32 ++++++++++++++------------- manifest.uuid | 2 +- src/sqlite.h.in | 27 +++++++++++++++++----- src/sqlite3ext.h | 5 +++++ src/test_rtree.c | 48 +++++++++++++++++++++++++++++++++------- src/vdbeInt.h | 6 +++++ src/vdbeapi.c | 28 +++++++++++++++++++++++ src/vdbemem.c | 4 ---- 11 files changed, 155 insertions(+), 46 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index c14c04cd05..aed7240dff 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -351,6 +351,7 @@ struct RtreeMatchArg { u32 magic; /* Always RTREE_GEOMETRY_MAGIC */ RtreeGeomCallback cb; /* Info about the callback functions */ int nParam; /* Number of parameters to the SQL function */ + sqlite3_value **apSqlParam; /* Original SQL parameter values */ RtreeDValue aParam[1]; /* Values for parameters to the SQL function */ }; @@ -1495,6 +1496,7 @@ static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){ memcpy(pBlob, sqlite3_value_blob(pValue), nBlob); nExpected = (int)(sizeof(RtreeMatchArg) + + pBlob->nParam*sizeof(sqlite3_value*) + (pBlob->nParam-1)*sizeof(RtreeDValue)); if( pBlob->magic!=RTREE_GEOMETRY_MAGIC || nBlob!=nExpected ){ sqlite3_free(pInfo); @@ -1503,6 +1505,7 @@ static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){ pInfo->pContext = pBlob->cb.pContext; pInfo->nParam = pBlob->nParam; pInfo->aParam = pBlob->aParam; + pInfo->apSqlParam = pBlob->apSqlParam; if( pBlob->cb.xGeom ){ pCons->u.xGeom = pBlob->cb.xGeom; @@ -3372,6 +3375,18 @@ static void rtreeFreeCallback(void *p){ sqlite3_free(p); } +/* +** This routine frees the BLOB that is returned by geomCallback(). +*/ +static void rtreeMatchArgFree(void *pArg){ + int i; + RtreeMatchArg *p = (RtreeMatchArg*)pArg; + for(i=0; inParam; i++){ + sqlite3_value_free(p->apSqlParam[i]); + } + sqlite3_free(p); +} + /* ** Each call to sqlite3_rtree_geometry_callback() or ** sqlite3_rtree_query_callback() creates an ordinary SQLite @@ -3390,8 +3405,10 @@ static void geomCallback(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){ RtreeGeomCallback *pGeomCtx = (RtreeGeomCallback *)sqlite3_user_data(ctx); RtreeMatchArg *pBlob; int nBlob; + int memErr = 0; - nBlob = sizeof(RtreeMatchArg) + (nArg-1)*sizeof(RtreeDValue); + nBlob = sizeof(RtreeMatchArg) + (nArg-1)*sizeof(RtreeDValue) + + nArg*sizeof(sqlite3_value*); pBlob = (RtreeMatchArg *)sqlite3_malloc(nBlob); if( !pBlob ){ sqlite3_result_error_nomem(ctx); @@ -3399,22 +3416,23 @@ static void geomCallback(sqlite3_context *ctx, int nArg, sqlite3_value **aArg){ int i; pBlob->magic = RTREE_GEOMETRY_MAGIC; pBlob->cb = pGeomCtx[0]; + pBlob->apSqlParam = (sqlite3_value**)&pBlob->aParam[nArg]; pBlob->nParam = nArg; for(i=0; iaParam[i], sqlite3_value_blob(aArg[i]), - sizeof(sqlite3_rtree_dbl)); - }else{ + pBlob->apSqlParam[i] = sqlite3_value_dup(aArg[i]); + if( pBlob->apSqlParam[i]==0 ) memErr = 1; #ifdef SQLITE_RTREE_INT_ONLY - pBlob->aParam[i] = sqlite3_value_int64(aArg[i]); + pBlob->aParam[i] = sqlite3_value_int64(aArg[i]); #else - pBlob->aParam[i] = sqlite3_value_double(aArg[i]); + pBlob->aParam[i] = sqlite3_value_double(aArg[i]); #endif - } } - sqlite3_result_blob(ctx, pBlob, nBlob, sqlite3_free); + if( memErr ){ + sqlite3_result_error_nomem(ctx); + rtreeMatchArgFree(pBlob); + }else{ + sqlite3_result_blob(ctx, pBlob, nBlob, rtreeMatchArgFree); + } } } diff --git a/ext/rtree/rtreeE.test b/ext/rtree/rtreeE.test index c450623790..b95b76457e 100644 --- a/ext/rtree/rtreeE.test +++ b/ext/rtree/rtreeE.test @@ -52,6 +52,9 @@ do_execsql_test rtreeE-1.1 { do_execsql_test rtreeE-1.1 { SELECT id FROM rt1 WHERE id MATCH Qcircle(0.0, 0.0, 50.0, 3) ORDER BY id; } {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24} +do_execsql_test rtreeE-1.1x { + SELECT id FROM rt1 WHERE id MATCH Qcircle('x:0 y:0 r:50.0 e:3') ORDER BY id; +} {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24} do_execsql_test rtreeE-1.2 { SELECT id FROM rt1 WHERE id MATCH Qcircle(100.0, 0.0, 50.0, 3) ORDER BY id; } {100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124} @@ -64,12 +67,12 @@ do_execsql_test rtreeE-1.3 { # last. # do_execsql_test rtreeE-1.4 { - SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,3) AND id%100==0 + SELECT id FROM rt1 WHERE id MATCH Qcircle('r:1000 e:3') AND id%100==0 } {200 100 0} # Exclude odd rowids on a depth-first search do_execsql_test rtreeE-1.5 { - SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,4) ORDER BY +id + SELECT id FROM rt1 WHERE id MATCH Qcircle('r:1000 e:4') ORDER BY +id } {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120 122 124 200 202 204 206 208 210 212 214 216 218 220 222 224} # Exclude odd rowids on a breadth-first search. diff --git a/ext/rtree/sqlite3rtree.h b/ext/rtree/sqlite3rtree.h index 5de0508d00..f683fc610a 100644 --- a/ext/rtree/sqlite3rtree.h +++ b/ext/rtree/sqlite3rtree.h @@ -98,6 +98,8 @@ struct sqlite3_rtree_query_info { int eParentWithin; /* Visibility of parent node */ int eWithin; /* OUT: Visiblity */ sqlite3_rtree_dbl rScore; /* OUT: Write the score here */ + /* The following fields are only available in 3.8.11 and later */ + sqlite3_value **apSqlParam; /* Original SQL values of parameters */ }; /* diff --git a/manifest b/manifest index 322b8def98..753486c81e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sinitialization\slogic\sin\sCREATE\sTABLE\sAS\sso\sthat\sthe\scorrect\saffinities\nare\sapplied\sto\sall\svalues\sbeing\sinserted\sinto\sthe\snew\stable,\seven\sif\sthe\nRHS\sis\sa\scompound\sSELECT.\s\sFix\sfor\sticket\s[f2ad7de056ab1dc9200]. -D 2015-05-20T17:36:49.966 +C Add\sthe\ssqlite3_value_dup()\sand\ssqlite3_value_free()\sinterfaces.\s\sUse\nthese\sinterfaces\sto\senhance\sR-Tree\sto\sadd\sthe\nsqlite3_rtree_query_info.apSqlParam\sfield. +D 2015-05-20T21:28:32.417 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -143,7 +143,7 @@ F ext/ota/sqlite3ota.c 2246b779f46ab20d5e7876f5b96c378c601d20f4 F ext/ota/sqlite3ota.h 00028de37eede471ff1947d455cc3f33d3a911c6 F ext/ota/test_ota.c a876f88550d7d59a3ef62d4c1a5c04c4c2f1ebe1 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c 60ec0a71d4d213665a706c795c887e7c4d148635 +F ext/rtree/rtree.c 50d9df06d2b7ca946646531c20b3b627514ad832 F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 541bbcab74613907fea08b2ecdcdd5b7aa724cc9 F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -158,11 +158,11 @@ F ext/rtree/rtreeA.test ace05e729a36e342d40cf94e9efc7b4723d9dcdf F ext/rtree/rtreeB.test c85f9ce78766c4e68b8b89fbf2979ee9cfa82b4e F ext/rtree/rtreeC.test df158dcc81f1a43ce7eef361af03c48ec91f1e06 F ext/rtree/rtreeD.test 636630357638f5983701550b37f0f5867130d2ca -F ext/rtree/rtreeE.test 388c1c8602c3ce55c15f03b509e9cf545fb7c41f +F ext/rtree/rtreeE.test b268eed6a621613fbc0a44157a8d6fe10cff3436 F ext/rtree/rtreeF.test 66deb9fd1611c7ca2e374adba63debdc2dbb12b4 F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195 F ext/rtree/rtree_util.tcl 06aab2ed5b826545bf215fff90ecb9255a8647ea -F ext/rtree/sqlite3rtree.h 83349d519fe5f518b3ea025d18dd1fe51b1684bd +F ext/rtree/sqlite3rtree.h 9c5777af3d2921c7b4ae4954e8e5697502289d28 F ext/rtree/tkt3363.test 142ab96eded44a3615ec79fba98c7bde7d0f96de F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024 F ext/userauth/sqlite3userauth.h 19cb6f0e31316d0ee4afdfb7a85ef9da3333a220 @@ -252,9 +252,9 @@ F src/resolve.c 99eabf7eff0bfa65b75939b46caa82e2b2133f28 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/select.c 95e728e1bdbca2ee45016308e3eb6d19095155cc F src/shell.c 07dda7cd692911d2f22269953418d049f2e2c0ee -F src/sqlite.h.in 0127e418883c2b41f7fbc056bc1033fa56fbd2a5 +F src/sqlite.h.in f97f23de94767ab7e2c97745308920a749d4a4b5 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad -F src/sqlite3ext.h 17d487c3c91b0b8c584a32fbeb393f6f795eea7d +F src/sqlite3ext.h 2ebeb634e751a61a6f0eebfa0f4669f46a42f6cd F src/sqliteInt.h 88738d94a343000e7a5c0e295d111c4cfccb18b0 F src/sqliteLimit.h 216557999cb45f2e3578ed53ebefe228d779cb46 F src/status.c f266ad8a2892d659b74f0f50cb6a88b6e7c12179 @@ -294,7 +294,7 @@ F src/test_osinst.c 5423dc1d355f594371f27dd292ca54bd320b8196 F src/test_pcache.c a5cd24730cb43c5b18629043314548c9169abb00 F src/test_quota.c 180813f43683be5725458fc1ff13ac455d8e722d F src/test_quota.h 2a8ad1952d1d2ca9af0ce0465e56e6c023b5e15d -F src/test_rtree.c bfe6f4386517f70054311109f3528adffec34485 +F src/test_rtree.c 43fff4c5a01576d6d213f27472598801a247890c F src/test_schema.c 2bdba21b82f601da69793e1f1d11bf481a79b091 F src/test_server.c a2615049954cbb9cfb4a62e18e2f0616e4dc38fe F src/test_sqllog.c b690c12933f50ff46491e0d56a251f84ae16e914 @@ -314,11 +314,11 @@ F src/util.c a6431c92803b975b7322724a7b433e538d243539 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 F src/vdbe.c 6aee8a041742413ab3113e6682bc7ad1628a2bbe F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d -F src/vdbeInt.h de3291a6688dfef9f61d47705c1bd57008b1185d -F src/vdbeapi.c 583d56b129dd27f12bed518270de9ebe521e6a75 +F src/vdbeInt.h f0ccddac48583d5f762dc554a9f79e85ea8807e0 +F src/vdbeapi.c f9ad1be11b9e8f2f8580656191abeeefd24f71dd F src/vdbeaux.c efe1667d31e8648dbe04a441e5aa9b62dbee2f03 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c 7bfbeef0978a2e1a05d979641fdbf7c189b7ddf4 +F src/vdbemem.c e87e076b863e4228d71d8c4d1c4df6836d810043 F src/vdbesort.c f5009e7a35e3065635d8918b9a31f498a499976b F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 F src/vtab.c c535e80259ebe616467181a83a4263555b97c694 @@ -1278,8 +1278,10 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c403502cdce8b82e570e6fc49ab7f5144800c189 0e45e8f1574ef19a43dbd118440ddbc5cec80ce7 -R a7c7024ecc6e55965138342c00704c17 -T +closed 0e45e8f1574ef19a43dbd118440ddbc5cec80ce7 +P 6a0cf3ce9e68d0127f9653232e588ed59d34eca5 +R bf385fc150043c4fd0764e8a32885eb2 +T *branch * value-dup +T *sym-value-dup * +T -sym-trunk * U drh -Z fd6f77c4d4a68df5c93e64187bb026e9 +Z 7924e70131eeabe4b6a3d5fe0f7548fa diff --git a/manifest.uuid b/manifest.uuid index af099e8f47..8af005bae6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6a0cf3ce9e68d0127f9653232e588ed59d34eca5 \ No newline at end of file +a7ee40c4fc62843ac5b96ba47ca14a66e8cd6961 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 734ffb1644..b07bdbd533 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -4294,12 +4294,12 @@ SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int64,int), #endif /* -** CAPI3REF: Obtaining SQL Function Parameter Values +** CAPI3REF: Obtaining SQL Values ** METHOD: sqlite3_value ** ** The C-language implementation of SQL functions and aggregates uses ** this set of interface routines to access the parameter values on -** the function or aggregate. +** the function or aggregate. ** ** The xFunc (for scalar functions) or xStep (for aggregates) parameters ** to [sqlite3_create_function()] and [sqlite3_create_function16()] @@ -4352,6 +4352,23 @@ const void *sqlite3_value_text16be(sqlite3_value*); int sqlite3_value_type(sqlite3_value*); int sqlite3_value_numeric_type(sqlite3_value*); +/* +** CAPI3REF: Copy And Free SQL Values +** METHOD: sqlite3_value +** +** ^The sqlite3_value_dup(V) interface makes a copy of the [sqlite3_value] +** object D and returns a pointer to that copy. ^The [sqlite3_value] returned +** is a [protected sqlite3_value] object even if the input is not. +** ^The sqlite3_value_dup(V) interface returns NULL if V is NULL or if a +** memory allocation fails. +** +** ^The sqlite3_value_free(V) interface frees an [sqlite3_value] object +** previously obtained from [sqlite_value_dup()]. ^If V is a NULL pointer +** then sqlite3_value_free(V) is a harmless no-op. +*/ +SQLITE_EXPERIMENTAL sqlite3_value *sqlite3_value_dup(const sqlite3_value*); +SQLITE_EXPERIMENTAL void sqlite3_value_free(sqlite3_value*); + /* ** CAPI3REF: Obtain Aggregate Function Context ** METHOD: sqlite3_context @@ -5875,7 +5892,7 @@ int sqlite3_blob_open( ** ** ^This function sets the database handle error code and message. */ -SQLITE_EXPERIMENTAL int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); +int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); /* ** CAPI3REF: Close A BLOB Handle @@ -7685,7 +7702,7 @@ int sqlite3_vtab_on_conflict(sqlite3 *); ** ** See also: [sqlite3_stmt_scanstatus_reset()] */ -SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( +int sqlite3_stmt_scanstatus( sqlite3_stmt *pStmt, /* Prepared statement for which info desired */ int idx, /* Index of loop to report on */ int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */ @@ -7701,7 +7718,7 @@ SQLITE_EXPERIMENTAL int sqlite3_stmt_scanstatus( ** This API is only available if the library is built with pre-processor ** symbol [SQLITE_ENABLE_STMT_SCANSTATUS] defined. */ -SQLITE_EXPERIMENTAL void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); +void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*); /* diff --git a/src/sqlite3ext.h b/src/sqlite3ext.h index f9a066592d..5c4488c3b0 100644 --- a/src/sqlite3ext.h +++ b/src/sqlite3ext.h @@ -267,6 +267,8 @@ struct sqlite3_api_routines { void (*result_text64)(sqlite3_context*,const char*,sqlite3_uint64, void(*)(void*), unsigned char); int (*strglob)(const char*,const char*); + sqlite3_value (*value_dup)(const sqlite3_value*); + void (*value_free)(sqlite3_value*); }; /* @@ -497,6 +499,9 @@ struct sqlite3_api_routines { #define sqlite3_result_blob64 sqlite3_api->result_blob64 #define sqlite3_result_text64 sqlite3_api->result_text64 #define sqlite3_strglob sqlite3_api->strglob +/* Version 3.8.11 and later */ +#define sqlite3_value_dup sqlite3_api->value_dup +#define sqlite3_value_free sqlite3_api->value_free #endif /* SQLITE_CORE */ #ifndef SQLITE_CORE diff --git a/src/test_rtree.c b/src/test_rtree.c index 7beec66455..797ec0026c 100644 --- a/src/test_rtree.c +++ b/src/test_rtree.c @@ -155,6 +155,11 @@ static int circle_geom( /* ** Implementation of "circle" r-tree geometry callback using the ** 2nd-generation interface that allows scoring. +** +** Two calling forms: +** +** Qcircle(X,Y,Radius,eType) -- All values are doubles +** Qcircle('x:X y:Y r:R e:ETYPE') -- Single string parameter */ static int circle_query_func(sqlite3_rtree_query_info *p){ int i; /* Iterator variable */ @@ -176,10 +181,9 @@ static int circle_query_func(sqlite3_rtree_query_info *p){ ** Return an error if the table does not have exactly 2 dimensions. */ if( p->nCoord!=4 ) return SQLITE_ERROR; - /* Test that the correct number of parameters (4) have been supplied, - ** and that the parameters are in range (that the radius of the circle - ** radius is greater than zero). */ - if( p->nParam!=4 || p->aParam[2]<0.0 ) return SQLITE_ERROR; + /* Test that the correct number of parameters (1 or 4) have been supplied. + */ + if( p->nParam!=4 && p->nParam!=1 ) return SQLITE_ERROR; /* Allocate a structure to cache parameter data in. Return SQLITE_NOMEM ** if the allocation fails. */ @@ -191,10 +195,38 @@ static int circle_query_func(sqlite3_rtree_query_info *p){ ** tested bounding boxes that intersect the circular region are detected ** is by testing if each corner of the bounding box lies within radius ** units of the center of the circle. */ - pCircle->centerx = p->aParam[0]; - pCircle->centery = p->aParam[1]; - pCircle->radius = p->aParam[2]; - pCircle->eScoreType = (int)p->aParam[3]; + if( p->nParam==4 ){ + pCircle->centerx = p->aParam[0]; + pCircle->centery = p->aParam[1]; + pCircle->radius = p->aParam[2]; + pCircle->eScoreType = (int)p->aParam[3]; + }else{ + const char *z = (const char*)sqlite3_value_text(p->apSqlParam[0]); + pCircle->centerx = 0.0; + pCircle->centery = 0.0; + pCircle->radius = 0.0; + pCircle->eScoreType = 0; + while( z && z[0] ){ + if( z[0]=='r' && z[1]==':' ){ + pCircle->radius = atof(&z[2]); + }else if( z[0]=='x' && z[1]==':' ){ + pCircle->centerx = atof(&z[2]); + }else if( z[0]=='y' && z[1]==':' ){ + pCircle->centery = atof(&z[2]); + }else if( z[0]=='e' && z[1]==':' ){ + pCircle->eScoreType = (int)atof(&z[2]); + }else if( z[0]==' ' ){ + z++; + continue; + } + while( z[0]!=0 && z[0]!=' ' ) z++; + while( z[0]==' ' ) z++; + } + } + if( pCircle->radius<0.0 ){ + sqlite3_free(pCircle); + return SQLITE_NOMEM; + } /* Define two bounding box regions. The first, aBox[0], extends to ** infinity in the X dimension. It covers the same range of the Y dimension diff --git a/src/vdbeInt.h b/src/vdbeInt.h index d68be06931..bb32bddc29 100644 --- a/src/vdbeInt.h +++ b/src/vdbeInt.h @@ -186,6 +186,12 @@ struct Mem { #endif }; +/* +** Size of struct Mem not including the Mem.zMalloc member or anything that +** follows. +*/ +#define MEMCELLSIZE offsetof(Mem,zMalloc) + /* One or more of the following flags are set to indicate the validOK ** representations of the value stored in the Mem struct. ** diff --git a/src/vdbeapi.c b/src/vdbeapi.c index e03640dfbd..e08398cd0b 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -212,6 +212,34 @@ int sqlite3_value_type(sqlite3_value* pVal){ return aType[pVal->flags&MEM_AffMask]; } +/* Make a copy of an sqlite3_value object +*/ +sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){ + sqlite3_value *pNew; + if( pOrig==0 ) return 0; + pNew = sqlite3_malloc( sizeof(*pNew) ); + if( pNew==0 ) return 0; + memset(pNew, 0, sizeof(*pNew)); + memcpy(pNew, pOrig, MEMCELLSIZE); + pNew->flags &= ~MEM_Dyn; + pNew->db = 0; + if( pNew->flags&(MEM_Str|MEM_Blob) ){ + if( 0==(pOrig->flags&MEM_Static) ){ + pNew->flags |= MEM_Ephem; + sqlite3VdbeMemMakeWriteable(pNew); + } + } + return pNew; +} + +/* Destroy an sqlite3_value object previously obtained from +** sqlite3_value_dup(). +*/ +void sqlite3_value_free(sqlite3_value *pOld){ + sqlite3ValueFree(pOld); +} + + /**************************** sqlite3_result_ ******************************* ** The following routines are used by user-defined functions to specify ** the function result. diff --git a/src/vdbemem.c b/src/vdbemem.c index 2fd6a71895..987e49a21a 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -770,10 +770,6 @@ void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){ } #endif /* SQLITE_DEBUG */ -/* -** Size of struct Mem not including the Mem.zMalloc member. -*/ -#define MEMCELLSIZE offsetof(Mem,zMalloc) /* ** Make an shallow copy of pFrom into pTo. Prior contents of From acd337455639a8f515c04859f09f853a84733b60 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 May 2015 11:38:22 +0000 Subject: [PATCH 07/14] Add the --database option to the fuzzershell test program. FossilOrigin-Name: c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 --- manifest | 13 ++++++------- manifest.uuid | 2 +- tool/fuzzershell.c | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 322b8def98..d68e6d812a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sthe\sinitialization\slogic\sin\sCREATE\sTABLE\sAS\sso\sthat\sthe\scorrect\saffinities\nare\sapplied\sto\sall\svalues\sbeing\sinserted\sinto\sthe\snew\stable,\seven\sif\sthe\nRHS\sis\sa\scompound\sSELECT.\s\sFix\sfor\sticket\s[f2ad7de056ab1dc9200]. -D 2015-05-20T17:36:49.966 +C Add\sthe\s--database\soption\sto\sthe\sfuzzershell\stest\sprogram. +D 2015-05-22T11:38:22.072 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -1230,7 +1230,7 @@ F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/extract.c 054069d81b095fbdc189a6f5d4466e40380505e2 F tool/fast_vacuum.c 5ba0d6f5963a0a63bdc42840f678bad75b2ebce1 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 -F tool/fuzzershell.c e8be9a8bd8e0e7814592c5e3e38de99ad7beee83 +F tool/fuzzershell.c e35a3e0918349f2a9e0498c17c6fe5a6c7d61d86 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce @@ -1278,8 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c403502cdce8b82e570e6fc49ab7f5144800c189 0e45e8f1574ef19a43dbd118440ddbc5cec80ce7 -R a7c7024ecc6e55965138342c00704c17 -T +closed 0e45e8f1574ef19a43dbd118440ddbc5cec80ce7 +P 6a0cf3ce9e68d0127f9653232e588ed59d34eca5 +R 549a709a6f5e577976c5b6d0eb103940 U drh -Z fd6f77c4d4a68df5c93e64187bb026e9 +Z 07941c2a844d4926d98c426b503acb2a diff --git a/manifest.uuid b/manifest.uuid index af099e8f47..ac2e3ceb4c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6a0cf3ce9e68d0127f9653232e588ed59d34eca5 \ No newline at end of file +c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 \ No newline at end of file diff --git a/tool/fuzzershell.c b/tool/fuzzershell.c index 4eea55ba0e..6890c0be1e 100644 --- a/tool/fuzzershell.c +++ b/tool/fuzzershell.c @@ -321,6 +321,7 @@ static void showHelp(void){ "and then evaluate each block of SQL contained therein.\n" "Options:\n" " --autovacuum Enable AUTOVACUUM mode\n" +" --database FILE Use database FILE instead of an in-memory database\n" " --heap SZ MIN Memory allocator uses SZ bytes & min allocation MIN\n" " --help Show this help text\n" " --lookaside N SZ Configure lookaside for N slots of SZ bytes each\n" @@ -453,6 +454,7 @@ int main(int argc, char **argv){ int jj; /* Loop counter for azInFile[] */ sqlite3_int64 iBegin; /* Start time for the whole program */ sqlite3_int64 iStart, iEnd; /* Start and end-times for a test case */ + const char *zDbName; /* Name of an on-disk database file to open */ iBegin = timeOfDay(); zFailCode = getenv("TEST_FAILURE"); @@ -466,6 +468,11 @@ int main(int argc, char **argv){ if( strcmp(z,"autovacuum")==0 ){ doAutovac = 1; }else + if( strcmp(z,"database")==0 ){ + if( i>=argc-1 ) abendError("missing argument on %s\n", argv[i]); + zDbName = argv[i+1]; + i += 1; + }else if( strcmp(z, "f")==0 && i+1 Date: Fri, 22 May 2015 12:37:37 +0000 Subject: [PATCH 08/14] Fix an assert in btree.c that can be false when using a corrupted database file. FossilOrigin-Name: a6eb2a39357c35dc13d549ef86c785ff5c69938a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/btree.c | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index d68e6d812a..debf5f12bd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s--database\soption\sto\sthe\sfuzzershell\stest\sprogram. -D 2015-05-22T11:38:22.072 +C Fix\san\sassert\sin\sbtree.c\sthat\scan\sbe\sfalse\swhen\susing\sa\scorrupted\sdatabase\nfile. +D 2015-05-22T12:37:37.573 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -192,7 +192,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c 30a80340481098d699398cba3536c895373b2e2c +F src/btree.c dbc8f9207278c109c3f38c9dc5f550c8bb5080d8 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c d5d9090788118178190c5724c19f93953b8c7a4e @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 6a0cf3ce9e68d0127f9653232e588ed59d34eca5 -R 549a709a6f5e577976c5b6d0eb103940 +P c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 +R b9e753c0683555ed773ae3f4504e148b U drh -Z 07941c2a844d4926d98c426b503acb2a +Z f51f66c2118a09b9970e631fa314a714 diff --git a/manifest.uuid b/manifest.uuid index ac2e3ceb4c..a98c44dfeb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 \ No newline at end of file +a6eb2a39357c35dc13d549ef86c785ff5c69938a \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4831657fcc..5e561cbcf4 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7860,7 +7860,8 @@ static int btreeCreateTable(Btree *p, int *piTable, int createTabFlags){ pgnoRoot==PENDING_BYTE_PAGE(pBt) ){ pgnoRoot++; } - assert( pgnoRoot>=3 ); + assert( pgnoRoot>=3 || CORRUPT_DB ); + testcase( pgnoRoot<3 ); /* Allocate a page. The page that currently resides at pgnoRoot will ** be moved to the allocated page (unless the allocated page happens From afe028a8153e8d10872f9363fc95c5bb8c896d57 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 May 2015 13:09:50 +0000 Subject: [PATCH 09/14] Fix two faulty assert statements discovered by fuzzing. FossilOrigin-Name: 799817bfb2bc95963c0e0d70063c4cb15c94ef74 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/btree.c | 3 ++- src/insert.c | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index debf5f12bd..b06174bcb6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sassert\sin\sbtree.c\sthat\scan\sbe\sfalse\swhen\susing\sa\scorrupted\sdatabase\nfile. -D 2015-05-22T12:37:37.573 +C Fix\stwo\sfaulty\sassert\sstatements\sdiscovered\sby\sfuzzing. +D 2015-05-22T13:09:50.891 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -192,7 +192,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240 F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3 F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79 -F src/btree.c dbc8f9207278c109c3f38c9dc5f550c8bb5080d8 +F src/btree.c 0eb4eb39e75be6170f1e59f7d6aabedaefb19938 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 973a22a6fd61350b454ad614832b1f0a5e25a1e4 F src/build.c d5d9090788118178190c5724c19f93953b8c7a4e @@ -210,7 +210,7 @@ F src/global.c 4f77cadbc5427d00139ba43d0f3979804cbb700e F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5 F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c 8176ba5bad8fcef643558ca5708f33ed05a4035a +F src/insert.c 35b7816918406ec49fbcc6c7fa7ab622597f662e F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c ba1863ea58c4c840335a84ec276fc2b25e22bc4e F src/lempar.c 7274c97d24bb46631e504332ccd3bd1b37841770 @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c6d5512f4b8b1237fa4cf5f3f2eae19b160bcf26 -R b9e753c0683555ed773ae3f4504e148b +P a6eb2a39357c35dc13d549ef86c785ff5c69938a +R d9917d1c8ed4ffaff7f5ca236b5ad758 U drh -Z f51f66c2118a09b9970e631fa314a714 +Z d8611b43fb13ded0a9ff190ab5f2029c diff --git a/manifest.uuid b/manifest.uuid index a98c44dfeb..d18f783771 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a6eb2a39357c35dc13d549ef86c785ff5c69938a \ No newline at end of file +799817bfb2bc95963c0e0d70063c4cb15c94ef74 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 5e561cbcf4..6b7da394ac 100644 --- a/src/btree.c +++ b/src/btree.c @@ -8011,7 +8011,8 @@ static int clearDatabasePage( rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange); if( rc ) goto cleardatabasepage_out; }else if( pnChange ){ - assert( pPage->intKey ); + assert( pPage->intKey || CORRUPT_DB ); + testcase( !pPage->intKey ); *pnChange += pPage->nCell; } if( freePageFlag ){ diff --git a/src/insert.c b/src/insert.c index c794ae4f56..18dbfed8b2 100644 --- a/src/insert.c +++ b/src/insert.c @@ -42,7 +42,7 @@ void sqlite3OpenTable( }else{ Index *pPk = sqlite3PrimaryKeyIndex(pTab); assert( pPk!=0 ); - assert( pPk->tnum=pTab->tnum ); + assert( pPk->tnum==pTab->tnum ); sqlite3VdbeAddOp3(v, opcode, iCur, pPk->tnum, iDb); sqlite3VdbeSetP4KeyInfo(pParse, pPk); VdbeComment((v, "%s", pTab->zName)); From 6b76418e67e8ec93caba0a13139a7fcfd5b8952c Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 22 May 2015 16:08:42 +0000 Subject: [PATCH 10/14] Have r-tree prefer to use the constraint "col MATCH ?" over "rowid = ?". FossilOrigin-Name: b9fb95194d4f7c535f1d175fd2e18d69d76e8fc4 --- ext/rtree/rtree.c | 15 ++++++++++++++- ext/rtree/rtreeE.test | 8 ++++++++ manifest | 17 +++++++++-------- manifest.uuid | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index c14c04cd05..553c2fb01b 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -1669,17 +1669,30 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ Rtree *pRtree = (Rtree*)tab; int rc = SQLITE_OK; int ii; + int bMatch = 0; /* True if there exists a MATCH constraint */ i64 nRow; /* Estimated rows returned by this scan */ int iIdx = 0; char zIdxStr[RTREE_MAX_DIMENSIONS*8+1]; memset(zIdxStr, 0, sizeof(zIdxStr)); + /* Check if there exists a MATCH constraint - even an unusable one. If there + ** is, do not consider the lookup-by-rowid plan as using such a plan would + ** require the VDBE to evaluate the MATCH constraint, which is not currently + ** possible. */ + for(ii=0; iinConstraint; ii++){ + if( pIdxInfo->aConstraint[ii].op==SQLITE_INDEX_CONSTRAINT_MATCH ){ + bMatch = 1; + } + } + assert( pIdxInfo->idxStr==0 ); for(ii=0; iinConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){ struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii]; - if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){ + if( bMatch==0 && p->usable + && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ + ){ /* We have an equality constraint on the rowid. Use strategy 1. */ int jj; for(jj=0; jj Date: Fri, 22 May 2015 17:29:27 +0000 Subject: [PATCH 11/14] The SRT_Table type for the SelectDest object is now just an SRT_EphemTab for which the ephemeral table has already been allocated. FossilOrigin-Name: b9727e6bbfc3c62c601227e86e62f2f39792fd1d --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/select.c | 20 ++++---------------- src/update.c | 4 +--- 4 files changed, 14 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index 155d76770a..405292cc69 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Have\sr-tree\sprefer\sto\suse\sthe\sconstraint\s"col\sMATCH\s?"\sover\s"rowid\s=\s?". -D 2015-05-22T16:08:42.447 +C The\sSRT_Table\stype\sfor\sthe\sSelectDest\sobject\sis\snow\sjust\san\sSRT_EphemTab\sfor\nwhich\sthe\sephemeral\stable\shas\salready\sbeen\sallocated. +D 2015-05-22T17:29:27.432 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -250,7 +250,7 @@ F src/printf.c 13ce37e5574f9b0682fa86dbcf9faf76b9d82a15 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 99eabf7eff0bfa65b75939b46caa82e2b2133f28 F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e -F src/select.c 95e728e1bdbca2ee45016308e3eb6d19095155cc +F src/select.c 6adad8d698a382f83009eed7b73080273fa993ca F src/shell.c 07dda7cd692911d2f22269953418d049f2e2c0ee F src/sqlite.h.in 0127e418883c2b41f7fbc056bc1033fa56fbd2a5 F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad @@ -308,7 +308,7 @@ F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/threads.c 6bbcc9fe50c917864d48287b4792d46d6e873481 F src/tokenize.c af8cbbca6db6b664ffecafa236b06629ef6d35c4 F src/trigger.c 322f23aad694e8f31d384dcfa386d52a48d3c52f -F src/update.c 3c4ecc282accf12d39edb8d524cf089645e55a13 +F src/update.c 487747b328b7216bb7f6af0695d6937d5c9e605f F src/utf.c fc6b889ba0779b7722634cdeaa25f1930d93820c F src/util.c a6431c92803b975b7322724a7b433e538d243539 F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 @@ -1278,8 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 799817bfb2bc95963c0e0d70063c4cb15c94ef74 -Q +b9e45596d823a6659f4ce2450afcd703feb788d8 -R 28f0e486e27f35ba4c09d0bec0224e3e -U dan -Z e4a60b1b66e40fbda6f3bf3e83ae873e +P b9fb95194d4f7c535f1d175fd2e18d69d76e8fc4 +R b9824a32563c5717dba8f6fd0e248f54 +U drh +Z 6ae4be6461472ee1a411850c6b256793 diff --git a/manifest.uuid b/manifest.uuid index c5d3ebcd5a..f4cd12aa80 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b9fb95194d4f7c535f1d175fd2e18d69d76e8fc4 \ No newline at end of file +b9727e6bbfc3c62c601227e86e62f2f39792fd1d \ No newline at end of file diff --git a/src/select.c b/src/select.c index fff0cd9a28..8fc2dbde3d 100644 --- a/src/select.c +++ b/src/select.c @@ -816,6 +816,8 @@ static void selectInnerLoop( int r1 = sqlite3GetTempRange(pParse, nPrefixReg+1); testcase( eDest==SRT_Table ); testcase( eDest==SRT_EphemTab ); + testcase( eDest==SRT_Fifo ); + testcase( eDest==SRT_DistFifo ); sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1+nPrefixReg); #ifndef SQLITE_OMIT_CTE if( eDest==SRT_DistFifo ){ @@ -1231,10 +1233,7 @@ static void generateSortTail( VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan)); } switch( eDest ){ - case SRT_Table: case SRT_EphemTab: { - testcase( eDest==SRT_Table ); - testcase( eDest==SRT_EphemTab ); sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid); sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid); sqlite3VdbeChangeP5(v, OPFLAG_APPEND); @@ -2583,15 +2582,14 @@ static int generateOutputSubroutine( */ codeOffset(v, p->iOffset, iContinue); + assert( pDest->eDest!=SRT_Exists ); + assert( pDest->eDest!=SRT_Table ); switch( pDest->eDest ){ /* Store the result as data using a unique key. */ - case SRT_Table: case SRT_EphemTab: { int r1 = sqlite3GetTempReg(pParse); int r2 = sqlite3GetTempReg(pParse); - testcase( pDest->eDest==SRT_Table ); - testcase( pDest->eDest==SRT_EphemTab ); sqlite3VdbeAddOp3(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst, r1); sqlite3VdbeAddOp2(v, OP_NewRowid, pDest->iSDParm, r2); sqlite3VdbeAddOp3(v, OP_Insert, pDest->iSDParm, r1, r2); @@ -2619,16 +2617,6 @@ static int generateOutputSubroutine( break; } -#if 0 /* Never occurs on an ORDER BY query */ - /* If any row exist in the result set, record that fact and abort. - */ - case SRT_Exists: { - sqlite3VdbeAddOp2(v, OP_Integer, 1, pDest->iSDParm); - /* The LIMIT clause will terminate the loop for us */ - break; - } -#endif - /* If this is a scalar select that is part of an expression, then ** store the results in the appropriate memory cell and break out ** of the scan loop. diff --git a/src/update.c b/src/update.c index 3af4017f1b..f8347448a1 100644 --- a/src/update.c +++ b/src/update.c @@ -743,12 +743,10 @@ static void updateVirtualTable( */ assert( v ); ephemTab = pParse->nTab++; - sqlite3VdbeAddOp2(v, OP_OpenEphemeral, ephemTab, pTab->nCol+1+(pRowid!=0)); - sqlite3VdbeChangeP5(v, BTREE_UNORDERED); /* fill the ephemeral table */ - sqlite3SelectDestInit(&dest, SRT_Table, ephemTab); + sqlite3SelectDestInit(&dest, SRT_EphemTab, ephemTab); sqlite3Select(pParse, pSelect, &dest); /* Generate code to scan the ephemeral table and call VUpdate. */ From 9dfedc824697a4f191ae360113f071bf3510b0eb Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 May 2015 19:55:10 +0000 Subject: [PATCH 12/14] Fix minor issues with the sqlite3_value_dup() interface. FossilOrigin-Name: 95edcf5010ecb8edd8eb74279c4766f9b655d4a2 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbeapi.c | 5 ++++- src/vdbemem.c | 5 ++++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index d5c7f0dca6..7a27a93f1a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\swith\sfixes\sand\senhancements\sfrom\strunk. -D 2015-05-22T18:40:48.061 +C Fix\sminor\sissues\swith\sthe\ssqlite3_value_dup()\sinterface. +D 2015-05-22T19:55:10.064 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -315,10 +315,10 @@ F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 F src/vdbe.c 6aee8a041742413ab3113e6682bc7ad1628a2bbe F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h f0ccddac48583d5f762dc554a9f79e85ea8807e0 -F src/vdbeapi.c f9ad1be11b9e8f2f8580656191abeeefd24f71dd +F src/vdbeapi.c 06b7b785dce358045138b8e10dbbc9d25ebf27c6 F src/vdbeaux.c efe1667d31e8648dbe04a441e5aa9b62dbee2f03 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 -F src/vdbemem.c e87e076b863e4228d71d8c4d1c4df6836d810043 +F src/vdbemem.c 21f9169289a804308f6cdde55e9417fb8336997f F src/vdbesort.c f5009e7a35e3065635d8918b9a31f498a499976b F src/vdbetrace.c 8befe829faff6d9e6f6e4dee5a7d3f85cc85f1a0 F src/vtab.c c535e80259ebe616467181a83a4263555b97c694 @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P a7ee40c4fc62843ac5b96ba47ca14a66e8cd6961 b9727e6bbfc3c62c601227e86e62f2f39792fd1d -R 9098cc91ef3cf8266e40130f2497d66b +P 9605d008f5c763137e9734d033fe4510ca316858 +R 0084568ba3e04d525eb096dd7e201fe6 U drh -Z 1a2a84e2d9cad97b20ef26fa2573d0ad +Z 0e179fe2ecd0f632949a18d2f8a6b466 diff --git a/manifest.uuid b/manifest.uuid index 09062a196e..aaea6a210b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9605d008f5c763137e9734d033fe4510ca316858 \ No newline at end of file +95edcf5010ecb8edd8eb74279c4766f9b655d4a2 \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index e08398cd0b..dcdb8292c9 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -226,7 +226,10 @@ sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){ if( pNew->flags&(MEM_Str|MEM_Blob) ){ if( 0==(pOrig->flags&MEM_Static) ){ pNew->flags |= MEM_Ephem; - sqlite3VdbeMemMakeWriteable(pNew); + if( sqlite3VdbeMemMakeWriteable(pNew)!=SQLITE_OK ){ + sqlite3ValueFree(pNew); + pNew = 0; + } } } return pNew; diff --git a/src/vdbemem.c b/src/vdbemem.c index 987e49a21a..1dbdb89895 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -796,7 +796,10 @@ void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){ int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){ int rc = SQLITE_OK; - assert( pTo->db==pFrom->db ); + /* The pFrom==0 case in the following assert() is when an sqlite3_value + ** from sqlite3_value_dup() is used as the argument + ** to sqlite3_result_value(). */ + assert( pTo->db==pFrom->db || pFrom->db==0 ); assert( (pFrom->flags & MEM_RowSet)==0 ); if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo); memcpy(pTo, pFrom, MEMCELLSIZE); From 10ca5b4809ce5592a3949cba6f766a66c52f8643 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 May 2015 21:04:54 +0000 Subject: [PATCH 13/14] Make sure sqlite3_value_dup() works correctly even for sqlite3_value objects that are marked SQLITE_STATIC. FossilOrigin-Name: f332ffc39b7a17fd6254d8dc699293a57a508ba0 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeapi.c | 11 +++++------ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 7a27a93f1a..2d270a2d6d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sminor\sissues\swith\sthe\ssqlite3_value_dup()\sinterface. -D 2015-05-22T19:55:10.064 +C Make\ssure\ssqlite3_value_dup()\sworks\scorrectly\seven\sfor\ssqlite3_value\nobjects\sthat\sare\smarked\sSQLITE_STATIC. +D 2015-05-22T21:04:54.462 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -315,7 +315,7 @@ F src/vacuum.c 2ddd5cad2a7b9cef7f9e431b8c7771634c6b1701 F src/vdbe.c 6aee8a041742413ab3113e6682bc7ad1628a2bbe F src/vdbe.h 7e538ecf47dccb307ea2d087c3ddc2dd8d70e79d F src/vdbeInt.h f0ccddac48583d5f762dc554a9f79e85ea8807e0 -F src/vdbeapi.c 06b7b785dce358045138b8e10dbbc9d25ebf27c6 +F src/vdbeapi.c 6a0d7757987018ff6b1b81bc5293219cd26bb299 F src/vdbeaux.c efe1667d31e8648dbe04a441e5aa9b62dbee2f03 F src/vdbeblob.c 4f2e8e075d238392df98c5e03a64342465b03f90 F src/vdbemem.c 21f9169289a804308f6cdde55e9417fb8336997f @@ -1278,7 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 9605d008f5c763137e9734d033fe4510ca316858 -R 0084568ba3e04d525eb096dd7e201fe6 +P 95edcf5010ecb8edd8eb74279c4766f9b655d4a2 +R 45d42bfafc5b3542d7e7526b77707d5f U drh -Z 0e179fe2ecd0f632949a18d2f8a6b466 +Z f0fdfb1783681230e2e7fa3690d67253 diff --git a/manifest.uuid b/manifest.uuid index aaea6a210b..ea8a4aa01a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -95edcf5010ecb8edd8eb74279c4766f9b655d4a2 \ No newline at end of file +f332ffc39b7a17fd6254d8dc699293a57a508ba0 \ No newline at end of file diff --git a/src/vdbeapi.c b/src/vdbeapi.c index dcdb8292c9..010fbfba16 100644 --- a/src/vdbeapi.c +++ b/src/vdbeapi.c @@ -224,12 +224,11 @@ sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){ pNew->flags &= ~MEM_Dyn; pNew->db = 0; if( pNew->flags&(MEM_Str|MEM_Blob) ){ - if( 0==(pOrig->flags&MEM_Static) ){ - pNew->flags |= MEM_Ephem; - if( sqlite3VdbeMemMakeWriteable(pNew)!=SQLITE_OK ){ - sqlite3ValueFree(pNew); - pNew = 0; - } + pNew->flags &= ~(MEM_Static|MEM_Dyn); + pNew->flags |= MEM_Ephem; + if( sqlite3VdbeMemMakeWriteable(pNew)!=SQLITE_OK ){ + sqlite3ValueFree(pNew); + pNew = 0; } } return pNew; From 18070e08c5ec5048335df96e36019a6c778091e6 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 May 2015 23:17:28 +0000 Subject: [PATCH 14/14] Fix incorrect validation of the size of the BLOB returned by a geometry function on the RHS of a MATCH operator in RTree. The old code worked for 64-bit systems (by chance) but fails on 32-bit. FossilOrigin-Name: 10cc44f5a63e6cadf6940bb7310a177ee7fa6ee2 --- ext/rtree/rtree.c | 4 +--- manifest | 13 ++++++------- manifest.uuid | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ext/rtree/rtree.c b/ext/rtree/rtree.c index 3521352b78..4e473a22c2 100644 --- a/ext/rtree/rtree.c +++ b/ext/rtree/rtree.c @@ -1483,9 +1483,7 @@ static int deserializeGeometry(sqlite3_value *pValue, RtreeConstraint *pCons){ /* Check that the blob is roughly the right size. */ nBlob = sqlite3_value_bytes(pValue); - if( nBlob<(int)sizeof(RtreeMatchArg) - || ((nBlob-sizeof(RtreeMatchArg))%sizeof(RtreeDValue))!=0 - ){ + if( nBlob<(int)sizeof(RtreeMatchArg) ){ return SQLITE_ERROR; } diff --git a/manifest b/manifest index 4f499d8cf9..cc487cf384 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\ssqlite3_value_dup()\sand\ssqlite3_value_free()\sinterfaces.\s\nUse\sthese\sinterfaces\sto\senhance\sR-Tree\sto\sadd\sthe\nsqlite3_rtree_query_info.apSqlParam\sfield. -D 2015-05-22T21:12:59.931 +C Fix\sincorrect\svalidation\sof\sthe\ssize\sof\sthe\sBLOB\sreturned\sby\sa\sgeometry\nfunction\son\sthe\sRHS\sof\sa\sMATCH\soperator\sin\sRTree.\s\sThe\sold\scode\sworked\sfor\n64-bit\ssystems\s(by\schance)\sbut\sfails\son\s32-bit. +D 2015-05-22T23:17:28.381 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 0a6ae26396ec696221021780dffbb894ff3cead7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -143,7 +143,7 @@ F ext/ota/sqlite3ota.c 2246b779f46ab20d5e7876f5b96c378c601d20f4 F ext/ota/sqlite3ota.h 00028de37eede471ff1947d455cc3f33d3a911c6 F ext/ota/test_ota.c a876f88550d7d59a3ef62d4c1a5c04c4c2f1ebe1 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761 -F ext/rtree/rtree.c 00c953695d8ae174c0f2947795e1e8a17ebb50cb +F ext/rtree/rtree.c 0f9b595bd0debcbedf1d7a63d0e0678d619e6c9c F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e F ext/rtree/rtree1.test 541bbcab74613907fea08b2ecdcdd5b7aa724cc9 F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba @@ -1278,8 +1278,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P b9727e6bbfc3c62c601227e86e62f2f39792fd1d f332ffc39b7a17fd6254d8dc699293a57a508ba0 -R 45d42bfafc5b3542d7e7526b77707d5f -T +closed f332ffc39b7a17fd6254d8dc699293a57a508ba0 +P c1814242e6ce035d486cfbad5a1f4b49aa8898f3 +R f01355780527736c645fe9d48d526152 U drh -Z 2115a6dbeb76c1fe460ac17d9b6aaa11 +Z c568275ed97c21c4c01709075e3bc4ce diff --git a/manifest.uuid b/manifest.uuid index b0343b532d..5d4569be1b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c1814242e6ce035d486cfbad5a1f4b49aa8898f3 \ No newline at end of file +10cc44f5a63e6cadf6940bb7310a177ee7fa6ee2 \ No newline at end of file