The Quick Start Guide for AQB.NET 3 describes the easy way of adding Active Query Builder to an application (please read it before reading this). This article will help you to get acquainted with the architecture of Active Query Builder 3.

Internal query objects structure

After a query is parsed by Active Query Builder, it becomes available for the programmer in two ways: low-level representation in a form of tokens tree. (we call this level "AST": "abstract syntax tree". The high-level object form consists of sub-queries, datasources, output query columns etc. The low-level representation is internally held by the high-level object form. The object form is available via the SQLQuery.QueryRoot reference.

The high-level query object form is a tree-like structure of sub-queries (unions, derived tables, common table expressions). It starts with the Query object of SubQuery class that has the SubQueries indexed property holding nested sub-queries. A SubQuery may consist of several SELECT statements joined with the UNION, EXCEPT or INTERSECT keywords, thus the SubQuery class is a collection of single SELECT queries, containing at least one item. A single SELECT query is represented by the UnionSubQuery object.

Non-visual Components

The SQLQuery object is a query building logic controller that provides the necessary means to operate with the query objects, and that's the object to which visual controls refer to perform manipulations with query objects. The internal query objects structure can be accessed via the SQLQuery.QueryRoot property.

The SQLQuery object must be created in a context of specific SQL syntax rules and connection to a database. The SQLContext object is responsible for definition of these things. It refers to metadata and syntax providers and contains the MetadataContainer and MetadataStructure objects to store information about database schema and it's visual presentation in a tree-like form.

Visual Controls

Active Query Builder user interface has the QueryNavigationBar control to deal with the tree-like structure of sub-queries. Visual controls for editing of single SELECT query parts, such as the DesignPaneControl and the QueryColumnsListControl, must be placed inside the QueryView panel that holds a reference to the currently active union sub-query (QueryView.ActiveUnionSubQuery). The Query Navigation Bar refers to the QueryView object to change the currently visible sub-query.

Architecture of Active Query Builder 3

This diagram can help you to find the needed objects to work with Active Query Builder in non-visual mode, or to build original combination of visual controls, or may be to create your own visual controls to deal with specific parts of the query and add them to Active Query Builder UI.

Below is the source code of initialization of Active Query Builder components that will help you to link them with each other.

// Non-visual objects
_sqlContext = new SQLContext
{
    SyntaxProvider = new MSSQLSyntaxProvider {ServerVersion = MSSQLServerVersion.MSSQL2012},
    MetadataProvider = new OLEDBMetadataProvider 
    {
        Connection = new OleDbConnection() {ConnectionString = ""}
    }
};

_sqlQuery = new SQLQuery(_sqlContext);

// Visual controls
queryView1.Query = _sqlQuery;

navBar1.Query = _sqlQuery;
navBar1.QueryView = queryView1;

databaseSchemaView1.SQLContext = _sqlContext;
databaseSchemaView1.QueryView = queryView1;

// Linking visual query builder with text editor
sqlTextEditor.QueryProvider = _sqlQuery;
_sqlQuery.SQLUpdated += sqlQuery_SQLUpdated;

// Initialization
databaseSchemaView1.InitializeDatabaseSchemaTree();
_sqlQuery.SQL = "SELECT * FROM dbo.Customers";

Customizable layout of user interface controls

The Dock Manager control lets hold any controls to the left, right or beneath its workspace as hideable panels.

The code samples of programmatic addition of sidebar panels to the DockManager control can be found here: WinForms, WPF.

Learn more

How to get formatted SQL text and setup formatting options?

This article was helpful for 1 person. Is this article helpful for you?