原帖是在http://www.cocos2d-x.org/boards/6/topics/7006
我發現,最簡單的方法,包括對sqlite的遊戲cocos2dx。
也就是說,從sqlite3 C++ api下載源代碼,並將sqlite3.c添加到Android.mk。
然後將這些代碼編譯爲您的cocos2dx代碼。
當你需要使用它時,在你的代碼中包含sqlite.h。
對於操作數據庫下面是我的示例代碼:
sqlite3 *pDB = NULL;
char* errMsg = NULL;
string sqlstr;
int result;
string dbPath = CCFileUtils::getWriteablePath();
dbPath.append("Settings.db");
result = sqlite3_open(dbPath.c_str(),&pDB);
if (result != SQLITE_OK)
CCLOG("OPENING WRONG, %d, MSG:%s",result,errMsg);
bool isExisted_;
sqlstr = "select count(type) from sqlite_master where type='table' and name='YourTableName'";
result = sqlite3_exec(pDB, sqlstr.c_str(), isExisted, &isExisted_, &errMsg);
if(result != SQLITE_OK)
CCLOG("check exist fail %d Msg: %s", result, errMsg);
result = sqlite3_exec(pDB, "create table YourTableName(ID INTEGER primary key autoincrement, name varchar(32), type INT, posX INT, posY INT, isUnlock INT)",NULL,NULL,&errMsg);
if(result != SQLITE_OK)
CCLOG("CREATE TABLE FAIL %d, Msg: %s",result,errMsg);
sqlite3_close(pDB);
你說「sqlite的C++ API」但我沒有找到關於SQLite的網站,反映和下載文件,我得到它們形成爲C(因此.C)沒有C++什麼。我是否錯過了一些東西,或者他們是否在同一個 –
@owengerig這是我的問題。它實際上是c,你可以在C++代碼中沒有任何問題的情況下使用它。 –