There is no CCFileManager in Cocos2d-x or I can’t find one.
Can somebody share knowledge how he/she has got this to work on Android?
I’m trying with these steps,
first - code for Android database,
than code for opening database
and then for searching - all from examples in first post, but it seems that my database is empty. This line CCLog(“row is %d,column is %d”,r,c); gives me that there’re 0 rows and 0 columns. My database has extension sqlite and I build it in SQLite Manager add-on for Firefox. I’ve placed it in Resource folder. It has one row and 7 columns - I’m trying with small example, just to get it work. Can somebody help?
I’ve got this to work. I’m working with two databases with .sqlite extenstion. I’ve probably had problem with saving dbPath to global variable, and when result=sqlite3_open(path.c_str(),&pdb); was executed it created new empty database, so that’s why there was 0 rows and 0 columns.
Hi
I made my sqlite database and I want to read from it in game.
where should I put my database ?
I tried:
\Resources
\proj.android\src\com\example\mytest\
I cannot create and read/write sqlite when running my application on Android. In fact, it seems that it crashes on function CCFileUtils::sharedFileUtils()->fullPathForFilename()
CCLOG("[SQLClient] Here 1");
std::string dbPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("activeschool.db3");
CCLOG("[SQLClient] Here 2");
What am I doing wrong? I’ve readed already many posts here, many tutorials, and I cannot find a reason to this happens. I’ve already added to manifest, but with no success.
I think the way the database is created and handled in this tutorial is too complicated. Here’s a simple and cross-platform (no #if CC_TARGET_PLATFORM, tested on iOS and Android using cocos2d-x 2.2.1 only so far) way of doing this:
And using the above class is simple enough. In your AppDelegate::applicationDidFinishLaunching() add the this line at the end Database::open(); and then use the class to execute SQL statements, something like Database::execute("YOUR SQL").
@mserougi
Thanks. May I know where you place your db file in proj.android folder?
If I understand correctly, the db file is in read-only and need to copy to writable path first. That’s the reason to check (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
For Android you would use the value returned by Context.getFilesDir() and place your SQLite database here. This usually return something like: /data/data//