template<class ObjectType, class ... Columns>
class sqlite::ObjectStatement< ObjectType, Columns >
SQLite prepared statement wrapper.
This class is meant to prepare a SQLite statement where each row of the result is supposed to fill one object of type ObjectType.
Columns is the type of each of the columns in the returned data. When calling getRow() the selected columns from the current result row will be converted to the typesspecified by Columns and passed to the constructor of ObjectType and the resulting object is returned.
After calling execute one can iterate over the statement to get all rows.
for(auto&& tvec3: vectors.execute()) {
tvec3.Print();
}
ObjectStatement(sqlite3 *db, const std::string &query, bool persistent)
Create a statement for an existing database object.
- Warning
- Be aware that you cannot iterate over this statement multiple times and should not have multiple independent iterators as the underlying sqlite statement object will change its state. One iteration over the rows per execute() call.
Definition at line 194 of file sqlite.h.
template<class ObjectType, class ... Columns>
template<class ... Parameters>
Execute the statement, providing all necessary parameters.
Definition at line 268 of file sqlite.h.
269 {
270 if (auto params = sqlite3_bind_parameter_count(m_statement); params != sizeof...(Parameters)) {
271 throw std::runtime_error("Number of arguments (" + std::to_string(sizeof...(Parameters)) +
272 ") doesn't match number of statement parameters (" + std::to_string(params) + ")");
273 }
274 sqlite3_reset(m_statement);
275 auto parameter_tuple = std::make_tuple(parameters...);
276 detail::visitTupleWithIndex(parameter_tuple, detail::ParameterBinder{m_statement});
277 return *this;
278 }