X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fdb%2Fsqlite3db.cpp;h=a828a4a265c2e5cd0f6e78259ff99a304b0bb27c;hb=59a5414ec47a2932a7802fcd1d98c4d80166564f;hp=86a4f87f3a6e84d0eb8113a87e1d5fd2ac0c0dae;hpb=dec33c63afafabf83c3039e916725cac6faef9b3;p=fms.git diff --git a/src/db/sqlite3db.cpp b/src/db/sqlite3db.cpp index 86a4f87..a828a4a 100644 --- a/src/db/sqlite3db.cpp +++ b/src/db/sqlite3db.cpp @@ -1,5 +1,12 @@ #include "../../include/db/sqlite3db.h" +#ifdef QUERY_LOG +#include +#include +#include +#include "../../include/stringfunctions.h" +#endif + #ifdef XMEM #include #endif @@ -12,7 +19,7 @@ DB::DB() Initialize(); } -DB::DB(std::string filename) +DB::DB(const std::string &filename) { Initialize(); Open(filename); @@ -22,7 +29,7 @@ DB::~DB() { if(IsOpen()) { - Close(); + Close(); } } @@ -30,7 +37,12 @@ const bool DB::Close() { if(IsOpen()) { - Poco::ScopedLock g(m_mutex); + sqlite3_stmt *st=0; + while((st=sqlite3_next_stmt(m_db,0))!=0) + { + sqlite3_finalize(st); + } + m_lastresult=sqlite3_close(m_db); if(m_lastresult==SQLITE_OK) { @@ -39,12 +51,12 @@ const bool DB::Close() } else { - return false; + return false; } } else { - return false; + return false; } } @@ -52,15 +64,17 @@ const bool DB::Execute(const std::string &sql) { if(IsOpen()) { - Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_exec(m_db,sql.c_str(),NULL,NULL,NULL); +#ifdef QUERY_LOG + Poco::Logger::get("querylog").information("Execute : "+sql); +#endif if(m_lastresult==SQLITE_OK) { return true; } else { - return false; + return false; } } else @@ -73,8 +87,10 @@ const bool DB::ExecuteInsert(const std::string &sql, long &insertid) { if(IsOpen()) { - Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_exec(m_db,sql.c_str(),NULL,NULL,NULL); +#ifdef QUERY_LOG + Poco::Logger::get("querylog").information("Execute Insert : "+sql); +#endif if(m_lastresult==SQLITE_OK) { insertid=sqlite3_last_insert_rowid(m_db); @@ -82,7 +98,7 @@ const bool DB::ExecuteInsert(const std::string &sql, long &insertid) } else { - return false; + return false; } } else @@ -95,7 +111,6 @@ const int DB::GetLastError(std::string &errormessage) { if(IsOpen()) { - Poco::ScopedLock g(m_mutex); int errcode=sqlite3_errcode(m_db); const char *errmsg=sqlite3_errmsg(m_db); if(errmsg) @@ -106,7 +121,7 @@ const int DB::GetLastError(std::string &errormessage) } else { - return SQLITE_OK; + return SQLITE_OK; } } @@ -118,8 +133,7 @@ void DB::Initialize() const bool DB::IsOpen() { - Poco::ScopedLock g(m_mutex); - return m_db ? true : false; + return m_db ? true : false; } const bool DB::Open(const std::string &filename) @@ -130,7 +144,6 @@ const bool DB::Open(const std::string &filename) } if(IsOpen()==false) { - Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_open(filename.c_str(),&m_db); if(m_lastresult==SQLITE_OK) { @@ -138,12 +151,12 @@ const bool DB::Open(const std::string &filename) } else { - return false; + return false; } } else { - return false; + return false; } } @@ -151,9 +164,14 @@ Statement DB::Prepare(const std::string &sql) { if(IsOpen()) { - Poco::ScopedLock g(m_mutex); sqlite3_stmt *statement=NULL; m_lastresult=sqlite3_prepare_v2(m_db,sql.c_str(),sql.size(),&statement,NULL); +#ifdef QUERY_LOG + size_t temp=reinterpret_cast(statement); + std::string tempstr(""); + StringFunctions::Convert(temp,tempstr); + Poco::Logger::get("querylog").information("Prepare : "+sql+" "+tempstr); +#endif if(m_lastresult==SQLITE_OK) { return Statement(statement); @@ -173,10 +191,12 @@ Recordset DB::Query(const std::string &sql) { if(IsOpen()) { - 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); +#ifdef QUERY_LOG + Poco::Logger::get("querylog").information("Query : "+sql); +#endif if(m_lastresult==SQLITE_OK) { return Recordset(rs,rows,cols); @@ -197,7 +217,6 @@ const int DB::SetBusyTimeout(const int ms) { if(IsOpen()) { - Poco::ScopedLock g(m_mutex); m_lastresult=sqlite3_busy_timeout(m_db,ms); return m_lastresult; }