Subject Re: Possible udf bug
Author i5cvalde
--- In firebird-support@yahoogroups.com, "jssahdra" <joga.singh@i...>
wrote:
> Hi,
> I am using 'addhour' to add hours to the date value. It gives me the
> return value even less than the date passed as parameter. Following
> is the command and its output. I am using firebird 1.5.1 on linux.
>
> select addhour('2004-09-27',75) from rdb$database;
>
> ADDHOUR
> =========================
>
> 2004-09-25 03:41:43.2704

Thanks for the report. I was just a serendipity, because I've not visited
this forum in a full year and today decided to look at the current topics
handled here. Don't know why someone from the frequent contributors didn't
verify and forward this to the development list.
It's not a logic bug. It's an numeric overflow. Using int32 internally is
not enough. Will have to use int64 instead. Didn't observe the problem
when
I created fbudf, because I use small values, sorry.
I fixed the source code. Just two declarations.

SQL> select addhour('2004-09-27', 75) from rdb$database;

ADDHOUR
=========================
2004-09-30 03:00:00.0000

SQL> select addhour('2004-09-27', 1175) from rdb$database;

ADDHOUR
=========================
2004-11-14 23:00:00.0000

SQL> select addhour('2004-09-27', 11175) from rdb$database;

ADDHOUR
=========================
2006-01-05 15:00:00.0000

Those functions add<time_portion> you use are wrappers for an internal
function. Fixing it makes addMillisecond, addSecond, addMinute and
AddHour to have much bigger range.

C.
--
Claudio Valderrama C.
www.cvalde.net - www.firebirdSql.org