limit number of joins

Answered

Comments

3 comments

  • Avatar
    Sergey Smagin (Product manager)

    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.

    0
    Comment actions Permalink
  • Avatar
    Rujuta

    I will wait for the code. Thanks.

    0
    Comment actions Permalink
  • Avatar
    Sergey Smagin (Product manager)

    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;
    }

     

    0
    Comment actions Permalink

Please sign in to leave a comment.