Commit 18373b16 authored by sergefp@mysql.com's avatar sergefp@mysql.com

Fix for BUG#8397 (second commit after review):

In Item_cache_decimal::store(item) the call item->val_decimal_result() 
returns NULL if the passed item has an SQL null value. Don't try copying
NULL into Item_cache_decimal::val in this case.
parent 1ca547f5
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1, t2;
SET SQL_WARNINGS=1; SET SQL_WARNINGS=1;
CREATE TABLE t1 ( CREATE TABLE t1 (
id int(11) NOT NULL auto_increment, id int(11) NOT NULL auto_increment,
...@@ -677,3 +677,19 @@ a ...@@ -677,3 +677,19 @@ a
9999.999 9999.999
0000.000 0000.000
drop table t1; drop table t1;
CREATE TABLE t1
(EMPNUM CHAR(3) NOT NULL,
HOURS DECIMAL(5));
CREATE TABLE t2
(EMPNUM CHAR(3) NOT NULL,
HOURS BIGINT);
INSERT INTO t1 VALUES ('E1',40);
INSERT INTO t1 VALUES ('E8',NULL);
INSERT INTO t2 VALUES ('E1',40);
SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t2);
EMPNUM
E1
SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t1);
EMPNUM
E1
DROP TABLE t1,t2;
# bug in decimal() with negative numbers by kaido@tradenet.ee # bug in decimal() with negative numbers by kaido@tradenet.ee
--disable_warnings --disable_warnings
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1, t2;
--enable_warnings --enable_warnings
SET SQL_WARNINGS=1; SET SQL_WARNINGS=1;
...@@ -268,3 +268,20 @@ insert into t1 values ('1'),('+1'),('-1'),('0000000001'),('+0000000001'),('-0000 ...@@ -268,3 +268,20 @@ insert into t1 values ('1'),('+1'),('-1'),('0000000001'),('+0000000001'),('-0000
--enable_warnings --enable_warnings
select * from t1; select * from t1;
drop table t1; drop table t1;
# Test for BUG#8397: decimal type in subselects (Item_cache_decimal)
CREATE TABLE t1
(EMPNUM CHAR(3) NOT NULL,
HOURS DECIMAL(5));
CREATE TABLE t2
(EMPNUM CHAR(3) NOT NULL,
HOURS BIGINT);
INSERT INTO t1 VALUES ('E1',40);
INSERT INTO t1 VALUES ('E8',NULL);
INSERT INTO t2 VALUES ('E1',40);
SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t2);
SELECT EMPNUM FROM t1 WHERE HOURS IN (SELECT HOURS FROM t1);
DROP TABLE t1,t2;
...@@ -4349,7 +4349,7 @@ my_decimal *Item_cache_real::val_decimal(my_decimal *decimal_val) ...@@ -4349,7 +4349,7 @@ my_decimal *Item_cache_real::val_decimal(my_decimal *decimal_val)
void Item_cache_decimal::store(Item *item) void Item_cache_decimal::store(Item *item)
{ {
my_decimal *val= item->val_decimal_result(&decimal_value); my_decimal *val= item->val_decimal_result(&decimal_value);
if (val != &decimal_value) if (val != &decimal_value && !item->null_value)
my_decimal2decimal(val, &decimal_value); my_decimal2decimal(val, &decimal_value);
null_value= item->null_value; null_value= item->null_value;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment