uce/site/doc/pages/sqlite_connect.txt
2026-06-16 23:02:45 +00:00

35 lines
1.0 KiB
Plaintext

:sig
SQLite* sqlite_connect(String path)
:params
path : filesystem path to the SQLite database file
return value : pointer to a SQLite connection struct
:see
>sqlite
sqlite_query
sqlite_error
sqlite_disconnect
:content
Opens an SQLite database file and returns a connection handle.
UCE opens SQLite with serialized/full-mutex connection mode, sets a busy timeout, enables foreign keys, and applies WAL-oriented defaults:
```sql
PRAGMA busy_timeout = 5000;
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
```
SQLite itself handles file locking and one-writer/many-reader concurrency. UCE does not add a separate app-level database lock.
Connections are registered for request cleanup, but explicit `sqlite_disconnect()` is still preferred when you are done with the handle.
:example
SQLite* db = sqlite_connect("/tmp/doc-sqlite-connect.db");
sqlite_query(db, "create table if not exists t(id integer primary key, name text)");
print(db != 0 ? "connected" : "failed to connect", "\n");
sqlite_disconnect(db);