SQLite read only IOS

Hi,

I work with Sqlite in my app, I try UPDATE data, when I probe in simulator all is fine, but when I try this in dispositive, I receive error 8, the Data Base is ready only.

In windows, for android all is ok. The app in device not problem. The problem is in IOS.

I don’t know what happen.

Thanks in advance.

Carlos

Where is your database?  Is it in system.ResourcesDirectory or system.DocumentsDirectory?

Thank Rob,

The DB Is it in system.ResourcesDirectory

Hi @cdarteagar,

system.ResourcesDirectory is read-only… you can’t write to files in that directory. You’ll need to make sure the database is in system.DocumentsDirectory.

Take care,

Brent

Thanks Brent,

How I put my DataBase in that system.DocumentsDirectory, I have created my DataBase with Sqlite Studio, this have many tables.

I try put in Documents directory, but when I try to read any table  I receive “Table don’t exist”.

Also I try copy Data Base from Resources to Documents the result is the same.

I’m not sure how well you’re going to like this answer.

You cannot pre-build an SQLite database in system.DocumentsDirectory.  You might be able to get it to work in the simulator because the system.DocumentsDirectory folder is accessible from a Mac or from Windows.  However, the app you deploy to iOS or Android is a read-only bundle of compiled and crytpologically signed code and data.  You cannot change this in anyway.  When the app installs, the OS creates a writable sandbox folder that Corona SDK accesses as system.DocumentsDirectory.  This folder will be empty.

It’s your responsibility to include your SQLlite database in your system.ResourcesDirectory (i.e. the folder with main.lua) and when you app starts the first time, you need to create a new database in system.DocumentsDirectory, create all the necessary tables and insert all the necessary records into those tables on first setup.

Rob

Thank you so much Rob.

We just did a tutorial on how to accomplish this:

https://coronalabs.com/blog/2015/05/19/tutorial-initializing-a-writable-sqlite-database-from-a-read-only-database/

Rob

Thanks Rob,

I used this solution, is ok. 

Where is your database?  Is it in system.ResourcesDirectory or system.DocumentsDirectory?

Thank Rob,

The DB Is it in system.ResourcesDirectory

Hi @cdarteagar,

system.ResourcesDirectory is read-only… you can’t write to files in that directory. You’ll need to make sure the database is in system.DocumentsDirectory.

Take care,

Brent

Thanks Brent,

How I put my DataBase in that system.DocumentsDirectory, I have created my DataBase with Sqlite Studio, this have many tables.

I try put in Documents directory, but when I try to read any table  I receive “Table don’t exist”.

Also I try copy Data Base from Resources to Documents the result is the same.

I’m not sure how well you’re going to like this answer.

You cannot pre-build an SQLite database in system.DocumentsDirectory.  You might be able to get it to work in the simulator because the system.DocumentsDirectory folder is accessible from a Mac or from Windows.  However, the app you deploy to iOS or Android is a read-only bundle of compiled and crytpologically signed code and data.  You cannot change this in anyway.  When the app installs, the OS creates a writable sandbox folder that Corona SDK accesses as system.DocumentsDirectory.  This folder will be empty.

It’s your responsibility to include your SQLlite database in your system.ResourcesDirectory (i.e. the folder with main.lua) and when you app starts the first time, you need to create a new database in system.DocumentsDirectory, create all the necessary tables and insert all the necessary records into those tables on first setup.

Rob

Thank you so much Rob.

We just did a tutorial on how to accomplish this:

https://coronalabs.com/blog/2015/05/19/tutorial-initializing-a-writable-sqlite-database-from-a-read-only-database/

Rob

Thanks Rob,

I used this solution, is ok.