示例#1
0
	SqliteDb *SqliteDb::openSqlite(const std::string &dbPath)
	{
		std::string filePath = FileUtils::getInstance()->fullPathForFilename(dbPath.c_str());
		SqliteDb *pSqlite = (SqliteDb*)g_sqliteCache.objectForKey(filePath);

		if (pSqlite)
		{
			return pSqlite;
		}

		pSqlite = new SqliteDb();

		if (!pSqlite->initWithFile(filePath))
		{
			CC_SAFE_RELEASE_NULL(pSqlite);
			return nullptr;
		}
		pSqlite->autorelease();

		g_sqliteCache.setObject(pSqlite, filePath);

		int res = sqlite3_open(filePath.c_str(), &pSqlite->_db);

		if (res)
		{
			CCLOG("create sqlite3 db failed");
			CC_SAFE_RELEASE_NULL(pSqlite);
			return nullptr;
		}

		return pSqlite;
	}
示例#2
0
SQLite* SQLite::openSQLite(const std::string &dbFile)
{
    std::string filePath = CCFileUtils::getInstance()->fullPathForFilename(dbFile.c_str());
    SQLite* sqlite = (SQLite*)sqliteCache.objectForKey(filePath);
    
    if (sqlite) {
        return sqlite;
    }
    
    sqlite = new SQLite();
    
    if (!sqlite->initWithFile(filePath)) {
        CC_SAFE_RELEASE_NULL(sqlite);
        return NULL;
    }
    sqlite->autorelease();
    
    sqliteCache.setObject(sqlite, filePath);
    
    return sqlite;
}