Skip to main content

sqlite3_open

Opens a connection to a database file. If the file does not exist it is created.
int sqlite3_open(const char *filename, sqlite3 **db_out);
filename
const char *
required
Path to the database file. Pass ":memory:" to open an in-memory database.
db_out
sqlite3 **
required
Output pointer that receives the database connection handle. Always set, even on error — call sqlite3_close() to release it.
Returns SQLITE_OK on success, or an error code. Call sqlite3_errmsg() for a description of the error.
sqlite3 *db;
if (sqlite3_open("app.db", &db) != SQLITE_OK) {
    fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return 1;
}

sqlite3_open_v2

Like sqlite3_open, but accepts flags and a VFS name.
int sqlite3_open_v2(
    const char *filename,
    sqlite3   **db_out,
    int         flags,
    const char *z_vfs
);
filename
const char *
required
Path to the database file or ":memory:".
db_out
sqlite3 **
required
Output pointer for the connection handle.
flags
int
required
Open mode flags. The _flags parameter is accepted but currently treated as advisory — Turso opens the database according to its own defaults.
z_vfs
const char *
Name of the VFS to use, or NULL for the default.
Returns intSQLITE_OK on success.

sqlite3_close

Closes a database connection and releases all associated resources. All prepared statements must be finalized before calling this function.
int sqlite3_close(sqlite3 *db);
db
sqlite3 *
required
The database connection to close.
Returns SQLITE_OK, or SQLITE_BUSY if there are unfinalized statements.
sqlite3_close(db);

sqlite3_errmsg

Returns a human-readable description of the most recent error on the connection.
const char *sqlite3_errmsg(sqlite3 *db);
db
sqlite3 *
required
The database connection.
Returns const char * — a null-terminated UTF-8 string. The pointer is valid until the next API call on db.
fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db));

sqlite3_errcode

Returns the numeric error code of the most recent error on the connection.
int sqlite3_errcode(sqlite3 *db);
db
sqlite3 *
required
The database connection.
Returns int — one of the SQLITE_* result code constants.

Build docs developers (and LLMs) love