I'm trying to build a .NET Managed data provider and I need to be able to parse SQL commands.
What are good, free (as in beer) objects to do this? - I haven't seen any standard .NET assemblies for this yet.
Thanks, Eli.
I'm trying to build a .NET Managed data provider and I need to be able to parse SQL commands.
What are good, free (as in beer) objects to do this? - I haven't seen any standard .NET assemblies for this yet.
Thanks, Eli.
There's a OO parser generator called ANTLR that might help you.
What is ANTLR? ANTLR, ANother Tool for Language Recognition, is a language tool that provides a framework for constructing recognizers, interpreters, compilers, and translators from grammatical descriptions containing actions in a variety of target languages. ANTLR provides excellent support for tree construction, tree walking, translation, error recovery, and error reporting.
In fact, there are a pile of grammars already encoded for ANTLR, including several SQL dialects: Grammar List
(for posterity: note that the "General SQL Parser" also recommended in these answers is not free)
What is your data provider talking to? If you're implementing your own data engine then so be it, but in general your provider should just be a connector and pass the sql on to some other engine.
You could also try
Microsoft.Data.Schema.ScriptDom
Microsoft.Data.Schema.ScriptDom.Sql
and the TSql100Parser
and related classes, although the documentation really isn't all that helpful (not many examples available). Here are the two most useful links I've found so far:
http://blogs.msdn.com/gertd/archive/2008/08/21/getting-to-the-crown-jewels.aspx
http://stackoverflow.com/questions/1779737/using-the-tsqlparser
It seems to me, though, that even though the parser and generator are complete, it would take quite a bit of work to get to the same level of comfort provided by General SQL Parser, and the license for GSP is not that expensive. In addition, the MS classes only support TSQL, whereas GSP can also work with other variants.