Subject Re: external functions in stored procedures
Author Eric Merritt
> >--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@t...>
> >wrote:
> > > At 07:38 AM 2/01/2005 +0000, you wrote:
> >
> > > When do see an exception and what is the exception?
> >
> > At compile time.
> >
> >ISC ERROR MESSAGE:
> >Dynamic SQL Error
> >SQL error code = -804
> >Function unknown
> >FLOOR
>
> If the declaration you used is the one from ib_udf.sql then you have a
> configuration blind spot somewhere.

>
> -- what does your declaration look like?

I pulled the declaration directly from ib_udf.sql.

However, here it is pulled from the database.

declare external function floor
double precision
returns double precision by value
entry_point 'IB_UDF_floor'
module_name 'ib_udf';


> -- What's your OS platform?

Redhat Linux RHEL3

>
> Is this a serious procedure or just a tryout for compiling?

Well, its resonably serious. I am using code from Joe Celko's 'Trees
and Hierarchies in Sql'. There is a bit of translation involved but
beyond that its pretty verbatim. I havn't really paid much attention
to the semantics yet becuse I have been dealing with getting it to
compile.

> When you do get
> the library configuration sorted out, you'll find that this
procedure will
> always go into an endless loop, since floor(intnum/2) will always be
equal
> to (intnum/2), because of the way SQL integer division works. Hence,
> floor() is meant to take and return doubles.

Hmm, thats interesting. I probably need to take a closer look at his
code and do a semantic translation instead of a syntactic translation.


> Try this instead, tho' it's a bit of mystery what it would be useful
for:
>
> REcreate procedure find_numer_denom (
> tnumer double precision,
> tdenom double precision)
> returns (
> numer double precision,
> denom double precision)
> as
> begin
> numer = tnumer + 1;
> denom = 2 * tdenom;
>
> while (floor(numer/2) = numer / 2) do
> begin
> numer = numer / 2;
> denom = denom / 2;
> end
> end
>

Its actually useful as a very small part of a rational number library
for an implementation of the nested intervals model for hierarchies a
RDBMS.