summaryrefslogtreecommitdiff
path: root/sql/item.cc
diff options
context:
space:
mode:
authorunknown <bar@mysql.com>2005-07-13 13:00:17 +0500
committerunknown <bar@mysql.com>2005-07-13 13:00:17 +0500
commit4a2af29fe784ff10b7506ee39d7054859fc6eb51 (patch)
tree9041e1c0fb031c01d3baa28560c8df50c1a532e1 /sql/item.cc
parent3378673653108ee89e8011e1d18cd394aea13039 (diff)
downloadmariadb-git-4a2af29fe784ff10b7506ee39d7054859fc6eb51.tar.gz
ctype_utf8.result:
adding test case sql_table.cc: sql_table.cc: - do not create a new item when charsets are the same - return ER_INVALID_DEFAULT if default value cannot be converted into the column character set. item.cc: - Allow conversion not only to Unicode, but also to and from "binary". - Adding safe_charset_converter() for Item_num and Item_varbinary, returning a fixed const Item. sql/item.cc: - Allow conversion not only to Unicode, but also to and from "binary". - Adding safe_charset_converter() for Item_num and Item_varbinary, returning a fixed const Item. sql/sql_table.cc: sql_table.cc: - do not create a new item when charsets are the same - return ER_INVALID_DEFAULT if default value cannot be converted into the column character set. mysql-test/r/ctype_utf8.result: adding test case
Diffstat (limited to 'sql/item.cc')
-rw-r--r--sql/item.cc44
1 files changed, 43 insertions, 1 deletions
diff --git a/sql/item.cc b/sql/item.cc
index c96794ff482..ee78d596891 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -212,15 +212,43 @@ bool Item::eq(const Item *item, bool binary_cmp) const
Item *Item::safe_charset_converter(CHARSET_INFO *tocs)
{
/*
+ Allow conversion from and to "binary".
Don't allow automatic conversion to non-Unicode charsets,
as it potentially loses data.
*/
- if (!(tocs->state & MY_CS_UNICODE))
+ if (collation.collation != &my_charset_bin &&
+ tocs != &my_charset_bin &&
+ !(tocs->state & MY_CS_UNICODE))
return NULL; // safe conversion is not possible
return new Item_func_conv_charset(this, tocs);
}
+/*
+ Created mostly for mysql_prepare_table(). Important
+ when a string ENUM/SET column is described with a numeric default value:
+
+ CREATE TABLE t1(a SET('a') DEFAULT 1);
+
+ We cannot use generic Item::safe_charset_converter(), because
+ the latter returns a non-fixed Item, so val_str() crashes afterwards.
+ Override Item_num method, to return a fixed item.
+*/
+Item *Item_num::safe_charset_converter(CHARSET_INFO *tocs)
+{
+ Item_string *conv;
+ char buf[64];
+ String *s, tmp(buf, sizeof(buf), &my_charset_bin);
+ s= val_str(&tmp);
+ if ((conv= new Item_string(s->ptr(), s->length(), s->charset())))
+ {
+ conv->str_value.copy();
+ conv->str_value.shrink_to_length();
+ }
+ return conv;
+}
+
+
Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs)
{
Item_string *conv;
@@ -2151,6 +2179,20 @@ bool Item_varbinary::eq(const Item *arg, bool binary_cmp) const
return FALSE;
}
+
+Item *Item_varbinary::safe_charset_converter(CHARSET_INFO *tocs)
+{
+ Item_string *conv;
+ String tmp, *str= val_str(&tmp);
+
+ if (!(conv= new Item_string(str->ptr(), str->length(), tocs)))
+ return NULL;
+ conv->str_value.copy();
+ conv->str_value.shrink_to_length();
+ return conv;
+}
+
+
/*
Pack data in buffer for sending
*/