@DTest not sure I understand your fiddle, but I prefer to work around the terminator limitations with comments like so rather than using an alien delimiter?
@JackDouglas CALL validate_foo(;DELETE FROM foo; --'); results in a syntax error and then the Delete statement (multiple queries) when run from command line, and with a privileged user, the delete definitely succeeds. My idiocy was that I thought it was happening inside the stored procedure.
My question wasnt related what the SQL query query should be, but how to create a a table with formula setting and fields. Does my question make sense?
@I'll-Be-Back you need to describe all of these details in your question - most of the people who will read your question are not here checking for what you said in chat.
@I'll-Be-Back also you need to describe the logic a bit better - does an admin update the formula for a category for him/herself, or does that formula apply to everyone?
@JackDouglas dynamic SQL isn't the devil. It's very practical in a lot of cases.
@AaronBertrand it's not the dynamic sql that would bother me here but the bouncing of a formula stored in the db (in sql) up to the php layer and back down again
@I'll-Be-Back you need to answer Aaron's excellent question too
@I'll-Be-Back also you need to describe the logic a bit better - does an admin update the formula for a category for him/herself, or does that formula apply to everyone?
@I'll-Be-Back can you give a clear answer to "why" you want this to be dynamic rather than coded into a view like the answer
Well I try my best to explain. I wanted this to be dynamic because the formula are subject to change every month or so. The formula setting should then save into database.
@JackDouglas the use of dynamic SQL does not mean it would have to be evaluated at the PHP layer. Can MySQL not construct dynamic SQL in a stored procedure?
@grid if the formulas are arbitrary and could change every month, we were thinking it could be done with dynamic sql instead - but if not, what you are suggesting is better in my view
and thanks for taking the time to join us in here - welcome! :)
@I'll-Be-Back this looks hideously overcomplicated to me, are you really sure you need to be this generic? Over the lifetime of the application, how many different formulas are you expecting your admins to ever enter?
and if you must be this generic, why not just enter the formula as text and carefully sanitise it
@I'll-Be-Back I'm not talking about the interface so much as how you store the formula - with your dropdowns you will need a whole set of tables of 'elements' for the formulas, and a way of linking them together. Far too much effort for no apparent gain as far as I can tell!