Reputation: 14996
I want to parse the SQL code of a file .sql using C#.
I want determinate Syntax Check of a file sql, specifically Insert, Update and Delete statements.
Specifically is there any parser freely available which can parse the SQL code in C# .NET ? better is freeware, source code included, and easy use.
I use Oracle
Upvotes: 2
Views: 5410
Reputation: 1
The miniSqlParser can parse and check SQL statements. This is a assembly of C# and open source. SQL Formatter is a web application of indenting SQLs, that use this assembly. Please try it.
Upvotes: 0
Reputation: 483
General SQL Parser can do offline SQL syntax check without connecting to a database. It's support Oracle, SQL Server, DB2, MySQL, MS-ACCESS, Teradata and PostGreSQL.
But it's a commercial SQL library and not open source.
Upvotes: 0
Reputation: 13572
You can try with ANTLR.
On grammar page you will find several grammars related to Oracle.
Unrelated, is there a way to just "Prepare" statement without execution? That way you could have Oracle check syntax and then catch eventual errors in your code. This will help you skip duplicating functionality already present in Oracle. Not to mention problem of handling changes between different versions of Oracle.
Edit:
Re comment about code examples: I used ANTLR briefly and I had hard time finding code examples on internet. Main source I found was examples from ANTLR download page. Now I see that Terence Parr, author of ANTLR, published new book and that accompanying source code contains more ANTLR examples.
Since you don't have much experience with ANTLR, may I, again, suggest that you try another approach, since this is fairly complex area and needs considerable learning effort to get you started. At least, that was my experience.
Upvotes: 2