Transactions and cached updates with Paradox tables - an example needed

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.
shrlduAsked:
Who is Participating?
 
dwwangConnect With a Mentor Commented:
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
 
dwwangCommented:
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
 
shrlduAuthor Commented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
dwwangCommented:
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
 
shrlduAuthor Commented:
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
 
shrlduAuthor Commented:
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
 
dwwangCommented:
I have tested with above procedure, and the result is correct.

Regards,
Wang
0
 
shrlduAuthor Commented:
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
 
dwwangCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.