Subject TIBOQuery modify Order affects Params
Author teamtlas
Hi

I am converting a number of BDE applications to IBO. Many of these
apps modify the Query SQL strings "ORDER BY" clause dynamically in
response to user input. The queries generally contain parameterised
"WHERE" clauses.

The problem I am having is that since converting to IBO the first
"Open" of a query executes fine but after closing the query and
modifying the "ORDER BY" clause dynamically, the second "Open" causes
parameter problems such as "nn/nn/nn nn:nn:nn.nnnn is not a valid
date and time".

The following (rather simplistic!)code serves as an illustration of
my problem...

with IBOQuery1 do
begin
close;
Params[0].AsInteger := 0;
Params[1].AsInteger := 999999999;
Params[2].AsDateTime := Date;
Params[3].AsString := '';
Params[4].AsString := 'zzzzzzzzzzzzzzzzzzzz';
Params[5].AsInteger := 0;
Params[6].AsInteger := 999999999;
Params[7].AsString := 'B';
SQL[10] := 'ORDER BY O.ODESC ASC';
open;
close;
Params[0].AsInteger := 0;
Params[1].AsInteger := 999999999;
Params[2].AsDateTime := Date;
Params[3].AsString := '';
Params[4].AsString := 'zzzzzzzzzzzzzzzzzzzz';
Params[5].AsInteger := 0;
Params[6].AsInteger := 999999999;
Params[7].AsString := 'B';
SQL[10] := 'ORDER BY O.ODESC DESC';
open;
end;

The TIBOQuery SQL is set at design time as...

SELECT O.ODESC, I.INVID, I.INVREVIEWED, I.INVOID, I.INVREVDAYS,
I.INVPLANNER, I.INVSOURCE, I.INVVAR, O.ODOC FROM Invi I
JOIN Objects O ON O.OID = I.INVOID
WHERE I.INVSOURCE <> 'NP'
AND I.INVPLANNER >= :FUser AND I.INVPLANNER <= :TUser
AND (I.INVREVIEWED + I.INVREVDAYS) <= :TDate
AND I.INVCONTROL = 'Y'
AND I.INVID >= :FItem AND I.INVID <= :TItem
AND O.OCLASS >= :FClass AND O.OCLASS <= :TClass
AND O.ODESC CONTAINING :Desc
ORDER BY O.ODESC

I have played around with using the OrderingItems/OrderingItemNo
properties instead of modifying the SQL directly but still get the
same problem.

What am I missing here?