The Alternate Names feature for both database objects and their fields lets completely substitute real names of objects for clearer descriptive names. User-friendly names let simplify understanding of database structure by end-users. 'Complete substitution' means replacement of objects names in both user interface, SQL expressions as well as in the query text which can be edited by end user together with visual query building. Active Query Builder lets assign an alternate name to every object and field loaded to the Metadata Container. You can get the SQL query text either with real or alternate names at any time.
The UseAltNames property determines the behaviour of specific components:
- The QueryBuilder.BehaviourOptions.UseAltNames property prescribes displaying of alternate names in the component's UI: database schema view, design pane, query columns list, etc.
- The SQLGenerationOptions and its inheritor class SQLFormattingOptions also have the UseAltNames property which determines the usage of alternate names in the generated SQL text.
Thus, the QueryBuilder.SQLGenerationOptions.UseAltNames property is applied to the QueryBuilder.SQL property and the QueryBuilder.SQLFormattingOptions.UseAltNames to the QueryBuilder.FormattedSQL property. We recommend setting the SQLGenerationOptions.UseAltNames to false to get the SQL for execution against the database server, and the SQLFormattingOptions.UseAltNames to true to display the query with friendly names to the user.
You can also specify additional sets of SQL formatting and generation options for various cases.
Some customers even use this peculiarity for refactoring of database structure by passing the suite of existing queries through the component and getting queries with new names of fields and objects in the result.
Defining alternate names
You can set them via the "alt_name" tag of fields and objects in the saved metadata XML file (manually using the or with the help of the Metadata Editor tool).
- You can set them when an object is added to the Metadata Container by handling the appropriate events. For example, you can use object descriptions loaded from the database as alternate names.
VCL and Java Editions: Use the QueryBuilder.MetadataContainer MetadataObjectLoaded (for objects) and ObjectMetadataLoaded (for fields) events during their load to the Metadata Container.
All .NET Editions: Use the QueryBuilder.MetadataContainer.ItemMetadataLoaded to change properties of newly added child items of the given item. See this event handler sample here: Adding fields and changing objects loaded in the Metadata Container.