summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2015-09-25 21:33:50 +0400
committerAlexander Barkov <bar@mariadb.org>2015-09-25 21:33:50 +0400
commit30711c6650fc7e2f166f29d0bc59eeab64dadb3e (patch)
treebd9a209f1e339c73a2d23c22c9c078ea992ebd08
parent26e4403f649839e82dd26f7a6b31165063eb2871 (diff)
downloadmariadb-git-30711c6650fc7e2f166f29d0bc59eeab64dadb3e.tar.gz
MDEV-8806 Numeric CAST produce different warnings for strings literals vs functions
-rw-r--r--mysql-test/r/func_group.result3
-rw-r--r--mysql-test/r/func_math.result3
-rw-r--r--mysql-test/r/func_misc.result2
-rw-r--r--mysql-test/r/func_regexp_pcre.result4
-rw-r--r--mysql-test/r/func_str.result13
-rw-r--r--mysql-test/r/func_time.result40
-rw-r--r--mysql-test/r/subselect_sj.result3
-rw-r--r--mysql-test/r/subselect_sj_jcl6.result3
-rw-r--r--mysql-test/r/xml.result4
-rw-r--r--mysql-test/suite/rpl/r/rpl_row_create_select.result4
-rw-r--r--mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test2
-rw-r--r--mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test2
-rw-r--r--mysql-test/t/ctype_ucs.test3
-rw-r--r--mysql-test/t/func_str.test9
-rw-r--r--sql/field.h17
-rw-r--r--sql/item.cc23
-rw-r--r--sql/item.h43
-rw-r--r--sql/item_func.cc34
-rw-r--r--sql/item_geofunc.h1
-rw-r--r--sql/item_strfunc.cc31
-rw-r--r--sql/item_strfunc.h5
-rw-r--r--sql/item_sum.cc2
-rw-r--r--sql/sql_do.cc2
23 files changed, 169 insertions, 84 deletions
diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result
index c407e7bb875..04f7b262bac 100644
--- a/mysql-test/r/func_group.result
+++ b/mysql-test/r/func_group.result
@@ -2107,6 +2107,9 @@ select avg(export_set( 3, 'y', sha(i))), group_concat(d) from t1 group by d orde
avg(export_set( 3, 'y', sha(i))) group_concat(d)
0 2008-10-02
0 2010-12-12
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'y,y,356a192b7913b04c54574d18c28d46e6395428ab,356a192b7913b04c54574d18c28d46e6395428ab,356a192b7913b04c54574d18c28d46e6395428ab,3'
+Warning 1292 Truncated incorrect DOUBLE value: 'y,y,da4b9237bacccdf19c0760cab7aec4a8359010b0,da4b9237bacccdf19c0760cab7aec4a8359010b0,da4b9237bacccdf19c0760cab7aec4a8359010b0,d'
drop table t1;
#
# MDEV-4290: crash in st_select_lex::mark_as_dependent
diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result
index c49e55d503a..d768672efe4 100644
--- a/mysql-test/r/func_math.result
+++ b/mysql-test/r/func_math.result
@@ -702,6 +702,9 @@ SELECT floor(log10(format(concat_ws(5445796E25, 5306463, 30837), -358821)))
as foo;
foo
2
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: '53064635.445796e3130837'
+Warning 1292 Truncated incorrect DOUBLE value: '179,769,313,486,231,570,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,'
#
# Bug #58137 char(0) column cause:
# my_gcvt: Assertion `width > 0 && to != ((void *)0)' failed
diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result
index a9548aa70e9..df69aff8b59 100644
--- a/mysql-test/r/func_misc.result
+++ b/mysql-test/r/func_misc.result
@@ -295,6 +295,8 @@ INSERT INTO t1 VALUES ('', 0);
SELECT COALESCE(a) = COALESCE(b) FROM t1;
COALESCE(a) = COALESCE(b)
1
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: ''
DROP TABLE t1;
#
# Bug #54461: crash with longblob and union or update with subquery
diff --git a/mysql-test/r/func_regexp_pcre.result b/mysql-test/r/func_regexp_pcre.result
index d114cccaf72..fcff0484b65 100644
--- a/mysql-test/r/func_regexp_pcre.result
+++ b/mysql-test/r/func_regexp_pcre.result
@@ -445,6 +445,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1003 select regexp_replace('abc','b','x') AS `REGEXP_REPLACE('abc','b','x')`
CREATE TABLE t1 AS SELECT REGEXP_REPLACE('abc','b','x')+0;
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'axc'
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -745,6 +747,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1003 select regexp_substr('abc','b') AS `REGEXP_SUBSTR('abc','b')`
CREATE TABLE t1 AS SELECT REGEXP_SUBSTR('abc','b')+0;
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'b'
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result
index d392da84ea7..9bc80613710 100644
--- a/mysql-test/r/func_str.result
+++ b/mysql-test/r/func_str.result
@@ -1160,6 +1160,8 @@ Warning 1292 Truncated incorrect DOUBLE value: 'notnumber'
SELECT * FROM t1, t2 WHERE num=substring(str from 1 for 6);
str num
notnumber 0
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'notnum'
DROP TABLE t1,t2;
CREATE TABLE t1(
id int(11) NOT NULL auto_increment,
@@ -1352,6 +1354,8 @@ cast(rtrim(' 20.06 ') as decimal(19,2))
select cast(ltrim(' 20.06 ') as decimal(19,2));
cast(ltrim(' 20.06 ') as decimal(19,2))
20.06
+Warnings:
+Note 1292 Truncated incorrect DECIMAL value: '20.06 '
select cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2));
cast(rtrim(ltrim(' 20.06 ')) as decimal(19,2))
20.06
@@ -2915,7 +2919,7 @@ format(rpad('111111111.1',
1111111,
'999999999999999999999999999999999999999999'),0,'be_BY')
;
-DO
+SELECT
round(
concat( (
coalesce( (
@@ -2930,9 +2934,14 @@ sha1('P'),
)
)
)
-);
+) AS r;
+r
+0
Warnings:
+Warning 1292 Truncated incorrect INTEGER value: '511993d3c99719e38a6779073019dacd7178ddb9'
Warning 1292 Truncated incorrect DECIMAL value: '[.DC2.]'
+Warning 1292 Truncated incorrect INTEGER value: '511993d3c99719e38a6779073019dacd7178ddb9'
+Warning 1292 Truncated incorrect DOUBLE value: '0.000000000000000000000000000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111'
SET @@global.max_allowed_packet:= @tmp_max;
SELECT @tmp_max:= @@global.max_allowed_packet;
@tmp_max:= @@global.max_allowed_packet
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index c0cf6d45ae2..b562aba13c9 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -163,6 +163,8 @@ Saturday 5
select monthname("1972-03-04"),monthname("1972-03-04")+0;
monthname("1972-03-04") monthname("1972-03-04")+0
March 0
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'March'
select time_format(000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T'),date_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
time_format(000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T') date_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
00|12|0|12|00|AM|12:00:00 AM|00|00:00:00 00|12|0|12|00|AM|12:00:00 AM|00|00:00:00
@@ -1966,6 +1968,9 @@ SELECT * FROM t1 GROUP BY SEC_TO_TIME(concat(a,'10'))*1;
a
2000-02-23
2005-05-04
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
DROP TABLE t1;
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
@@ -2015,22 +2020,37 @@ SELECT * FROM t1 GROUP BY FROM_UNIXTIME(concat(a,'10'))*1;
a
2000-02-23
2005-05-04
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
SELECT * FROM t1 GROUP BY (-FROM_UNIXTIME(concat(a,'10')))*1;
a
2005-05-04
2000-02-23
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
SELECT * FROM t1 GROUP BY (-FROM_UNIXTIME(concat(a,'10')));
a
2005-05-04
2000-02-23
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
SELECT * FROM t1 GROUP BY ABS(FROM_UNIXTIME(concat(a,'10')));
a
2000-02-23
2005-05-04
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
SELECT * FROM t1 GROUP BY @a:=(FROM_UNIXTIME(concat(a,'10'))*1);
a
2000-02-23
2005-05-04
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
DROP TABLE t1;
SET TIME_ZONE='+02:00';
#
@@ -2042,10 +2062,18 @@ SELECT a, FROM_UNIXTIME(CONCAT(a,'10')) AS f1, FROM_UNIXTIME(CONCAT(a,'10'))+0 A
a f1 f2
2005-05-04 1970-01-01 02:33:25 19700101023325.000000
2000-02-23 1970-01-01 02:33:20 19700101023320.000000
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
SELECT * FROM t1 GROUP BY FROM_UNIXTIME(CONCAT(a,'10'))+0;
a
2000-02-23
2005-05-04
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
DROP TABLE t1;
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
@@ -2053,16 +2081,28 @@ SELECT * FROM t1 GROUP BY FROM_UNIXTIME(concat(a,'10'))/1;
a
2000-02-23
2005-05-04
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2000-02-2310'
DROP TABLE t1;
CREATE TABLE t1 (a DATE);
INSERT INTO t1 VALUES ('2005-05-04');
SELECT CONCAT(FROM_UNIXTIME(CONCAT(a,'10')) MOD FROM_UNIXTIME(CONCAT(a,'10'))) AS f2 FROM t1;
f2
0.000000
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
SELECT CHAR_LENGTH(CONCAT(FROM_UNIXTIME(CONCAT(a,'10')) MOD FROM_UNIXTIME(CONCAT(a,'10')))) AS f2 FROM t1;
f2
8
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
CREATE TABLE t2 AS SELECT CONCAT(FROM_UNIXTIME(CONCAT(a,'10')) MOD FROM_UNIXTIME(CONCAT(a,'10'))) AS f2 FROM t1;
+Warnings:
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
+Warning 1292 Truncated incorrect DECIMAL value: '2005-05-0410'
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
diff --git a/mysql-test/r/subselect_sj.result b/mysql-test/r/subselect_sj.result
index a937cc960f3..d8b5ffaf330 100644
--- a/mysql-test/r/subselect_sj.result
+++ b/mysql-test/r/subselect_sj.result
@@ -2094,6 +2094,9 @@ f1 f2 f3 f3
4 0 0 0
4 0 0 0
0 NULL NULL NULL
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'foo'
+Warning 1292 Truncated incorrect DOUBLE value: 'foo'
DROP TABLE t1, t2, t3, t4;
set @tmp803457=@@optimizer_switch;
#
diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result
index 73dd69681d2..0fd9ab322e5 100644
--- a/mysql-test/r/subselect_sj_jcl6.result
+++ b/mysql-test/r/subselect_sj_jcl6.result
@@ -2108,6 +2108,9 @@ f1 f2 f3 f3
4 0 0 0
4 0 0 0
0 NULL NULL NULL
+Warnings:
+Warning 1292 Truncated incorrect DOUBLE value: 'foo'
+Warning 1292 Truncated incorrect DOUBLE value: 'foo'
DROP TABLE t1, t2, t3, t4;
set @tmp803457=@@optimizer_switch;
#
diff --git a/mysql-test/r/xml.result b/mysql-test/r/xml.result
index b6f0f048c68..41dbc744228 100644
--- a/mysql-test/r/xml.result
+++ b/mysql-test/r/xml.result
@@ -1184,6 +1184,8 @@ aa bb
SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,..)');
ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,..)')
+Warnings:
+Warning 1292 Truncated incorrect INTEGER value: ''
#
# Bug#62429 XML: ExtractValue, UpdateXML max arg length 127 chars
#
@@ -1243,6 +1245,8 @@ DROP TABLE t1;
SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,..)') AS e;
e
+Warnings:
+Warning 1292 Truncated incorrect INTEGER value: ''
SELECT ExtractValue('<a><b>abc</b><c>2</c><d>1</d></a>','substring(/a/b,/a/c)') AS e;
e
bc
diff --git a/mysql-test/suite/rpl/r/rpl_row_create_select.result b/mysql-test/suite/rpl/r/rpl_row_create_select.result
index ac95d50df9d..81bbd3bc2fd 100644
--- a/mysql-test/suite/rpl/r/rpl_row_create_select.result
+++ b/mysql-test/suite/rpl/r/rpl_row_create_select.result
@@ -8,7 +8,7 @@ include/master-slave.inc
#value of 21.
CREATE TABLE t1 AS SELECT REPEAT('A', 1000) DIV 1 AS a;
Warnings:
-Warning 1918 Encountered illegal value '' when converting to DECIMAL
+Warning 1292 Truncated incorrect DECIMAL value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -16,7 +16,7 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
CREATE TABLE t2 AS SELECT CONVERT(REPEAT('A', 255) USING UCS2) DIV 1 AS a;
Warnings:
-Warning 1918 Encountered illegal value '' when converting to DECIMAL
+Warning 1292 Truncated incorrect DECIMAL value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
SHOW CREATE TABLE t2;
Table Create Table
t2 CREATE TABLE `t2` (
diff --git a/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test b/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test
index 866e387cddb..575fdb2e89d 100644
--- a/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test
+++ b/mysql-test/suite/rpl/t/rpl_switch_stm_row_mixed.test
@@ -149,7 +149,9 @@ insert into t1 select "yesterday_24_";
create table t2 ENGINE=MyISAM select rpad(UUID(),100,' ');
create table t3 select 1 union select UUID();
+--disable_warnings
create table t4 select * from t1 where 3 in (select 1 union select 2 union select UUID() union select 3);
+--enable_warnings
create table t5 select * from t1 where 3 in (select 1 union select 2 union select curdate() union select 3);
# what if UUID() is first:
--disable_warnings
diff --git a/mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test b/mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test
index 70a2063c23c..57954698a2c 100644
--- a/mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test
+++ b/mysql-test/suite/rpl/t/rpl_temp_table_mix_row.test
@@ -192,7 +192,9 @@ DROP TEMPORARY TABLE t1;
# INSERT INTO t1 VALUES(1);
--echo # The rows event will binlogged after 'INSERT INTO t1 VALUES(1)'
+--disable_warnings
INSERT INTO t1 VALUES(uuid()+0);
+--enable_warnings
COMMIT;
source include/show_binlog_events.inc;
diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test
index 13f9f5c9b6d..2875a2bfcb4 100644
--- a/mysql-test/t/ctype_ucs.test
+++ b/mysql-test/t/ctype_ucs.test
@@ -737,7 +737,10 @@ DROP TABLE t1;
--echo #
--echo # Bug#59648 my_strtoll10_mb2: Assertion `(*endptr - s) % 2 == 0' failed.
--echo #
+--disable_warnings
+# Enable warnings when "MDEV-8844 Unreadable control characters printed as is in warnings" is fixed
SELECT HEX(CHAR(COALESCE(NULL, CHAR(COUNT('%s') USING ucs2), 1, @@global.license, NULL) USING cp850));
+--enable_warnings
SELECT CONVERT(QUOTE(CHAR(0xf5 using ucs2)), SIGNED);
--echo End of 5.0 tests
diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test
index 14af10b0320..511f1f31736 100644
--- a/mysql-test/t/func_str.test
+++ b/mysql-test/t/func_str.test
@@ -1549,7 +1549,12 @@ format(rpad('111111111.1',
'999999999999999999999999999999999999999999'),0,'be_BY')
;
-DO
+#
+# Originally it was DO instead of SELECT here.
+# But in mysqltest --disable_prepare_warnings affects SELECT queries only
+# and can't suppress prepare time warnings for DO.
+#
+SELECT
round(
concat( (
coalesce( (
@@ -1564,7 +1569,7 @@ round(
)
)
)
-);
+) AS r;
--connection conn1
SET @@global.max_allowed_packet:= @tmp_max;
diff --git a/sql/field.h b/sql/field.h
index 4f5abf6924f..f3e1ed38258 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -279,6 +279,23 @@ protected:
cs, cptr, end - cptr, decimal_value);
return decimal_value;
}
+
+ longlong longlong_from_string_with_check(const String *str) const
+ {
+ return longlong_from_string_with_check(str->charset(),
+ str->ptr(), str->end());
+ }
+ double double_from_string_with_check(const String *str) const
+ {
+ return double_from_string_with_check(str->charset(),
+ str->ptr(), str->end());
+ }
+ my_decimal *decimal_from_string_with_check(my_decimal *decimal_value,
+ const String *str)
+ {
+ return decimal_from_string_with_check(decimal_value, str->charset(),
+ str->ptr(), str->end());
+ }
// End of String-to-number conversion methods
public:
diff --git a/sql/item.cc b/sql/item.cc
index c17147bde01..a431477a5f7 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -317,8 +317,7 @@ my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value)
if (!(res= val_str(&str_value)))
return 0;
- return decimal_from_string_with_check(decimal_value,
- res->charset(), res->ptr(), res->end());
+ return decimal_from_string_with_check(decimal_value, res);
}
@@ -2955,10 +2954,7 @@ void Item_string::print(String *str, enum_query_type query_type)
double Item_string::val_real()
{
DBUG_ASSERT(fixed == 1);
- return double_from_string_with_check(str_value.charset(),
- str_value.ptr(),
- str_value.ptr() +
- str_value.length());
+ return double_from_string_with_check(&str_value);
}
@@ -2969,8 +2965,7 @@ double Item_string::val_real()
longlong Item_string::val_int()
{
DBUG_ASSERT(fixed == 1);
- return longlong_from_string_with_check(str_value.charset(), str_value.ptr(),
- str_value.ptr()+ str_value.length());
+ return longlong_from_string_with_check(&str_value);
}
@@ -3408,10 +3403,7 @@ double Item_param::val_real()
case STRING_VALUE:
case LONG_DATA_VALUE:
{
- int dummy_err;
- char *end_not_used;
- return my_strntod(str_value.charset(), (char*) str_value.ptr(),
- str_value.length(), &end_not_used, &dummy_err);
+ return double_from_string_with_check(&str_value);
}
case TIME_VALUE:
/*
@@ -3444,9 +3436,7 @@ longlong Item_param::val_int()
case STRING_VALUE:
case LONG_DATA_VALUE:
{
- int dummy_err;
- return my_strntoll(str_value.charset(), str_value.ptr(),
- str_value.length(), 10, (char**) 0, &dummy_err);
+ return longlong_from_string_with_check(&str_value);
}
case TIME_VALUE:
return (longlong) TIME_to_ulonglong(&value.time);
@@ -3472,8 +3462,7 @@ my_decimal *Item_param::val_decimal(my_decimal *dec)
return dec;
case STRING_VALUE:
case LONG_DATA_VALUE:
- string2my_decimal(E_DEC_FATAL_ERROR, &str_value, dec);
- return dec;
+ return decimal_from_string_with_check(dec, &str_value);
case TIME_VALUE:
{
return TIME_to_my_decimal(&value.time, dec);
diff --git a/sql/item.h b/sql/item.h
index 13f65b36404..4654c4ac1cc 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -1278,7 +1278,38 @@ public:
/*
Make sure the null_value member has a correct value.
*/
- virtual void update_null_value () { (void) val_int(); }
+ virtual void update_null_value ()
+ {
+ switch (cmp_type()) {
+ case INT_RESULT:
+ (void) val_int();
+ break;
+ case REAL_RESULT:
+ (void) val_real();
+ break;
+ case DECIMAL_RESULT:
+ {
+ my_decimal tmp;
+ (void) val_decimal(&tmp);
+ }
+ break;
+ case TIME_RESULT:
+ {
+ MYSQL_TIME ltime;
+ (void) get_temporal_with_sql_mode(&ltime);
+ }
+ break;
+ case STRING_RESULT:
+ {
+ StringBuffer<MAX_FIELD_WIDTH> tmp;
+ (void) val_str(&tmp);
+ }
+ break;
+ case ROW_RESULT:
+ DBUG_ASSERT(0);
+ null_value= true;
+ }
+ }
/*
Inform the item that there will be no distinction between its result
@@ -3231,18 +3262,12 @@ public:
longlong val_int()
{
DBUG_ASSERT(fixed == 1);
- return longlong_from_string_with_check(str_value.charset(),
- str_value.ptr(),
- str_value.ptr()+
- str_value.length());
+ return longlong_from_string_with_check(&str_value);
}
double val_real()
{
DBUG_ASSERT(fixed == 1);
- return double_from_string_with_check(str_value.charset(),
- str_value.ptr(),
- str_value.ptr() +
- str_value.length());
+ return double_from_string_with_check(&str_value);
}
my_decimal *val_decimal(my_decimal *decimal_value)
{
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 3537ebe21af..7876929a427 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -955,11 +955,8 @@ double Item_func_hybrid_result_type::val_real()
ltime.time_type= mysql_type_to_time_type(field_type());
return TIME_to_double(&ltime);
}
- char *end_not_used;
- int err_not_used;
String *res= str_op(&str_value);
- return (res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
- &end_not_used, &err_not_used) : 0.0);
+ return res ? double_from_string_with_check(res) : 0.0;
}
case TIME_RESULT:
case ROW_RESULT:
@@ -1000,14 +997,8 @@ longlong Item_func_hybrid_result_type::val_int()
ltime.time_type= mysql_type_to_time_type(field_type());
return TIME_to_ulonglong(&ltime);
}
- int err_not_used;
- String *res;
- if (!(res= str_op(&str_value)))
- return 0;
-
- char *end= (char*) res->ptr() + res->length();
- CHARSET_INFO *cs= res->charset();
- return (*(cs->cset->strtoll10))(cs, res->ptr(), &end, &err_not_used);
+ String *res= str_op(&str_value);
+ return res ? longlong_from_string_with_check(res) : 0;
}
case TIME_RESULT:
case ROW_RESULT:
@@ -1052,13 +1043,8 @@ my_decimal *Item_func_hybrid_result_type::val_decimal(my_decimal *decimal_value)
ltime.time_type= mysql_type_to_time_type(field_type());
return date2my_decimal(&ltime, decimal_value);
}
- String *res;
- if (!(res= str_op(&str_value)))
- return NULL;
-
- str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
- res->length(), res->charset(), decimal_value);
- break;
+ String *res= str_op(&str_value);
+ return res ? decimal_from_string_with_check(decimal_value, res) : 0;
}
case ROW_RESULT:
case TIME_RESULT:
@@ -5965,10 +5951,7 @@ longlong Item_func_get_system_var::val_int()
{
null_value= cached_null_value;
if (!null_value)
- cached_llval= longlong_from_string_with_check (cached_strval.charset(),
- cached_strval.c_ptr(),
- cached_strval.c_ptr() +
- cached_strval.length());
+ cached_llval= longlong_from_string_with_check(&cached_strval);
else
cached_llval= 0;
cache_present|= GET_SYS_VAR_CACHE_LONG;
@@ -6043,10 +6026,7 @@ double Item_func_get_system_var::val_real()
{
null_value= cached_null_value;
if (!null_value)
- cached_dval= double_from_string_with_check (cached_strval.charset(),
- cached_strval.c_ptr(),
- cached_strval.c_ptr() +
- cached_strval.length());
+ cached_dval= double_from_string_with_check(&cached_strval);
else
cached_dval= 0;
cache_present|= GET_SYS_VAR_CACHE_DOUBLE;
diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h
index d814019bd74..2379e6184d1 100644
--- a/sql/item_geofunc.h
+++ b/sql/item_geofunc.h
@@ -41,7 +41,6 @@ public:
void fix_length_and_dec();
enum_field_types field_type() const { return MYSQL_TYPE_GEOMETRY; }
Field *tmp_table_field(TABLE *t_arg);
- bool is_null() { (void) val_int(); return null_value; }
};
class Item_func_geometry_from_text: public Item_geometry_func
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index d9cb252b998..b61da4f679c 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -116,40 +116,27 @@ bool Item_str_func::fix_fields(THD *thd, Item **ref)
my_decimal *Item_str_func::val_decimal(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed == 1);
- char buff[64];
- String *res, tmp(buff,sizeof(buff), &my_charset_bin);
- res= val_str(&tmp);
- if (!res)
- return 0;
- (void)str2my_decimal(E_DEC_FATAL_ERROR, (char*) res->ptr(),
- res->length(), res->charset(), decimal_value);
- return decimal_value;
+ StringBuffer<64> tmp;
+ String *res= val_str(&tmp);
+ return res ? decimal_from_string_with_check(decimal_value, res) : 0;
}
double Item_str_func::val_real()
{
DBUG_ASSERT(fixed == 1);
- int err_not_used;
- char *end_not_used, buff[64];
- String *res, tmp(buff,sizeof(buff), &my_charset_bin);
- res= val_str(&tmp);
- return res ? my_strntod(res->charset(), (char*) res->ptr(), res->length(),
- &end_not_used, &err_not_used) : 0.0;
+ StringBuffer<64> tmp;
+ String *res= val_str(&tmp);
+ return res ? double_from_string_with_check(res) : 0.0;
}
longlong Item_str_func::val_int()
{
DBUG_ASSERT(fixed == 1);
- int err;
- char buff[22];
- String *res, tmp(buff,sizeof(buff), &my_charset_bin);
- res= val_str(&tmp);
- return (res ?
- my_strntoll(res->charset(), res->ptr(), res->length(), 10, NULL,
- &err) :
- (longlong) 0);
+ StringBuffer<22> tmp;
+ String *res= val_str(&tmp);
+ return res ? longlong_from_string_with_check(res) : 0;
}
diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h
index d1abbe198b1..1a9f855dec5 100644
--- a/sql/item_strfunc.h
+++ b/sql/item_strfunc.h
@@ -67,6 +67,11 @@ public:
enum Item_result result_type () const { return STRING_RESULT; }
void left_right_max_length();
bool fix_fields(THD *thd, Item **ref);
+ void update_null_value()
+ {
+ StringBuffer<MAX_FIELD_WIDTH> tmp;
+ (void) val_str(&tmp);
+ }
};
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 1a97a086a16..a52c4d783f2 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -912,7 +912,7 @@ bool Aggregator_distinct::setup(THD *thd)
arg= item_sum->get_arg(0);
if (arg->const_item())
{
- (void) arg->val_int();
+ (void) arg->is_null();
if (arg->null_value)
always_null= true;
}
diff --git a/sql/sql_do.cc b/sql/sql_do.cc
index 468b1bc33da..9e58031f6a4 100644
--- a/sql/sql_do.cc
+++ b/sql/sql_do.cc
@@ -32,7 +32,7 @@ bool mysql_do(THD *thd, List<Item> &values)
if (setup_fields(thd, 0, values, MARK_COLUMNS_NONE, 0, 0))
DBUG_RETURN(TRUE);
while ((value = li++))
- value->val_int();
+ (void) value->is_null();
free_underlaid_joins(thd, &thd->lex->select_lex);
if (thd->is_error())