Re: Parametrized query fails
Posted in 1996
>Alexander Ponomarenko <shura@bitcom.msk.ru> wrote:
> :...
> :Possible my bad English was the cause of your misunderstanding of my question. I
> :asked about query with parameters, i.e. when I don't know in advance contents of
> :field. We have in our program form like this:
> :..
> :Address: _____
> :Phone: _____
> :..
> :User can type something in fields but can leave they blank. Of course, we can
> :analyze address and if it is null substitute one query by another, but how this is
> :inconvenient! We have tens of field, so for any possible combination we should
> :have NOFIELDS^2 queries. Horrible! Is there some other way to do this?
> :Thanks in advance!
If you prepare your select statements, then the combinations can be reduced
to NOFIELDS*2 rather than NOFIELDS^2. Furthermore, we use general purpose
functions in I4gl (see Power-4gl in sig.) to reduce the combinations to 1.
The programming for a query is then reduced to something like:
let prep_str = "select ... from mytable where 1=1"
,critstr("mytable.address","=","'",myrecord.address,"'")
,critstr("mytable.phone","=","'",myrecord.phone,"'")
,...
Parameter 1: Table column name
Parameter 2: Relation operator, e.g. "=", "matches".
Parameter 3 and 5: Stuff surrounding the value.
Parameter 4: The value as entered by the user.
If the user is looking for a particular address and a blank phone
number, then the result might be:
select ... from mytable where 1=1
and mytable.address = '42nd street'
and mytable.phone is null
...
Now, I don't know how Delphi works but, whatever you do, keep away
from NOFIELDS^2 :)
--
----------------------------------------------------------------------
John H. Frantz Power-4gl: Extending Informix-4gl
frantz@centrum.is http://www.strengur.is/~frantz/pow4gl.html