Subject Re: Confusing behavior of UDF in stored procedure
Author lutterot
--- In firebird-support@yahoogroups.com, "Alan McDonald" <alan@...> wrote:
>
> > Hello!
> >
> > I have written a UDF varchar_to_guid which seems to work fine:
> >
> > /* Gives back the 16 byte GUID for a VARCHAR */
> > DECLARE EXTERNAL FUNCTION VARCHAR_TO_GUID
> > VARCHAR(32765) BY DESCRIPTOR
> > RETURNS CHAR(16) CHARACTER SET OCTETS FREE_IT
> > ENTRY_POINT 'udf_varchar_to_guid' MODULE_NAME 'guid_udf';
> >
> > Now I am using this UDF in a stored procedure CreateStringId:
> >
> > CREATE PROCEDURE CreateStringId(val VARCHAR(32765))
> > RETURNS (id CHAR(16))
> > AS BEGIN
> > id = varchar_to_guid(:val);
> > SUSPEND;
> > END^
> >
> > Now when I am using this procedure like this
> >
> > select id from CreateStringId('abc')
> >
> > then I get a different result from using the UDF directly like this
> >
> > select varchar_to_guid('abc') from SOMETABLE
> >
> > And when I hard-code the string 'abc' into the store procedure
like this
> >
> > CREATE PROCEDURE CreateStringId(val VARCHAR(32765))
> > RETURNS (id CHAR(16))
> > AS BEGIN
> > id = varchar_to_guid('abc');
> > SUSPEND;
> > END^
> >
> > then the result is the correct one (i.e. the same as using the UDF
> > directly).
> >
> > Can anybody help me out and explain this behavior to me?
> >
> > Thank you,
> > Christof
>
>
> can you change your procedure to this:
>
> > CREATE PROCEDURE CreateStringId(val VARCHAR(32765))
> > RETURNS (id CHAR(16))
> > AS BEGIN
> > SELECT varchar_to_guid(:val) FROM RDB$DATABASE INTO :ID;
> > SUSPEND;
> > END^
>
> I have never used the syntax you have used here - not sure it's legal.
> Alan

Unfortunately this yields the same wrong result...