I've created a "before insert" trigger (with HeidiSQL) for a table to preset some fields on inserts. Is it possible to sync the data when I perform an insert in my application? I don't want to preset the fields in the AfterInsert event of my TUniQuery.
Thanks
MYSQL "before insert" trigger synchronise
-
AndreyZ
Hello AndreyZ,
thanks for your reply. But that does not work for me. When I'm in insert state the value of the field is still NULL.
In my case I set a required field ("language") in a "before insert" trigger in mysql. In my application I've got a grid and draw a country flag image for every row in dependence which language is selected. When a user inserts a new row, I need to know the default language to change the position of a combobox where the user can select his language. But I don't get the value while I'm in insert state. After posting the data I get the correct value from my trigger, but that's too late.
I don't want to preset the default value in my application because I don't want to compile my application after changing the default value. And I've got a few other tables where I would like to preset the data directly in mysql and not in my application.
I could set the "required" property of my fields to false and perform an auto-post after insert and then change the stated to edit. But then I have to work with transactions to rollback the insert in case that the user cancels his action. I hope there is a better solution to solve my problem...
Thanks
thanks for your reply. But that does not work for me. When I'm in insert state the value of the field is still NULL.
In my case I set a required field ("language") in a "before insert" trigger in mysql. In my application I've got a grid and draw a country flag image for every row in dependence which language is selected. When a user inserts a new row, I need to know the default language to change the position of a combobox where the user can select his language. But I don't get the value while I'm in insert state. After posting the data I get the correct value from my trigger, but that's too late.
I don't want to preset the default value in my application because I don't want to compile my application after changing the default value. And I've got a few other tables where I would like to preset the data directly in mysql and not in my application.
I could set the "required" property of my fields to false and perform an auto-post after insert and then change the stated to edit. But then I have to work with transactions to rollback the insert in case that the user cancels his action. I hope there is a better solution to solve my problem...
Thanks
-
AndreyZ
If you set field values in a trigger, the only way to obtain these values on a client side is to read them again from the server (perform the refresh operation). To solve the problem, you can set the default value for the "language" field on the server and set the TUniQuery.Options.DefaultValues property to True. The DefaultValues property is used to request default values/expressions from a server and assign them to the DefaultExpression property of the fields. In this case you don't need to recompile your application every time you change default value on the server because TUniQuery will obtain default values directly from the server every time it is opened.
Thank you for the information.
I think currently it's the easiest sollution to set the default values in the fields on the server. I will have to post and refresh my data on the client side when I need to calculate something before inserts... But it's fine for my use at the moment. Thank you for the fast response.
I think currently it's the easiest sollution to set the default values in the fields on the server. I will have to post and refresh my data on the client side when I need to calculate something before inserts... But it's fine for my use at the moment. Thank you for the fast response.