47 #ifndef _MIRA_SQLITEQUERY_H_ 48 #define _MIRA_SQLITEQUERY_H_ 51 #include <serialization/adapters/std/pair> 52 #include <serialization/adapters/std/vector> 81 SQLiteQuery(sqlite3* db, sqlite3_stmt* statement,
bool more);
103 return mStatement != NULL;
112 return mMore ==
false;
129 std::string getName(std::size_t column);
140 const char* data = getTxtValue(column);
142 MIRA_THROW(XBadCast,
"Value of column '" << column <<
"' is NULL");
143 return fromString<T>(data);
154 T
getValue(std::size_t column,
const T& defaultValue)
156 const char* data = getTxtValue(column);
159 return fromString<T>(data);
173 int getDataType(std::size_t column);
180 bool isNull(std::size_t column);
205 const char* getTxtValue(std::size_t column);
208 sqlite3_stmt* mStatement;
226 typedef std::vector<std::vector<std::pair<int, std::string>>>
ValueVector;
250 return mCurrent >= mCache.size();
259 return mHeader.size();
269 if(column>=mHeader.size())
270 MIRA_THROW(XAccessViolation,
"Column " << column <<
" does not exist");
272 return mHeader[column];
285 MIRA_THROW(XBadCast,
"Value of column '" << column <<
"' is NULL");
286 return fromString<T>(mCache[mCurrent][column].second);
297 T
getValue(std::size_t column,
const T& defaultValue)
303 return fromString<T>(mCache[mCurrent][column].second);
321 int getDataType(std::size_t column);
327 bool isNull(std::size_t column);
368 template<
typename Reflector>
371 r.member(
"Header", mHeader,
"The header of the query");
372 r.member(
"Values", mCache,
"The values of the query");
380 MIRA_THROW(XAccessViolation,
"Access to invalid query object.");
386 if(column>=mCache[mCurrent].size())
387 MIRA_THROW(XAccessViolation,
"Column " << column <<
" does not exist");
void next()
Advance to next row.
Definition: SQLiteQuery.h:340
ValueVector mCache
Definition: SQLiteQuery.h:391
void validate()
Definition: SQLiteQuery.h:377
std::size_t mCurrent
Definition: SQLiteQuery.h:392
A cached SQLite query object that supports serialization.
Definition: SQLiteQuery.h:222
std::vector< std::string > HeaderVector
Definition: SQLiteQuery.h:225
std::vector< std::vector< std::pair< int, std::string > > > ValueVector
Definition: SQLiteQuery.h:226
int getColumnCount() const
Return the column count of the query.
Definition: SQLiteQuery.h:257
HeaderVector mHeader
Definition: SQLiteQuery.h:390
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Contains toString and fromString functions for converting data types to strings and the other way rou...
SQLiteQuery & operator++()
Preincrement operator.
Definition: SQLiteQuery.h:198
T getValue(std::size_t column)
Return a typecasted value for a given column in the current row.
Definition: SQLiteQuery.h:138
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
T getValue(std::size_t column)
Returns a typecasted value for a given column in the current row.
Definition: SQLiteQuery.h:282
std::string getName(std::size_t column)
Returns the name of a given column.
Definition: SQLiteQuery.h:267
bool eof() const
Return if the query contains data.
Definition: SQLiteQuery.h:248
void validate(std::size_t column)
Definition: SQLiteQuery.h:383
bool eof() const
Return if the query contains data.
Definition: SQLiteQuery.h:110
int getColumnCount() const
Return the column count of the query.
Definition: SQLiteQuery.h:119
T getValue(std::size_t column, const T &defaultValue)
Returns a typecasted value for a given column in the current row.
Definition: SQLiteQuery.h:297
void reflect(Reflector &r)
Reflect method for serialization.
Definition: SQLiteQuery.h:369
T getValue(std::size_t column, const T &defaultValue)
Return a typecasted value for a given column in the current row.
Definition: SQLiteQuery.h:154
ValueVector getValues() const
Return the cached values.
Definition: SQLiteQuery.h:359
SQLiteCachedQuery & operator++()
Preincrement operator.
Definition: SQLiteQuery.h:349
Class representing a result of a SQLite database query.
Definition: SQLiteQuery.h:66
bool valid() const
SQLiteQuery is valid if statement is not null.
Definition: SQLiteQuery.h:101