Page 1 of 1
Record locking
Posted: 08.09.2005, 17:09
by stefax
Hello,
I am new to ZeosLib and I have to say it's a wonderful set of components. Now I am developing an application that uses a MySQL 4.1 database. My question is pretty simple: do I have to issue a SELECT...FOR UPDATE manually when updating a record? Should I use a table component and call the "edit" method followed by "post" or issuing an UPDATE SQL statement is preferrable?
Thanks
Stefano
Posted: 12.09.2005, 05:54
by Michael
Hi stefax,
First of all ...
...
And now I want to try to answer your question that is imho partly philosophical...
My suggestion is: Only use TZTable if the database table has a very small number of records that will not grow that much e. g.: System data like users or so. Use TZQuery as often as you can.
The background: TZTable always fetches all records from the server into the client's memory (it's like a SELECT * FROM "table"). The advantage of using TZTable is that you don't have to care about updating, deleting oder inserting. SQL-Statements for these functions are generated, kept and used automatically in background. That makes them pretty comfortable but not customizable.
On the other hand there is the TZQuery it is very dynamic and you can use it to send any kind of SQL-Statement to the server. Especially for SELECT-Statements there is a big advantage: You are able to customize them to your needs so that you only get a certain set of your data and not all the data as with TZTable. This makes data retrieving faster because not all the data is taken from the server onto the client. On the other hand you have explicitly to define your INSERT, UPDATE and DELETE Statements if your TZQuery ResultSet should be modifyable (6.1.5: RequestLive=true / 6.5.1: ReadOnly=false).
If you want to get more informations about the ZeosLib Basics, please refer to our Knowledge Base. There is an article abount using
ZeosLib 6.1.5 with the Firebird Server. Ignore all the Firebird related stuff and you will get basic knowledge on how to use ZeosLib.
I hope this will help a little bit
Posted: 12.09.2005, 14:40
by stefax
Thanks for your answer Michael
I ended up using TZQuery since I have no guarantee that the number of records will not grow significantly and everything works like a charm.
Thanks again
Stefano
Posted: 12.09.2005, 17:35
by fduenas
Also you can use the TZUpdateSQL object to use multistatements when inserting, updaing or deleting. so you for example lock a table when you will update a record and then unlock it after updating.
The only issue here when using a TZquery binded to a TZUpdateSQL is that when inserting a new record, AutoIncrement columns and columns with default values will not be updated in the TZQuery resultset after posting the changes. The values are generated and in the database, but will not be reflected at client side. so you will have to use an extra line of code to retrieve the updated values. I'm doign that way and don't have problems.
I think This should be a feature request to developer team. this things only happen when using TZUpdateSQL, and it is beacuse the'calculateDefaults' and a 'DoAfterPostUpdates' (for AutoIncrement values) have not been implemented in this component.