views:

40

answers:

2

Hi, Is there any sql query validator in frontend side or in any language for validating the query syntax before executing in the database ?.In my current project i have to validate the the sql query in flex before it goes to back end ,coz it has to pass lot many layers before hitting database and the hitting the DB and coming back with an exception is an too expensive process .So im in need of sql query validator in front end side to atleast say its a valid query .

+1  A: 

for SQL Parsing at runtime you can look at: SQL4J is a SQL-parser written in Java. http://www.cs.toronto.edu/~jglu/sql4j/index.htm

http://jsqlparser.sourceforge.net/

Perhaps you can use Antlr, it has a number of SQL grammars. http://www.antlr.org/grammar/list

Or as advised, use the parser of open source SQL utilities like SQuirreL SQL Client. http://squirrel-sql.sourceforge.net/

or use parts of an open source pure Java DBMS like SmallSQL. http://www.smallsql.de/

There is Eclipse IDE plugins for validating SQL from IDE.

Check out: http://www.eclipse.org/datatools/

YoK
but those i can jus validate once tht too by user intervention .My requirement is tht i will generating a query from flex using using the help of user by clicking button or some actions .That generated query should be validated syntactically over there itself through a piece of code .
Bhaswanth
@Bhaswanth so you generate query dynamically ? isn't it a query and you just pass criteria or values selected by user to query ?
YoK
@YoK, as far as I can understand he is using it as a debugging tool/exception handler.
Unreason
@Yok : similar to the concept of criteria .But not exactly the same .Let us think user directly wrote a query and i need to validate it in front end before gng backend .
Bhaswanth
@unreason :yaa ..sort of
Bhaswanth
@Bhaswanth I have added few parsers and validator links to my answer. Hope these help.
YoK
@YoK :thank you ..sure i ll look into them .
Bhaswanth
@Bhaswanth, feel free to upvote answers that are helpfull; see http://stackoverflow.com/faq
Unreason
@Unreason :sure .Im a newbee to this .Jus learning the way to act .Thanks for the info .
Bhaswanth
+1  A: 

You could grab the SQL BNF grammar and use parser generator to validate input.

I am sure you would have to tweak the standard grammar and this is not trivial. Also, I am sure that you can find something better, but I hope the above will get you somewhere.

Unreason
ya ..this can help lil bit.will look into it..thanks :)
Bhaswanth