HomeActive Query Builder - Query analysis and modificationProgrammatic modification of SQL queriesHow to take additional actions after user has been added an object to the Design Pane?

2.3. How to take additional actions after user has been added an object to the Design Pane?

Active Query Builder allows to customize objects added to the Design Pane via the QueryBuilder.DatasourceAdded event.

The followng code checks all fields of the newly added datasource. The next sample illustrates adding of alias for a newly added datasource

private void queryBuilder_DatasourceAdded(UnionSubQuery query, DataSource addedObject)
{
    // Select all fields

    CriteriaList cl = query.CriteriaList;
    CriteriaItem ci;
     
    cl.BeginUpdate();
     
    try
    {
        for (int i = 0; i < addedObject.Fields.Count; i++)
        {
            ci = cl.FindField(addedObject, addedObject.Fields[i].Name);
             
            if (ci == null)
            {
                ci = cl.AddField(addedObject, addedObject.Fields[i].Name);
            }
             
            ci.Select = true;
        }
    }
    finally
    {
        cl.EndUpdate();
    }
}

 

private void queryBuilder_DatasourceAdded(UnionSubQuery query, DataSource addedObject)
{
    if (addedObject.MetadataObject != null)
    {
        using (AstTokenIdentifier alias = query.CreateUniqueAlias(addedObject.MetadataObject.Name))
        {
            addedObject.Alias = alias.Token;
        }
    }
}

This page was: Helpful | Not Helpful