[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'SQLDB' (#fcl)

# TSQLQuery

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

Class to handle SQL commands (with or without result set)

## Declaration

Source position: sqldb.pp line 656

`type TSQLQuery = class(TCustomSQLQuery)`
`public`
`property SchemaType: TSchemaType;` |  | Schema type
`property StatementType: TStatementType;` |  | SQL statement type
`published`
`property MaxIndexesCount: Integer;` |  | Maximum allowed number of indexes.
`property FieldDefs: TFieldDefs;` |  | Definitions of available fields in the underlying database
`property Active: Boolean;` |  | Is the dataset open or closed.
`property AutoCalcFields: Boolean;` |  | How often should the value of calculated fields be calculated
`property Filter: string;` |  | Filter to apply to the data in memory.
`property Filtered: Boolean;` |  | Is the filter active or not.
`property AfterCancel: TDataSetNotifyEvent;` |  | Event triggered after a Cancel operation.
`property AfterClose: TDataSetNotifyEvent;` |  | Event triggered after the dataset is closed
`property AfterDelete: TDataSetNotifyEvent;` |  | Event triggered after a successful Delete operation.
`property AfterEdit: TDataSetNotifyEvent;` |  | Event triggered after the dataset is put in edit mode.
`property AfterInsert: TDataSetNotifyEvent;` |  | Event triggered after the dataset is put in insert mode.
`property AfterOpen: TDataSetNotifyEvent;` |  | Event triggered after the dataset is opened.
`property AfterPost: TDataSetNotifyEvent;` |  | Event called after changes have been posted to the underlying database
`property AfterRefresh: TDataSetNotifyEvent;` |  | Event triggered after the data has been refreshed.
`property AfterScroll: TDataSetNotifyEvent;` |  | Event triggered after the cursor has changed position.
`property BeforeCancel: TDataSetNotifyEvent;` |  | Event triggered before a Cancel operation.
`property BeforeClose: TDataSetNotifyEvent;` |  | Event triggered before the dataset is closed.
`property BeforeDelete: TDataSetNotifyEvent;` |  | Event triggered before a Delete operation.
`property BeforeEdit: TDataSetNotifyEvent;` |  | Event triggered before the dataset is put in edit mode.
`property BeforeInsert: TDataSetNotifyEvent;` |  | Event triggered before the dataset is put in insert mode.
`property BeforeOpen: TDataSetNotifyEvent;` |  | Event triggered before the dataset is opened.
`property BeforePost: TDataSetNotifyEvent;` |  | Event called before changes are posted to the underlying database
`property BeforeRefresh: TDataSetNotifyEvent;` |  | Event triggered before the data is refreshed.
`property BeforeScroll: TDataSetNotifyEvent;` |  | Event triggered before the cursor changes position.
`property OnCalcFields: TDataSetNotifyEvent;` |  | Event triggered when values for calculated fields must be computed.
`property OnDeleteError: TDataSetErrorEvent;` |  | Event triggered when a delete operation fails.
`property OnEditError: TDataSetErrorEvent;` |  | Event triggered when an edit operation fails.
`property OnFilterRecord: TFilterRecordEvent;` |  | Event triggered to filter records.
`property OnNewRecord: TDataSetNotifyEvent;` |  | Event triggered when a new record is created.
`property OnPostError: TDataSetErrorEvent;` |  | Event triggered when a post operation fails.
`property Database: TDataBase;` |  | The TSQLConnection instance on which to execute SQL Statements
`property Transaction: TDBTransaction;` |  | Transaction in which to execute SQL statements
`property ReadOnly: Boolean;`
`property SQL: TStringList;` |  | The SQL statement to execute
`property InsertSQL: TStringList;` |  | Statement to be used when inserting a new row in the database
`property UpdateSQL: TStringList;` |  | Statement to be used when updating an existing row in the database
`property DeleteSQL: TStringList;` |  | Statement to be used when deleting a new row in the database
`property RefreshSQL: TStringList;` |  | Refresh query to re-fetch field values after a DB update
`property IndexDefs: TIndexDefs;` |  | Index definitions for the dataset
`property Options: TSQLQueryOptions;` |  | Options controlling the behaviour of the dataset
`property Params: TParams;` |  | Parameters detected in the SQL statement.
`property ParamCheck: Boolean;` |  | Should the SQL statement be checked for parameters
`property Macros: TParams;` |  | Set of macros for this SQL statement.
`property MacroCheck: Boolean;` |  | Check for macros in the SQL statement.
`property MacroChar: Char;` |  | Macro delimiter character
`property ParseSQL: Boolean;` |  | Should the SQL statement be parsed or not
`property UpdateMode: TUpdateMode;` |  | How to create update SQL statements.
`property UsePrimaryKeyAsKey: Boolean;` |  | Should primary key fields be marked pfInKey
`property DataSource: TDataSource;` |  | Source for parameter values for unbound parameters
`property Sequence: TSQLSequence;` |  | Sequence to use for auto-generating values using a sequence
`property ServerFilter: string;` |  | Append server-side filter to SQL statement
`property ServerFiltered: Boolean;` |  | Should server-side filter be applied
`property ServerIndexDefs: TServerIndexDefs;` |  | List of indexes on the primary table of the query
`end;`

## Inheritance

`TSQLQuery` |  | Class to handle SQL commands (with or without result set)
`TCustomSQLQuery` |  | Custom Class to handle SQL commands (with or without result set)
`TCustomBufDataset` |  | Dataset connected to a database.
`TDBDataset` |  | Dataset connected to a database.
`TDataSet` |  | Base class for records-based data-access
`TComponent,IUnknown,IInterfaceComponentReference`
`TPersistent,IFPObserved`
`TObject`

## Description

TSQLQuery exposes the properties and some methods introduced in TCustomSQLQuery. It encapsulates a single SQL statement: it implements all the necessary #fcl.db.TDataset functionality to be able to handle a result set. It can also be used to execute a single SQL statement that does not return data, using the TCustomSQLQuery.ExecSQL method.

Typically, the TSQLQuery.Database property must be set once, the TSQLQuery.Transaction property as well. Then the TSQLQuery.SQL property can be set. Depending on the kind of SQL statement, the Open method can be used to retrieve data, or the ExecSQL method can be used to execute the SQL statement (this can be used for DDL statements, or update statements).

## See also

TSQLTransaction |  | Transaction in which a TSQLQuery is handled
TSQLConnection |  | An abstract class representing a connection to a SQL Database
TCustomSQLQuery.ExecSQL |  | Execute a SQL statement that does not return a result set
TSQLQuery.SQL |  | The SQL statement to execute

Documentation generated on: May 14 2021