![]() |
OpenMS
2.7.0
|
Enumerations | |
enum class | SqlState { SQL_ROW , SQL_DONE , SQL_ERROR } |
Functions | |
template<typename T > | |
UInt64 | clearSignBit (T) |
template<> | |
UInt64 | clearSignBit (UInt64 value) |
only allow UInt64 specialization More... | |
SqlState | nextRow (sqlite3_stmt *stmt, SqlState current=SqlState::SQL_ROW) |
retrieves the next row from a prepared statement More... | |
template<typename ValueType > | |
bool | extractValue (ValueType *, sqlite3_stmt *, int) |
Extracts a specific value from an SQL column. More... | |
template<> | |
bool | extractValue< double > (double *dst, sqlite3_stmt *stmt, int pos) |
template<> | |
bool | extractValue< int > (int *dst, sqlite3_stmt *stmt, int pos) |
template<> | |
bool | extractValue< Int64 > (Int64 *dst, sqlite3_stmt *stmt, int pos) |
template<> | |
bool | extractValue< String > (String *dst, sqlite3_stmt *stmt, int pos) |
template<> | |
bool | extractValue< std::string > (std::string *dst, sqlite3_stmt *stmt, int pos) |
bool | extractValueIntStr (String *dst, sqlite3_stmt *stmt, int pos) |
Special case where an integer should be stored in a String field. More... | |
double | extractDouble (sqlite3_stmt *stmt, int pos) |
float | extractFloat (sqlite3_stmt *stmt, int pos) |
convenience function; note: in SQL there is no float, just double. So this might be narrowing. More... | |
int | extractInt (sqlite3_stmt *stmt, int pos) |
Int64 | extractInt64 (sqlite3_stmt *stmt, int pos) |
String | extractString (sqlite3_stmt *stmt, int pos) |
char | extractChar (sqlite3_stmt *stmt, int pos) |
bool | extractBool (sqlite3_stmt *stmt, int pos) |
|
strong |
UInt64 OpenMS::Internal::SqliteHelper::clearSignBit | ( | T | ) |
Sql only stores signed 64bit ints, so we remove the highest bit, because some/most of our sql-insert routines first convert to string, which might yield an uint64 which cannot be represented as int64, and sqlite would attempt to store it as double(!), which will loose precision
only allow UInt64 specialization
bool OpenMS::Internal::SqliteHelper::extractValue | ( | ValueType * | , |
sqlite3_stmt * | , | ||
int | |||
) |
Extracts a specific value from an SQL column.
dst
Destination (where to store the value) stmt
Sqlite statement object pos
Column position
For example, to extract a specific integer from column 5 of an SQL statement, one can use:
sqlite3_stmt* stmt; sqlite3* db; SqliteConnector::prepareStatement(db, &stmt, select_sql); sqlite3_step(stmt);
double target; while (sqlite3_column_type(stmt, 0) != SQLITE_NULL) { extractValue<double>(&target, stmt, 5); sqlite3_step( stmt ); } sqlite3_finalize(stmt);
bool OpenMS::Internal::SqliteHelper::extractValue< double > | ( | double * | dst, |
sqlite3_stmt * | stmt, | ||
int | pos | ||
) |
bool OpenMS::Internal::SqliteHelper::extractValue< int > | ( | int * | dst, |
sqlite3_stmt * | stmt, | ||
int | pos | ||
) |
bool OpenMS::Internal::SqliteHelper::extractValue< Int64 > | ( | Int64 * | dst, |
sqlite3_stmt * | stmt, | ||
int | pos | ||
) |
bool OpenMS::Internal::SqliteHelper::extractValue< std::string > | ( | std::string * | dst, |
sqlite3_stmt * | stmt, | ||
int | pos | ||
) |
bool OpenMS::Internal::SqliteHelper::extractValue< String > | ( | String * | dst, |
sqlite3_stmt * | stmt, | ||
int | pos | ||
) |
bool OpenMS::Internal::SqliteHelper::extractValueIntStr | ( | String * | dst, |
sqlite3_stmt * | stmt, | ||
int | pos | ||
) |
Special case where an integer should be stored in a String field.
SqlState OpenMS::Internal::SqliteHelper::nextRow | ( | sqlite3_stmt * | stmt, |
SqlState | current = SqlState::SQL_ROW |
||
) |
retrieves the next row from a prepared statement
If you receive 'SqlState::SQL_DONE', do NOT query nextRow() again, because you might enter an infinite loop! To avoid oversights, you can pass the old return value into the function again and get an Exception which will tell you that there is buggy code!
current | Return value of the previous call to this function. |
Exception::SqlOperationFailed | if state would be SqlState::ERROR |