September 6, 2011 at 12:14 am
Does anyone know of a tool that can do more structural and syntactic checking on T-SQL code than Ctrl+F5 does, w/o actually trying to run the code?
I'm hoping that it can check for block completeness (e.g., each BEGIN matches up with an END), COMMITs and ROLLBACKs are reachable (and there's not more or fewer COMMITS or ROLLBACKS than there are BEGIN TRANSACTIONS)... And, some of the more sundry stuff that Ctrl+F5 usually does.
Otherwise, I know there are BNF & EBNF's of T-SQL available on the net, so how hard would it be to go about writing such a beast?
September 6, 2011 at 1:49 am
I strongly suggest to avoid coding such a parser. It could tak you months or years and never work completely.
Don't re-invent the wheel, there are lots of parsers ready to use.
http://www.sqlparser.com/index.php
http://jsqlparser.sourceforge.net/
... just to name a few.
Hope this helps
Gianluca
-- Gianluca Sartori
September 6, 2011 at 2:04 am
http://blogs.msdn.com/b/gertd/archive/2008/08/21/getting-to-the-crown-jewels.aspx - there are links in this article to some sample parsing code.
The Microsoft.Data.Schema.ScriptDom.Sql Namespace (details here -> http://msdn.microsoft.com/en-us/library/microsoft.data.schema.scriptdom.sql.aspx) seems to have enough support for parsing requirements.
There's also a walkthrough on how to write custom static code analysis here -> http://msdn.microsoft.com/en-us/library/dd172127.aspx
Edit: Just read the previous post - +1 to reusing existing parsers as opposed to writing your own (unless you just want to explore SQL parsing heh)
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply