RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TDatabase.Execute Method

Executes an SQL statement.

Pascal
function Execute(const SQL: string; Params: TParams = nil; Cache: Boolean = False; Cursor: phDBICur = nil): Integer;
C++
__fastcall int Execute(const AnsiString SQL, TParams Params = nil, Boolean Cache = False, phDBICur Cursor = nil);

Use Execute to execute an SQL statement against the database without the overhead of using a TQuery object. Execute supports Data Definition Language (DDL) SQL statements and those Data Manipulation Language (DDL) SQL statements that do not return result sets. Examples of DDL statements include: CREATE INDEX, ALTER TABLE, and DROP DOMAIN. The DML statements that perform an action on data but do not return a result set are: INSERT, DELETE, and UPDATE. 

SQL is a string value containing the statement to be executed. 

Params is a value of type TParams and lists any parameters used by the SQL statement. Parameter binding is by index only (not by name). The TParam objects in Params must be in the same order as the the parameters in the SQL statement to which each corresponds. Use the CreateParam method (TParams) to create one TParams object for each parameter in the SQL statement. Use properties and methods of TParam to configure each TParam and to give each a value prior to calling Execute. If the SQL statement does not include any parameters, pass a nil (Delphi) or NULL (C++) value for Params

Cache specifies whether the prepared SQL statement is cached for reuse within the current transaction. Caching statements can speed their processing if they are used more than once in a transaction. 

Cursor allows you to execute a SELECT statement and from it create a Borland Database Engine (BDE) dataset. If SQL is a SELECT statement, Cursor returns the BDE cursor to the result set. Cursor is a pointer to an already existing BDE cursor. There is currently no provision in the VCL to assign the cursor created by this parameter to a dataset component (like TTable). This limits its use to cursors subsequently operated on using BDE API code. The result set returned in Cursor is always read-only. If the SQL statement does not return a result set, pass a nil (Delphi) or NULL (C++) value for Cursor. 

Execute returns the number of records affected by executing the SQL statement. 

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!