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:
Add the following handlers in the "system.web/httpHandlers" section of your "web.config" file:
<add verb="*"
path="handlers/exchange.axd"
type="QueryBuilder.Web.Server.Handlers.Exchange, QueryBuilder.Web.Server"
/>
<add verb="*"
path="handlers/sessonKeeper.axd"
type="QueryBuilder.Web.Server.Handlers.SessionKeeper, QueryBuilder.Web.Server"
/>
Create metadata and syntax provider components in the Session_Start section of the "global.asax" file. Define a proper database connection object for the metadata provider or load metadata from the XML file. Link providers to the QueryBuilder object by setting the MetadataProvider and SyntaxProvider properties
// Initialize SessionStore.Init(Session.SessionID); // Get an instance of the QueryBuilder object for the current session ActiveDatabaseSoftware.ActiveQueryBuilder.QueryBuilder queryBuilder1 = SessionStore.Current.QueryBuilder; // Creation of a syntax provider object is needed only for the Standard version of the component. // The Free/Trial version creates and assigns the Universal syntax provider by default which can not be changed. AutoSyntaxProvider syntaxProvider = new AutoSyntaxProvider(); queryBuilder1.SyntaxProvider = syntaxProvider; // you may load metadata from the database connection using live database connection and metadata provider OleDbConnection connection = new OleDbConnection(); connection.ConnectionString = "<your connection string here>"; OLEDBMetadataProvider metadataProvider = new OLEDBMetadataProvider(); metadataProvider.Connection = connection; queryBuilder1.MetadataProvider = metadataProvider; // call the RefreshMetadata to load metadata from a database connection queryBuilder1.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);
Get content from the "web_parts" directory ("css", "img" and "js" sub-folders) and place it to your project's web-root folder.
Typical HTML code can be found in the "web_parts\index.html" file, you may add this content to your web-page.
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.