From 3e897bc3b6b838fe4b91d0ee4148d4b6c530c20d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Jun 2003 20:04:52 +0500 Subject: [PATCH 1/2] Fix for bug #666 (Nice number, yeah?) sql/item_strfunc.cc: Item_func_elt::valXXX() functions don't expect NULL argument if it is not the first one. --- sql/item_strfunc.cc | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 208be1ecd7f..9d4f7641b1d 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1539,37 +1539,46 @@ void Item_func_elt::update_used_tables() double Item_func_elt::val() { uint tmp; + null_value=1; if ((tmp=(uint) item->val_int()) == 0 || tmp > arg_count) - { - null_value=1; return 0.0; - } + + double result= args[tmp-1]->val(); + if (args[tmp-1]->is_null()) + return 0.0; + null_value=0; - return args[tmp-1]->val(); + return result; } longlong Item_func_elt::val_int() { uint tmp; + null_value=1; if ((tmp=(uint) item->val_int()) == 0 || tmp > arg_count) - { - null_value=1; return 0; - } + + int result= args[tmp-1]->val_int(); + if (args[tmp-1]->is_null()) + return 0; + null_value=0; - return args[tmp-1]->val_int(); + return result; } String *Item_func_elt::val_str(String *str) { uint tmp; + null_value=1; if ((tmp=(uint) item->val_int()) == 0 || tmp > arg_count) - { - null_value=1; return NULL; - } + + String *result= args[tmp-1]->val_str(str); + if (args[tmp-1]->is_null()) + return NULL; + null_value=0; - return args[tmp-1]->val_str(str); + return result; } From 8bed69fa9ec200925d9a9ec36419d2c5eecf9739 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 Jun 2003 17:07:43 +0500 Subject: [PATCH 2/2] Test case for bug #666 mysql-test/r/func_str.result: test for bug #666 result mysql-test/t/func_str.test: test for bug #666 --- mysql-test/r/func_str.result | 13 +++++++++++++ mysql-test/t/func_str.test | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 1a4cb9217e4..09818c14462 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -234,3 +234,16 @@ INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf'); SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password"); 1 DROP TABLE t1; +CREATE TABLE t1 ( +wid int(10) unsigned NOT NULL auto_increment, +data_podp date default NULL, +status_wnio enum('nowy','podp','real','arch') NOT NULL default 'nowy', +PRIMARY KEY(wid), +); +INSERT INTO t1 VALUES (8,NULL,'real'); +INSERT INTO t1 VALUES (9,NULL,'nowy'); +SELECT elt(status_wnio,data_podp) FROM t1 GROUP BY wid; +elt(status_wnio,data_podp) +NULL +NULL +DROP TABLE t1; diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 118de6cd01e..476629f98d3 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -125,3 +125,15 @@ CREATE TABLE t1 (id int(11) NOT NULL auto_increment, tmp text NOT NULL, KEY id ( INSERT INTO t1 VALUES (1, 'a545f661efdd1fb66fdee3aab79945bf'); SELECT 1 FROM t1 WHERE tmp=AES_DECRYPT(tmp,"password"); DROP TABLE t1; + +CREATE TABLE t1 ( + wid int(10) unsigned NOT NULL auto_increment, + data_podp date default NULL, + status_wnio enum('nowy','podp','real','arch') NOT NULL default 'nowy', + PRIMARY KEY(wid), +); + +INSERT INTO t1 VALUES (8,NULL,'real'); +INSERT INTO t1 VALUES (9,NULL,'nowy'); +SELECT elt(status_wnio,data_podp) FROM t1 GROUP BY wid; +DROP TABLE t1;