diff options
author | patg@krsna.patg.net <> | 2005-07-31 21:28:52 -0700 |
---|---|---|
committer | patg@krsna.patg.net <> | 2005-07-31 21:28:52 -0700 |
commit | 8109934e1d7af65d16eae90c0d301aa95f138d03 (patch) | |
tree | 507c672dbbe5bca974611526c1a4a5564f3344ee /sql/item_strfunc.cc | |
parent | 4098c40d87ac11fe5043061f16a95a455376a782 (diff) | |
download | mariadb-git-8109934e1d7af65d16eae90c0d301aa95f138d03.tar.gz |
BUG 11104 (same as changeset 1.1891 on the 5.0 tree, but realised this
needed to be fixed in earlier versions)
Fixed the iteration of how substrings are handled with negative indexes in
SUBSTRING_INDEX
Diffstat (limited to 'sql/item_strfunc.cc')
-rw-r--r-- | sql/item_strfunc.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 930014de771..f070382e5c1 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1084,11 +1084,23 @@ String *Item_func_substr_index::val_str(String *str) } } else - { // Start counting at end - for (offset=res->length() ; ; offset-=delimeter_length-1) + { + /* + Negative index, start counting at the end + */ + for (offset=res->length(); offset ;) { + /* + this call will result in finding the position pointing to one + address space less than where the found substring is located + in res + */ if ((int) (offset=res->strrstr(*delimeter,offset)) < 0) return res; // Didn't find, return org string + /* + At this point, we've searched for the substring + the number of times as supplied by the index value + */ if (!++count) { offset+=delimeter_length; |