Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlStatement.getTableNames() not returning all tables used #30

Closed
davidkirberich opened this issue Nov 13, 2018 · 1 comment
Closed
Assignees

Comments

@davidkirberich
Copy link

davidkirberich commented Nov 13, 2018

Hi, as I was comparing the table name extraction from the TSqlParser (which uses Microsoft.SqlServer.TransactSql.ScriptDom) with an extraction I once wrote (which uses Microsoft.SqlServer.Management.SqlParser). I realized one issue, where the TSqlParser is not returning the correct tables names.

Example (see query.txt attached):

  • My parser recognized 15 distinct tables
  • TSqlParser recognized 14 distinct tables. A nested query within a column was not successfully discovered (Table9 in the attachment)
Expected result Actual result
#TempTable1 #TempTable1
#TempTable2 #TempTable2
#TempTable3 #TempTable3
#TempTable4 #TempTable4
#TempTable5 #TempTable5
#TempTable6 #TempTable6
Table1 Table1
Table2 Table2
Table3 Table3
Table4 Table4
Table5 Table5
Table6 Table6
Table7 Table7
Table8 Table8
Table9 -

Sample code

SqlStatement sqlStatement = new SqlStatement();
if (sqlStatement.ParseString(mySqlQuery))
{
// Sorry, I am lazy so I aggregate the result and compare it in Excel
string tableNames = sqlStatement.getTableNames().OrderBy(p => p).Aggregate((i, j) => i + "\n" + j);
}

query.txt

(Edit: 14.11.2018, false query.txt was uploaded. Find attached the correct one)

keif888 added a commit that referenced this issue Jan 9, 2019
…of Microsoft.SqlServer.TransactSql.ScriptDom.FunctionCall
@keif888
Copy link
Owner

keif888 commented Jan 9, 2019

Issue fixed in source. Wasn't handling ExpressionCallTarget's which are a type of function CallTarget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants