Belle II Software  release-08-01-10
ObjectStatement< ObjectType, Columns > Class Template Reference

SQLite prepared statement wrapper. More...

#include <sqlite.h>

Classes

class  iterator
 Iterator class to allow iterating over the rows. More...
 

Public Types

using value_type = ObjectType
 each row gets converted to a instance of this type
 

Public Member Functions

iterator begin ()
 Iterator to the beginning.
 
iterator end () const
 Iterator to the end.
 
 ObjectStatement (sqlite3 *db, const std::string &query, bool persistent)
 Create a statement for an existing database object.
 
 ~ObjectStatement ()
 Clean up the statement.
 
template<class ... Parameters>
ObjectStatementexecute (Parameters... parameters)
 Execute the statement, providing all necessary parameters.
 
bool step ()
 Step to the next row in the result. More...
 
value_type getRow () const
 Return the current row.
 

Private Attributes

sqlite3_stmt * m_statement {nullptr}
 pointer to the statement object
 

Detailed Description

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.

ObjectStatement<TVector3, double, double, double> vectors(connection, "SELECT x,y,z from vectors");
for(auto&& tvec3: vectors.execute()) {
tvec3.Print();
}
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.

Member Function Documentation

◆ step()

bool step ( )
inline

Step to the next row in the result.

Returns
true if a new row is loaded, false if there a no more rows.

Definition at line 267 of file sqlite.h.

268  {
269  if (auto ret = sqlite3_step(m_statement); ret != SQLITE_ROW) {
270  if (ret == SQLITE_DONE) return false;
271  detail::checkSQLiteError(ret);
272  }
273  return true;
274  }
sqlite3_stmt * m_statement
pointer to the statement object
Definition: sqlite.h:285

The documentation for this class was generated from the following file: