Subject Re: [IBO] Prepared and unprepared
Author Helen Borrie
At 11:21 AM 30/06/2003 +0200, you wrote:

> >Did you realise this is a completely unnecessary consumption of
> >resources? If the only thing in your query that changes is the value of
> >the parameter(s) then you only have to call Refresh. The query stays both
> >active and prepared.
>
>OK - if I understand you correctly, I could accomplish the same by doing
>the following :
>
>with MyQuery do
>begin
> //Leave out the "If Active" statement
> ParamByName('XYZ').AsSomething := varXYZ;
> if not prepared then prepare; //prepare if not prepared already
> Open;
>end;

the statement
if not prepared then prepare;
isn't needed if you used ParamByName(), because this method includes that
test. Even if it didn't, both the Open() method (of bi-di datasets) and
First() method (of the uni-di dataset) also include this test.


>With queries where the SQL changes, I could do the following :
>
>with MyQuery do
>begin
> If Active then Close;
> SQL := 'some SQL string';
> ParamByName('XYZ').AsSomething := varXYZ;
> if not prepared then prepare; //prepare if not prepared already
> Open;
>end;

No. But this wasn't what your previous example did. There, you were not
assigning a new SQL property. Here, you are. So the above code doesn't
save you anything. Assigning a new SQL property cause the dataset to
entirely recreate itself, with all the overhead that goes with it.

Helen