I have a form which generates MySQL query at run-time after submitting this form. This query includes series of CASE WHEN END
statements like this:
CASE
WHEN <any_user_defined_condition> THEN <any_user_defined_value>
ELSE <any_user_defined_value>
END,
CASE
WHEN <any_user_defined_condition> THEN <any_user_defined_value>
WHEN <any_user_defined_condition> THEN <any_user_defined_value>
ELSE <any_user_defined_value>
END,
CASE
WHEN <any_user_defined_condition> THEN <any_user_defined_value>
ELSE <any_user_defined_value>
END
Please suggest me a PHP regular expression which can validate above format so that I can validate MySQL query format before saving it into the database.
Thanks a ton in advance!
Edited:
I have few drop-downs through which user can create certain pre-decided conditions which is known as <any_user_defined_condition>
in my question. And of course, I am validating it strictly before allowing the user to submit it. So overall, <any_user_defined_condition>
will be replaced by some AGGREGATE
functions or some MYSQL built-in
functions along-with user-specified strings
(which will be again 100% SQL-Injection safe). Ultimately, I don't care about the formatting (whether this entire example written in one line or in multiple lines) but I am actually concerned about the style of string.