11 #include <RADCore/RADCore.h>
20 using RADSqlRow = std::map<std::string, RADCore::RADVariant>;
40 const std::vector<RADSqlRow>&
rows()
const;
43 std::vector<RADSqlRow> rows_;
84 const std::string& sql);
95 bool migrateTo(
int targetVersion,
const std::vector<std::pair<int, std::string>>& migrations);
101 std::shared_ptr<Impl> pImpl_;
133 bool bind(
int index, int64_t value);
135 bool bind(
int index,
double value);
137 bool bind(
int index,
const std::string& value);
139 bool bind(
int index,
const std::vector<uint8_t>& value);
158 std::shared_ptr<Impl> pImpl_;
183 bool active_ =
false;
#define RAD_EVENT(Name, Signature)
Declares a typed RADCore event; example: RAD_EVENT(done, (int)).
Definition: RADCore.h:65
#define RADEvents
Marks a public event declaration block in RADObject-derived classes.
Definition: RADCore.h:43
RADCore task event loop with locked and low-latency scheduling strategies.
Definition: RADCore.h:956
Typed shared future with optional continuation support.
Definition: RADCore.h:1514
Base class for event receivers, senders, and thread-affinity aware objects.
Definition: RADCore.h:931
Simple worker thread pool that reports completion through RADFuture.
Definition: RADCore.h:1637
Small value container used by models, futures, settings, and database rows.
Definition: RADCore.h:364
SQLite connection wrapper with RADCore event reporting.
Definition: RADDatabase.h:47
RADSqlDatabase()
Creates a database object with no file assigned yet.
void close()
Closes the SQLite connection.
int schemaVersion()
Returns current schema version from the rad_schema_version table.
const std::string & fileName() const
Returns the configured SQLite database file path.
std::string lastError() const
Returns the most recent SQLite error message.
void setFileName(std::string fileName)
Sets the SQLite database file path used by open().
RADCore::Event< void(std::string) > errorOccurred
Raised when SQLite open, execute, query, or transaction handling fails.
Definition: RADDatabase.h:51
bool execute(const std::string &sql)
Executes SQL that does not need row results.
RADCore::RADFutureT< RADSqlResult > queryAsync(RADCore::RADThreadPool &pool, RADCore::EventLoop &completionLoop, const std::string &sql)
Runs query asynchronously on pool and posts completion to completionLoop.
RADSqlResult query(const std::string &sql)
Executes SQL and returns collected result rows.
bool rollback()
Rolls back the active transaction.
bool isOpen() const
Returns true when a SQLite connection is open.
bool commit()
Commits the active transaction.
~RADSqlDatabase() override
Closes the SQLite handle if still open.
RADSqlDatabase(std::string fileName)
Creates a database object targeting fileName.
bool migrateTo(int targetVersion, const std::vector< std::pair< int, std::string >> &migrations)
Applies ordered migrations until targetVersion is reached.
bool beginTransaction()
Starts a SQLite transaction.
bool open()
Opens the configured SQLite database file.
RADSqlStatement prepare(const std::string &sql)
Prepares a reusable SQL statement.
Value object containing rows returned from a SQL query.
Definition: RADDatabase.h:26
RADSqlResult(std::vector< RADSqlRow > rows)
Creates a result from already-collected rows.
const RADSqlRow & row(size_t index) const
Returns a row by index; callers must pass an index below rowCount().
size_t rowCount() const
Returns the number of rows in this result.
const std::vector< RADSqlRow > & rows() const
Returns all rows for range iteration or bulk inspection.
RADSqlResult()=default
Creates an empty result.
bool empty() const
Returns true when no rows are present.
Prepared SQLite statement with typed binding and row stepping.
Definition: RADDatabase.h:105
RADSqlStatement & operator=(RADSqlStatement &&other) noexcept
Moves statement ownership.
bool bind(int index, double value)
Binds double at 1-based index.
bool bindNull(int index)
Binds null at 1-based index.
std::string columnName(int column) const
Returns column name by zero-based index.
RADCore::RADVariant columnValue(int column) const
Returns column value by zero-based index.
void reset()
Resets statement execution state.
bool bind(int index, const RADCore::RADVariant &value)
Binds a RADVariant at 1-based index.
bool step()
Advances one row; returns true when a row is available.
~RADSqlStatement()
Finalizes the statement.
RADSqlStatement(const RADSqlStatement &)=delete
Statement ownership is movable but not copyable.
RADSqlStatement & operator=(const RADSqlStatement &)=delete
Statement ownership is movable but not copyable.
bool bind(int index, const std::vector< uint8_t > &value)
Binds bytes at 1-based index.
void clearBindings()
Clears all current bindings.
RADSqlStatement()
Creates an invalid statement.
std::string lastError() const
Returns the last statement error.
RADSqlStatement(RADSqlStatement &&other) noexcept
Moves statement ownership.
bool isValid() const
Returns true when a statement was prepared successfully.
bool execute()
Executes until done for statements that do not return rows.
bool bind(int index, int64_t value)
Binds integer at 1-based index.
bool bind(int index, const std::string &value)
Binds text at 1-based index.
int columnCount() const
Returns number of columns in the current row.
RAII transaction that rolls back unless committed.
Definition: RADDatabase.h:162
RADSqlTransaction & operator=(const RADSqlTransaction &)=delete
Transactions cannot be copied.
bool rollback()
Rolls back the transaction.
RADSqlTransaction(RADSqlDatabase &database)
Begins a transaction on database.
bool isActive() const
Returns true when begin succeeded and the transaction is active.
RADSqlTransaction(const RADSqlTransaction &)=delete
Transactions cannot be copied.
bool commit()
Commits the transaction.
~RADSqlTransaction()
Rolls back if still active.
Definition: RADDatabase.h:17
std::map< std::string, RADCore::RADVariant > RADSqlRow
One SQLite result row keyed by column name.
Definition: RADDatabase.h:20