2

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

2
  • Are you looking to validate the SQL before it's passed to Oracle for execution? Commented Aug 3, 2010 at 10:50
  • How can I do that?, anyway, requeriments of my application is validate SQL without execution. Only I need with sql file and "PARSER". Commented Aug 4, 2010 at 8:15

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thx, mr. Zendar; any sample application in .NEt -with source code if is possible- that use AntLR ??
@zendar the grammar page link is out of date. Two possible replacements: antlr3.org/grammar/list.html or github.com/antlr/grammars-v4
0

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.

Comments

0

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.

1 Comment

Chinese language, not english

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.