Place the QueryBuilder component on the form.
using ActiveDatabaseSoftware.ActiveQueryBuilder; ... QueryBuilder queryBuilder1 = new QueryBuilder();
Place required metadata and syntax provider components on the form. Define a proper database connection object for the metadata provider.
OleDbConnection connection = new OleDbConnection(); connection.ConnectionString = "<your connection string here>"; OLEDBMetadataProvider metadataProvider = new OLEDBMetadataProvider(); metadataProvider.Connection = connection; UniversalSyntaxProvider syntaxProvider = new UniversalSyntaxProvider();
Link the components above to the QueryBuilder by setting MetadataProvider and SyntaxProvider properties
queryBuilder1.MetadataProvider = metadataProvider; queryBuilder1.SyntaxProvider = syntaxProvider;
Place an SQLBuilder component on the form to get SQL code generated by the QueryBuilder component with formatting. Link it to the QueryBuilder object by setting the QueryBuilder property.
PlainTextSQLBuilder sqlBuilder = new PlainTextSQLBuilder(); sqlBuilder.QueryBuilder = queryBuilder1;
Add the TextBox or any other text editing component to a form.
Now you should establish connection between SQLBuilder and the TextBox components.
Enter the following code to Leave event of TextBox component:
if (textBox1.Modified)
{
try
{
queryBuilder1.SQL = textBox1.Text;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Parsing error");
}
textBox1.Modified = false;
}Enter the following code to SQLUpdated event of SQLBuilder component:
textBox1.Text = sqlBuilder.SQL;
queryBuilder1.RefreshMetadata();
That's all! Now you can run your application.
Create a new solution and add a new project – ASP.NET Web Application.
Add references to the following assemblies:
You may also need to add the assemblies for specific metadata providers to retrieve metadata from a database, e.g.:
For IIS 6, Add the following handlers in the "system.web/httpHandlers" section of your "web.config" file:
<add verb="*"
path="handlers/exchange.axd"
type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.Handlers.Exchange, ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server"
/>
<add verb="*"
path="handlers/sessonKeeper.axd"
type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.Handlers.SessionKeeper, ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server"
/>
<add verb="*"
path="handlers/clientError.axd"
type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.ClientErrorHandler, ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server"
/>
For IIS 7, Add the following handlers in the "configuration/system.webServer" section of your "web.config" file:
<add name="handlers/clientError.axd_*"
path="handlers/clientError.axd"
verb="*"
type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.Handlers.ClientErrorCollector, ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server"
preCondition="integratedMode,runtimeVersionv2.0"
/>
<add name="handlers/sessonKeeper.axd_*"
path="handlers/sessonKeeper.axd"
verb="*"
type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.Handlers.SessionKeeper, ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server"
preCondition="integratedMode,runtimeVersionv2.0"
/>
<add name="handlers/exchange.axd_*"
path="handlers/exchange.axd"
verb="*"
type="ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server.Handlers.Exchange, ActiveDatabaseSoftware.ActiveQueryBuilder.Web.Server"
preCondition="integratedMode,runtimeVersionv2.0"
/>
Get content from the "web_parts" directory ("css", "img" and "js" sub-folders) and place it to the same folder as the web page.
Please make sure that the "js/release/" folder that contains two required *.js files is placed in the same directory as the web page, i.e. if you accessing the web page with Active Query Builder via the "http://yourserver/path/page.aspx" URL, these files should be accessible at the following addresses: "http://yourserver/path/js/release/lib.js" and "http://yourserver/path/js/release/usr_v0_x_x.js".
Typical HTML code can be found in the "web_parts\Default.aspx" file, you may add this content to your web-page.
Place your initialization code in the QueryBuilderControl.Init event handler. There you should create Metadata and Syntax provider components and link these providers to the QueryBuilder object by setting the MetadataProvider and SyntaxProvider properties. Define a proper database connection object as a source for the Metadata provider or load metadata from the XML file.
The server side of the component is based on the WinForms .NET Edition of Active Query Builder. There are two object references available to get access to their methods and properties: QueryBuilderControl.QueryBuilder and QueryBuilderControl.PlainTextSQLBuilder.
private void QueryBuilderControl1_OnInit(object sender, EventArgs e)
{
QueryBuilderControl control = sender as QueryBuilderControl;
// Get instance of QueryBuilder
QueryBuilder queryBuilder = control.QueryBuilder;
// ========================================================
// you may load metadata from the database connection using live database connection
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = "<your connection string here>";
OLEDBMetadataProvider metadataProvider = new OLEDBMetadataProvider();
metadataProvider.Connection = connection;
queryBuilder.MetadataProvider = metadataProvider;
// call the RefreshMetadata to load metadata from a database connection
queryBuilder.RefreshMetadata();
// ========================================================
// or you may load metadata from the pre-generated XML file
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(ConfigurationManager.AppSettings["XmlMetaData"]));
queryBuilder.MetadataContainer.LoadFromXML(doc.OuterXml);
}That's all! Now you can run your web project.
Place the ActiveQueryBuilderX control on the form.
Add the TextBox or any other text editor control to a form. In case of using the TextBox control you should set its MultiLine property to True.
Now you should establish connection between the ActiveQueryBuilderX and the TextBox controls.
Enter the following code to Leave event of TextBox control:
ActiveQueryBuilderX1.SQL = TextBox1.Text
Enter the following code to OnSQLChanged event of ActiveQueryBuilderX control:
TextBox.Text := ActiveQueryBuilderX1.FormattedSQL
That's all! Now you can run your application.
And don't forget to fill the ConnectionString property of ActiveQueryBuilderX control with the right ADO connection string and to turn the Connected property to True!
Place the TacQueryBuilder component on the form.
Place required metadata and syntax provider components on the form. Define database connection for the metadata provider.
Link the components above to the TacQueryBuilder by setting MetadataProvider and SyntaxProvider properties
Place a TacSQLBuilder component on the form to get SQL code generated by the Query Builder with formatting. Link it to the TacQueryBuilder component by setting the QueryBuilder property.
Add the TMemo or any other text editing component (for example, TSynEdit) to a form.
Now you should establish connection between the TacSQLBuilder and the TMemo components.
Enter the following code to OnExit event of TMemo component:
acQueryBuilder1.SQL := Memo1.Text;
Enter the following code to OnSQLUpdated event of TacSQLBuilder component:
Memo1.Text := acSQLBuilderPlainText1.SQL;
acQueryBuilder1.RefreshMetadata;
That's all! Now you can run your application.
And don't forget to activate your database connection component!

Drop com.adbs.querybuilder.QueryBuilder on a form using a visual form designer or create an instance programmatically.
import com.adbs.querybuilder.*; ... QueryBuilder queryBuilder1 = new QueryBuilder();
Add any text control on your form (for example, JTextPane). Handle its Focus event and put changed query text to the query builder.
jTextPane1.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent evt)
{
try
{
queryBuilder1.setSQL(jTextPane1.getText());
}
catch (QueryBuilderException ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
});Create PlainTextSQLBuilder instance and bind it to the query builder instance.
PlainTextSQLBuilder sqlBuilder = new PlainTextSQLBuilder(); sqlBuilder.setQueryBuilder(queryBuilder1);
Handle SQLUpdated event of the PlainTextSQLBuilder to receive notification about query text changes.
sqlBuilder.addSQLUpdatedEventListener(new SQLUpdatedEventListener()
{
public void sqlUpdatedEventOccurred(SQLUpdatedEvent event)
{
try
{
// set the query text to a text control
jTextPane1.setText(sqlBuilder.getSQL());
}
catch (QueryBuilderException ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage());
}
}
});Create metadata provider and supply it with SQL server connection. Set corresponding syntax provider and call the RefreshMetadata method to load objects from a database.
try
{
JdbcMetadataProvider metadataProvider = new JdbcMetadataProvider();
Class.forName("com.mysql.jdbc.Driver");
metadataProvider.setConnection(DriverManager.getConnection("jdbc:mysql://host:port/database", "user", "password"));
MySQLSyntaxProvider syntaxProvider = new MySQLSyntaxProvider();
queryBuilder1.setSyntaxProvider(syntaxProvider);
queryBuilder1.setMetadataProvider(metadataProvider);
queryBuilder1.refreshMetadata();
}
catch (ClassNotFoundException ex)
{
JOptionPane.showMessageDialog(this, "Failed to load JDBC driver: \n" + ex.getMessage());
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(this, ex.getMessage());
}That's all! Now you can run your application.