diff options
author | Alexander Barkov <bar@mariadb.com> | 2020-08-09 14:25:22 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2020-08-10 07:47:59 +0400 |
commit | 9b2fe4bd12e72fbb4235ec01f5013e331d87e9c3 (patch) | |
tree | 4bf0859aa31db6de7d31a59e8403afe3f5871626 | |
parent | 2b6dd87b2c137229863f5eb0128a869b12785cdb (diff) | |
download | mariadb-git-9b2fe4bd12e72fbb4235ec01f5013e331d87e9c3.tar.gz |
MDEV-23435 Functions do not convert numbers to character_set_results
-rw-r--r-- | mysql-test/main/ctype_filename.result | 65 | ||||
-rw-r--r-- | mysql-test/main/ctype_filename.test | 62 | ||||
-rw-r--r-- | sql/protocol.cc | 45 | ||||
-rw-r--r-- | sql/protocol.h | 1 |
4 files changed, 155 insertions, 18 deletions
diff --git a/mysql-test/main/ctype_filename.result b/mysql-test/main/ctype_filename.result index ec4a14c4a23..1064ef95cae 100644 --- a/mysql-test/main/ctype_filename.result +++ b/mysql-test/main/ctype_filename.result @@ -32,5 +32,70 @@ EXECUTE IMMEDIATE _latin1 0x01; ERROR 42000: You@0020have@0020an@0020error@0020in@0020your@0020SQL@0020syntax@003b@0020check@0020the@0020manual@0020that@0020corresponds@0020to@0020your@0020MariaDB@0020server@0020version@0020for@0020the@0020right@0020syntax@0020to@0020use@0020near@0020@0027@005c0001@0027@0020at@0020line@00201 SET NAMES utf8; # +# MDEV-23435 Functions do not convert numbers to character_set_results +# +SET NAMES utf8, character_set_results=filename; +CREATE TABLE t1 (a DATETIME(6)); +INSERT INTO t1 VALUES ('2001-01-01 00:00:00.000000'); +SELECT a, COALESCE(a) AS c FROM t1; +a c +2001@002d01@002d01@002000@003a00@003a00@002e000000 2001@002d01@002d01@002000@003a00@003a00@002e000000 +DROP TABLE t1; +CREATE TABLE t1 (a TIME(6)); +INSERT INTO t1 VALUES ('00:00:00.000000'); +SELECT a, COALESCE(a) AS c FROM t1; +a c +00@003a00@003a00@002e000000 00@003a00@003a00@002e000000 +DROP TABLE t1; +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2001-01-01'); +SELECT a, COALESCE(a) AS c FROM t1; +a c +2001@002d01@002d01 2001@002d01@002d01 +DROP TABLE t1; +CREATE TABLE t1 (a TINYINT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +a c +@002d1 @002d1 +DROP TABLE t1; +CREATE TABLE t1 (a SMALLINT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +a c +@002d1 @002d1 +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMINT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +a c +@002d1 @002d1 +DROP TABLE t1; +CREATE TABLE t1 (a BIGINT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +a c +@002d1 @002d1 +DROP TABLE t1; +CREATE TABLE t1 (a DECIMAL(10.2)); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +a c +@002d1 @002d1 +DROP TABLE t1; +CREATE TABLE t1 (a FLOAT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +a c +@002d1 @002d1 +DROP TABLE t1; +CREATE TABLE t1 (a DOUBLE); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +a c +@002d1 @002d1 +DROP TABLE t1; +SET NAMES utf8; +# # End of 10.5 tests # diff --git a/mysql-test/main/ctype_filename.test b/mysql-test/main/ctype_filename.test index bd82714ca0e..940be6a7c24 100644 --- a/mysql-test/main/ctype_filename.test +++ b/mysql-test/main/ctype_filename.test @@ -42,6 +42,68 @@ SET NAMES filename; EXECUTE IMMEDIATE _latin1 0x01; SET NAMES utf8; +--echo # +--echo # MDEV-23435 Functions do not convert numbers to character_set_results +--echo # + +--disable_ps_protocol + +SET NAMES utf8, character_set_results=filename; + +CREATE TABLE t1 (a DATETIME(6)); +INSERT INTO t1 VALUES ('2001-01-01 00:00:00.000000'); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TIME(6)); +INSERT INTO t1 VALUES ('00:00:00.000000'); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE); +INSERT INTO t1 VALUES ('2001-01-01'); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TINYINT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a SMALLINT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a MEDIUMINT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a BIGINT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DECIMAL(10.2)); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a FLOAT); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE); +INSERT INTO t1 VALUES (-1); +SELECT a, COALESCE(a) AS c FROM t1; +DROP TABLE t1; + +SET NAMES utf8; + +--enable_ps_protocol + --echo # --echo # End of 10.5 tests diff --git a/sql/protocol.cc b/sql/protocol.cc index c6e2339c0d0..369ef27877d 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -1200,6 +1200,16 @@ bool Protocol::store_string_aux(const char *from, size_t length, } +bool Protocol_text::store_numeric_string_aux(const char *from, size_t length) +{ + CHARSET_INFO *tocs= thd->variables.character_set_results; + // 'tocs' is NULL when the client issues SET character_set_results=NULL + if (tocs && (tocs->state & MY_CS_NONASCII)) // Conversion needed + return net_store_data_cs((uchar*) from, length, &my_charset_latin1, tocs); + return net_store_data((uchar*) from, length); // No conversion +} + + bool Protocol::store_warning(const char *from, size_t length) { BinaryStringBuffer<MYSQL_ERRMSG_SIZE> tmp; @@ -1235,8 +1245,8 @@ bool Protocol_text::store_tiny(longlong from) field_pos++; #endif char buff[22]; - return net_store_data((uchar*) buff, - (size_t) (int10_to_str((int) from, buff, -10) - buff)); + size_t length= (size_t) (int10_to_str((int) from, buff, -10) - buff); + return store_numeric_string_aux(buff, length); } @@ -1247,9 +1257,8 @@ bool Protocol_text::store_short(longlong from) field_pos++; #endif char buff[22]; - return net_store_data((uchar*) buff, - (size_t) (int10_to_str((int) from, buff, -10) - - buff)); + size_t length= (size_t) (int10_to_str((int) from, buff, -10) - buff); + return store_numeric_string_aux(buff, length); } @@ -1260,9 +1269,9 @@ bool Protocol_text::store_long(longlong from) field_pos++; #endif char buff[22]; - return net_store_data((uchar*) buff, - (size_t) (int10_to_str((long int)from, buff, - (from <0)?-10:10)-buff)); + size_t length= (size_t) (int10_to_str((long int)from, buff, + (from < 0) ? - 10 : 10) - buff); + return store_numeric_string_aux(buff, length); } @@ -1273,10 +1282,10 @@ bool Protocol_text::store_longlong(longlong from, bool unsigned_flag) field_pos++; #endif char buff[22]; - return net_store_data((uchar*) buff, - (size_t) (longlong10_to_str(from,buff, - unsigned_flag ? 10 : -10)- - buff)); + size_t length= (size_t) (longlong10_to_str(from, buff, + unsigned_flag ? 10 : -10) - + buff); + return store_numeric_string_aux(buff, length); } @@ -1288,7 +1297,7 @@ bool Protocol_text::store_decimal(const my_decimal *d) #endif StringBuffer<DECIMAL_MAX_STR_LENGTH> str; (void) d->to_string(&str); - return net_store_data((uchar*) str.ptr(), str.length()); + return store_numeric_string_aux(str.ptr(), str.length()); } @@ -1299,7 +1308,7 @@ bool Protocol_text::store(float from, uint32 decimals, String *buffer) field_pos++; #endif Float(from).to_string(buffer, decimals); - return net_store_data((uchar*) buffer->ptr(), buffer->length()); + return store_numeric_string_aux(buffer->ptr(), buffer->length()); } @@ -1310,7 +1319,7 @@ bool Protocol_text::store(double from, uint32 decimals, String *buffer) field_pos++; #endif buffer->set_real(from, decimals, thd->charset()); - return net_store_data((uchar*) buffer->ptr(), buffer->length()); + return store_numeric_string_aux(buffer->ptr(), buffer->length()); } @@ -1350,7 +1359,7 @@ bool Protocol_text::store(MYSQL_TIME *tm, int decimals) #endif char buff[MAX_DATE_STRING_REP_LENGTH]; uint length= my_datetime_to_str(tm, buff, decimals); - return net_store_data((uchar*) buff, length); + return store_numeric_string_aux(buff, length); } @@ -1362,7 +1371,7 @@ bool Protocol_text::store_date(MYSQL_TIME *tm) #endif char buff[MAX_DATE_STRING_REP_LENGTH]; size_t length= my_date_to_str(tm, buff); - return net_store_data((uchar*) buff, length); + return store_numeric_string_aux(buff, length); } @@ -1374,7 +1383,7 @@ bool Protocol_text::store_time(MYSQL_TIME *tm, int decimals) #endif char buff[MAX_DATE_STRING_REP_LENGTH]; uint length= my_time_to_str(tm, buff, decimals); - return net_store_data((uchar*) buff, length); + return store_numeric_string_aux(buff, length); } /** diff --git a/sql/protocol.h b/sql/protocol.h index 18a01255708..574e7efed05 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -206,6 +206,7 @@ public: class Protocol_text :public Protocol { + bool store_numeric_string_aux(const char *from, size_t length); public: Protocol_text(THD *thd_arg, ulong prealloc= 0) :Protocol(thd_arg) |