FB4 UDR - again (sorry)

15 views
Skip to first unread message

zora...@gmail.com

unread,
Jun 8, 2021, 10:52:32 AMJun 8
to firebird...@googlegroups.com

Hello

 

FB4, Del[hi 10.4.2

 

In FB3 I have UDF containing simple function to convert datetime to double:

 

function CurrentTimestampToDouble(const p: PBoolean): PDouble;  //true=UTC, false=now

var

  dt: TDateTime;

  d: double;

begin

  if p^ then

    dt := TkbmMWDateTime.Now.UTC

  else

    dt := TkbmMWDateTime.Now.Local;

  d := dt;

  result := ib_util_malloc(SizeOf(d));

  result := @d;

end;

 

Since FB4 docs strongly discourage using UDFs anymore, I would like to create new UDR with this function. There is little information on creating UDRs. I’ve looked at all the docs in FB4 release and all the examples, but I still cannot figure out what to do.

 

Is there some working example (code) how to create new UDR dll and can it be done in Delphi?

 

Any information is greatly appreciated.

 

Thank you

Zoran

 

Dimitry Sibiryakov

unread,
Jun 8, 2021, 11:05:32 AMJun 8
to firebird...@googlegroups.com
08.06.2021 16:52, zora...@gmail.com wrote:
> I would like to create new UDR with this function.

For such simple function you don't need UDR, SQL is enough. Something like this (using
provided udf_compat library):

CREATE FUNCTION CurrentTimestampToDouble(Boolean P) RETURNS DOUBLE PRECISION DETERMINISTIC
AS
BEGIN
IF (P)
RETURN getExactTimestampUTC() - timestamp '1899-12-30';
ELSE
RETURN LOCAL_TIMESTAMP - timestamp '1899-12-30';
END

--
WBR, SD.

zora...@gmail.com

unread,
Jun 8, 2021, 7:24:46 PMJun 8
to firebird...@googlegroups.com
Thank you Dimitry.

I run into problem. Is it possible that FB4 function compiler has a glitch? Or I'm doing something wrong? I'm using udf_compat library.

When I run:
CREATE FUNCTION CurrentTimestampToDouble(P Boolean) RETURNS DOUBLE PRECISION DETERMINISTIC AS
BEGIN
IF (P) THEN
RETURN getExactTimestampUTC() - timestamp '1899-12-30';
ELSE
RETURN LOCAL_TIMESTAMP - timestamp '1899-12-30';
END

I get an error:
Engine Error (code = 335544569):
Dynamic SQL Error.
SQL error code = -104.
Unexpected end of command - line 4, column 48.

SQL Error (code = -104):
Invalid token.

If I run:
SELECT getExactTimestampUTC() - timestamp '1899-12-30' FROM RDB$DATABASE;
Result is correct.


I've tried a simple function:
CREATE FUNCTION F(X INT) RETURNS INT
AS
BEGIN
RETURN X+1;
END

And I get the same error:

Engine Error (code = 335544569):
Dynamic SQL Error.
SQL error code = -104.
Unexpected end of command - line 4, column 12.

SQL Error (code = -104):
Invalid token.


Regards
Zoran
--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-support/8fe14466-9794-d779-f0e5-8d75bb481d2b%40ibphoenix.com.

Lucas Schatz

unread,
Jun 8, 2021, 7:48:30 PMJun 8
to firebird-support
no problem at all, you simply forgot to set term

set term ^ ;

CREATE FUNCTION F(X INT) RETURNS INT
AS
BEGIN
  RETURN X+1;
END^
set term ; ^
Reply all
Reply to author
Forward
0 new messages