Skip to content

Commit

Permalink
Manually manage query life-time
Browse files Browse the repository at this point in the history
(cherry picked from commit 9763c0fed23a6bbcf5241d64b41f62324dd8e07b)
  • Loading branch information
uroni committed May 14, 2016
1 parent 2a20c6c commit 13c8a1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 11 additions & 5 deletions DBSettingsReader.cpp
Expand Up @@ -30,20 +30,26 @@
CDBSettingsReader::CDBSettingsReader(THREAD_ID tid, DATABASE_ID did, const std::string &pTable, const std::string &pSQL)
{
table=pTable;
IDatabase *db=Server->getDatabase(tid, did);
db=Server->getDatabase(tid, did);
if(pSQL.empty() )
query=db->Prepare("SELECT value FROM "+table+" WHERE key=?");
query=db->Prepare("SELECT value FROM "+table+" WHERE key=?", false);
else
query=db->Prepare(pSQL);
query=db->Prepare(pSQL, false);
}

CDBSettingsReader::CDBSettingsReader(IDatabase *pDB, const std::string &pTable, const std::string &pSQL)
: db(pDB)
{
table=pTable;
if(pSQL.empty() )
query=pDB->Prepare("SELECT value FROM "+table+" WHERE key=?");
query=pDB->Prepare("SELECT value FROM "+table+" WHERE key=?", false);
else
query=pDB->Prepare(pSQL);
query=pDB->Prepare(pSQL, false);
}

CDBSettingsReader::~CDBSettingsReader()
{
db->destroyQuery(query);
}

bool CDBSettingsReader::getValue(std::string key, std::string *value)
Expand Down
2 changes: 2 additions & 0 deletions DBSettingsReader.h
Expand Up @@ -6,6 +6,7 @@ class CDBSettingsReader : public CSettingsReader
public:
CDBSettingsReader(THREAD_ID tid, DATABASE_ID did, const std::string &pTable, const std::string &pSQL="");
CDBSettingsReader(IDatabase *pDB, const std::string &pTable, const std::string &pSQL="");
~CDBSettingsReader();

bool getValue(std::string key, std::string *value);

Expand All @@ -14,5 +15,6 @@ class CDBSettingsReader : public CSettingsReader
private:
std::string table;

IDatabase* db;
IQuery *query;
};

0 comments on commit 13c8a1b

Please sign in to comment.