Languages

Menu
Sites
Language
How to package db file into my application?
Hello, I want to know how I can package my sqlite db file into my application. I create data folder into my project directory and put my database.db. But that db file is not transferred into target when I try to run as. In this time, the db file should be packaged for my use. Could you give me some guide for it? Thanks

Responses

6 Replies
daniel kim

Hi,

This example code create the db file into private data of application. so it looks like that you don't need manage the db file manually.

    char* resource = app_get_data_path();
    int siz = strlen(resource)+10;

    char* path = malloc(sizeof(char)*siz);

    memset(path, 0, siz);

    strncat(path, resource, siz);
    strncat(path, "test.db", siz);

   int ret = sqlite3_open(path, &db);

 Regards.

Dongeup Ham

The preload data in the application data directory is not allowed, so your data didn't be copied.

If you want to use the fixed data, you can include the file in /res directory of applicaiton and copy it after application is running first time.

Or you can make the db data in runtime.

bhoomika rathod

hello,
i am developing an application in which i need to use fixed data created in sqlite browser. But i have no idea about your solution mentioned ni second line.

Will you plz tell me how it actually works? And how can i load data in my app?

Alex Dem

Hi,
You could also try to place in yourProject/shared/res folder, after installation db should be placed into /opt/usr/apps/org.tizen.yourapp/shared/res folder.
Alexey.

병재 임

Hello Mr. Hong.

I think you need to create db in correct place with crrect time

Please make below db and call this one when app is created.

 

//Create DB in runtime

sqlite3 *db_handle = NULL;
char* data_path = app_get_data_path();
if(data_path == NULL)
{
 ERROR("Failed to get resource path=NULL!!!");
}
std::string db_path(data_path);
free(data_path);
db_path += "db_name.db";
char* your_db_path =  new char[db_path.length()+1];
strcpy(your_db_path, db_path.c_str());
sqlite3_open_v2(your_db_path,&db_handle,SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE,NULL);

Alex Dem

Hi,
just fyi, similar topic regarding db:
https://developer.tizen.org/forums/native-application-development/unable-access-database-created-trusted-folder
Alexey.