summaryrefslogtreecommitdiff
path: root/sql/sp_head.cc
diff options
context:
space:
mode:
authorunknown <pem@mysql.comhem.se>2003-11-20 18:30:02 +0100
committerunknown <pem@mysql.comhem.se>2003-11-20 18:30:02 +0100
commit50685be51b54985cccaa299cb6d7a43ff1cbe2a1 (patch)
tree82b8d16e4a5c68f8d19c2be8c4018c973464d68c /sql/sp_head.cc
parent8bd2c19af8ed2d5efa3b77c38ffd72356bdb8a73 (diff)
downloadmariadb-git-50685be51b54985cccaa299cb6d7a43ff1cbe2a1.tar.gz
Fixed BUG#1874: Don't call fix_fields() indiscriminately, it resets null_value
for some items, which made aggregates like MIN(), MAX() and SUM() fail. mysql-test/r/sp.result: Test case for aggregate functions in SELECT INTO. (BUG#1874) mysql-test/t/sp.test: Test case for aggregate functions in SELECT INTO. (BUG#1874)
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r--sql/sp_head.cc37
1 files changed, 27 insertions, 10 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 342c1ebd6b5..41db1f6dd70 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -54,26 +54,40 @@ sp_eval_func_item(THD *thd, Item *it, enum enum_field_types type)
it= it->this_item();
DBUG_PRINT("info", ("type: %d", type));
- if (it->fix_fields(thd, 0, &it))
+ if (!it->fixed && it->fix_fields(thd, 0, &it))
{
DBUG_PRINT("info", ("fix_fields() failed"));
DBUG_RETURN(it); // Shouldn't happen?
}
/* QQ How do we do this? Is there some better way? */
- if (type == MYSQL_TYPE_NULL || it->is_null())
+ if (type == MYSQL_TYPE_NULL)
it= new Item_null();
else
{
switch (sp_map_result_type(type)) {
case INT_RESULT:
- DBUG_PRINT("info", ("INT_RESULT: %d", it->val_int()));
- it= new Item_int(it->val_int());
- break;
+ {
+ longlong i= it->val_int();
+
+ DBUG_PRINT("info", ("INT_RESULT: %d", i));
+ if (it->null_value)
+ it= new Item_null();
+ else
+ it= new Item_int(it->val_int());
+ break;
+ }
case REAL_RESULT:
- DBUG_PRINT("info", ("REAL_RESULT: %g", it->val()));
- it= new Item_real(it->val());
- break;
+ {
+ double d= it->val();
+
+ DBUG_PRINT("info", ("REAL_RESULT: %g", d));
+ if (it->null_value)
+ it= new Item_null();
+ else
+ it= new Item_real(it->val());
+ break;
+ }
default:
{
char buffer[MAX_FIELD_WIDTH];
@@ -81,8 +95,11 @@ sp_eval_func_item(THD *thd, Item *it, enum enum_field_types type)
String *s= it->val_str(&tmp);
DBUG_PRINT("info",("default result: %*s",s->length(),s->c_ptr_quick()));
- it= new Item_string(thd->strmake(s->c_ptr_quick(), s->length()),
- s->length(), it->collation.collation);
+ if (it->null_value)
+ it= new Item_null();
+ else
+ it= new Item_string(thd->strmake(s->c_ptr_quick(), s->length()),
+ s->length(), it->collation.collation);
break;
}
}