예제 #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.cpp 프로젝트: hustg4/CocosLua
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;
}