get field value after event triggered

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

get field value after event triggered

Post by ads42 » Fri 25 Jan 2013 15:40

Hi,
I have to post datas on a table where the id of a field (uuid) is set by a trigger.
How can I get the value of this field after calling MyTable.post ?
Refresh change the record position.
Regards

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: get field value after event triggered

Post by DemetrionQ » Tue 29 Jan 2013 16:28

Hello.

MySql server does not return information about fields filled by the trigger during data change, thus TMyTable doesn't let getting this information either.
To solve this problem, you can use an autoincrement field or a unique key with value set on the client.

ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

Re: get field value after event triggered

Post by ads42 » Tue 29 Jan 2013 16:49

the solution I have found for now is :
Bookmark := theTable.GetBookmark;
theTable.Refresh;
theTable.GotoBookmark(Bookmark);

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: get field value after event triggered

Post by DemetrionQ » Mon 18 Feb 2013 12:10

Hello.

GotoBookmark moves to a record taking into account only its number in your dataset. As a result, your method can not work in the following situations:
- you are using ORDER BY;
- another user (or just another TMyTable, TMyQuery ) has inserted a new record before your TMyTable.Refresh operation.
That's why we recommend using an autoincrement field or a unique key with value set on the client.
Last edited by DemetrionQ on Tue 19 Feb 2013 09:07, edited 1 time in total.

ads42
Posts: 36
Joined: Tue 08 Jan 2013 14:13

Re: get field value after event triggered

Post by ads42 » Mon 18 Feb 2013 12:17

yep, I've seen that bookmark was a bad idea.
Autoincrement is not possible also since I have to sync database with other database that are in multiple system, using autoinc will create duplicate id....

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: get field value after event triggered

Post by DemetrionQ » Wed 20 Feb 2013 11:12

Hello.

To solve the problem, you can transform the field, which you modify with a trigger, to autoincrement, and set an appropriate start value to it. You can do this using the following SQL instructions:

Code: Select all

ALTER TABLE tablename MODIFY id_fieldname INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY;
ALTER TABLE tablename AUTO_INCREMENT = 42;
/*instead of "42" set the needed start value for autoincrement counter*/

Post Reply