Preparing Queries

From RAD Studio
Jump to: navigation, search

Go Up to Using Query-type Datasets


Preparing a query is an optional step that precedes query execution. Preparing a query submits the SQL statement and its parameters, if any, to the data access layer and the database server for parsing, resource allocation, and optimization. In some datasets, the dataset may perform additional setup operations when preparing the query. These operations improve query performance, making your application faster, especially when working with updatable queries.

An application can prepare a query by setting the Prepared property to True. If you do not prepare a query before executing it, the dataset automatically prepares it for you each time you call Open or ExecSQL. Even though the dataset prepares queries for you, you can improve performance by explicitly preparing the dataset before you open it the first time.

CustQuery.Prepared := True;
CustQuery->Prepared = true;

When you explicitly prepare the dataset, the resources allocated for executing the statement are not freed until you set Prepared to False.

Set the Prepared property to False if you want to ensure that the dataset is re-prepared before it executes (for example, if you add a parameter).

Note: When you change the text of the SQL property for a query, the dataset automatically closes and unprepares the query.

See Also