Skip to content

Commit

Permalink
no need for a bool and an integer to check the number of times a data…
Browse files Browse the repository at this point in the history
…base is open - use an unsigned int
  • Loading branch information
Jonathan Marshall committed Feb 26, 2011
1 parent 50ecc77 commit d153d81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
25 changes: 10 additions & 15 deletions xbmc/dbwrappers/Database.cpp
Expand Up @@ -37,8 +37,7 @@ using namespace dbiplus;

CDatabase::CDatabase(void)
{
m_bOpen = false;
m_iRefCount = 0;
m_openCount = 0;
m_sqlite = true;
m_bMultiWrite = false;
}
Expand Down Expand Up @@ -255,7 +254,7 @@ bool CDatabase::Open(DatabaseSettings &dbSettings)
{
if (IsOpen())
{
m_iRefCount++;
m_openCount++;
return true;
}

Expand Down Expand Up @@ -385,9 +384,6 @@ bool CDatabase::Connect(DatabaseSettings &dbSettings, bool create)
CreateTables();
}

// Mark our db as open here to make our destructor to properly close the file handle
m_bOpen = true;

// sqlite3 post connection operations
if (dbSettings.type.Equals("sqlite3"))
{
Expand All @@ -396,7 +392,7 @@ bool CDatabase::Connect(DatabaseSettings &dbSettings, bool create)
m_pDS->exec("PRAGMA count_changes='OFF'\n");
}

m_iRefCount++;
m_openCount = 1; // our database is open
return true;
}

Expand Down Expand Up @@ -428,22 +424,21 @@ bool CDatabase::UpdateVersion(const CStdString &dbName)

bool CDatabase::IsOpen()
{
return m_bOpen;
return m_openCount > 0;
}

void CDatabase::Close()
{
if (!m_bOpen)
return ;
if (m_openCount == 0)
return;

if (m_iRefCount > 1)
if (m_openCount > 1)
{
m_iRefCount--;
return ;
m_openCount--;
return;
}

m_iRefCount = 0;
m_bOpen = false;
m_openCount = 0;

if (NULL == m_pDB.get() ) return ;
if (NULL != m_pDS.get()) m_pDS->close();
Expand Down
3 changes: 1 addition & 2 deletions xbmc/dbwrappers/Database.h
Expand Up @@ -116,7 +116,6 @@ class CDatabase

bool UpdateVersion(const CStdString &dbName);

bool m_bOpen;
bool m_sqlite; ///< \brief whether we use sqlite (defaults to true)

std::auto_ptr<dbiplus::Database> m_pDB;
Expand All @@ -128,5 +127,5 @@ class CDatabase
bool UpdateVersionNumber();

bool m_bMultiWrite; /*!< True if there are any queries in the queue, false otherwise */
int m_iRefCount;
unsigned int m_openCount;
};

0 comments on commit d153d81

Please sign in to comment.