Data Access Controls
The Data Access tab provides 9 database components for connecting to local and remote databases. All components share a common interface for connection management and query execution.
Common Properties
All database components (except TDBFTable) share these connection properties:
| Property | Type | Default | Description |
cHost | String | "localhost" | Database server hostname or IP address |
nPort | Numeric | varies | Server port (driver-specific default) |
cDatabase | String | "" | Database name |
cUser | String | "" | Authentication username |
cPassword | String | "" | Authentication password |
lConnected | Logical | .F. | Current connection status (read-only) |
lAutoConnect | Logical | .F. | Automatically connect when the form is activated |
cCharset | String | "UTF8" | Character set for the connection |
Common Events
| Event | Category | Description |
OnConnect | Connection | Successfully connected to the database |
OnDisconnect | Connection | Disconnected from the database |
OnError | Error | Connection or query error. Params: nCode, cMessage |
OnBeforeQuery | Query | Fired before a query executes. Params: cSQL. Return .F. to cancel |
OnAfterQuery | Query | Fired after a query completes. Params: oResultSet, nRows |
Common Methods
| Method | Description |
Connect() | Open a connection to the database server |
Disconnect() | Close the connection |
Execute( cSQL ) | Execute a SQL statement (INSERT, UPDATE, DELETE). Returns nAffectedRows |
Query( cSQL ) | Execute a SELECT query. Returns an oResultSet object |
BeginTrans() | Start a transaction |
Commit() | Commit the current transaction |
Rollback() | Roll back the current transaction |
TDBFTable CT_DBFTABLE = 53
Native xBase DBF table access. Provides direct access to DBF/NTX/CDX files without a server. The classic Harbour/Clipper data format.
| Property | Type | Default | Description |
cFile | String | "" | Path to the .dbf file |
cAlias | String | "" | Work area alias name |
lShared | Logical | .T. | Open in shared mode (multi-user) |
lReadOnly | Logical | .F. | Open as read-only |
cDriver | String | "DBFCDX" | RDD driver (DBFCDX, DBFNTX, DBFNSX) |
TSQLite CT_SQLITE = 54
SQLite embedded database. Zero-configuration, serverless, single-file database engine.
| Property | Type | Default | Description |
cFile | String | "" | Path to the .db or .sqlite file |
lInMemory | Logical | .F. | Use an in-memory database (no file) |
lWAL | Logical | .T. | Enable Write-Ahead Logging for better concurrency |
lForeignKeys | Logical | .T. | Enable foreign key constraint enforcement |
TMySQL CT_MYSQL = 55
MySQL / MariaDB client connector. Default port: 3306.
| Property | Type | Default | Description |
nPort | Numeric | 3306 | Server port |
lSSL | Logical | .F. | Use SSL/TLS connection |
lCompress | Logical | .F. | Enable protocol compression |
TPostgreSQL CT_POSTGRESQL = 56
PostgreSQL client connector. Default port: 5432.
| Property | Type | Default | Description |
nPort | Numeric | 5432 | Server port |
cSchema | String | "public" | Default schema |
lSSL | Logical | .F. | Use SSL/TLS connection |
TFirebird CT_FIREBIRD = 57
Firebird SQL client connector. Default port: 3050.
| Property | Type | Default | Description |
nPort | Numeric | 3050 | Server port |
cRole | String | "" | SQL role name |
nDialect | Numeric | 3 | SQL dialect (1 or 3) |
TSQLServer CT_SQLSERVER = 58
Microsoft SQL Server client connector. Default port: 1433.
| Property | Type | Default | Description |
nPort | Numeric | 1433 | Server port |
lTrustedAuth | Logical | .F. | Use Windows integrated authentication |
cAppName | String | "" | Application name for server monitoring |
TOracle CT_ORACLE = 59
Oracle Database client connector. Default port: 1521.
| Property | Type | Default | Description |
nPort | Numeric | 1521 | Server port |
cServiceName | String | "" | Oracle service name (alternative to cDatabase) |
cSchema | String | "" | Default schema |
TODBC CT_ODBC = 60
Generic ODBC connector. Connects to any database with an ODBC driver.
| Property | Type | Default | Description |
cDSN | String | "" | ODBC Data Source Name |
cConnString | String | "" | Full ODBC connection string (overrides individual properties) |
TADOConnection CT_ADO = 61
ADO (ActiveX Data Objects) connector. Windows-only. Connects to any OLE DB provider.
| Property | Type | Default | Description |
cProvider | String | "" | OLE DB provider name |
cConnString | String | "" | Full ADO connection string |
| Platform | Availability |
| Windows | Full support via COM/OLE |
| macOS | Not available |
| Linux | Not available |
Code Example: SQLite Database
// Connecting to an SQLite database and querying data
FUNCTION Main()
LOCAL oDB, oRS
// Create and configure the SQLite connection
oDB := TSQLite():New()
oDB:cFile := "myapp.db"
oDB:lWAL := .T.
oDB:OnError := { |n, c| QOut( "DB Error: " + c ) }
// Connect and create a table
oDB:Connect()
oDB:Execute( "CREATE TABLE IF NOT EXISTS customers (" + ;
" id INTEGER PRIMARY KEY AUTOINCREMENT," + ;
" name TEXT NOT NULL," + ;
" email TEXT," + ;
" city TEXT )" )
// Insert some records
oDB:Execute( "INSERT INTO customers (name, email, city) VALUES ('John', 'john@test.com', 'NYC')" )
oDB:Execute( "INSERT INTO customers (name, email, city) VALUES ('Maria', 'maria@test.com', 'Madrid')" )
// Query data
oRS := oDB:Query( "SELECT * FROM customers ORDER BY name" )
DO WHILE ! oRS:Eof()
QOut( oRS:FieldGet( "name" ), oRS:FieldGet( "email" ) )
oRS:MoveNext()
ENDDO
oRS:Close()
oDB:Disconnect()
RETURN NIL
9 Data Access Controls
All SQL-based components share the same Query/Execute interface. Switch databases by simply changing the
component class -- your application code stays the same. TDBFTable uses the classic xBase navigation model.