Files
SQLite/SQLite/SQLiteStatement.cpp
T
2020-02-12 19:57:50 +01:00

33 lines
629 B
C++

#include "SQLiteClient.h"
#include "SQLiteStatement.h"
#include <sqlite3.h>
#include <sstream>
#include <stdexcept>
namespace SQLite {
SQLiteStatement::SQLiteStatement(SQLiteClient& client, const std::string& query)
{
int returnCode = sqlite3_prepare_v2(client, query.c_str(), -1, &m_pStatement, nullptr);
if (returnCode != SQLITE_OK)
{
std::stringstream err;
err << "SQL error: " << sqlite3_errmsg(client);
throw std::runtime_error(err.str());
}
}
SQLiteStatement::~SQLiteStatement()
{
sqlite3_finalize(m_pStatement);
}
SQLiteStatement::operator sqlite3_stmt*()
{
return m_pStatement;
}
} // namespace SQLite