Subject Freepascal UDF date functions no longer work with Firebird 1.5
Author wwtresearch
Hi there,

I have not been able to get the date functions from the
freepascal udf library which previously worked with both linux/win32
Firebird 1.0.3 on my Firebird 1.5RC8 installation.

In linux the error message is: Error reading data from the connection.
resulting in a lost database connection and a core file in /tmp.
Windows fails also.

I would be grateful for any suggestions on how to modify such
freepascal UDFs to be compatible with Firebird 1.5.


Robin

----------------------------------------------------------------------
Below is a shortened version of the freepascal source code that I have
been testing.

{
$Id: fpc_udf_dt.pp,v 0.1 2000/07/11 07:36:07 frank Exp $
(C)2000 Frank Schlottmann-Goedde
time/date handling user defined functions (UDF)
for Interbase 6.0 SS for Linux use at your own risc
}

library fpc_udf_dt;
{$mode objfpc}
{$PACKRECORDS C}

uses strings;

{$linklib gds} {I only need isc_decode_date at the moment}

type

isc_quad= record
low:longint;
high:dword;
end;

pisc_quad=^isc_quad;

Tm = record
tm_sec : longint; // Seconds
tm_min : longint; // Minutes
tm_hour : longint; // Hour (0--23)
tm_mday : longint; // Day of month (1--31)
tm_mon : longint; // Month (0--11)
tm_year : longint; // Year (calendar year minus 1900)
tm_wday : longint; // Weekday (0--6) Sunday = 0)
tm_yday : longint; // Day of year (0--365)
tm_isdst : longint; // 0 if daylight savings time is not in
effect)
tm_gmtoff: longint;
end;

procedure isc_decode_date(_para1:PISC_QUAD; _para2:pointer); cdecl;
external;

procedure init_tm(var tm_date:Tm);
begin
with tm_date do
begin
tm_sec := 0;
tm_min := 0;
tm_hour := 0;
tm_mday := 0;
tm_mon := 0;
tm_year := 0;
tm_wday := 0;
tm_yday := 0;
tm_isdst := 0;
tm_gmtoff{.low} := 0;
{ tm_gmtoff.high:= 0; }
end;
end;

function dt_Year(ib_date: PISC_QUAD): longint;export;
var
tm_date:Tm;
begin
init_tm(tm_date);
isc_decode_date(ib_date,@tm_date);
result :=tm_date.tm_year+1900;
end;

exports
dt_Year name 'dt_year';

end.

The UDF declaration is:

DECLARE EXTERNAL FUNCTION DT_YEAR
TIMESTAMP
RETURNS INTEGER BY VALUE
ENTRY_POINT 'dt_year' MODULE_NAME 'libfpc_udf_dt';

e.g. select dt_year('01.01.2004') from rdb$database;