Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any Javascript/Jquery Library To validate SQL statment?

i have a textarea in my project where users can save SQL queries but one of the requirements is to check if this query is valid or not

EXAMPLE

if user entered something like :

SELECT ** FROM EMP 

this should return false and an error message just saying invalid it doesn't have to give any reasons

mainly the queries will be just select statement

NOTICE i DON'T want to use any server side at this point

Question

Does any one knows a javascript / jquery library or plugin that have this functionality or any thing similar

i have Google this and it didn't show any thing

Thanks

like image 807
Mina Gabriel Avatar asked Nov 01 '12 01:11

Mina Gabriel


1 Answers

Here is an example fiddle using the JS SQL Parser:

http://jsfiddle.net/Hb6az/

The parser will throw an error if it hits something unexpected, so you have to wrap your checking code in a try {} catch(error) {} block.

like image 77
Laurence Avatar answered Sep 25 '22 03:09

Laurence