Getting unformatted SQL Text
Active Query Builder is a component intended to build SQL queries as well as to parse them and represent them visually. Thus, the main property of the QueryBuilder component is the SQL property. You can read it to get unformatted SQL query text for executing against a database server, and you can write to it to parse a query and represent it visually.
Getting formatted SQL Text
.NET 2.x and 1.x, Java and VCL Editions
Active Query Builder for .NET 3
sqlTextEditor1.Text = FormattedSQLBuilder.GetSQL(sqlQuery1.QueryRoot, new SQLFormattingOptions());
Refer to the following articles for details:
- How to get and set SQL text in ASP.NET Edition using Razor View engine
- How to get and set SQL text in ASP.NET Edition using ASPX View engine
Saving and Loading SQL query text between work sessions
- with the layout of objects within the Design Pane
The QueryBuilder.LayoutSQL property allows to save and to load the layout of objects within the Design Pane together with the query text, so the component's visual state could be saved between work sessions.
- with text formatting
To keep the formatting of the text in the SQL text editor you should read and write the SqlTextEditor.Text property.
- combining these techniques
Both properties should be used to save both SQL text formatting and query visual layout between work sessions. The sequence of reading them to save a query doesn't matter, but you should write the QueryBuilder.LayoutSQL property first and then write the formatted SQL query text to the QueryBuilder.SQL and SqlTextEditor.Text properties.
Synchronizing Active Query Builder with the SQL Text Editor
Use the QueryBuilder.SQLUpdated event to get new SQL query text each time when the query is updated in Active Query Builder visually or programmatically. To disable the firing of this event during batch programmatic changes, use the BeginUpdate and EndUpdate methods.