Home → Active Query Builder - Query analysis and modification → Analyzing SQL query structure → Understanding complex SQL query structure representation
1.2. Understanding complex SQL query structure representation
Each query and sub-query in the query is represented with the SubQuery object in Active Query Builder; The main query representation class Query is descendant of the SubQuery class. The main query can be accessed via the QueryBuilder.Query property. To get access to the list of sub-queries, use the QueryBuilder.SubQueries collection.
Each sub-query may not be a single "SELECT ... FROM ..." statement, but a set of statements joined with the UNION, EXCEPT, INTERSECT and other keywords. Each single "SELECT ... FROM ..." statement is represented via the UnionSubQuery object.
There are few useful helpers you may use in your project:
The QueryBuilder.Query.FisrtSelect() method returns the link to an object representing the first single SELECT statement in the query.
The QueryBuilder.ActiveSubQuery.ActiveUnionSubQuery property gets the single SELECT statement currently visible to the end-user. The QueryBuilder.ActiveUnionSubQueryChanged event is fired when user switches to another statement.
The UnionSubQuery object holds datasources, their links (UnionSubQuery.FromClause), expressions and criteria (UnionSubQuery.CriteriaList) of the single SELECT statement. To get list of all datasources, use the UnionSubQuery.FromClause.GetDatasources() method. The CriteriaList collection is organized the same way as you see it in the Query Columns Grid: each item of this collection (CriteriaItem) represents a single row of this grid; columns are accessible via the corresponding properties.