Solved

Transactions and cached updates with Paradox tables - an example needed

Posted on 1998-12-25
9
235 Views
Last Modified: 2010-04-04
I would like to see a clear example of using transactions and cached updates with Paradox tables in Delphi 4. Is it possible for instace to insert (or edit) a couple of records and then cancel all insertions (or updates made during edition)?

I tried something like that with transaction:

Table1.Open;
Database1.Open;
Database1.StartTransaction;
for i := 1 to 10 do
begin
  Tabel1.Insert;
  Table1.Post;
end;
Database1.RollBack;

but in the result I had records inserted into the table.
0
Comment
Question by:shrldu
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:dwwang
Comment Utility
Here is some limit on transactions on Paradox tables:

1. For Paradox, local transactions can only be performed on tables with valid indexes. Data cannot be rolled back on Paradox tables that do not have indexes.
2. Only a limited number of records can be locked and modified. With Paradox tables, you are limited to 255 records. With dBASE the limit is 100.
3. TransIsolation level must only be set to tiDirtyRead.

I think most likely 1 or 3 may not be satisfied in you programm.      
0
 

Author Comment

by:shrldu
Comment Utility
No. I have the index on an autoincremental field. As the example shows the limit is far from being reached. And one just is not able to not set TransIsolation to something different than tiDirtyRead - because in other case the exception is raised...


0
 
LVL 4

Expert Comment

by:dwwang
Comment Utility
May I ask whether you set the database property of the table to your database component?

Because I see you write "table1.open" before database1.open, that couldn't be possible when you does not open the database first.
0
 

Author Comment

by:shrldu
Comment Utility
It is possible. I did it without generating any error. But of course I changed the order (first Database1.Open, then Table1.Open - and the results was the same.
And I checked InTransaction value between StartTrasaction and RollBack - it was True.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:shrldu
Comment Utility
I see that I am messing up a lot <g>. Now I changed the code putting Table1.Database.StartTransaction etc.
Now the exception is raised with a message saying that Transisolation level is not tiDirtyRead. Is seems then that Database1 and Table1 are not connected properly just like you suggested.
So perhaps I set up the properties of Database1 component wrongly:
I set AliasName to the name of the alias of my Paradox table, and DatabaseName to the name of Paradox table...
Isn't it enough? Database property of TTable is read-only, isn't it?

0
 
LVL 4

Accepted Solution

by:
dwwang earned 100 total points
Comment Utility
Oh, I see.

Just as I said, you need to connect the table with the database component.

1. You need to set the "databaseName" property of your database component(normally it's left blank), e.g. MyDB. Then set the AliasName of this database component to the paradox aliases, such as DBDEMOS.

2. In the property editor of your table component, drop down the comboBox of the "databaseName" property, now you can see "MyDB" in it, then select "MyDB" as the property value.

Now you can do other things as usual, such as

    Database1.Open;
    Database1.StartTransaction;
    Table1.Open;
    for i := 1 to 10 do
    begin
      Tabel1.Insert;
      Table1.Post;
    end;
    Database1.RollBack;
0
 
LVL 4

Expert Comment

by:dwwang
Comment Utility
I have tested with above procedure, and the result is correct.

Regards,
Wang
0
 

Author Comment

by:shrldu
Comment Utility
Yes, now it works. I had on my form a DBGrid, and after RollBack I saw the records which did not exist in reality. I had to use Table1.Last to synchronize the DBGrid with my table.
But thanks to it I noticed, that the autoincremental field starts with greater and greater value after every try... Evidently it means that RollBack cannot cancel the change of the maximum value of autoincremental fields. Can it be cured? Could you comment on that?
Thank you for your patience!

0
 
LVL 4

Expert Comment

by:dwwang
Comment Utility
I also noticed that, but seems it can not be cured. Transactions are usually based on logs, so when you rollback them, the programm just check the log and do reverse action, e.g. delete the records you inserted. However, the status of autoInc fields are already affected, and can't be restored.

Maybe we could suggest Inprise to include this function in the next version of BDE? :)

Regards,
Wang
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now