Exemplo n.º 1
0
bool BXDatabase::Open()
{
  std::string databaseFilePath = "";

  if (m_pDatabase)
    Close();
  
  try
  {
    databaseFilePath = getDatabaseFilePath();
    m_pDBPoolObject = g_application.GetDBConnectionPool()->GetSqliteConnectionPoolObject( databaseFilePath );  
    m_pDatabase = m_pDBPoolObject->GetDatabase();

    if ( !m_pDatabase )
    {
      LOG(LOG_LEVEL_ERROR, "ERROR: Could not get valid database from pool. file [%s]\n", databaseFilePath.c_str());
      Close();
      return false;
    }
  }
  catch(...)
  {
    LOG(LOG_LEVEL_ERROR, "Error when opening database file [%s], error %s\n", databaseFilePath.c_str(), GetLastErrorMessage());
    return false;
  }

  m_bOpen = true;

  return true;
}
Exemplo n.º 2
0
bool BXDatabase::FileExists()
{
  std::string databaseFilePath = getDatabaseFilePath();
  bool bExists = BXUtils::FileExists(databaseFilePath);
  if (!bExists)
  {
    LOG(LOG_LEVEL_ERROR, "Database file does not exist");
  }

  return bExists;
}
Exemplo n.º 3
0
void BXDatabase::Close()
{
  if (!m_bOpen)
  {
    return ;
  }

  m_bOpen = false;

  if (m_pDatabase && m_pDBPoolObject)
    g_application.GetDBConnectionPool()->ReturnToPool( m_pDBPoolObject, getDatabaseFilePath() );  

  m_pDatabase = NULL;
  m_pDBPoolObject = NULL;
}
CppSQLite3DB* StoreDatabase::prepare(CCString *dbName)
{
    CppSQLite3DB* db = new CppSQLite3DB();
    if(db) {
        CCString *dbPath = getDatabaseFilePath(dbName);
    	try {
    		db->open(dbPath->getCString());
        } catch (CppSQLite3Exception &e) {
            CCLOG("%d : %s", e.errorCode(), e.errorMessage());
        }
        // create statement instance for sql queries/statements
        return db;
    }
    CC_SAFE_DELETE(db);
    return NULL;
}