Builds meta-queries from templates, dynamically generating a set of input fields for the place holders within a meta-query template, then letting the user enter values in any or all fields, and finally returning a finished meta-query.
For a list of all members of this type, see QueryPicker Members.
System.Object
MarshalByRefObject
Component
Control
ScrollableControl
ContainerControl
UserControl
QueryPicker
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
This control is handy for certain predefined meta-queries:
Each of these queries are specified as a separate template for both Sql Server and Oracle. Each template contains place holders of the form {name} for any parameters that the user needs to supply at runtime, e.g. a table or column filter, an owner name (for Oracle). For any place holder so defined, when a given query template is selected on the control, it will dynamically generate TextBox input fields for each. You eventually call the ProcessInputs method back in your main line code, which then makes two values available via properties: Query and Description. (Eventually, the control will allow specifying arbitrary meta-queries via some configuration file.) Here is one example of a meta-query template for Oracle, where there are three place holders, for Owner, Column, and Table. The final clause in the where predicate filters out any table names containing underscores or dollar signs, which seems to be a reasonable choice for limiting the noise. Note that due to the like operators, the user is free to either specify a specific value for a field or to include wildcards (%).
select table_name as TableName, column_name as ColumnName
from sys.ALL_TAB_COLS
where owner LIKE '{Owner}'
and column_name LIKE '{Column}'
and table_name LIKE '{Table}'
and not regexp_like(table_name, '[$_]', 'i')
order by table_name, column_name
This example code fragment shows instrumenting your main program by preparing via the (Setup method, invoking a separate query-picker form as a dialog, then processing the results.
queryForm.Setup(dbType, connectionDetails);
queryForm.ShowDialog();
if (queryForm.Query.Length > 0)
{
queryTextBox.AppendText("\n\n" +
SQL_COMMENT + " " + queryForm.Description + "\n" +
queryForm.Query);
queryTextBox.Find(queryForm.Query);
if ((!queryForm.Query.StartsWith(SQL_COMMENT) || queryForm.Query.Contains("\n"))
&& queryForm.Query.Length > 0)
{ RefreshQueryResult(); }
}
The queryForm above requires very little to interface with the control, shown here:
public partial class StandardQueryPickerForm : Form
{
public StandardQueryPickerForm()
{
InitializeComponent();
}
public string Query
{
get { return queryPicker.Query; }
}
public string Description
{
get { return queryPicker.Description; }
}
public void Setup(ConnectionStringManager.DBTypes dbType,
ConnectionDetails connectionDetails)
{
queryPicker.Setup(dbType, connectionDetails);
}
private void executeButton_Click(object sender, EventArgs e)
{
queryPicker.ProcessInputs();
if (Query.Length > 0) { Close(); }
}
private void cancelButton_Click(object sender, EventArgs e)
{
Close();
}
}
Since CleanCode 0.9.19.
Namespace: CleanCodeControls.Forms
Assembly: CleanCodeControls (in CleanCodeControls.dll)
QueryPicker Members | CleanCodeControls.Forms Namespace