diff options
author | unknown <venu@myvenu.com> | 2003-07-11 18:55:03 -0700 |
---|---|---|
committer | unknown <venu@myvenu.com> | 2003-07-11 18:55:03 -0700 |
commit | a5ce6a49dd0dc782e225d24735b1af40ed8e3b18 (patch) | |
tree | 46157d23bd0e0599894062a2dffc90255e304899 /sql | |
parent | 531a5d76bf5c38589df89985fa43b6a0d215b28e (diff) | |
download | mariadb-git-a5ce6a49dd0dc782e225d24735b1af40ed8e3b18.tar.gz |
Add the support of 'SUBSTR' function compatible with Oracle and SAPDB (SCRUM #872)
sql/lex.h:
Add SUBSTR aliased to SUBSTRING
sql/item_strfunc.cc:
Implement SUBSTR negative offset
mysql-test/t/func_str.test:
New tests for SUBSTR
mysql-test/r/func_str.result:
Updated SUBSTR results
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_strfunc.cc | 3 | ||||
-rw-r--r-- | sql/lex.h | 1 |
2 files changed, 3 insertions, 1 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 2d29f76c2d7..92a68002b9e 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)}, |