added sqlite connection class (progress)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#include "sqlite_connection.hpp"
|
||||
#include "sqlite_error.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace matador::backends::sqlite {
|
||||
|
||||
sqlite_connection::sqlite_connection(sql::connection_info info)
|
||||
: connection_impl(std::move(info)) {
|
||||
|
||||
}
|
||||
|
||||
void sqlite_connection::open()
|
||||
{
|
||||
const auto ret = sqlite3_open(info().database.c_str(), &sqlite_db_);
|
||||
|
||||
if (ret != SQLITE_OK) {
|
||||
throw_sqlite_error(ret, sqlite_db_, "open");
|
||||
}
|
||||
}
|
||||
|
||||
void sqlite_connection::close()
|
||||
{
|
||||
int ret = sqlite3_close(sqlite_db_);
|
||||
|
||||
throw_sqlite_error(ret, sqlite_db_, "close");
|
||||
|
||||
sqlite_db_ = nullptr;
|
||||
}
|
||||
|
||||
bool sqlite_connection::is_open()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void sqlite_connection::execute(const std::string &stmt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void sqlite_connection::prepare(const std::string &stmt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "sqlite_error.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
namespace matador::backends::sqlite {
|
||||
|
||||
void throw_sqlite_error(int ec, sqlite3 *db, const std::string &source)
|
||||
{
|
||||
if (ec != SQLITE_OK) {
|
||||
std::stringstream msg;
|
||||
msg << "sqlite error (" << source << "): " << sqlite3_errmsg(db);
|
||||
throw std::logic_error(msg.str());
|
||||
}
|
||||
}
|
||||
|
||||
void throw_sqlite_error(int ec, sqlite3 *db, const std::string &source, const std::string &sql)
|
||||
{
|
||||
if (ec != SQLITE_OK) {
|
||||
std::stringstream msg;
|
||||
msg << "sqlite error (" << source << ", sql: " << sql << "): " << sqlite3_errmsg(db);
|
||||
throw std::logic_error(msg.str());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user