ComponentOne Query 8.0
Changing Query Items for the Duration of SQL Generation

To enable full control over the process of generating SQL statements, C1Query allows the developer to modify the collection of query items for the duration of SQL generation. Developers can modify the whole collection of query items modifying any property of any query item and also adding and removing items. This can be done in the following events: BeforeSQLGeneration, BeforeSQLGeneration and SQLGenerationItem.

All modifications to query items made in these events are temporary. They have effect only for the current SQL generation process. SQL generation is initiated when the BuildSQL method is called. After this method returns, all changes to query items made in the aforementioned events are retracted. This enables programmatic control over the SQL generation process without affecting the user query shown in C1QueryFrame controls.

Calling the BuildSQL method triggers the following sequence of events (assuming there are two C1QueryFrame controls attached to a C1Query control):

Example Title
Copy Code
C1QueryFrame1.BeforeSQLGeneration

C1QueryFrame1.SQLGenerationItem for the 1st query item

C1QueryFrame1.SQLGenerationItem for the 2nd query item

...

C1QueryFrame2.BeforeSQLGeneration

C1QueryFrame2.SQLGenerationItem for the 1st query item

C1QueryFrame2.SQLGenerationItem for the 2nd query item

...

C1Query.BeforeSQLGeneration

BeforeSQLGeneration events can be used to modify the collection of query items as a whole, adding and deleting items. Note that it is not necessary to delete an item in order to exclude it from generation, you can set its Checked property to False instead.

The SQLGenerationItem event provides a simplified way of modifying query items. It is fired for every query item, so you don't need to navigate through query items to make modifications (which is necessary if you do it in BeforeSQLGeneration event). In most cases, it is sufficient to use the SQLGenerationItem event, write some simple code modifying a query item passed to that event. In more complicated cases, when you need to manipulate the query items collection as a whole, use BeforeSQLGeneration and BeforeSQLGeneration events.

For an example on how to modify query items during SQL generation, see the SQLGenerationItem sample in the SAMPLES directory.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback