Using the C1Query Control to Generate SQL > Generating SQL Statements > Errors in SQL Generation |
If generation fails, the BuildSQL method returns False. SQL generation can fail for the following reasons (for a complete list of possible errors, see Error Codes):
There is an error in the schema. Schema errors are detected in the schema designer when you save a schema or select Verify schema from the Schema menu. To avoid such errors, it is recommended that you correct all schema errors before using the control to generate SQL. Schema errors trigger the C1Query Error event in the C1Query control.
There is an error in the user query. For example, the field name has not been specified in a query item. Such errors trigger the Error event in the C1QueryFrame control where the incorrect item has been found. To find out which item is responsible for the error, use the ErrorItemID property.
The user query contains fields that are unrelated one to another, there is no natural SQL statement including all these fields. This error triggers the Error event in the C1Query control. This error usually means that the user query is incomplete, can be completed by adding an additional field(s), usually from another folder, connecting the existing fields, or it may be the opposite: the user could mistakenly enter a field that does not relate to other fields in the query. If your schema is correct and contains enough relationships to connect all fields that are supposed to be connected, this error will occur only in situations where the user makes an obvious mistake, and specifies a query that does not make sense. For details about relating fields to each other and managing the “unrelated fields” situations, see Managing Query Extensions. See also Relationships, Join Groups and Extensions in Schema Designer.
The Error event allows the programmers to intercept the error and replace the default error handling (message box) with one of their own.