Home ScriptDom + DeleteStatement
Reply: 1

ScriptDom + DeleteStatement

Mohsen Hasani
1#
Mohsen Hasani Published in 2017-11-14 09:00:59Z

I want to insert "DeleteStatement" after any "DeclareTableVariableStatement" but I don't know how! it's my sample code.

public override void Visit(StatementList node)
{
    foreach (DeclareTableVariableStatement declareTableVariableStatement in node.Statements.Where(a => a is DeclareTableVariableStatement).ToList())
    {
        BeginEndBlockStatement deleteBeginEndBlockStatement = new BeginEndBlockStatement()
        {
            StatementList = new StatementList()
        };

        DeleteStatement deleteStatement = new DeleteStatement()
        {
           DeleteSpecification=new DeleteSpecification()
           {
                Target= ???
           }
        };
        deleteBeginEndBlockStatement.StatementList.Statements.Add(deleteStatement);
        node.Statements.Insert(node.Statements.IndexOf(declareTableVariableStatement) + 1, deleteBeginEndBlockStatement);
    }
    base.Visit(node);
}
Mohsen Hasani
2#
Mohsen Hasani Reply to 2017-11-14 10:15:48Z

I found the solution !

public override void Visit(StatementList node)
{
    foreach (DeclareTableVariableStatement declareTableVariableStatement in node.Statements.Where(a => a is DeclareTableVariableStatement).ToList())
    {
        BeginEndBlockStatement deleteBeginEndBlockStatement = new BeginEndBlockStatement()
        {
            StatementList = new StatementList()
        };

        DeleteStatement deleteStatement = new DeleteStatement()
        {
            DeleteSpecification = new DeleteSpecification()
            {
                Target = new VariableTableReference()
                {
                    Variable = new VariableReference()
                    {
                        Name = declareTableVariableStatement.Body.VariableName.Value
                    }
                }
            }
        };

        deleteBeginEndBlockStatement.StatementList.Statements.Add(deleteStatement);
        node.Statements.Insert(node.Statements.IndexOf(declareTableVariableStatement) + 1, deleteBeginEndBlockStatement);
    }
    base.Visit(node);
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302285 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO