Active Query Builder support area

limit number of joins

Avatar
  • updated
  • Completed

Hi 

I need to put a limit on the number of joins / number of tables the user can drag in the design pane. So if the user exceeds the max number allowed, there should be an alert for the same, 

 

Thanks

Avatar
Andrey Zavyalov, PM

Hello, Rujuta.

Below are two code samples to deal with this task.

The first approach is to analyse the whole query. This seems a bit overboard, but you can do this only after loading the query from a file, not on each query update.

The second is to handle the QueryBuilder.DataSourceAdding. There you can warn the user on reaching a certain amount of tables in a sub-query, and/or deny adding when this number exceeds a reasonable limit.

The 1st variant:

private void queryBuilder1_SQLUpdated(object sender, EventArgs e)
{
const int MAX_DATASOURCES = 10;

var unionSubQueriesList = queryBuilder1.SQLQuery.QueryRoot.GetChildrenRecursive<UnionSubQuery>(true);
foreach (var unionSubQuery in unionSubQueriesList)
{
var dataSourcesCount = unionSubQuery.GetChildrenRecursive<DataSource>(false).Count;
if (dataSourcesCount > MAX_DATASOURCES)
{
// switch design pane to the over-complicated SELECT
queryBuilder1.ActiveUnionSubQuery = unionSubQuery;
MessageBox.Show("Keep it simple!");
}
}

// ...
}

The 2nd variant:

private void queryBuilder1_DataSourceAdding(MetadataObject fromObject, ref bool abort)
{
const int MAX_DATASOURCES = 4;

var unionSubQuery = queryBuilder1.ActiveUnionSubQuery;
var count = unionSubQuery.GetChildrenRecursive<DataSource>(false).Count;

abort = count >= MAX_DATASOURCES;
}

 

Avatar
Rujuta

I will wait for the code. Thanks.

Avatar
Andrey Zavyalov, PM

Thank you for a good question!

This task can be solved by handing the QueryBuilder.DataSourceAdding event in which you can deny the addition of new objects. We will provide the code sample tomorrow.

Meanwhile, you can review the QueryUIEventsDemo project included in the installation project and available on the GitHub.