Project

General

Profile

Download (1.2 KB) Statistics
| Branch: | Tag: | Revision:
88cf406f David Sorber
#include <iostream>

#include "DBManager.h"

143a60e7 David Sorber
// 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);
}
}

88cf406f David Sorber
DBManager::DBManager(const std::string& db_path)
{
143a60e7 David Sorber
88cf406f David Sorber
int rc = sqlite3_open(db_path.c_str(), &this->db);
if (rc)
{
std::cerr << "Uh-oh spaghetti O's" << std::endl;
}
else
{
6e4119a4 David Sorber
std::cout << "DB connected\n" << std::endl;
88cf406f David Sorber
}
}

DBManager::~DBManager()
{
sqlite3_close(this->db);
}