Active Query Builder support area

Determination of presence of the INTO clause in a query

Last modified:


The SyntaxProvider.DenyIntoClause property set to true prescribes Active Query Builder to raise an exception on parsing a query with the INTO clause. But sometimes you may want to determine if such clause is present in a query instead of raising an exception. Use the following code to determine it's presence.
var hasInto = false;

// MySql
if (queryBuilder1.SyntaxProvider is MySQLSyntaxProvider)
{
    var usqList = queryBuilder1.GetUnionSubQueryList();

    foreach (var unionSubQuery in usqList)
    {
        var extender = (MySQLSubQuerySelectExpressionExtender) unionSubQuery.QueryAST.Extender;

        hasInto = extender.IntoFile != null;
        if (hasInto) break;
    }
}

// Access
else if (queryBuilder1.SyntaxProvider is MSAccessSyntaxProvider)
{
    var usqList = queryBuilder1.GetUnionSubQueryList();

    foreach (var unionSubQuery in usqList)
    {
        var extender = (AccessSubQuerySelectExpressionExtender) unionSubQuery.QueryAST.Extender;

        hasInto = extender.Into != null;
        if (hasInto) break;
    }
}

// MS SQL Server
else if (queryBuilder1.SyntaxProvider is MSSQLSyntaxProvider)
{
    var usqList = queryBuilder1.GetUnionSubQueryList();

    foreach (var unionSubQuery in usqList)
    {
        var extender = (MSSQLSubQuerySelectExpressionExtender)unionSubQuery.QueryAST.Extender;

        hasInto = extender.Into != null;
        if (hasInto) break;
    }
}

// PostgreSql
else if (queryBuilder1.SyntaxProvider is PostgreSQLSyntaxProvider)
{
    var usqList = queryBuilder1.GetUnionSubQueryList();

    foreach (var unionSubQuery in usqList)
    {
        var extender = (PostgreSQLSubQuerySelectExpressionExtender)unionSubQuery.QueryAST.Extender;

        hasInto = extender.IntoClause != null;
        if (hasInto) break;
    }
}

MessageBox.Show(hasInto ? "INTO Clause is found" : "INTO Clause isn't found");

Is this article helpful for you?