X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fdb%2Fsqlite3db.cpp;h=f8bb003114ce4905e38d07abb091465e9772ed46;hb=221236a4d3aac4144529d418ce368db5c98facb0;hp=1b63715094084439c8510a272434d99f4ceab7b9;hpb=c7fcb4c4bc5012a584add81a9509fc1f84c3c688;p=fms.git diff --git a/src/db/sqlite3db.cpp b/src/db/sqlite3db.cpp index 1b63715..f8bb003 100644 --- a/src/db/sqlite3db.cpp +++ b/src/db/sqlite3db.cpp @@ -12,7 +12,7 @@ DB::DB() Initialize(); } -DB::DB(std::string filename) +DB::DB(const std::string &filename) { Initialize(); Open(filename); @@ -22,7 +22,7 @@ DB::~DB() { if(IsOpen()) { - Close(); + Close(); } } @@ -30,8 +30,7 @@ const bool DB::Close() { if(IsOpen()) { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); + Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_close(m_db); if(m_lastresult==SQLITE_OK) { @@ -40,12 +39,12 @@ const bool DB::Close() } else { - return false; + return false; } } else { - return false; + return false; } } @@ -53,8 +52,7 @@ const bool DB::Execute(const std::string &sql) { if(IsOpen()) { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); + Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_exec(m_db,sql.c_str(),NULL,NULL,NULL); if(m_lastresult==SQLITE_OK) { @@ -62,7 +60,7 @@ const bool DB::Execute(const std::string &sql) } else { - return false; + return false; } } else @@ -75,8 +73,7 @@ const bool DB::ExecuteInsert(const std::string &sql, long &insertid) { if(IsOpen()) { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); + Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_exec(m_db,sql.c_str(),NULL,NULL,NULL); if(m_lastresult==SQLITE_OK) { @@ -85,7 +82,7 @@ const bool DB::ExecuteInsert(const std::string &sql, long &insertid) } else { - return false; + return false; } } else @@ -98,8 +95,7 @@ const int DB::GetLastError(std::string &errormessage) { if(IsOpen()) { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); + Poco::ScopedLock g(m_mutex); int errcode=sqlite3_errcode(m_db); const char *errmsg=sqlite3_errmsg(m_db); if(errmsg) @@ -110,7 +106,7 @@ const int DB::GetLastError(std::string &errormessage) } else { - return SQLITE_OK; + return SQLITE_OK; } } @@ -122,21 +118,19 @@ void DB::Initialize() const bool DB::IsOpen() { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); - return m_db ? true : false; + Poco::ScopedLock g(m_mutex); + return m_db ? true : false; } const bool DB::Open(const std::string &filename) { - if(IsOpen()==false) + if(IsOpen()==true) { Close(); } if(IsOpen()==false) { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); + Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_open(filename.c_str(),&m_db); if(m_lastresult==SQLITE_OK) { @@ -144,12 +138,12 @@ const bool DB::Open(const std::string &filename) } else { - return false; + return false; } } else { - return false; + return false; } } @@ -157,8 +151,7 @@ Statement DB::Prepare(const std::string &sql) { if(IsOpen()) { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); + Poco::ScopedLock g(m_mutex); sqlite3_stmt *statement=NULL; m_lastresult=sqlite3_prepare_v2(m_db,sql.c_str(),sql.size(),&statement,NULL); if(m_lastresult==SQLITE_OK) @@ -180,8 +173,7 @@ Recordset DB::Query(const std::string &sql) { if(IsOpen()) { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); + Poco::ScopedLock g(m_mutex); char **rs=NULL; int rows,cols; m_lastresult=sqlite3_get_table(m_db,sql.c_str(),&rs,&rows,&cols,NULL); @@ -205,8 +197,7 @@ const int DB::SetBusyTimeout(const int ms) { if(IsOpen()) { - //ZThread::Guard g(m_mutex); - PThread::Guard g(m_mutex); + Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_busy_timeout(m_db,ms); return m_lastresult; }