|
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:
RADSqlDatabase with event-based error reporting.RADSqlStatement.RADSqlResult rows and RAII RADSqlTransaction helpers.queryAsync() and ordered schema migrations.Example: