Subject | TIB_Session + TIB_Connection + TIB_Transaction + TIB_Cursor + Thread |
---|---|
Author | lamekisser |
Post date | 2002-04-05T20:16:09Z |
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
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