Active Query Builder support area

How to detect incorrect/unknown object and field names in the query?

Last modified:

On parsing a query, the component gets objects listed in the FROM clause of the query and tries to find corresponding objects in the Metadata Container. Of course, the Metadata Container should be duly filled with database objects to find the correspondence. You can fill it by connecting Active Query Builder to a live database connection or you can pre-load the Metadata Container from the XML file.

Two collections list objects and fields in the query: QueryBuilder.QueryStatistics.UsedDatabaseObjects and QueryBuilder.QueryStatistics.UsedDatabaseObjectFields. Each item in these collections has the MetadataObject property that refers to the MetadataItem object contained in the MetadataContainer. If an item has the null reference in the MetadataObject property, this may indicate that this object does not exist in the database.

Another reason for failure might be that objects in the query are typed with omitted database or schema names, while the appropriate database and schema objects are incorrectly marked as default in the Metadata Container. Incorrect omission usually arises when the query has been written on behalf of another database user. In this case, the database server itself will fail to execute such a query.

For some reason, you may want to deny parsing of queries with incorrect object names by setting the QueryBuilder.BehaviorOptions.ParsingErrorOnUnknownObjects property to True.

Is this article helpful for you?