Scheme and data for the test database https://gist.github.com/koceg/435c0d2b1246a69d048f
My goal is to update the board table when someone inserts a new row into the objects_properties table. The column name for the update is dynamic β it depends on the id property of objects_properties .
So far I have created a trigger and a stored procedure, but I get this error:
Dynamic sql is not allowed in a stored function or trigger.
Am I doing something wrong or does mysql not allow calling a stored procedure with a prepared statement inside a trigger? If so, how can I do what I want?
I have an idea, but it's ugly even in pseudo-code. Real SQL will be even worse because there will be dozens of codes:
SWITCH (property_code) CASE 'name' INSERT INTO boards (id, name) VALUES (@object_id, @value) ON DUPLICATE KEY UPDATE name = @value; CASE 'address' INSERT INTO boards (id, address) VALUES (@object_id, @value) ON DUPLICATE KEY UPDATE address = @value; CASE 'district' INSERT INTO boards (id, district) VALUES (@object_id, @value) ON DUPLICATE KEY UPDATE district = @value;
PS I canβt move this logic into my application because this database is used by several applications.
source share