Jump to content

Validate SQL Code before Execution


Tazerenix

Recommended Posts

Nope, but since you should only be putting data into a preexisting tested query where the syntax of the query is known to be correct, that should not be a problem if you have validated and escaped the data.

 

What sort of problem are you having that you are trying to solve?

 

 

Link to comment
Share on other sites

Playing the devil's advocate, what if the dynamically produced SQL that was being validated for syntax errors was for a DELETE query and the resulting bad syntax either did not get built with the LIMIT 0 term or it was treated as a comment or got enclosed in quotes so that it was not seen (perhaps as an argument NOT in a WHERE condition) and all the rows just got deleted?

 

If you are talking about needing to do this as the result of putting data into an existing syntactically correct query, as long as you properly validate and escape the data, you cannot produce a syntax error.

 

There are some database errors that are not due to syntax, such as the 'database has gone away' type that are out of your control and you still need error checking, error reporting, and error recovery logic in your code to address them. It does not really make sense to add the extra overhead of trying to detect a syntax error in a query before you run it in order to prevent the syntax error that you would get when you actually do run it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.