Subject | Re: [IBO] TIB_Session + TIB_Connection + TIB_Transaction + TIB_Cursor + Thread |
---|---|
Author | Jason Wharton |
Post date | 2002-04-05T22:30:58Z |
Don't use NIL owners for any components except perhaps your TIB_Session.
Use the TIB_Session as the owner for all components and have a separate
TIB_Session for each thread.
With a TIB_Cursor calling execute only executes the query and does not
perform a fetch. It is advisable with cursors that you call the First method
when you want the first record in the dataset and then can to the end of the
dataset and for sure Close it.
You should also be sure to Commit your transactions as well.
HTH,
Jason Wharton
CPS - Mesa AZ
http://www.ibobjects.com
Use the TIB_Session as the owner for all components and have a separate
TIB_Session for each thread.
With a TIB_Cursor calling execute only executes the query and does not
perform a fetch. It is advisable with cursors that you call the First method
when you want the first record in the dataset and then can to the end of the
dataset and for sure Close it.
You should also be sure to Commit your transactions as well.
HTH,
Jason Wharton
CPS - Mesa AZ
http://www.ibobjects.com
----- Original Message -----
From: "lamekisser" <lamekisser@...>
To: <IBObjects@yahoogroups.com>
Sent: Friday, April 05, 2002 1:16 PM
Subject: [IBO] TIB_Session + TIB_Connection + TIB_Transaction + TIB_Cursor +
Thread
> Hello,
>
> I am new to IBObjects, I am doing multithreading, and this is my best
> attempt to access Firebird within thread's Execute procedure:
>
> session := TIB_Session.Create(nil);
>
> connection := TIB_Connection.CreateForSession(nil,session);
> connection.DatabaseName :=
> 'localhost:c:\try.fdb';
> connection.Username := 'sysdba';
> connection.Password := 'masterkey';
>
> transaction := TIB_Transaction.Create(nil);
> transaction.IB_Connection := connection; //// Q2A
>
> cursor := TIB_Cursor.Create(nil);
> cursor.IB_Connection := connection; //// Q2B
> cursor.IB_Transaction := transaction;
> cursor.SQL.Text := 'select * from members';
> cursor.Execute;
>
> /// Q3
> while (cursor.Eof = False) do
> begin
> Memo1.Lines.Add(cursor.FieldByName('ID').AsString);
> cursor.Next;
> end;
>
> Questions:
> 1. Is the sequence of creating T_IBSession, TIB_Connection,
> TIB_Transaction and TIB_Cursor above correct?
> 2. If the sequence is correct (praying), why do I need to include the
> line marked with Q2B? Isn't it obvious that the connection was
> already linked at Q2A.
> 3. The codes above do produce output, but there is an extra blank
> record at the beginning. Do I need to add 'if (cursor.Bof) then
> cursor.Next;' at line Q3 (a little bit weird)?
>
> Thanks in advance,
> Billy