From: drh Date: Sun, 1 Feb 2009 19:23:32 +0000 (+0000) Subject: Fix the SUBSTR() function so that when the 3rd argument is negative, X-Git-Tag: version-3.6.15~523 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e79c5945448199b2b3871e2d09ce78d1038b8d6;p=thirdparty%2Fsqlite.git Fix the SUBSTR() function so that when the 3rd argument is negative, it counts backwards from the selected start point. Ticket #3625. (CVS 6227) FossilOrigin-Name: 2217339badf1e84edbed1309c39b9f8dfd7646ff --- diff --git a/manifest b/manifest index 0affed7bcc..8d8ce81557 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sreplace()\sfunction\sto\sreturn\sa\scopy\sof\sits\sfirst\sargument\swhen\nthe\s2nd\sargument\sis\san\sempty\sstring.\s\sTicket\s#3624.\s(CVS\s6226) -D 2009-02-01T18:08:41 +C Fix\sthe\sSUBSTR()\sfunction\sso\sthat\swhen\sthe\s3rd\sargument\sis\snegative,\nit\scounts\sbackwards\sfrom\sthe\sselected\sstart\spoint.\s\sTicket\s#3625.\s(CVS\s6227) +D 2009-02-01T19:23:32 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 3871d308188cefcb7c5ab20da4c7b6aad023bc52 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -113,7 +113,7 @@ F src/date.c 870770dde3fb56772ab247dfb6a6eda44d16cfbc F src/delete.c 6249005bdd8f85db6ec5f31ddb5c07de023693cc F src/expr.c 76dc3dc83b56ab8db50a772714fac49def8bbf12 F src/fault.c dc88c821842157460750d2d61a8a8b4197d047ff -F src/func.c 8ead6d9a505fcb00817516060c2ebcd47665c720 +F src/func.c 5a9abbe0c9a39cacf10d2f554994d04ada7cfd97 F src/global.c ab003581ea4ff193cfe17a00e1303bc51db619a5 F src/hash.c 5824e6ff7ba78cd34c8d6cd724367713583e5b55 F src/hash.h 28f38ebb1006a5beedcb013bcdfe31befe7437ae @@ -538,7 +538,7 @@ F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b F test/sqllimits1.test 2f7ca3c7e7cef39a9c499e941e98b7f1708c4780 F test/subquery.test b524f57c9574b2c0347045b4510ef795d4686796 F test/subselect.test d24fd8757daf97dafd2e889c73ea4c4272dcf4e4 -F test/substr.test 4be572ac017143e59b4058dc75c91a0d0dc6d4e0 +F test/substr.test ab7e08b417c7ecf4ad4d6971b7a307738566dbab F test/sync.test ded6b39d8d8ca3c0c5518516c6371b3316d3e3a3 F test/table.test 0aac9468b69d2683e68ee2682cdae28d82a453ec F test/tableapi.test 505031f15b18a750184d967d2c896cf88fcc969c @@ -693,7 +693,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 0d2abbbff5d9e12e2382ed201bf1648c5918c1c0 -R 87a8317c9de06e2182db29db65f9d562 +P ffebf10f6fb2c7f3083992e2c712682b4cdcc6f0 +R d0d1ee83ba6397bbefb0b7fb547d0a98 U drh -Z 69ffdf34dd35b084b6e374302eafe7c5 +Z dfb41a03d301c769a684a42ff2c19839 diff --git a/manifest.uuid b/manifest.uuid index f630dbe0d8..51be913163 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ffebf10f6fb2c7f3083992e2c712682b4cdcc6f0 \ No newline at end of file +2217339badf1e84edbed1309c39b9f8dfd7646ff \ No newline at end of file diff --git a/src/func.c b/src/func.c index 76c4de66da..24e2d838d6 100644 --- a/src/func.c +++ b/src/func.c @@ -16,7 +16,7 @@ ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.212 2009/02/01 18:08:41 drh Exp $ +** $Id: func.c,v 1.213 2009/02/01 19:23:32 drh Exp $ */ #include "sqliteInt.h" #include @@ -200,6 +200,14 @@ static void substrFunc( }else if( p1>0 ){ p1--; } + if( p2<0 ){ + p1 += p2; + p2 = -p2; + if( p1<0 ){ + p2 += p1; + p1 = 0; + } + } if( p1+p2>len ){ p2 = len-p1; } diff --git a/test/substr.test b/test/substr.test index 055b8fd86b..fb5d330214 100644 --- a/test/substr.test +++ b/test/substr.test @@ -11,7 +11,7 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing the built-in SUBSTR() functions. # -# $Id: substr.test,v 1.3 2007/10/12 19:11:55 drh Exp $ +# $Id: substr.test,v 1.4 2009/02/01 19:23:32 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -72,6 +72,12 @@ substr-test 1.7 abcdefg -1 10 g substr-test 1.8 abcdefg -5 3 cde substr-test 1.9 abcdefg -7 3 abc substr-test 1.10 abcdefg -100 98 abcde +substr-test 1.11 abcdefg 5 -1 d +substr-test 1.12 abcdefg 5 -4 abcd +substr-test 1.13 abcdefg 5 -5 abcd +substr-test 1.14 abcdefg -5 -1 b +substr-test 1.15 abcdefg -5 -2 ab +substr-test 1.16 abcdefg -5 -3 ab # Make sure everything works with long unicode characters # @@ -80,6 +86,7 @@ substr-test 2.2 \u1234\u2345\u3456 2 1 \u2345 substr-test 2.3 \u1234\u2345\u3456 1 2 \u1234\u2345 substr-test 2.4 \u1234\u2345\u3456 -1 1 \u3456 substr-test 2.5 a\u1234b\u2345c\u3456c -5 3 b\u2345c +substr-test 2.6 a\u1234b\u2345c\u3456c -2 -3 b\u2345c # Basic functionality for BLOBs #