well i dug a little deeper in my old parser utility.
i expected the tables to be identified as TOKEN_TABLE, but they end up being TOKEN_ID instead; i guess with a connection , TOKEN_ID's eventually map to objectname(object_id), but i'll have to wrestle with this a little more. I really expected objects to get tokenized to TOKEN_TABLE.
string sqltext = @"Select * from
Tabl1 A join Table2 b
on a.id = b.id
Inner Join Table3 c
On c.id = b.id
Where a.id = 1 ";
//this.richTextBox1.Text;
//this.richTextBox2.Clear();
System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
//the partser is a nice static method, just call it, no object needed.
Microsoft.SqlServer.Management.SqlParser.Parser.ParseOptions myParseOptions = new Microsoft.SqlServer.Management.SqlParser.Parser.ParseOptions();
myParseOptions.BatchSeparator = "GO";
myParseOptions.IsQuotedIdentifierSet = true;
Microsoft.SqlServer.Management.SqlParser.Parser.Scanner MyScanner = new Microsoft.SqlServer.Management.SqlParser.Parser.Scanner(myParseOptions);
MyScanner.SetSource(sqltext, 0);
Microsoft.SqlServer.Management.SqlParser.Parser.Tokens token;
int state = 0;
int start;
int end;
bool isPairMatch;
bool isExecAutoParamHelp;
//System.Array Alltokens = Enum.GetValues(typeof(Microsoft.SqlServer.Management.SqlParser.Parser.Tokens));
while ((token = (Microsoft.SqlServer.Management.SqlParser.Parser.Tokens)MyScanner.GetNext(ref state, out start, out end, out isPairMatch, out isExecAutoParamHelp)) != Microsoft.SqlServer.Management.SqlParser.Parser.Tokens.EOF)
{
string str = sqltext.Substring(start, end - start + 1);
Convert.ToInt32(token).ToString();
Console.WriteLine("{0}: {1}: {2}", Convert.ToInt32(token).ToString(), token, str);
//richTextBox2.AppendText(String.Format("{0}: {1}: {2}", Convert.ToInt32(token).ToString(), token, str));
}
here's the representationof the tokens i got:
286: TOKEN_SELECT: Select
42: 42: *
242: TOKEN_FROM: from
171: TOKEN_ID: Tabl1
171: TOKEN_ID: A
157: TOKEN_JOIN: join
171: TOKEN_ID: Table2
171: TOKEN_ID: b
269: TOKEN_ON: on
171: TOKEN_ID: a
46: 46: .
171: TOKEN_ID: id
61: 61: =
171: TOKEN_ID: b
46: 46: .
171: TOKEN_ID: id
152: TOKEN_INNER: Inner
157: TOKEN_JOIN: Join
171: TOKEN_ID: Table3
171: TOKEN_ID: c
269: TOKEN_ON: On
171: TOKEN_ID: c
46: 46: .
171: TOKEN_ID: id
61: 61: =
171: TOKEN_ID: b
46: 46: .
171: TOKEN_ID: id
306: TOKEN_WHERE: Where
171: TOKEN_ID: a
46: 46: .
171: TOKEN_ID: id
61: 61: =
180: TOKEN_INTEGER: 1
Lowell