Subject RE: [firebird-support] Re: Possible to write this in a way that indices will be used
Author Maya Opperman
Thank you Sasha and Milan, I'm <deep breath> going to dive in and try doing this regex stuff all inside the stored proc, executing it with EXECUTE STATEMENT.

I'll let you know how it goes..

-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Sasha Matijasic
Sent: 16 May 2008 12:37 PM
To: firebird-support@yahoogroups.com
Subject: RE: [firebird-support] Re: Possible to write this in a way that indices will be used

>
> Maya Opperman wrote:
> > If :IInputParam is null then
> > .. do SQL without mentioning input param
> > Else
> > .. re-do same sql, but this time add where t.Field = :IInputParam
>
> For such cases, I have a simple find&replace function that rewrites the
> query. I write statements like this:
>
> where ... { and t.Field = :IInputParam }
>
> after params are filled, the function reads the SQL statements looking
> for { } and when param inside it is NULL it removes the {...} part
> completely.
>

I agree with Milan on this. With a couple of helper functions you can easily write your own very limited query builder.
Although, when using such methods I prefer writing queries like this:

/*where*/ /*condition1: t.Field = :IinputParam*/ ...

that way i can copy the sql and paste it to flamerobin and it runs and I can uncomment any part of where clauses for testing.
In runtime it is relatively easy to use regex for replacing desired parts of query.

Sasha


------------------------------------

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

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