Subject RE: [firebird-support] FB, Delphi 7, IB components and transactions
Author Alan McDonald
> >> I am a newbie when it comes to transactions, so please excuse my
> >> ignorance when it comes to transactions.
> >>
> >> I am using FB 1.5.2, with Delphi 7 and the IB components. My
> >> question is, why when I insert a record into a table don't I see
> >> it in another running program?
> >>
> >> I have a small test application with a query which selects a
> >> count of records from a table. On a form I show this number when
> >> I click the Refresh button. I have another button which inserts a
> >> new record into the table. So my form has the following components:
> >>
> >> IBQuery1 - which does a SELECT COUNT(*) on the table
> >> IBQuery2 - which inserts a record
> >> IBDatabase - used by both queries
> >> IBTransaction - used by the IBQuery1, IBQuery2 and IBDatabase
> components
> >>
> >> When I click the Refresh button I execute the following code:
> >>
> >> IBQuery1.Close();
> >> IBQuery1.Open();
> >>
> >> When I click the Insert button I execute the following code:
> >>
> >> IBQuery2.ExecSQL;
> >>
> >> I then run two copies of this test program. I insert a record in
> >> one instance of the program, click refresh and I see the record
> >> count increase. I click Refresh on the other instance of the
> >> application and the count does not change.
> >>
> >> Can this behavior be changed? I changed the transaction component
> >> to be read-commited, but that did not change the behavior. Maybe
> >> this is all about a different mindset and how one works with
> >> IB/FB? Are there any articles which talk about this? Maybe I need
> >> to try other components which work differently from a programming
> >> point of view?
> >>
> >> Any help or tips would be greatly appreciated by the FB newbie.
> >>
> >> Regards,
> >> Diego
> >
> >you need to commit the transaction to see the change in another
> application.
> >Instead of
> >Query.Close
> >Query.Open
> >Use IB_Connection.DefaultTransaction.Refresh(true);
> >
> >Alan
>
> Hi Alan,
>
> Thanks for the reply.
>
> Even still, if I don't commit it, and the application crashes at
> any stage after doing an ExecSQL to insert a new record, that
> record will be there when I re-run the application after a crash?
> It doesn't mean the record is not inserted in to the database?
>
> BTW this is a single user application.
>
> Cheers,
> Diego

Firstly, there's something very wrong if your app crashes when you insert.
We need to know more about exactly what you are doing to help your there.
Secondly, if the app crashes on insert (i.e. no commit has taken place) then
the record will not be visible when you start up again unless you are
autocommiting your query. This is not recommended now that you are away from
the bde. So I suggest you start building your test app again from scratch
and don't change the defaults for the moment.
Alan