Subject Re: [firebird-support] UDFs and Exceptions
Author Helen Borrie
At 11:46 PM 3/08/2006, you wrote:
>Is there a wish list?

Kind of - there's a tracker category for Feature requests.

>
>It's pretty clear that UDFs can't provoke an SQL error, which is unfortunate
>for me, because I have a Regular Expression UDF and it would've been
>great if I could've returned an error in this way when the pattern had an
>error (as opposed to not matching). I can see that this would be tough to
>do
>for the general case, but if you can do by descriptor argument passing, ISTM
>that with a little additional work, you could pass a callback address so
>that the
>UDF could trigger an SQL error to the client.

Yikes, that sounds like a disaster waiting to happen.
You shouldn't write UDFs that have the potential to crash or to pass
back bad results. You should write them so that they return a result
of a valid type under any condition. It's up to your UDF code to
work out whether it got a silly input, and your application or PSQL
code will need to do whatever's needed to recognise whether the value
returned is good or is the result of silly input.

>
>So then I tried creating a stored procedure as an intermediary, which could
>detect the pattern error and raise an exception. Unfortunately, it appears
>that SPs can't be used as part of a predicate. Is there a way around this?

No, a SP is not a function. Some folk are working on "external
procedures" for Fb 2+, which might go somewhere near what you're
thinking about.

>
>Also, when you use by-descriptor argument passing, can you affect the
>copy that the client has (like a Pascal var parameter)? I'm thinking not,
>but
>it never hurts to ask.

No, a UDF is hooked to the database engine.

> Finally, is there a way to return more than one thing from a UDF (like an
>array)?

No. A UDF is strictly a function, i.e. it returns one result. You
could write a function that returns a comma-separated string and
write an executable SP (that could be called from within other SPs)
to parse it out cyclically from a FOR loop. If I remember rightly,
there is such a procedure in the download for my book, which you can
pick up from the Apress website (
http://www.apress.com/book/bookDisplay.html?bID=301 )

./heLen


>
>
>
>Michael D. Spence
>Mockingbird Data Systems, Inc.
>
>
>
>[Non-text portions of this message have been removed]
>
>
>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>Visit http://www.firebirdsql.org and click the Resources item
>on the main (top) menu. Try Knowledgebase and FAQ links !
>
>Also search the knowledgebases at http://www.ibphoenix.com
>
>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>Yahoo! Groups Links
>
>
>
>