Subject Re: [IBO] Using a single TIB_Cursor for all
Author Helen Borrie
At 10:03 AM 15/11/2004 -0600, you wrote:

>I have a question about using a single (global, so to speak) TIB_Cursor
>component (perhaps on a DataModule) for all SELECT statements for an
>entire application.
>
>Suppose 10 clients running a Delphi application on Win_____, with
>Firebird server on Win or Linux. The Delphi application has, say, 500
>places where it needs data from the database. 50 of those are to create
>static selection lists in TListBoxes, the other 450 are the usual
>looking up details of names, invoices, payments, inventory items,
>receipt numbers, etc. etc.
>
>I can think of three options:
>1. Using the same curFactotum for every select:
>with DataModule1.curFactotum do try
> SQL.Clear;
> SQL.Add('SELECT SUM(AMOUNT )FROM PAYMENTS WHERE PAYER_ID=1234' );
> First;
> if not eof then while not eof do begin
> DoSomethingWith_Fields[0].AsString:
> Next;
> finally
> Close;
> Unprepare; // is this necessary re: server resources?
> end;
>-------------------------------
>2. Create 500 'static' TIB_Cursor components with 'static'
>parameterised SQL:
>
>with DataModule1.curSumPaymentsForPayer do try
> if not prepared then prepare;
> Params[0].AsInteger:=iParam;
> First;
> if not eof then while not eof do begin
> DoSomethingWith_Fields[0].AsFloat:
> Next;
> finally
> Close;
> Unprepare; // unless we think we'll use it again
> end;
>---------------------------------
>3. Set up, and select from, a Stored Procedure
>-------------------------------------------
>Also: Is the result of calling "unprepare" (releasing resources on the
>server?? Nothing else?) carried out automatically by calling
>"curFactotum.SQL.Clear" ?

Well, theoretically, all are possible. Whether they make sense or not is
another thing entirely.

Your model of pulling a set over to the client, doing something
user-invisible to it and then sending update statements back one by one
isn't a sensible client/server strategy. If you have 450 places where the
application is interested in data, and 440 of those "places" are update,
insert or delete operations, then you don't want datasets for them, you
want executable statements. Then, it's valid to have a single factotum
ib_cursor or, better, ib_dsql, to carry out those tasks directly. For the
other 10 you probably need scrollable datasets (ib_queries),
well-controlled with parameters and transaction management.

Helen