diff options
author | unknown <venu@myvenu.com> | 2003-07-14 07:37:09 -0700 |
---|---|---|
committer | unknown <venu@myvenu.com> | 2003-07-14 07:37:09 -0700 |
commit | 837fc104e2342bdaf580d881c13c48585110ccd7 (patch) | |
tree | a83cf3081de5d9b3f85c408631e25a5b8e114157 | |
parent | 6b001731c1c5b31c50c7a6aa1ee8dec5ceb09f91 (diff) | |
parent | 0465279561895b5312d058dc560ab29f03d38cd7 (diff) | |
download | mariadb-git-837fc104e2342bdaf580d881c13c48585110ccd7.tar.gz |
Merge venu@bk-internal.mysql.com:/home/bk/mysql-4.1
into myvenu.com:/home/venu/work/sql/dev-4.1
-rw-r--r-- | mysql-test/r/func_str.result | 21 | ||||
-rw-r--r-- | mysql-test/t/func_str.test | 11 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 3 | ||||
-rw-r--r-- | sql/lex.h | 1 |
4 files changed, 35 insertions, 1 deletions
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index c2a921e1a54..611660675c8 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -532,3 +532,24 @@ t1 CREATE TABLE `t1` ( `replace(_latin2'abcd',_latin2'b',_latin2'B')` char(4) character set latin2 NOT NULL default '' ) TYPE=MyISAM CHARSET=latin1 drop table t1; +select SUBSTR('abcdefg',3,2); +SUBSTR('abcdefg',3,2) +cd +select SUBSTRING('abcdefg',3,2); +SUBSTRING('abcdefg',3,2) +cd +select SUBSTR('abcdefg',-3,2) FROM DUAL; +SUBSTR('abcdefg',-3,2) +ef +select SUBSTR('abcdefg',-1,5) FROM DUAL; +SUBSTR('abcdefg',-1,5) +g +select SUBSTR('abcdefg',0,0) FROM DUAL; +SUBSTR('abcdefg',0,0) + +select SUBSTR('abcdefg',-1,-1) FROM DUAL; +SUBSTR('abcdefg',-1,-1) + +select SUBSTR('abcdefg',1,-1) FROM DUAL; +SUBSTR('abcdefg',1,-1) + diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index c9e7b1a529d..1fabd997366 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -294,3 +294,14 @@ select ; show create table t1; drop table t1; + +# +# test for SUBSTR +# +select SUBSTR('abcdefg',3,2); +select SUBSTRING('abcdefg',3,2); +select SUBSTR('abcdefg',-3,2) FROM DUAL; +select SUBSTR('abcdefg',-1,5) FROM DUAL; +select SUBSTR('abcdefg',0,0) FROM DUAL; +select SUBSTR('abcdefg',-1,-1) FROM DUAL; +select SUBSTR('abcdefg',1,-1) FROM DUAL; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index f5cc88e2e4e..b25619d0bb1 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -979,13 +979,14 @@ void Item_func_right::fix_length_and_dec() String *Item_func_substr::val_str(String *str) { String *res = args[0]->val_str(str); - int32 start = (int32) args[1]->val_int()-1; + int32 start = (int32) args[1]->val_int(); int32 length = arg_count == 3 ? (int32) args[2]->val_int() : INT_MAX32; int32 tmp_length; if ((null_value=(args[0]->null_value || args[1]->null_value || (arg_count == 3 && args[2]->null_value)))) return 0; /* purecov: inspected */ + start= (int32)((start < 0) ? res->length() + start : start -1); start=res->charpos(start); length=res->charpos(length,start); if (start < 0 || (uint) start+1 > res->length() || length <= 0) diff --git a/sql/lex.h b/sql/lex.h index a148baad07f..c2860f4551a 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -627,6 +627,7 @@ static SYMBOL sql_functions[] = { { "STD", SYM(STD_SYM),0,0}, { "STDDEV", SYM(STD_SYM),0,0}, { "STRCMP", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_strcmp)}, + { "SUBSTR", SYM(SUBSTRING),0,0}, { "SUBSTRING", SYM(SUBSTRING),0,0}, { "SUBSTRING_INDEX", SYM(SUBSTRING_INDEX),0,0}, { "SUBTIME", SYM(FUNC_ARG2),0,CREATE_FUNC(create_func_subtime)}, |