summaryrefslogtreecommitdiff
path: root/sql/item_timefunc.cc
diff options
context:
space:
mode:
authorunknown <gkodinov/kgeorge@macbook.gmz>2007-01-30 17:43:34 +0200
committerunknown <gkodinov/kgeorge@macbook.gmz>2007-01-30 17:43:34 +0200
commit3cb3a9a149ecc29634c748d0da7932d1814a9b7f (patch)
tree5c7cb0cb4906ff6bc2e08245db1b6d5f5d6c589c /sql/item_timefunc.cc
parent24903ed56ca2cceb3b9cb9f690ab47cc95e072be (diff)
downloadmariadb-git-3cb3a9a149ecc29634c748d0da7932d1814a9b7f.tar.gz
Bug #25643: SEC_TO_TIME function problem
Checking for NULL before calling the val_xxx() methods only checks for such arguments that are known to be NULLs at compile time. The arguments that may or may not contain NULLs (e.g. function calls and possibly others) are not checked at all. Fixed by first calling the val_xxx() method and then checking for null in SEC_TO_TIME(). In addition QUARTER() was not returning 0 (as all the val_int() functions do when processing a NULL value). mysql-test/r/func_time.result: Bug #25643: SEC_TO_TIME function problem - test case mysql-test/t/func_time.test: Bug #25643: SEC_TO_TIME function problem - test case sql/item_timefunc.cc: Bug #25643: SEC_TO_TIME function problem - null handling fixed for QUARTER() and SEC_TO_TIME()
Diffstat (limited to 'sql/item_timefunc.cc')
-rw-r--r--sql/item_timefunc.cc9
1 files changed, 6 insertions, 3 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index e99db62068d..83b48645d1c 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -1054,7 +1054,8 @@ longlong Item_func_quarter::val_int()
{
DBUG_ASSERT(fixed == 1);
TIME ltime;
- (void) get_arg0_date(&ltime, TIME_FUZZY_DATE);
+ if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
+ return 0;
return (longlong) ((ltime.month+2)/3);
}
@@ -1668,6 +1669,7 @@ String *Item_func_sec_to_time::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
TIME ltime;
+ longlong arg_val= args[0]->val_int();
if ((null_value=args[0]->null_value) || str->alloc(19))
{
@@ -1675,7 +1677,7 @@ String *Item_func_sec_to_time::val_str(String *str)
return (String*) 0;
}
- sec_to_time(args[0]->val_int(), args[0]->unsigned_flag, &ltime);
+ sec_to_time(arg_val, args[0]->unsigned_flag, &ltime);
make_time((DATE_TIME_FORMAT *) 0, &ltime, str);
return str;
@@ -1686,11 +1688,12 @@ longlong Item_func_sec_to_time::val_int()
{
DBUG_ASSERT(fixed == 1);
TIME ltime;
+ longlong arg_val= args[0]->val_int();
if ((null_value=args[0]->null_value))
return 0;
- sec_to_time(args[0]->val_int(), args[0]->unsigned_flag, &ltime);
+ sec_to_time(arg_val, args[0]->unsigned_flag, &ltime);
return (ltime.neg ? -1 : 1) *
((ltime.hour)*10000 + ltime.minute*100 + ltime.second);