Subject | Re: Confusing behavior of UDF in stored procedure |
---|---|
Author | lutterot |
Post date | 2007-06-19T03:14:11Z |
--- In firebird-support@yahoogroups.com, "Adam" <s3057043@...> wrote:
Cheers,
Christof
>like this
> --- In firebird-support@yahoogroups.com, "lutterot" <lutteroth@> 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
> >Yes, the same wrong value as the stored procedure.
> > 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?
>
> Does the following query return the same 'wrong' value?
> select varchar_to_guid(cast('abc' as varchar(32765)) from SOMETABLE;
Cheers,
Christof