MacroScopeParser by Chad Miller 22 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1733"></script>download | new post
Uses MacroScope/Antlr to parse SQL query for tables and table aliases
- #requires -version 2
- #Chad Miller
- #http://www.sev17.com/
- #Uses MacroScope/Antlr to parse SQL query for tables and table aliases
- #Download MacroScope from http://macroscope.sourceforge.net/ and compile from source
- #Or grab compiled assemblies from http://cid-ea42395138308430.skydrive.live.com/embedicon.aspx/Public/Blog/macroscopeParser.zip
- param ($commandText)
- #Assumes MacroScope and Antlr3 assemblies are in same directory
- add-type -Path $(Resolve-Path .\Antlr3.Runtime.dll | Select-Object -ExpandProperty Path)
- add-type -Path $(Resolve-Path .\MacroScope.dll | Select-Object -ExpandProperty Path)
- #######################
- function Get-Table
- {
- param($table)
- $table
- if ($table.HasNext)
- { Get-Table $table.Next }
- }
- $sqlparser =[MacroScope.Factory]::CreateParser($commandText)
- $expression = $sqlparser.queryExpression()
- Get-Table $expression.From.Item | Select @{n='Name';e={$_.Source.Identifier}}, @{n='Alias';e={$_.Alias}}
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
PowerShell Code Repository