From 1b40adcb064b96064bc71d975f054579b41fa378 Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Thu, 4 Aug 2005 15:25:03 +0500 Subject: grant.result, grant.test: fixing tests accordingly item.cc: Bug #10892 user variables not auto cast for comparisons When mixing strings with different character sets, and coercibility is the same, we allow conversion if one character set is superset for other character set. --- sql/item.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sql') diff --git a/sql/item.cc b/sql/item.cc index 84dbc382a52..41cda365750 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -455,14 +455,16 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags) ; // Do nothing } else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) && - derivation < dt.derivation && - collation->state & MY_CS_UNICODE) + derivation <= dt.derivation && + collation->state & MY_CS_UNICODE && + !(dt.collation->state & MY_CS_UNICODE)) { // Do nothing } else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) && - dt.derivation < derivation && - dt.collation->state & MY_CS_UNICODE) + dt.derivation <= derivation && + dt.collation->state & MY_CS_UNICODE && + !(collation->state & MY_CS_UNICODE)) { set(dt); } -- cgit v1.2.1 From 2c8fc886b91903d0cbb9064c64c7209ee816369e Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Mon, 8 Aug 2005 16:20:46 +0500 Subject: item.cc: After review fix --- sql/item.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sql') diff --git a/sql/item.cc b/sql/item.cc index 41cda365750..b3d2932acf6 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -455,16 +455,18 @@ bool DTCollation::aggregate(DTCollation &dt, uint flags) ; // Do nothing } else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) && - derivation <= dt.derivation && collation->state & MY_CS_UNICODE && - !(dt.collation->state & MY_CS_UNICODE)) + (derivation < dt.derivation || + (derivation == dt.derivation && + !(dt.collation->state & MY_CS_UNICODE)))) { // Do nothing } else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) && - dt.derivation <= derivation && dt.collation->state & MY_CS_UNICODE && - !(collation->state & MY_CS_UNICODE)) + (dt.derivation < derivation || + (dt.derivation == derivation && + !(collation->state & MY_CS_UNICODE)))) { set(dt); } -- cgit v1.2.1 From 6128521b5bd11f9a27520f25d5673f3042390e99 Mon Sep 17 00:00:00 2001 From: "patg@krsna.patg.net" <> Date: Mon, 8 Aug 2005 13:46:13 -0700 Subject: item_strfunc.cc: BUG #11104 Took out the offset-=delimiter_length-1 out of the for loop. It was causing basically this: select substring_index('the king of the the hill', 'the', -2) to not work. The first iteration, offset would be initialised to 24, then strstr would point at 'the king of the the* hill' ('*'means right before the character following), returning a offset of 16. The for loop would then decrement offset by two (3 - 1), to 14, now pointing at "the king of th*e the hill", _skipping_ past the 'e' in the second to last 'the', and therefore strstr would never have a chance of matching the second to last 'the', then moving on to the 'the' at the begginning of the string! In a nutshell, offset was being decremented by too great a value, preventing the second to last 'the' from being ever found, hence the result of 'king of the the hill' from the query that is reported in the bug report func_str.test: BUG #11104 Added tests to make sure fix addresses issues in original bug report func_str.result: BUG #11104 New results for new tests --- sql/item_strfunc.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'sql') diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d316c7eaf72..52a2dedb67c 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -42,7 +42,7 @@ static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname) { my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0), - c1.collation->name,c1.derivation_name(), + c1.collation->name,c1.derivation_name(), c2.collation->name,c2.derivation_name(), fname); } @@ -1188,10 +1188,22 @@ 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; -- cgit v1.2.1