SQLite-backed tables
OpenADS can open and drive a SQLite database through the same
ACE / rddads surface used for DBF / ADT tables. From the point of
view of a Harbour / Clipper / X# application the SQLite table
behaves like an ordinary work area — navigation (Skip,
GoTop, GoBottom), field read/write, and the standard Ads*
calls all work.
Requirements
- OpenADS built with
OPENADS_WITH_SQLITE— this is ON by default inCMakeLists.txt(the SQLite amalgamation is vendored via FetchContent). - The connection URI must start with
sqlite://followed by the path to the.dbfile.
How it works
The SQLite path is selected entirely by the connection URI.
AdsConnect60 calls parse_sqlite_uri(); when the URI matches
sqlite://… it opens a SqliteConnection instead of the native
DBF/CDX engine. Every later ACE call (AdsOpenTable90,
AdsGetField, AdsSetField, AdsSkip, AdsSeek,
AdsCreateIndex61, …) is routed to the SQLite backend.
1. Connect with a sqlite:// URI
LOCAL hConn
AdsConnect60( "sqlite:///path/to/database.db", ;
ADS_LOCAL_SERVER, NIL, NIL, 0, @hConn )
The third slash is the leading / of the absolute file path, so
sqlite:///tmp/app.db opens /tmp/app.db.
2. Open an existing table
Through rddads the table opens like any other work area:
USE customers VIA "ADSCDX" NEW SHARED
(X# applications use the AXDBFCDX RDD; the ACE-level routing is
identical.)
Field-type mapping
The field type is inferred from the SQLite column’s declared type (case-insensitive substring match):
| SQLite declared type contains | OpenADS field type | Length |
|---|---|---|
INT |
Integer | 4 |
REAL / FLOA / DOUB |
Double | 8 (6 dec) |
BLOB |
Binary | 10 |
anything else (e.g. TEXT) |
Character | 64 |
Encryption
A cipher key can be supplied as a query parameter; it is URL-decoded before use:
AdsConnect60( "sqlite:///path/db.sqlite?key=mypassword", ;
ADS_LOCAL_SERVER, NIL, NIL, 0, @hConn )
Current limitations
- Open only —
AdsCreateTabledoes not create SQLite tables. Passing a SQLite connection handle falls back to the native DBF path; create the schema in SQLite directly instead. - Indexes are exposed as
SqliteIndexwith basic seek / next / prev that map toORDER BYqueries. - Transactions map to ordinary SQLite transactions.
Other SQL backends (OpenADS Plus)
SQLite is one of four SQL backends selected the same way — by the connection URI. PostgreSQL, MariaDB / MySQL and any ODBC-reachable engine are also supported behind the ACE ABI:
| Backend | Connection URI |
|---|---|
| SQLite | sqlite:///path/to/db.sqlite[?key=…] |
| PostgreSQL | postgresql://user:pass@host:5432/dbname |
| MariaDB / MySQL | mariadb://user:pass@host:3306/dbname |
| ODBC (any) | odbc://Driver={…};Server=…;Database=…;UID=…;PWD=… |
All four sit behind a single pluggable backend-ops registry
(one BackendTableOps struct + one registration line per
backend), so the ABI navigation / field functions stay
backend-agnostic. Read + navigation + column SEEK work today;
write is per-backend. Identifiers are restricted to safe ASCII and
SEEK values use prepared-statement parameters. See
docs/OPENADS_PLUS.md.