Subject Pass query parameters as argument for UDF. Does it work or not?
Author Andrew Guts
Hello all,

Please clarify: is it possible to pass query parameter to UDF ?

According the document "Firebird v1 Closed Bugs"
http://umn.dl.sourceforge.net/sourceforge/firebird/Firebird_v1_ClosedBugs.html
SF ID 409769
it is possible. But I have "unknown data type" error. Why so?

I am writing a searching UDF for using with search service of our website.
How to pass search pattern to the function? Now I have to build static
SQL query on the fly,
but it imposes considerable restrictions to search pattern.
For example I have to trim both type of quotes, percent symbol and so on.
I'm thinking about wrapping the query by stored procedure. Is it right?

/* double str_match(unsigned char* text, unsigned char* pattern); */
DECLARE EXTERNAL FUNCTION STRMATCH
CSTRING(256), CSTRING(256)
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'str_match' MODULE_NAME 'fe_udf';

Usage :

select id, description, strmatch(description, :pattern) as k
from products where legacy = 0 and strmatch(description, :pattern) >=
:mfactor
order by 3 desc, 2

The "pattern" could be something like 'Lexmark laser printers A4 with USB'
and the "mfactor" have to be estimated before using:

select strmatch(description, :pattern) as k, count(id) as f
from products where legacy = 0
group by strmatch(description, :pattern)
order by 1 desc

By the way, anybody could use free and improve my UDF library. Sources:
http://developer.fe-club.net/freesrc/fe_udf.zip
The new search service will be deployed on site http://price.fe.ua in
couple of days.

Thank to all Interbase people! You make it possible.

Andrew