Article View: comp.lang.pascal.delphi.databases
Article #192Re: How to secure database transactions?
From: M.H. Avegaart
Date: Fri, 14 Apr 2000 00:00
Date: Fri, 14 Apr 2000 00:00
80 lines
4024 bytes
4024 bytes
"Tim" <tim.hoebeek@NOSPAM.advalvas.be> schreef in bericht news:u33cfsojbhlif6g35ba31k27pgqhm11j4s@4ax.com... > >I can see you copied this from the example... > > Well, that was the point I started from, but I have difficulties > seeing the bigger picture. I think I understand what all the > statements individually do, but I haven't got a clue about how all > those statements relate to each other and whom is a descendant of > whom. > > >The example shows transactions AND cached updates. You are not using cached > >updates, so you would only use: > > What is the defference between the two and can't they be mingled? I > thought one was using cached updates when the CachedUpdates property > of the TQuery component was set to true. Transaction handling is a feature of the database you are using. If your database doesn't support transactions or if you don't want to burden the database server with the overhead of transactions you can use local caching. With local caching, all updates to a specified dataset are stored and only executed on the database with ApplyUpdates. Cached changes are not really stored with the table, but locally to the dataset, so if you retreive data from the same table with another dataset you will get the old values ! For transaction handling you can specify weither you want to read old or new data with the TransIsolation property of the TDatabase. > > >Database.StartTransaction; > >try > > Query.ExecSQL; > > Database.Commit; > > Aren't those SQL statementsexecuted at that moment and commited? Does > StartTransaction put some kind of marker in the database, so it knows > to what place it should roll back? StartTransaction initiates a kind of separated memory space for you to store your changes. Those changes are applied to the complete database on a Commit. The memory is discarded with a Rollback. > > > Ok := True; > >except > > Database1.Rollback; > > Ok := False; > >end; > > In the other case the rollback is executed and none of the code is > executed, right? Yes > > Would it be possible then to start a transaction, call the same > procedure for a couple of times (running inserts against the database) > from within the try block and when anything goes wrong, performing a > rollback as if nothing happened? You can only call StartTransaction ONCE. After StartTransaction you can make all the changes you want (as long as the database server has enough memory available). Finally you should either call Commit or Rollback. > > What's this 'Database' then in Database.StartTransaction? Is it a > database from the type TDatabase? Yes. You will need a separate TDatabase object to call transaction handling routines. > > The fog in my head is clearing now, but some things remain unclear. > > Thank you very much for your help, > > > Tim. >
Technical Details
Message-ID:
<8d6mku$hmo$1@porthos.nl.uu.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<pmf9fsghf7fo4tlk7jplcch8ieb74t13it@4ax.com> <8d45g5$cq6$1@porthos.nl.uu.net> <u33cfsojbhlif6g35ba31k27pgqhm11j4s@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: ffff5,f1c16399821b6318 X-Google-Attributes: gidffff5,public X-Google-Thread: 10baee,f1c16399821b6318 X-Google-Attributes: gid10baee,public X-Google-Thread: fd817,f1c16399821b6318 X-Google-Attributes: gidfd817,public X-Google-Thread: f8e31,f1c16399821b6318 X-Google-Attributes: gidf8e31,public From: "M.H. Avegaart" <avegaart@NOSPAMmccomm.nl> Subject: Re: How to secure database transactions? Date: 2000/04/14 Message-ID: <8d6mku$hmo$1@porthos.nl.uu.net> X-Deja-AN: 611033817 References: <pmf9fsghf7fo4tlk7jplcch8ieb74t13it@4ax.com> <8d45g5$cq6$1@porthos.nl.uu.net> <u33cfsojbhlif6g35ba31k27pgqhm11j4s@4ax.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Complaints-To: abuse@nl.uu.net X-Trace: porthos.nl.uu.net 955702750 18136 193.67.87.80 (14 Apr 2000 08:59:10 GMT) Organization: UUNET-NL (http://www.nl.uu.net) X-MSMail-Priority: Normal NNTP-Posting-Date: 14 Apr 2000 08:59:10 GMT Newsgroups: comp.lang.pascal.delphi.databases,comp.lang.pascal.delphi.misc,borland.public.delphi.students,alt.comp.lang.borland-delphi