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

Renamed SqliteConn:m_conn to SqliteConn::m_sqliteConn

parent e12dbca6
Branches
Tags
No related merge requests found
......@@ -33,22 +33,22 @@ namespace rdbms {
SqliteConn::SqliteConn(const std::string &filename):
m_transactionInProgress(false) {
try {
m_conn = nullptr;
if(sqlite3_open_v2(filename.c_str(), &m_conn, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI, nullptr)) {
std::string msg = sqlite3_errmsg(m_conn);
sqlite3_close(m_conn);
m_sqliteConn = nullptr;
if(sqlite3_open_v2(filename.c_str(), &m_sqliteConn, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI, nullptr)) {
std::string msg = sqlite3_errmsg(m_sqliteConn);
sqlite3_close(m_sqliteConn);
throw exception::Exception(msg);
}
{
char *errMsg = nullptr;
if(SQLITE_OK != sqlite3_exec(m_conn, "PRAGMA foreign_keys = ON;", nullptr, nullptr, &errMsg)) {
if(SQLITE_OK != sqlite3_exec(m_sqliteConn, "PRAGMA foreign_keys = ON;", nullptr, nullptr, &errMsg)) {
exception::Exception ex;
ex.getMessage() << "Failed to to set PRAGMA foreign_keys = ON";
if(nullptr != errMsg) {
ex.getMessage() << ": " << errMsg;
sqlite3_free(errMsg);
}
sqlite3_close(m_conn);
sqlite3_close(m_sqliteConn);
throw ex;
}
}
......@@ -70,9 +70,9 @@ SqliteConn::~SqliteConn() throw() {
void SqliteConn::close() {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr != m_conn) {
sqlite3_close(m_conn);
m_conn = nullptr;
if(nullptr != m_sqliteConn) {
sqlite3_close(m_sqliteConn);
m_sqliteConn = nullptr;
}
}
......@@ -83,7 +83,7 @@ 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) {
if(nullptr == m_sqliteConn) {
throw exception::Exception("Connection is closed");
}
......@@ -101,13 +101,13 @@ void SqliteConn::commit() {
try {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_conn) {
if(nullptr == m_sqliteConn) {
throw exception::Exception("Connection is closed");
}
if(m_transactionInProgress) {
char *errMsg = nullptr;
if(SQLITE_OK != sqlite3_exec(m_conn, "COMMIT", nullptr, nullptr, &errMsg)) {
if(SQLITE_OK != sqlite3_exec(m_sqliteConn, "COMMIT", nullptr, nullptr, &errMsg)) {
exception::Exception ex;
ex.getMessage() << "sqlite3_exec failed";
if(nullptr != errMsg) {
......@@ -130,13 +130,13 @@ void SqliteConn::rollback() {
try {
std::lock_guard<std::mutex> lock(m_mutex);
if(nullptr == m_conn) {
if(nullptr == m_sqliteConn) {
throw exception::Exception("Connection is closed");
}
if(m_transactionInProgress) {
char *errMsg = nullptr;
if(SQLITE_OK != sqlite3_exec(m_conn, "ROLLBACK", nullptr, nullptr, &errMsg)) {
if(SQLITE_OK != sqlite3_exec(m_sqliteConn, "ROLLBACK", nullptr, nullptr, &errMsg)) {
exception::Exception ex;
ex.getMessage() << "sqlite3_exec failed";
if(nullptr != errMsg) {
......@@ -210,7 +210,7 @@ std::list<std::string> SqliteConn::getTableNames() {
// isOpen
//------------------------------------------------------------------------------
bool SqliteConn::isOpen() const {
return nullptr != m_conn;
return nullptr != m_sqliteConn;
}
} // namespace rdbms
......
......@@ -115,7 +115,7 @@ private:
/**
* The database connection.
*/
sqlite3 *m_conn;
sqlite3 *m_sqliteConn;
/**
* True of there is an on-going transaction.
......
......@@ -49,7 +49,7 @@ SqliteStmt::SqliteStmt(
const uint maxPrepareRetries = 20; // A worst case scenario of 2 seconds
for(unsigned int i = 0; i <= maxPrepareRetries; i++) {
const int prepareRc = sqlite3_prepare_v2(m_conn.m_conn, sql.c_str(), nByte, &m_stmt, nullptr);
const int prepareRc = sqlite3_prepare_v2(m_conn.m_sqliteConn, sql.c_str(), nByte, &m_stmt, nullptr);
if(SQLITE_OK == prepareRc) {
break;
......@@ -71,7 +71,7 @@ SqliteStmt::SqliteStmt(
}
}
const std::string msg = sqlite3_errmsg(m_conn.m_conn);
const std::string msg = sqlite3_errmsg(m_conn.m_sqliteConn);
sqlite3_finalize(m_stmt);
throw exception::Exception(std::string(__FUNCTION__) + " failed: sqlite3_prepare_v2 failed: " + msg);
}
......@@ -232,7 +232,7 @@ void SqliteStmt::executeNonQuery() {
Sqlite::rcToStr(stepRc));
}
m_nbAffectedRows = sqlite3_changes(m_conn.m_conn);
m_nbAffectedRows = sqlite3_changes(m_conn.m_sqliteConn);
// Throw an exception if the SQL statement returned a result set
if(SQLITE_ROW == stepRc) {
......@@ -254,7 +254,7 @@ uint64_t SqliteStmt::getNbAffectedRows() const {
void SqliteStmt::beginExclusiveTransaction() {
try {
char *errMsg = nullptr;
if(SQLITE_OK != sqlite3_exec(m_conn.m_conn, "BEGIN EXCLUSIVE", nullptr, nullptr, &errMsg)) {
if(SQLITE_OK != sqlite3_exec(m_conn.m_sqliteConn, "BEGIN EXCLUSIVE", nullptr, nullptr, &errMsg)) {
exception::Exception ex;
ex.getMessage() << "sqlite3_exec failed";
if(nullptr != errMsg) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment