diff options
author | unknown <bar@bar.mysql.r18.ru> | 2003-08-21 14:15:25 +0500 |
---|---|---|
committer | unknown <bar@bar.mysql.r18.ru> | 2003-08-21 14:15:25 +0500 |
commit | 34e882dd79663c428199a76ba8fcfe6d704592af (patch) | |
tree | c97e84f2eab14aa455ae3c07b91e184b75d6cd28 /sql/item_timefunc.cc | |
parent | 8359a2c7298f4c936ca2a0bde083d87d35538e1d (diff) | |
download | mariadb-git-34e882dd79663c428199a76ba8fcfe6d704592af.tar.gz |
CAST(expr AS CHAR(10)) is now working
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r-- | sql/item_timefunc.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 6ddafd40755..31ce2ad9cdc 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1474,6 +1474,59 @@ void Item_typecast::print(String *str) str->append(')'); } +String *Item_char_typecast::val_str(String *str) +{ + String *res, *res1; + uint32 length; + + if (!charset_conversion && !(res= args[0]->val_str(str))) + { + null_value= 1; + return 0; + } + else + { + // Convert character set if differ + if (!(res1= args[0]->val_str(&tmp_value)) || + str->copy(res1->ptr(), res1->length(),res1->charset(), cast_cs)) + { + null_value= 1; + return 0; + } + res= str; + } + + /* + Cut the tail if cast with length + and the result is longer than cast length, e.g. + CAST('string' AS CHAR(1)) + */ + if (cast_length >= 0 && + (res->length() > (length= (uint32) res->charpos(cast_length)))) + { // Safe even if const arg + if (!res->alloced_length()) + { // Don't change const str + str_value= *res; // Not malloced string + res= &str_value; + } + res->length((uint) length); + } + null_value= 0; + return res; +} + +void Item_char_typecast::fix_length_and_dec() +{ + uint32 char_length; + charset_conversion= !my_charset_same(args[0]->collation.collation, cast_cs) && + args[0]->collation.collation != &my_charset_bin && + cast_cs != &my_charset_bin; + collation.set(cast_cs, DERIVATION_IMPLICIT); + char_length= (cast_length >= 0) ? cast_length : + args[0]->max_length/args[0]->collation.collation->mbmaxlen; + max_length= char_length * cast_cs->mbmaxlen; +} + String *Item_datetime_typecast::val_str(String *str) { TIME ltime; |