In Android, sqlite3_open return SQLITE_CANTOPEN

I am trying to invoke the sqlite3_open functionality. In Win32, the db can be opened successfully. However, it return * SQLITE_CANTOPEN* in Android.

@
sqlite3 *gDataBaseConn = NULL;
ret = sqlite3_open(“data.db”, &gDataBaseConn);
@

I need the help. Thank you very much!

I also hava this problem!who can help?

Hi,
the solution is here: http://www.cocos2d-x.org/boards/6/topics/7006?r=11429#message-11429

Lukasz, Thank you for your help.

I paste the solution for the link:

  1. use CCFileUtils::getFileData() to read the sqlite file into a char*
  2. use standard ofstrem to write the char* into a file in CCFileUtils::getWriteablePath() (in android is /data/data/xxx/xx)
  3. than you can use sqlite3_open() to open the file in step 2

but the db file may not exist,i just use sqlite3_open to create it. how can i do for it?

i also hava a question,in the same case,why pic can be read,but the db is not?their path is same! anyone know?

tugua wang wrote:

but the db file may not exist,i just use sqlite3_open to create it. how can i do for it?

Create your DB in CCFileUtils::getWriteablePath().

tugua wang wrote:

i also hava a question,in the same case,why pic can be read,but the db is not?their path is same! anyone know?

The problem is that everything inside assets folder is read-only so it is necessary to copy DB to location where it can be modified. I have not tried opening DB from assets folder but i think it can be done only in SQLITE_OPEN_READONLY mode.

oh,i see.thanks!

if i use “Create your DB in CCFileUtils::getWriteablePath()”,but how can i get this path? CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(“xxx.db”);?because when next time opening the app, i should judge if the db file has been created using the path.