Skip to content
Snippets Groups Projects
Commit e12dbca6 authored by Steven Murray's avatar Steven Murray
Browse files

SqliteConn guards against itself being closed

parent f24c2852
Branches
Tags
No related merge requests found
......@@ -70,7 +70,7 @@ SqliteConn::~SqliteConn() throw() {
void SqliteConn::close() {
std::lock_guard<std::mutex> lock(m_mutex);
if(m_conn != nullptr) {
if(nullptr != m_conn) {
sqlite3_close(m_conn);
m_conn = nullptr;
}
......@@ -83,6 +83,10 @@ std::unique_ptr<Stmt> SqliteConn::createStmt(const std::string &sql, const Stmt:
try {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_conn) {
throw exception::Exception("Connection is closed");
}
return cta::make_unique<SqliteStmt>(autocommitMode , *this, sql);
} catch(exception::Exception &ex) {
throw exception::Exception(std::string(__FUNCTION__) + " failed for SQL statement " + sql + ": " +
......@@ -96,6 +100,11 @@ std::unique_ptr<Stmt> SqliteConn::createStmt(const std::string &sql, const Stmt:
void SqliteConn::commit() {
try {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_conn) {
throw exception::Exception("Connection is closed");
}
if(m_transactionInProgress) {
char *errMsg = nullptr;
if(SQLITE_OK != sqlite3_exec(m_conn, "COMMIT", nullptr, nullptr, &errMsg)) {
......@@ -120,6 +129,11 @@ void SqliteConn::commit() {
void SqliteConn::rollback() {
try {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_conn) {
throw exception::Exception("Connection is closed");
}
if(m_transactionInProgress) {
char *errMsg = nullptr;
if(SQLITE_OK != sqlite3_exec(m_conn, "ROLLBACK", nullptr, nullptr, &errMsg)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment