Subject | Re: [firebird-support] Re: FB, Delphi 7, IB components and transactions |
---|---|
Author | Diego Barros |
Post date | 2005-01-13T22:09:09Z |
Hello,
Thanks for the reply, I appreciate it.
Thanks for the reply, I appreciate it.
On Thursday, January 13, 2005, at 11:07PM, Svein Erling Tysvær <svein.erling.tysvaer@...> wrote:
>> 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?
>
>Probably because of transactions...
I neglected to mention that this is a single user application that I am writing. Even still, I was running two instances of my test application to try and get a better idea as to what happens when dealing with transactions and which application can see what when the other makes a change to the database.
>
>> 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.
>
>Well, I haven't seen any commit of the transaction yet, that makes it
>similar to writing a letter to your friend and upon asking, he says he
>hasn't received it. Upon asking at the postoffice you discover they
>expect you to actually send the letter.
If this is a single instance, single user application, then I don't have to commit transactions, do I? Because in that scenario there is no recipient of the letter. There is no other user, client, or application which will want to see any changes I make to the database. But, for a multi-user application, then what you say is true and is required when coding against IB/FB.
>> 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?
>
>Well, I think some of it can be changed by the transaction settings,
>more specifically whether or not you see changes that have been
>committed after you started your transaction. But there is no way to
>make visible outside your own transaction anything that hasn't been
>committed. Take a look at this article: http://www.ibobjects
>com/docs/ti_Transactions.ZIP, even though IBObjects is different from
>the Borland components I hope it should give you an idea.
Playing around with the settings last night I noticed that setting the transaction to read-commited, and the AutoStopAction (I think that's the name, I'm not at my machine now) to saCommit, resulted in the other instance being able to see the changes the first one made to the database. This was two instances of the application running at the same time, hence using different transactions.
Cheers,
Diego