Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Transactions and cached updates with Paradox tables - an example needed

Posted on 1998-12-25
9
Medium Priority
?
255 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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

885 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