Using Cordova version 3.x and Android version 2.x to 4.x.
I am wondering:
window.sqlite.openDatabase()
function wrapper around window.openDatabase()
?window.openDatabase
) is a deprecated web standard. But it is available in most desktop and mobile browsers. Most browsers implement the specification using SQLite. In Android, browsers and WebViews support WebSQL, along with local storage and session storage from the first versions, and also IndexedDB since KitKat.Then we have that Android independently supports SQLite to be used from Java APIs as one of its main persistence mechanisms.
Cordova is special. The app runs in a WebView so it should be using WebSQL, but in Android the plugin overrides the API and implants into the window object new functions that might default to a different implementation, rather than the browser API.
So in a Cordova app, once it is loaded, when you call openDatabase
you are actually calling a new function that Cordova has placed in the windows object overriding the old standard one. From the Cordova docs:
Some devices already provide an implementation of this spec. For those devices, the built-in support is used instead of replacing it with Cordova's implementation. For devices that don't have storage support, Cordova's implementation should be compatible with the W3C specification.
That quote is ambiguous and no longer in the docs. For "built-in" they meant built-in WebSQL support in the WebView. The docs I linked are old, from a 2.x version. In those versions, Cordova only defaulted to the custom implementation if the WebView did not support WebSQL (I think this never happened) or if the device was affected by the bug 16175. The default implementation consisted on using the Storage.java
plugin that used the Java API to create an SQLite database. I've been reading the most recent sources and on newer (3.x) versions they seem to be using WebSQLite always.
Yes both create a DB file but the path to it will be different. In fact you can open the same DB from the JavaScript code and the Java code in your app.
Same type of DB. SQLite is a native C layer that manages the file structure. In fact, you could also use this native C API from a native Android app.
Cordova / Phonegap use SQLIte from the built-in support if available (in Android it is).
Yes, they stay there.
Yes, there's a limit. Check here for more info.