Replace output SELECT * with output columns

Answered

Comments

4 comments

  • Avatar
    Sergey Smagin (Product manager)

    Hello, Marc.

    This task has already been completed in the QueryTransformer object. The sample is below.

    QueryTransformer _queryTransformer = new QueryTransformer { 
    QueryBuilder = _queryBuilder,
    AlwaysExpandColumnsInQuery = true
    };
    _queryBuilder.SQL = _queryTransformer.SQL;

    Let me know if you have any further questions.


    0
    Comment actions Permalink
  • Avatar
    Marc

    Isn't that just in the v3? I'm using the ASP.NET edition. I think I figured it out. Please confirm:

    var queryBuilder = QueryBuilderControl1.QueryBuilder;
    var selectExpression = FindFirstSelect(queryBuilder.ResultQueryAST);
    queryBuilder.SyntaxProvider.ExpandQueryColumns(selectExpression);
    
        private SQLSubQuerySelectExpression FindFirstSelect(SQLSubQueryExpressions queryGroup) {
            SQLSubQuerySelectExpression result = null;
            for (int i = 0; i < queryGroup.Count; i++) {
                if (queryGroup[i] is SQLSubQuerySelectExpression) {
                    return (SQLSubQuerySelectExpression) queryGroup[i];
                } else if (queryGroup[i] is SQLSubQueryExpressions) {
                    result = FindFirstSelect((SQLSubQueryExpressions) queryGroup[i]);
                    if (result != null) {
                        return result;
                    }
                }
            }
            return result;
        }
    
    0
    Comment actions Permalink
  • Avatar
    Sergey Smagin (Product manager)

    Hello, Marc.

    I confirm that the QueryTransformer object exists in the ASP.NET version. You can use both ways to cope with this task.

    0
    Comment actions Permalink
  • Avatar
    ActiveDBSoft support team

    Sorry for a mistake, this API is not yet backported from v3.

    You could use low-level API for this:

    var ctx = queryBuilder1.SQLContext;
    var syntax = ctx.SyntaxProvider;
    
    using (var queryAst = (SQLSelectStatement) queryBuilder1.ResultQueryAST.Clone(ctx)) { syntax.ExpandQueryColumns(queryAst.FirstUnionSubQuery()); var resultSql = queryAst.GetSQL(ctx.SQLBuilderExpressionForServer); MessageBox.Show(resultSql); }

    0
    Comment actions Permalink

Please sign in to leave a comment.