Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Transactions and cached updates with Paradox tables - an example needed

Posted on 1998-12-25
9
Medium Priority
?
252 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 4

Expert Comment

by:dwwang
ID: 1352996
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
ID: 1352997
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
ID: 1352998
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:shrldu
ID: 1352999
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
 

Author Comment

by:shrldu
ID: 1353000
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 400 total points
ID: 1353001
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
ID: 1353002
I have tested with above procedure, and the result is correct.

Regards,
Wang
0
 

Author Comment

by:shrldu
ID: 1353003
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
ID: 1353004
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

715 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