Need to see your CREATE FUNCTION along with the prototype for the RPGLE code.

Charles

On Wed, Mar 28, 2012 at 6:30 PM, Thomas Garvey <tgarvey@xxxxxxxxxx> wrote:
Hi,

I'm trying to develop a User Defined Function that will test a given value
against a regular expression pattern.  I've found code online by Scott
Klement that utilizes the regcomp (Compile Regular Expression) and regexec
(Execute Compiled Regular Expression) APIs.  I've put this into an RPGLE
module and created a service program, then registered the UDF using the
CREATE FUNCTION command in SQL.  Then I use the scalar function to test
values in a character field of a table.

For example...

SELECT str
FROM   strTable
WHERE regexpsrv(str, '\d{3}-\d{4}') = 1

The function gets passed the test value (str), and the regular expression
pattern (inside the single quotes), and a value of 0 or 1 is returned (1 if
the test value contains the regular expression pattern, 0 if not).

The problem is, it ALWAYS returns a zero.  My test database has values that
should sometimes return a zero, but mostly a 1.  Incidentally, the regular
expression essentially is looking for 3 digits, followed by a dash, followed
by 4 digits (a phone number of the form xxx-xxxx).

I can put the thing in debug and the expression is compiled and returns a
zero for the result of the regcomp call.  But the call to regexec just
always returns a zero, as in 'it doesn't match.  The thing is, I can go to a
Regular Expression test site
(http://www.regular-expressions.info/javascriptexample.html), which allows
me to essentially do the same thing (enter a test value and an expression)
to test the expression against various values.  It tells me the correct
results based on the sample data I have.  MY UDF just rejects everything.

If anyone can point me in a direction, or tell me what I'm doing wrong, I'd
appreciate it very much.

Thanks in advance,

Thomas Garvey

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].