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:

PropertyTypeDefaultDescription
cHostString"localhost"Database server hostname or IP address
nPortNumericvariesServer port (driver-specific default)
cDatabaseString""Database name
cUserString""Authentication username
cPasswordString""Authentication password
lConnectedLogical.F.Current connection status (read-only)
lAutoConnectLogical.F.Automatically connect when the form is activated
cCharsetString"UTF8"Character set for the connection

Common Events

EventCategoryDescription
OnConnectConnectionSuccessfully connected to the database
OnDisconnectConnectionDisconnected from the database
OnErrorErrorConnection or query error. Params: nCode, cMessage
OnBeforeQueryQueryFired before a query executes. Params: cSQL. Return .F. to cancel
OnAfterQueryQueryFired after a query completes. Params: oResultSet, nRows

Common Methods

MethodDescription
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.

PropertyTypeDefaultDescription
cFileString""Path to the .dbf file
cAliasString""Work area alias name
lSharedLogical.T.Open in shared mode (multi-user)
lReadOnlyLogical.F.Open as read-only
cDriverString"DBFCDX"RDD driver (DBFCDX, DBFNTX, DBFNSX)

TSQLite CT_SQLITE = 54

SQLite embedded database. Zero-configuration, serverless, single-file database engine.

PropertyTypeDefaultDescription
cFileString""Path to the .db or .sqlite file
lInMemoryLogical.F.Use an in-memory database (no file)
lWALLogical.T.Enable Write-Ahead Logging for better concurrency
lForeignKeysLogical.T.Enable foreign key constraint enforcement

TMySQL CT_MYSQL = 55

MySQL / MariaDB client connector. Default port: 3306.

PropertyTypeDefaultDescription
nPortNumeric3306Server port
lSSLLogical.F.Use SSL/TLS connection
lCompressLogical.F.Enable protocol compression

TPostgreSQL CT_POSTGRESQL = 56

PostgreSQL client connector. Default port: 5432.

PropertyTypeDefaultDescription
nPortNumeric5432Server port
cSchemaString"public"Default schema
lSSLLogical.F.Use SSL/TLS connection

TFirebird CT_FIREBIRD = 57

Firebird SQL client connector. Default port: 3050.

PropertyTypeDefaultDescription
nPortNumeric3050Server port
cRoleString""SQL role name
nDialectNumeric3SQL dialect (1 or 3)

TSQLServer CT_SQLSERVER = 58

Microsoft SQL Server client connector. Default port: 1433.

PropertyTypeDefaultDescription
nPortNumeric1433Server port
lTrustedAuthLogical.F.Use Windows integrated authentication
cAppNameString""Application name for server monitoring

TOracle CT_ORACLE = 59

Oracle Database client connector. Default port: 1521.

PropertyTypeDefaultDescription
nPortNumeric1521Server port
cServiceNameString""Oracle service name (alternative to cDatabase)
cSchemaString""Default schema

TODBC CT_ODBC = 60

Generic ODBC connector. Connects to any database with an ODBC driver.

PropertyTypeDefaultDescription
cDSNString""ODBC Data Source Name
cConnStringString""Full ODBC connection string (overrides individual properties)

TADOConnection CT_ADO = 61

ADO (ActiveX Data Objects) connector. Windows-only. Connects to any OLE DB provider.

PropertyTypeDefaultDescription
cProviderString""OLE DB provider name
cConnStringString""Full ADO connection string
PlatformAvailability
WindowsFull support via COM/OLE
macOSNot available
LinuxNot 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.

On This Page

Common Properties Common Events Common Methods TDBFTable CT_DBFTABLE = 53 TSQLite CT_SQLITE = 54 TMySQL CT_MYSQL = 55 TPostgreSQL CT_POSTGRESQL = 56 TFirebird CT_FIREBIRD = 57 TSQLServer CT_SQLSERVER = 58 TOracle CT_ORACLE = 59 TODBC CT_ODBC = 60 TADOConnection CT_ADO = 61 Code Example: SQLite Database