Project

General

Profile

« Previous | Next » 

Revision 143a60e7

Added by David Sorber over 9 years ago

After much contemplation I realized that my previous approach to solving this execute query template function problem was more wrong than right. Several days of staring at and reading about variadic templates later I figured out the correct way to accomplish my goal.

View differences:

software/sqlite_poc/DBManager.cc
#include "DBManager.h"
// Helper function for int64_t type
void get_value(int64_t& val, int idx, sqlite3_stmt* stmt)
{
if (sqlite3_column_type(stmt, idx) != SQLITE_INTEGER)
{
assert(false);
}
val = sqlite3_column_int64(stmt, idx);
}
// Helper function for double type
void get_value(double& val, int idx, sqlite3_stmt* stmt)
{
if (sqlite3_column_type(stmt, idx) != SQLITE_FLOAT)
{
assert(false);
}
val = sqlite3_column_double(stmt, idx);
}
// Helper function for string type
void get_value(std::string& val, int idx, sqlite3_stmt* stmt)
{
if (sqlite3_column_type(stmt, idx) == SQLITE_TEXT)
{
val.assign(reinterpret_cast<const char*>(sqlite3_column_text(stmt, idx)));
}
else if (sqlite3_column_type(stmt, idx) == SQLITE_NULL)
{
val.assign("");
}
else
{
assert(false);
}
}
DBManager::DBManager(const std::string& db_path)
{
int rc = sqlite3_open(db_path.c_str(), &this->db);
if (rc)
{

Also available in: Unified diff