What database does PhoneGap use and what is the size limit?

CordovaMobileOffline

Cordova Problem Overview


I wrote an HTML5 database that abstracts localStorage, indexedDB, and WebSQL. Using straight HTML5 my database options look like this:

  • IE10 - indexedDB - 1GB max
  • FireFox - indexedDB - unlimited
  • Safari - WebSQL - 50MB max
  • Chrome - IndexedDB (or Web SQL) - unlimited (with the HTML5 Quota API ref1, ref2)
  • Opera - WebSQL (until they switch to webkit?) - unlimited

I would like to expand the maximum database size using PhoneGap or the Quota API. From PhoneGap's documentation it looks like the current PhoneGap database ecosphere is:

  • WebSQL - Android, Blackberry, iPhone, and webOS
  • localStorage - Windows Phone 7
  • indexedDB - Windows Phone 8 and, i am guessing, everywhere indexedDB is available but WebSQL isn't.

There are also the PhoneGap SqlLite plugins. iOS, Android, Windows Phone 8+


QUESTION 1 - Is my understanding of what database PhoneGap will use accurate?

QUESTION 2 - Is there any solid documentation about how much data a PhoneGap database of a given type will store? *If it is a PhoneGap database and not the browsers database implementation.

QUESTION 3 - Does PhoneGap have plans to adhere to the the Web Storage standards thereby dropping WebSQL in favor of indexedDB? If so, will I still be able to use my existing WebSQL code (via a built in PhoneGap-polyfill) once the switch to indexedDB is made?

QUESTION 4 - In situations where database size is limited and cannot be expanded by either PhoneGap or the Quota API, but access to the file system is available, is it reasonable to assume that "extra" data could be stored on the device's file system or on a SD card?

Cordova Solutions


Solution 1 - Cordova

> Is my understanding of what database PhoneGap will use accurate?

Yes it is. PhoneGap can use LocalStorage, SessionStorage, or SQLite databases. You can also, alternatively use PhoneGap to connect to the devices native classes via a plugin, and pass the native class data, that it will then store on the device.

> Is there any solid documentation about how much data a PhoneGap database of a given type will store? If it is a PhoneGap database and not the browsers database implementation.

  1. LocalStorage :: 10MB
  2. SessionStorage :: 10MB
  3. SQLite Database :: 50MB-80MB (depends on the device)
  4. Native Database using plugin call :: Unlimited data amount
  5. IndexedDB :: 5MB. Still existant. But very buggy, theres a list of devices/OS's that run it here

> Does PhoneGap have plans to adhere to the the Web Storage standards thereby dropping WebSQL in favor of indexedDB? If so, will I still be able to use my existing WebSQL code (via a built in PhoneGap-polyfill) once the switch to indexedDB is made?

WebSQL is slowly being deprecated. Its replacement is IndexedDB or SQLite. The best option for you, however, is either SQLite or the Native Database (for example Core Data on the iOS)

> In situations where database size is limited and cannot be expanded by either PhoneGap or the Quota API, but access to the file system is available, is it reasonable to assume that "extra" data could be stored on the device's file system or on a SD card?

It is definitely possible.

  • On Android you can specify the location of the database, and therefore push data to an external database.
  • On iOS, you can use the native database call to store data on CoreData, there is no external memory.
  • In all cases of all OS's, you can create a flat database file, like a Text file, store your data in key-value lists, and then pull those into your app at first run. Beware of the memory management in this case.

I've added an explanation of how to go about coding for the SQLite and LocalStorage databases in my answer.

Solution 2 - Cordova

I was able to run a test on an Android 4.0.4 tablet. It uses WebSQL (an old version of WebSQL that doesn't even support db.changeVersion) and it allowed me to fill up the entire hard drive (12GB with my database). I don't know about other devices or how SD cards work.

enter image description here

Solution 3 - Cordova

IndexedDB -

  • It is incompatible with many types of mobile OS and versions
  • It is only compatible with very specific versions of mobile OS
  • Developers cannot use SQL with IndexedDB. SQL statements can be used on SQLite and WebSQL
  • Most developers actively avoid using IndexedDB as much as they can

WebSQL -

  • It has been deprecated by W3C which means it is no longer maintained or developed
  • It requires another plugin called Polyfill to enable mobile applications to work with popular mobile OS such as Google Android and Apple iOS

SQLite -

  • It received an award from Google
  • SQLite has its official website. IndexedDB and WebSQL do not
  • On Google, SQLite returns 1.8 million results. WebSQL returns a bit less than 700K results and IndexedDB returns 282K results.
  • Developer can use common SQL statements with SQLite.

If you want a quick tutorial on SQLite

https://stackoverflow.com/questions/19570868/storage-of-sqlite-database-using-android-and-phonegap/25518453#25518453

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1873073View Question on Stackoverflow
Solution 1 - CordovaSashaZdView Answer on Stackoverflow
Solution 2 - Cordovauser1873073View Answer on Stackoverflow
Solution 3 - CordovaKershawRocksView Answer on Stackoverflow