Skip to content

Commit 1094ffd

Browse files
author
Alexander Barkov
committed
WL#2649 Number-to-string conversions
added: include/ctype_numconv.inc mysql-test/include/ctype_numconv.inc mysql-test/r/ctype_binary.result mysql-test/t/ctype_binary.test Adding tests modified: mysql-test/r/bigint.result mysql-test/r/case.result mysql-test/r/create.result mysql-test/r/ctype_cp1251.result mysql-test/r/ctype_latin1.result mysql-test/r/ctype_ucs.result mysql-test/r/func_gconcat.result mysql-test/r/func_str.result mysql-test/r/metadata.result mysql-test/r/ps_1general.result mysql-test/r/ps_2myisam.result mysql-test/r/ps_3innodb.result mysql-test/r/ps_4heap.result mysql-test/r/ps_5merge.result mysql-test/r/show_check.result mysql-test/r/type_datetime.result mysql-test/r/type_ranges.result mysql-test/r/union.result mysql-test/suite/ndb/r/ps_7ndb.result mysql-test/t/ctype_cp1251.test mysql-test/t/ctype_latin1.test mysql-test/t/ctype_ucs.test mysql-test/t/func_str.test Fixing tests @ sql/field.cc - Return str result using my_charset_numeric. - Using real multi-byte aware str_to_XXX functions to handle tricky charset values propely (e.g. UCS2) @ sql/field.h - Changing derivation of non-string field types to DERIVATION_NUMERIC. - Changing binary() for numeric/datetime fields to always return TRUE even if charset is not my_charset_bin. We need this to keep ha_base_keytype() return HA_KEYTYPE_BINARY. - Adding BINARY_FLAG into some fields, because it's not being set automatically anymore with "my_charset_bin to my_charset_numeric" change. - Changing derivation for numeric/datetime datatypes to a weaker value, to make "SELECT concat('string', field)" use character set of the string literal for the result of the function. @ sql/item.cc - Implementing generic val_str_ascii(). - Using max_char_length() instead of direct read of max_length to make "tricky" charsets like UCS2 work. NOTE: in the future we'll possibly remove all direct reads of max_length - Fixing Item_num::safe_charset_converter(). Previously it alligned binary string to character string (for example by adding leading 0x00 when doing binary->UCS2 conversion). Now it just converts from my_charset_numbner to "tocs". - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work. - Other misc changes @ sql/item.h - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to bit operations instead of hard-coded bit masks. - Addding new method DTCollation.set_numeric(). - Adding new methods to Item. - Adding helper functions to make code look nicer: agg_item_charsets_for_string_result() agg_item_charsets_for_comparison() - Changing charset for Item_num-derived items from my_charset_bin to my_charset_numeric (which is an alias for latin1). @ sql/item_cmpfunc.cc - Using new helper functions - Other misc changes @ sql/item_cmpfunc.h - Fixing strcmp() to return max_length=2. Previously it returned 1, which was wrong, because it did not fit '-1'. @ sql/item_func.cc - Using new helper functions - Other minor changes @ sql/item_func.h - Removing unused functions - Adding helper functions agg_arg_charsets_for_string_result() agg_arg_charsets_for_comparison() - Adding set_numeric() into constructors of numeric items. - Using fix_length_and_charset() and fix_char_length() instead of direct write to max_length. @ sql/item_geofunc.cc - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when character_set_connection=ucs2). @ sql/item_geofunc.h - Changing class for Item_func_geometry_type and Item_func_as_wkt from Item_str_func to Item_str_ascii_func, to make them return UCS2 result properly (when @@character_set_connection=ucs2). @ sql/item_strfunc.cc - Implementing Item_str_func::val_str(). - Renaming val_str to val_str_ascii for some items, to make them work with UCS2 properly. - Using new helper functions - All single-argument functions that expect string result now call this method: agg_arg_charsets_for_string_result(collation, args, 1); This enables character set conversion to @@character_set_connection in case of pure numeric input. @ sql/item_strfunc.h - Introducing Item_str_ascii_func - for functions which return pure ASCII data, for performance purposes, as well as for the cases when the old implementation of val_str() was heavily 8-bit oriented and implementing a UCS2-aware version is tricky. @ sql/item_sum.cc - Using new helper functions. @ sql/item_timefunc.cc - Using my_charset_numeric instead of my_charset_bin. - Using fix_char_length(), fix_length_and_charset() and fix_length_and_charset_datetime() instead of direct write to max_length. - Using tricky-charset aware function str_to_time_with_warn() @ sql/item_timefunc.h - Using new helper functions for charset and length initialization. - Changing base class for Item_func_get_format() to make it return UCS2 properly (when character_set_connection=ucs2). @ sql/item_xmlfunc.cc - Using new helper function @ sql/my_decimal.cc - Adding a new DECIMAL to CHAR converter with real multibyte support (e.g. UCS2) @ sql/mysql_priv.h - Introducing a new derivation level for numeric/datetime data types. - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC. - Adding prototypes for str_set_decimal() - Adding prototypes for character-set aware str_to_xxx() functions. @ sql/protocol.cc - Changing charsetnr to "binary" client-side metadata for numeric/datetime data types. @ sql/time.cc - Adding to_ascii() helper function, to convert a string in any character set to ascii representation. In the future can be extended to understand digits written in various non-Latin word scripts. - Adding real multy-byte character set aware versions for str_to_XXXX, to make these these type of queries work correct: INSERT INTO t1 SET datetime_column=ucs2_expression; @ strings/ctype-ucs2.c - endptr was not calculated correctly. INSERTing of UCS2 values into numeric columns returned warnings about truncated wrong data.
1 parent 68ac1c9 commit 1094ffd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+12967
-546
lines changed

mysql-test/include/ctype_numconv.inc

+1,605
Large diffs are not rendered by default.

mysql-test/r/case.result

+7-7
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ Table Create Table
101101
t1 CREATE TABLE `t1` (
102102
`c1` varchar(1) CHARACTER SET latin1 COLLATE latin1_danish_ci NOT NULL DEFAULT '',
103103
`c2` varchar(1) CHARACTER SET latin1 COLLATE latin1_danish_ci NOT NULL DEFAULT '',
104-
`c3` varbinary(1) NOT NULL DEFAULT '',
105-
`c4` varbinary(1) NOT NULL DEFAULT '',
106-
`c5` varbinary(4) NOT NULL DEFAULT '',
107-
`c6` varbinary(4) NOT NULL DEFAULT '',
104+
`c3` varchar(1) NOT NULL DEFAULT '',
105+
`c4` varchar(1) NOT NULL DEFAULT '',
106+
`c5` varchar(4) NOT NULL DEFAULT '',
107+
`c6` varchar(4) NOT NULL DEFAULT '',
108108
`c7` decimal(2,1) NOT NULL DEFAULT '0.0',
109109
`c8` decimal(2,1) NOT NULL DEFAULT '0.0',
110110
`c9` decimal(2,1) DEFAULT NULL,
111111
`c10` double NOT NULL DEFAULT '0',
112112
`c11` double NOT NULL DEFAULT '0',
113-
`c12` varbinary(5) NOT NULL DEFAULT ''
113+
`c12` varchar(5) NOT NULL DEFAULT ''
114114
) ENGINE=MyISAM DEFAULT CHARSET=latin1
115115
DROP TABLE t1;
116116
SELECT CASE
@@ -155,8 +155,8 @@ t1 CREATE TABLE `t1` (
155155
`COALESCE(1.0)` decimal(2,1) NOT NULL DEFAULT '0.0',
156156
`COALESCE('a')` varchar(1) NOT NULL DEFAULT '',
157157
`COALESCE(1,1.0)` decimal(2,1) NOT NULL DEFAULT '0.0',
158-
`COALESCE(1,'1')` varbinary(1) NOT NULL DEFAULT '',
159-
`COALESCE(1.1,'1')` varbinary(4) NOT NULL DEFAULT '',
158+
`COALESCE(1,'1')` varchar(1) NOT NULL DEFAULT '',
159+
`COALESCE(1.1,'1')` varchar(4) NOT NULL DEFAULT '',
160160
`COALESCE('a' COLLATE latin1_bin,'b')` varchar(1) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT ''
161161
) ENGINE=MyISAM DEFAULT CHARSET=latin1
162162
DROP TABLE t1;

mysql-test/r/create.result

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ explain t2;
438438
Field Type Null Key Default Extra
439439
a int(11) YES NULL
440440
b bigint(11) NO 0
441-
c bigint(11) unsigned NO 0
441+
c bigint(10) unsigned NO 0
442442
d date YES NULL
443443
e varchar(1) NO
444444
f datetime YES NULL
@@ -457,7 +457,7 @@ Table Create Table
457457
t2 CREATE TABLE `t2` (
458458
`ifnull(a,a)` tinyint(4) DEFAULT NULL,
459459
`ifnull(b,b)` smallint(6) DEFAULT NULL,
460-
`ifnull(c,c)` mediumint(8) DEFAULT NULL,
460+
`ifnull(c,c)` mediumint(9) DEFAULT NULL,
461461
`ifnull(d,d)` int(11) DEFAULT NULL,
462462
`ifnull(e,e)` bigint(20) DEFAULT NULL,
463463
`ifnull(f,f)` float(3,2) DEFAULT NULL,

0 commit comments

Comments
 (0)