Executing a query at runtime

From InterBase
Jump to: navigation, search

Go Up to Executing a query


To execute a query at runtime, use one of the following methods:

  • Open executes a query that returns a result set, such as with the SELECT statement.
  • ExecSQL executes a query that does not return a result set, such as with the INSERT, UPDATE, or DELETE statements.
Note: If you do not know at design time whether a query will return a result set at runtime, code both types of query execution statements in a try...except block. Put a call to the Open method in the try clause. This allows you to suppress the error message that would occur due to using an activate method not applicable to the type of SQL statement used. Check the type of exception that occurs. If it is other than an ENoResult exception, the exception occurred for another reason and must be processed. This works because an action query will be executed when the query is activated with the Open method, but an exception occurs in addition to that.
try
  IBQuery2.Open;
except
  on E: Exception do
    if not (E is ENoResultSet) then
      raise;
end;

Topics