Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite database on PhoneGap / iOS - More than 5mb possible

I'm a little confused about the limitations of using SQLite in a Phonegap-Native-App on iOS.

You can read many posts about the limit of 5mb storage and the fact, that your Ipad can ask you to increase the storage.

Now I've managed to insert nearly 7000 rows into my SQLite database, using the usual Phonegap-Storage-API. The corresponding db-file has a size of 26 MB. A following select-statement "select * from " worked and was showing the db's content. I've done that in the simulator and on the device. I didn't get the question to increase the storage.

How can that be? Do I misunderstand something? Is there really a 5mb limit for SQLite dbs in Phonegap? I'm using Phonegap 1.2 and iOS 5.

like image 606
Sascha Avatar asked Jan 24 '12 13:01

Sascha


3 Answers

You can use a native SQLite DB (same as WebSQL) with a phonegap plugin, and you will not have any limitation. In iOS5.1, WebSQL is considered temporary data that can be deleted at any time...That plugin save the database in the Document folder, that mean that the DB is not deleted and is saved by iCloud.

Here is the Native SQLite phonegap plugin : https://github.com/davibe/Phonegap-SQLitePlugin Regarding this plugin, there are some differences between the WebSQL API, here is an adaptor: https://gist.github.com/2009518

You should also migrate the old WebSQL db file (stored in Library/WebKit or Caches directory) to the Document folder. Here is a code to do that : https://gist.github.com/2009491

And if the data are important, you should save it to a server. I wrote a small lib to synchronize the SQlite DB to a server : https://github.com/orbitaloop/WebSqlSync

like image 129
Samuel Avatar answered Sep 22 '22 00:09

Samuel


I found out by myself:

It succeeds to open the first transaction and insert the 7000 records at one time in that one and only transaction.

If I split the inserts into separate transactions, let's say 500 records per transaction, the limitation of 5 MB takes affect. PhoneGap doesn't say anything, it just doesn't insert the records.

like image 20
Sascha Avatar answered Sep 23 '22 00:09

Sascha


The problem with HTML5 Storage on devices, it will not allow you to increase the size. Have a look with this solution:

Solved iOS Database Size Limitation of 5MB (using Plugin)

Hope this will help you.

Cheers

like image 22
Lauren Avatar answered Sep 23 '22 00:09

Lauren