The System.Data unit provides a database-agnostic layer for executing queries and managing data, with native support for SQLite.
| Method | Description |
|---|---|
Create(driver, params) |
Static factory (e.g., DataBase.Create('SQLite', ['my.db'])). |
Query(sql [, params]) |
Executes SELECT and returns a DataSet. |
Exec(sql [, params]) |
Executes non-query (INSERT/UPDATE/DELETE). |
BeginTransaction |
Starts a transaction. |
Commit / Rollback |
Transaction control. |
| Member | Description |
|---|---|
Step |
Moves to next record and returns True if one exists. Practical for loops. |
Next |
Advances to next row. Returns False if EOF. |
Eof |
Returns True if the last record has been passed. |
FieldCount |
Number of columns in the result set. |
AsString(name/idx) |
Returns field value as string (using name or 0-based index). |
AsInteger(name/idx) |
Returns field value as integer. |
AsFloat(name/idx) |
Returns field value as float. |
IsNull(name/idx) |
Returns True if the field is NULL. |
StringifyAll |
Converts entire set to JSON array string. |
uses System.Data;
var db := DataBase.Create('SQLite', [':memory:']);
db.Exec('CREATE TABLE Users (ID INTEGER, Name TEXT)');
db.Exec('INSERT INTO Users VALUES (1, "Alice")');
var ds := db.Query('SELECT Name FROM Users');
while ds.Step do
PrintLn(ds.AsString(0).ToHtml); Alice
uses System.Data;
var db := DataBase.Create('SQLite', [':memory:']);
db.Exec('CREATE TABLE Users (ID INTEGER, Name TEXT)');
db.Exec('INSERT INTO Users VALUES (1, "Alice")');
db.Exec('UPDATE Users SET Name = ? WHERE ID = ?', ['Bob', 1]); The SQLite driver is built-in. Other drivers can be registered by the host application to support PostgreSQL, MySQL, or SQL Server.