Subject | Re: [IBO] Problems with TIB_Query with Parameters |
---|---|
Author | Helen Borrie |
Post date | 2003-08-25T16:27:26Z |
At 03:48 PM 25/08/2003 +0000, you wrote:
IB_Cursor.
valid, a parameter has to substitute for a field value without changing the
structure of the query. Changing the criteria for a LIKE expression
changes the structure. You are also going to need to implement some way to
collect the position of the wildcard from the user.
In native IB, you would use an SQLWhereItem in the OnPrepareSQL event to
implement this.
So your "base" SQL property would be
SELECT * FROM TABLE2
ORDER BY FIELD4
and, when ready to apply or change the where clause, call InvalidateSQL on
the dataset.
In OnPrepareSQL, do
...
var
SomeWildConstant: string;
...
SomeWildConstant := '%' + QuotedStr(SomeConstant);
with Sender as TIB_Statement do
begin
SQLWhereitems.Clear;
SQLWhereItems.Add('FIELD3 LIKE + SomeWildConstant;
end;
probably tried to evaluate it too early. Set your breakpoint *after*
ParamByName has been called (since ParamByName calls Prepare if the query
isn't prepared).
Helen
>Hello,Except TIB_Query is the wrong component for a DML query. Use TIB_DSQL or
>
>I have two parametrized queries (TIB_Query components), one is
>UPDATE, and the other is SELECT.
>First one works perfectly:
>
>UPDATE
> TABLE1
>SET
> FIELD1 = :FIELD1
>WHERE
> FIELD2 = :FIELD2
IB_Cursor.
>However, the other one fails:That's invalid SQL. Not just because there is no wildcard; but, to be
>
>SELECT
> *
>FROM
> TABLE2
>WHERE
> (FIELD3 like :FIELD3)
valid, a parameter has to substitute for a field value without changing the
structure of the query. Changing the criteria for a LIKE expression
changes the structure. You are also going to need to implement some way to
collect the position of the wildcard from the user.
In native IB, you would use an SQLWhereItem in the OnPrepareSQL event to
implement this.
So your "base" SQL property would be
SELECT * FROM TABLE2
ORDER BY FIELD4
and, when ready to apply or change the where clause, call InvalidateSQL on
the dataset.
In OnPrepareSQL, do
...
var
SomeWildConstant: string;
...
SomeWildConstant := '%' + QuotedStr(SomeConstant);
with Sender as TIB_Statement do
begin
SQLWhereitems.Clear;
SQLWhereItems.Add('FIELD3 LIKE + SomeWildConstant;
end;
>Both queries share exactly the same properties and settings, exceptUsing '=' should be fine. But Params[] is nil in an unprepared query. You
>the SQL text shown above.
>
>Using equal sign instead of LIKE (my first guess) doesn't help.
>Delphi gives an AV when trying to evaluate the value of ParamByName
>('FIELD3') in debug mode.
probably tried to evaluate it too early. Set your breakpoint *after*
ParamByName has been called (since ParamByName calls Prepare if the query
isn't prepared).
Helen