Schema and data for test database - https://gist.github.com/koceg/435c0d2b1246a69d048f
My goal is to update boards table, when somebody inserts a new row in the objects_properties table. The name of the column to update is dynamic - it depends on a property_id from objects_properties.
So far I've created a trigger and a stored procedure, but I'm getting this error:
Dynamic sql is not allowed in stored function or trigger.
Am I doing something wrong or is mysql not allowing to call 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 a pseudocode. Real SQL will be even worse, because there will be a few dozens 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;
P.S. I can't move this logic to my application, because this database is used by several applications.