0

I'm using TransactSQL.ScriptDom to parse SQL statements. I have rules defined where I want to find a) IF statements and b) UPDATE statements. When I'm looking through non-dynamic SQL, the rules work just fine. However, when I'm looking through dynamic SQL, my code only detects the IF blocks; it does not detect the UPDATE statements.

For instance, this code gets hit in a debugger in both the non-dynamic and dynamic scenarios:

public override void Visit(IfStatement ifStatement)
{
    ...
}

However, this code does not get hit in any dynamic SQL scenario, and I've also tried using UpdateSpecification:

public override void Visit(UpdateStatement updateStatement)
{
    ...
}

Now, if I change the code to Visit(TSqlFragment test), the code will get hit, but I only see a node of type AsciiStringLiteral for my UPDATE statement. Is there a better way to get my code to visit an UPDATE statement?

WEFX
  • 8,298
  • 8
  • 66
  • 102

1 Answers1

0

Disregard, this was user error. I had a type-o in my dynamic SQL where I was incorrectly using single-quotes. In other words, I was using this:

@"EXEC('UPDATE dbo.MyTable
                SET MyColumn = 'MyValue';');",

... instead of this:

@"EXEC('UPDATE dbo.MyTable
                SET MyColumn = ''MyValue'';');",

(I considered deleting this question altogether, but I'll leave it up in case it helps others.)

WEFX
  • 8,298
  • 8
  • 66
  • 102