RADLib
RADical C++ application framework

RADDatabase provides a compact SQLite wrapper for application data, settings, browser-style history/bookmark stores, local caches, and embedded metadata. It favors explicit result objects and boolean status returns over hidden exception flow for routine SQL failures.

RADSqlDatabase owns a SQLite connection. It derives from RADCore::RADObject and raises an errorOccurred(std::string) event when open, execute, query, or transaction handling fails. After setFileName(), call open()/close() and check isOpen() or lastError(). execute() runs statements that need no rows, while query() returns a RADSqlResult. queryAsync() runs a query on a RADCore::RADThreadPool and posts completion to an EventLoop as a RADCore::RADFutureT<RADSqlResult>. Schema evolution is handled by schemaVersion() and migrateTo(), which applies ordered migrations from the rad_schema_version table.

RADSqlResult is a value object holding the returned rows. Each row is a RADSqlRow (a std::map of column name to RADCore::RADVariant). Use rowCount(), empty(), row(index), and rows() to inspect results.

RADSqlStatement is a move-only prepared statement obtained from prepare(). It offers typed, 1-based bind() overloads (integer, double, text, blob, and RADVariant) plus bindNull(), clearBindings(), and reset(). Advance with step() for row-returning queries or execute() for writes, and read the current row via columnCount(), columnName(), and columnValue().

RADSqlTransaction is an RAII helper that begins a transaction on construction and rolls back in its destructor unless commit() was called; RADSqlDatabase also exposes beginTransaction(), commit(), and rollback() directly.

Core features:

  • Connection ownership through RADSqlDatabase with event-based error reporting.
  • Prepared statements with typed binding through RADSqlStatement.
  • Explicit RADSqlResult rows and RAII RADSqlTransaction helpers.
  • Async queries via queryAsync() and ordered schema migrations.
  • No hidden exception flow for routine SQL failures.

Example:

RADDatabase::RADSqlDatabase db("history.sqlite");
if (db.open()) {
auto stmt = db.prepare("INSERT INTO visits(url, ts) VALUES(?, ?)");
stmt.bind(1, std::string("https://radcomp.tech"));
stmt.bind(2, int64_t(1721030400));
stmt.execute();
tx.commit();
auto result = db.query("SELECT url FROM visits ORDER BY ts DESC");
for (const auto& row : result.rows()) {
// row.at("url") holds a RADCore::RADVariant.
}
}
SQLite connection wrapper with RADCore event reporting.
Definition: RADDatabase.h:47
RAII transaction that rolls back unless committed.
Definition: RADDatabase.h:162