Skip to content

Pascal scripting API

This is the reference for the classes available to Pascal scripts. The API centres on two classes — TSQLiteDatabase, which represents a connection to a database, and TSQLiteQuery, which runs SQL and exposes its result set — together with helper routines such as DisplayData(). For complete, runnable examples, see Scripting examples.

The TSQLiteDatabase class

constructor Create(AOwner: TComponent) 

Creates and returns a new instance of a TSQLiteDatabase object. 

property FileName: string; 

Sets or retrieves the value of the filename associated with the database object. The filename must point to an existing SQLite3 database, or :memory: for opening an in- memory database. 

property Connected: Boolean; 

When called with an argument, connects or disconnects the database to the filename set by the FileName property. Returns True if connected to the database. 

procedure Open; 

Connects to the database. Similar to calling Connected(True) except it does not return a value. 

procedure Close; 

Disconnects from database. Similar to calling Connected(False) except it does not return a value. 

procedure Execute(const SQL: string); 

Executes an SQL statement in the current database. 

procedure BeginTransaction; 

Starts a transaction. 

procedure Commit; 

Commits the current transaction. 

procedure Rollback; 

Rolls back the current transaction. 

property InTransaction: Boolean; 

Returns True if a transaction is active, and False otherwise. 

procedure Free; 

Destroys the object and frees its associated memory. 

The TSQLiteQuery class

TSQLiteQuery represents a dataset with a result set that is based on an SQL statement.

constructor Create(AOwner: TComponent); 

Creates and returns a new instance of a sqlitequery object. 

property Database: TSQLiteDatabase; 

Specifies the database object associated with the query. 

property Active: Boolean; 

Specifies whether or not the dataset is open. 

procedure Open; 

Opens the query by executing the SQL statement. Similar to calling 

Active := True. 

If the SQL statement returns a cursor the following functions and properties can be used to iterate through the result set: First, Last, Next, Prior, Eof, Bof. 

procedure Close; 

Closes the query. 

property Eof: Boolean; 

Test eof (end of file) to determine if the dataset is positioned at the last record. 

property Bof: Boolean; 

Test bof (beginning of file) to determine if the dataset is positioned at the first record. 

procedure F``irst;

Moves to the first record in the dataset.

procedure Last; 

Moves to the last record in the dataset. 

procedure Next; 

Moves to the next record in the dataset. 

procedure Prior; 

Moves to the previous record in the dataset. 

procedure Edit; 

Enables editing of data in the dataset. 

procedure Post; 

Writes the modified record to the database. 

procedure Insert; 

Inserts a new, empty record in the dataset. 

procedure D``elete;

Deletes the active record and positions the dataset on the next record.

procedure Cancel; 

Cancels modifications to the active record if those changes are not yet posted. 

property RecordCount: Integer; 

Indicates the total number of records associated with the dataset. Note: the value returned by this property is only valid after reaching the last record in the dataset. 

property RecNo: Integer; 

Indicates the active record in the dataset. 

property FieldCount: Integer; 

Indicates the number of field components associated with the dataset. 

function FieldByName(const Value: string): TField; 

Finds a field based on its name. Returns a TField object, or nil if the field was not found. 

function Fields(const Index: Integer): TField; 

Finds a field based on its index. Returns a TField object. An 'index out of range' error occurs if the Index is < 0 or >= FieldCount. 

property SQL: string; 

Sets or retrieves the text of the SQL statement to execute for the query. 

procedure Free; 

Destroys the object and frees its associated memory. 

The TField class

property FieldName: string; 

Returns the name of the field. 

property Value: Variant; 

Sets or retrieves the value of the field in the current record, as a variant. To set the value of the field, the dataset must be in the Edit mode, set by a previous call to Insert or Edit. 

property AsString: string; 

Sets or retrieves the value of the field in the current record, as string. To set the value of the field, the dataset must be in the Edit mode, set by a previous call to Insert or Edit. 

property AsFloat: Double; 

Sets or retrieves the value of the field in the current record, as a floating point number. To set the value of the field, the dataset must be in the Edit mode, set by a previous call to Insert or Edit. 

property AsBoolean: Boolean; 

Sets or retrieves the value of the field in the current record, as a boolean value. To set the value of the field, the dataset must be in the Edit mode, set by a previous call to Insert or Edit. 

property Size: Integer; 

Indicates the size used in the definition of the physical database field for data types that support different sizes.