Make the 3rd parameter of the SUBSTR() function optional. Ticket #2579. (CVS 4486)

FossilOrigin-Name: 4a807d48ea9923c1e3df4a5ad503710e62ae29f8
This commit is contained in:
drh 2007-10-12 19:11:55 +00:00
parent 0a99ded1ba
commit 64f31519b7
5 changed files with 46 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Add\san\sexplicit\stype\sconversion\sin\san\sAWK\sscript\sto\swork\saround\nbugs\sin\scygwin.\s\sTicket\s#2713.\s(CVS\s4485)
D 2007-10-12T18:36:26
C Make\sthe\s3rd\sparameter\sof\sthe\sSUBSTR()\sfunction\soptional.\s\sTicket\s#2579.\s(CVS\s4486)
D 2007-10-12T19:11:55
F Makefile.in 75b729d562e9525d57d9890ec598b38e1a8b02bc
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -91,7 +91,7 @@ F src/date.c 49c5a6d2de6c12000905b4d36868b07d3011bbf6
F src/delete.c 849846d06d29851dde0d9f424a5de5817eb140d1
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 20a45339a6ba1e98c07e7f2039e8ffad0290fb77
F src/func.c 9d88141c4cffb3a04719e5a0fda65cde34bfa1e5
F src/func.c e8e8978804ba453e9e1377db8824c90871b53cfb
F src/hash.c 45a7005aac044b6c86bd7e49c44bc15d30006d6c
F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
F src/insert.c df9712e1f67201573a9677d3a2fe401d52d84dda
@ -421,7 +421,7 @@ F test/speed3.test e312d7e442a5047d730569fdae2ba99bc94e1a13
F test/sqllimits1.test 3b08a538c9828041a5c1454293594d922602044d
F test/subquery.test 8203f85db56ba022a57a0589890090c8feed4e59
F test/subselect.test 974e87f8fc91c5f00dd565316d396a5a6c3106c4
F test/substr.test d36c864a238e1f51e7829af660906f05d47b5e32
F test/substr.test 4be572ac017143e59b4058dc75c91a0d0dc6d4e0
F test/sync.test ded6b39d8d8ca3c0c5518516c6371b3316d3e3a3
F test/table.test 13b1c2e2fb4727b35ee1fb7641fc469214fd2455
F test/tableapi.test 92651a95c23cf955e92407928e640536402fa3cc
@ -557,7 +557,7 @@ F www/fullscanb.gif f7c94cb227f060511f8909e10f570157263e9a25
F www/index-ex1-x-b.gif f9b1d85c3fa2435cf38b15970c7e3aa1edae23a3
F www/index.tcl 26d51247806337cc1464b62a8a1d7f0a0e3acaa1
F www/indirect1b1.gif adfca361d2df59e34f9c5cac52a670c2bfc303a1
F www/lang.tcl 1c1e7573dc5f93971f1533393f06e79e68d7e5e1
F www/lang.tcl e015c489a30cbf5669bc6aef5c932a6b4f6ddf48
F www/limits.tcl 9035eb73e814ccb298595fd57670dec817533616
F www/lockingv3.tcl e52345bd20323bef6146bfce18ae0829b2b7c87d
F www/mingw.tcl d96b451568c5d28545fefe0c80bee3431c73f69c
@ -581,7 +581,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P a7292c14ded6cfca65850ef8169799d2d5f35a61
R 543195db97b17525243d1b59b6c19dbd
P 043cee2fd9319f24bb5c70d6619bfe8f8e2e3b91
R 1df8a48ac33d659b8c4b4d1ef001d500
U drh
Z a55d964d9bc5c4c7e6901f8d6a15f858
Z cbea4efc34541b98a3b5677cab7e87e4

View File

@ -1 +1 @@
043cee2fd9319f24bb5c70d6619bfe8f8e2e3b91
4a807d48ea9923c1e3df4a5ad503710e62ae29f8

View File

@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.174 2007/09/03 11:04:22 danielk1977 Exp $
** $Id: func.c,v 1.175 2007/10/12 19:11:55 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -169,7 +169,7 @@ static void substrFunc(
int p0type;
i64 p1, p2;
assert( argc==3 );
assert( argc==3 || argc==2 );
p0type = sqlite3_value_type(argv[0]);
if( p0type==SQLITE_BLOB ){
len = sqlite3_value_bytes(argv[0]);
@ -185,7 +185,11 @@ static void substrFunc(
}
}
p1 = sqlite3_value_int(argv[1]);
p2 = sqlite3_value_int(argv[2]);
if( argc==3 ){
p2 = sqlite3_value_int(argv[2]);
}else{
p2 = SQLITE_MAX_LENGTH;
}
if( p1<0 ){
p1 += len;
if( p1<0 ){
@ -1329,6 +1333,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
{ "max", 0, 1, SQLITE_UTF8, 1, 0 },
{ "typeof", 1, 0, SQLITE_UTF8, 0, typeofFunc },
{ "length", 1, 0, SQLITE_UTF8, 0, lengthFunc },
{ "substr", 2, 0, SQLITE_UTF8, 0, substrFunc },
{ "substr", 3, 0, SQLITE_UTF8, 0, substrFunc },
{ "abs", 1, 0, SQLITE_UTF8, 0, absFunc },
{ "round", 1, 0, SQLITE_UTF8, 0, roundFunc },

View File

@ -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.2 2007/09/12 17:01:45 danielk1977 Exp $
# $Id: substr.test,v 1.3 2007/10/12 19:11:55 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -105,4 +105,26 @@ subblob-test 4.4 61E188B462E28D8563E3919663 -2 1 96
subblob-test 4.5 61E188B462E28D8563E3919663 -5 4 63E39196
subblob-test 4.6 61E188B462E28D8563E3919663 -100 98 61E188B462E28D8563E391
# Two-argument SUBSTR
#
proc substr-2-test {id string idx result} {
db eval {
DELETE FROM t1;
INSERT INTO t1(t) VALUES($string)
}
do_test substr-$id.1 [subst {
execsql {
SELECT substr(t, $idx) FROM t1
}
}] [list $result]
set qstr '[string map {' ''} $string]'
do_test substr-$id.2 [subst {
execsql {
SELECT substr($qstr, $idx)
}
}] [list $result]
}
substr-2-test 5.1 abcdefghijklmnop 5 efghijklmnop
substr-2-test 5.2 abcdef -5 bcdef
finish_test

View File

@ -1,7 +1,7 @@
#
# Run this Tcl script to generate the lang-*.html files.
#
set rcsid {$Id: lang.tcl,v 1.136 2007/10/03 20:15:28 drh Exp $}
set rcsid {$Id: lang.tcl,v 1.137 2007/10/12 19:11:55 drh Exp $}
source common.tcl
if {[llength $argv]>0} {
@ -1499,9 +1499,13 @@ that is running. Example: "2.8.0"</td>
</tr>
<tr>
<td valign="top" align="right">substr(<i>X</i>,<i>Y</i>,<i>Z</i>)</td>
<td valign="top" align="right">
substr(<i>X</i>,<i>Y</i>,<i>Z</i>)<br>
substr(<i>X</i>,<i>Y</i>)</td>
<td valign="top">Return a substring of input string <i>X</i> that begins
with the <i>Y</i>-th character and which is <i>Z</i> characters long.
If <i>Z</i> is omitted then all character through the end of the string
are returned.
The left-most character of <i>X</i> is number 1. If <i>Y</i> is negative
the the first character of the substring is found by counting from the
right rather than the left. If <i>X</i> is string