tags:

views:

47

answers:

2

I am looking for an application, that would give me some more descriptive information about syntax errors in SQL queries, than:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near (...)

Finally I always find out what is wrong with my query, but it is a little bit strange that this error messages are so general. I known that it is difficult to spot errors "for sure" in such language like SQL, but using at least some heuristics (if not exact rules) it should be possible to give some suggestions about common possible problems.

Does anyone know such tool?

A: 

Well, have not seen such tool yet, it would be really great if mysql could take care of this and show more better error messages. Would love to see if any one comes up with solution too.

Sarfraz
+1  A: 

The MySQL parser is built with bison/flex.

When an error occurs, the application layer (MySQL in that case) has very inaccurate information about why the parsing failed and it is difficult to give better reporting to the user than is currently does.

Considers a simple calculator and a parenthesis error like:

( ... (.....)

Where the second parenthesis is missing? You need a human brain to answer that question since localizing the error means being able not only to understand the syntax but also the content being processed. A parser will just see that at the end of the statement to process, the count of parenthesis is wrong and report the error. It can't do better, even if the statement is very large, that's why when coding in C (or other languages), if you made some error about parenthesis or braces, the compiler may give totally wrong information.

Consider this:

select from mytable where s=''and r=''';

Where is the mistake? Did I incorrectly used ' instead of " for the whole where clause because I wanted to have:

select from mytable where s="'and r=''";

Maybe I wanted this:

select from mytable where s=''and r='';

The later seems possible to a humain brain, because a human brain knows that chances are low that the content of an attribute looks like part of a SQL statement. But for a parser, this would mean reparsing the content of what was not understood, which is quite paradoxical. And the human brain could be wrong, maybe my application was processing data entered by someone that entered weird strings in a web form.

So maybe the MySQL parser can be improved but I don't think that the result obtained will be worth the effort.

bernard