How to deploy SQLite file to documents folder?

Hello,

I have an SQLite file populated and need to get it to the documents folder when the app is installed. How can I do this? I also deployed an app with the SQLite file in the resource folder for read only and get the error that the table was not found when it is there. How can I use an existing DB file? I am down until this is resolved. Works in simulator.

Warren

Android or IOS?  I know there are strange issues with the system resource folder on Android (it’s not a regular folder/directory but Corona attempts to make it look like a regular folder when it can)

Actually I will need to do this for both. I am testing on an Android though.

I’m not sure if it would work with SQLite as well, but what we did in a project for several music files in a zip that needed to be downloaded, unzipped and the content copied into another folder, was to open the files, dumping their binary data, and saving it to a new file in the place we wanted.

something like

local file = io.open(system.pathForFile("myFile", system.ResourcesDirectory), "rb"); local data = file:read("\*a"); io.close(file); file = io.open(system.pathForFile("myFile", system.DocumentsDirectory), "wb+"); file:write(data); io.close(file);

Haven’t tested directly this code, but should give you an idea of the logic behind it.

So I would just copy the db file from the resource directory which is the app folder to the documents folder?

Yup, only the first time the app is loaded, or you can also check if the database exists in the docs folder and if not copy it there.

Thanks. I will give that a try today and let you know how it goes.

Warren

How much data do you have in it?   You can also create and populate in your code if it’s not there.   

I thought of populating it myself if I need to. If copying it over does not work I will do that instead. It’s a lot of text rows but could still do it.

Android or IOS?  I know there are strange issues with the system resource folder on Android (it’s not a regular folder/directory but Corona attempts to make it look like a regular folder when it can)

Actually I will need to do this for both. I am testing on an Android though.

I’m not sure if it would work with SQLite as well, but what we did in a project for several music files in a zip that needed to be downloaded, unzipped and the content copied into another folder, was to open the files, dumping their binary data, and saving it to a new file in the place we wanted.

something like

local file = io.open(system.pathForFile("myFile", system.ResourcesDirectory), "rb"); local data = file:read("\*a"); io.close(file); file = io.open(system.pathForFile("myFile", system.DocumentsDirectory), "wb+"); file:write(data); io.close(file);

Haven’t tested directly this code, but should give you an idea of the logic behind it.

So I would just copy the db file from the resource directory which is the app folder to the documents folder?

Yup, only the first time the app is loaded, or you can also check if the database exists in the docs folder and if not copy it there.

Thanks. I will give that a try today and let you know how it goes.

Warren

How much data do you have in it?   You can also create and populate in your code if it’s not there.   

I thought of populating it myself if I need to. If copying it over does not work I will do that instead. It’s a lot of text rows but could still do it.