Subject Re: [IBO] first steps: query and cursor
Author Helen Borrie
At 11:19 PM 30-11-01 +0100, Boris wrote:
>For looking up city-names on zips I today coded this routine:
> with IB_Cursor1 do begin
> ParamByName('plz').AsString:=Edit1.Text;

For IB_Cursor, use First, not Open.

> Open;
> while not Eof do begin
> ComboBox1.Items.Add(Fields[2].AsString);
> Next;
> end;
> Close;
> end;
>Did I get that correctly?
>I've got the feeling, this routine may still be optimized:
>Can I save the Open/Close-routines somehow?

See above.

>What is better to use: Query or Cursor?

Cursor is perfect for this type of operation - you don't don't any of the overhead for the bi-directional dataset that IB_Query imposes.

>Should I Unprepare after using?
>Is preparation made automatically?
>Do I need preparation anyway?

No. Prepare is needed to feed the metadata info to the component. It only needs to be unprepared if the statement is going to be changed. (No unprepare is necessary if only the param values change). IBO automatically unprepares the statement when necessary.


All for Open and Open for All
InterBase Developer Initiative ยท