2

When parsing in a SQL query like:

SELECT g.A, g.B, g.C FROM dbo.Goat g inner join dbo.Badger b on g.A=b.A

and iterating through TSqlParserToken there is a Property called TokenType. I get the following:

SELECT   Select
     WhiteSpace
g    Identifier
.    Dot
A    Identifier
,    Comma
     WhiteSpace
g    Identifier
.    Dot
B    Identifier
,    Comma
     WhiteSpace
g    Identifier
.    Dot
C    Identifier
     WhiteSpace
FROM     From
     WhiteSpace
dbo  Identifier
.    Dot
Goat     Identifier
     WhiteSpace
g    Identifier
     WhiteSpace
inner    Inner
     WhiteSpace
join     Join
     WhiteSpace
dbo  Identifier
.    Dot
Badger   Identifier
     WhiteSpace
b    Identifier
     WhiteSpace
on   On
     WhiteSpace
g    Identifier
.    Dot
A    Identifier
=    EqualsSign
b    Identifier
.    Dot
A    Identifier 

I understand that in order for the parser to return these values it need to have an awareness of the underlying schema. Is it possible for me to feed the parser with the underlying objects so it can return a more aware set of tokens?

The TSqlTokenType enum also has values such as ‘Table’,’Schema’, ‘View’ so I’m sure this must be possible. It’s just the documentation is scarce. Dan

dandcg
  • 442
  • 4
  • 16
  • The output does not show any of table, schema or view? Or am I missing it? – usr Apr 01 '13 at 20:59
  • dbo = Identifier, . = Dot, Goat = Identifier - "dbo" should show schema, "Goat" should show table. – dandcg Apr 02 '13 at 12:35
  • what do you mean when say "more aware set of tokens"? plese give code whehe you get this array of tokens. It seems that you get result of lexer run not parser. – shibormot Apr 04 '13 at 23:13
  • No I am running the parser - I can distill it down into the required statement information. What I need to find out is whether this version of the parser can support schema binding. I know if I can reference an object, but wondered if I can deduce whether that object is a table or a view etc?# – dandcg Apr 08 '13 at 10:58
  • Have got some very good answers for this please see http://social.msdn.microsoft.com/Forums/en-US/ssdt/thread/24fd8fa5-b1af-44e0-89a2-a278bbf11ae0 – dandcg Apr 12 '13 at 18:19

0 Answers0