Question:
Given a SQL string like
CREATE VIEW TestView AS
SELECT value1, value2
FROM TABLE_0
UNION
(SELECT * FROM TABLE_2) AS value1
,value2
FROM TABLE_12
UNION
SELECT * FROM TABLE_3
(in lowercase)
And an array of string like
string[] tables = new string[]{"table_1", "table_2", "table_3"}
Now I did:
if (strViewDefinition.Contains(strObjectName)) // aaaaargh
for each strObjectName in tables, to check whether or not the view depends on this object.
But this fails on table_12 (and results in cyclic dependencies) for example, because tables contains "table_1". Aaargh.
I need a regex that can check if the view definition contains a function name, table-valued function or another view...
( For checking with System.Text.RegularExpressions.Regex.IsMatch( )
My trial was:
string whateverneedsescaping= System.Text.RegularExpressions.Regex.Escape(@"+-*\/%=,\n\r");
string fieldsep = @"[\s\n\r," + whateverneedsescaping+ "]*";
string strPattern = fieldsep + "VIEW/FUNCTION_NAME" + fieldsep;
But it fails, plus it doesn't account for object names embraced in brackets, like
"[TABLE_NAME]"
Anybody can help ?