summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <bar@bar.mysql.r18.ru>2003-06-25 15:07:20 +0500
committerunknown <bar@bar.mysql.r18.ru>2003-06-25 15:07:20 +0500
commit15ee7b04daeefdb5010efed309ff412d43f88fa5 (patch)
treed7966a8ac0e15ab459907fab638b4ea53f14f81c /sql
parent4ccada56f13de8bd27b2fa3d7e7601a05e403758 (diff)
downloadmariadb-git-15ee7b04daeefdb5010efed309ff412d43f88fa5.tar.gz
LOCATE(), INSTR(), POSITION(), FIND_IN_SET(), SUBSTRING_INDEX()
now process arguments according to standard SQL collation determation rules.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_func.cc20
-rw-r--r--sql/item_func.h9
-rw-r--r--sql/item_strfunc.cc11
-rw-r--r--sql/item_strfunc.h2
4 files changed, 30 insertions, 12 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index d0362ea9369..dc979cea2f8 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -1045,10 +1045,18 @@ longlong Item_func_coercibility::val_int()
return (longlong) args[0]->derivation();
}
+void Item_func_locate::fix_length_and_dec()
+{
+ maybe_null=0; max_length=11;
+ if (cmp_collation.set(args[0]->collation, args[1]->collation))
+ my_coll_agg_error(args[0]->collation, args[1]->collation, func_name());
+}
+
longlong Item_func_locate::val_int()
{
String *a=args[0]->val_str(&value1);
String *b=args[1]->val_str(&value2);
+ bool binary_cmp= (cmp_collation.collation->state & MY_CS_BINSORT) ? 1 : 0;
if (!a || !b)
{
null_value=1;
@@ -1063,7 +1071,7 @@ longlong Item_func_locate::val_int()
{
start=(uint) args[2]->val_int()-1;
#ifdef USE_MB
- if (use_mb(a->charset()))
+ if (use_mb(cmp_collation.collation))
{
start0=start;
if (!binary_cmp)
@@ -1076,7 +1084,7 @@ longlong Item_func_locate::val_int()
if (!b->length()) // Found empty string at start
return (longlong) (start+1);
#ifdef USE_MB
- if (use_mb(a->charset()) && !binary_cmp)
+ if (use_mb(cmp_collation.collation) && !binary_cmp)
{
const char *ptr=a->ptr()+start;
const char *search=b->ptr();
@@ -1095,7 +1103,7 @@ longlong Item_func_locate::val_int()
return (longlong) start0+1;
}
skipp:
- if ((l=my_ismbchar(a->charset(),ptr,strend)))
+ if ((l=my_ismbchar(cmp_collation.collation,ptr,strend)))
ptr+=l;
else ++ptr;
++start0;
@@ -1201,6 +1209,8 @@ void Item_func_find_in_set::fix_length_and_dec()
}
}
}
+ if (cmp_collation.set(args[0]->collation, args[1]->collation))
+ my_coll_agg_error(args[0]->collation, args[1]->collation, func_name());
}
static const char separator=',';
@@ -1228,7 +1238,6 @@ longlong Item_func_find_in_set::val_int()
null_value=0;
int diff;
- CHARSET_INFO *charset= find->charset();
if ((diff=buffer->length() - find->length()) >= 0)
{
const char *f_pos=find->ptr();
@@ -1242,7 +1251,8 @@ longlong Item_func_find_in_set::val_int()
const char *pos= f_pos;
while (pos != f_end)
{
- if (my_toupper(charset,*str) != my_toupper(charset,*pos))
+ if (my_toupper(cmp_collation.collation,*str) !=
+ my_toupper(cmp_collation.collation,*pos))
goto not_found;
str++;
pos++;
diff --git a/sql/item_func.h b/sql/item_func.h
index 4e39833c467..9ba5bea8b87 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -610,17 +610,13 @@ public:
class Item_func_locate :public Item_int_func
{
String value1,value2;
- bool binary_cmp;
+ DTCollation cmp_collation;
public:
Item_func_locate(Item *a,Item *b) :Item_int_func(a,b) {}
Item_func_locate(Item *a,Item *b,Item *c) :Item_int_func(a,b,c) {}
const char *func_name() const { return "locate"; }
longlong val_int();
- void fix_length_and_dec()
- {
- maybe_null=0; max_length=11;
- binary_cmp = args[0]->binary() || args[1]->binary();
- }
+ void fix_length_and_dec();
};
@@ -684,6 +680,7 @@ class Item_func_find_in_set :public Item_int_func
String value,value2;
uint enum_value;
ulonglong enum_bit;
+ DTCollation cmp_collation;
public:
Item_func_find_in_set(Item *a,Item *b) :Item_int_func(a,b),enum_value(0) {}
longlong val_int();
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 1c770456793..a57800c89d1 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1037,6 +1037,15 @@ void Item_func_substr::fix_length_and_dec()
}
+void Item_func_substr_index::fix_length_and_dec()
+{
+ max_length= args[0]->max_length;
+ if (collation.set(args[0]->collation, args[1]->collation) ||
+ (collation.derivation == DERIVATION_NONE))
+ my_coll_agg_error(args[0]->collation, args[1]->collation, func_name());
+}
+
+
String *Item_func_substr_index::val_str(String *str)
{
String *res =args[0]->val_str(str);
@@ -1054,6 +1063,8 @@ String *Item_func_substr_index::val_str(String *str)
if (!res->length() || !delimeter_length || !count)
return &empty_string; // Wrong parameters
+ res->set_charset(collation.collation);
+
#ifdef USE_MB
if (use_mb(res->charset()))
{
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index 3f2860f4b2b..6cc6d730627 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -215,7 +215,7 @@ class Item_func_substr_index :public Item_str_func
public:
Item_func_substr_index(Item *a,Item *b,Item *c) :Item_str_func(a,b,c) {}
String *val_str(String *);
- void fix_length_and_dec() { max_length= args[0]->max_length; }
+ void fix_length_and_dec();
const char *func_name() const { return "substr_index"; }
};