Difference between window.openDatabase () and window.sqlitePlugin.openDatabase () functions?

Using Cordoba version 3.x and Android version 2.x - 4.x.

I am wondering:

  • As far as I understand, all Android devices by default have a sqlite program / interface for creating a sqlite database?
  • Do both of the above database function calls create an sqlite database on the device?
  • If the answer above is no , then what type of database performs both of the above create functions?
  • If the answer is yes , is it window.sqlite.openDatabase() wrapping the function around window.openDatabase() ?
  • Are the databases created by the call persistent? That is, is data available after closing and reopening cord packaging packages?
  • Is there a maximum database size that can be created in the two above ways?
+8
android sqlite cordova web-sql phonegap-plugins
source share
1 answer
  • WebSQL ( window.openDatabase ) is an outdated web standard. But it is available in most desktop and mobile browsers. Most browsers implement the specification using SQLite. On Android, browsers and WebViews support WebSQL, as well as local storage and session storage from the first versions, as well as IndexedDB with KitKat.

Then we have that Android independently supports SQLite for use with the Java API as one of the main mechanisms for saving it.

Cordoba is special. The application works in WebView, so it should use WebSQL, but in Android, the plugin redefines the API and implants in new window objects, which can by default use a different implementation, and not the browser API.

So, in the Cordova application, when it loads, when you call openDatabase , you actually call the new function that Cordoba has placed in the Windows object, overriding the old standard one. From Cordoba documents :

Some devices already provide an implementation of this specification. For these devices, built-in support is used instead of being replaced with a Cordoba implementation. For devices without storage support, the Cordova implementation must be compatible with the W3C specification.

This quote is ambiguous and is no longer in the docs. For "built-in", they meant built-in support for WebSQL in WebView. The documents I'm linked to are old, from version 2.x. In these versions, Cordova didnโ€™t execute a custom implementation by default if WebView didnโ€™t support WebSQL (I think this never happened), or if the device was affected by error 16175 . The default implementation was to use the Storage.java plugin, which used the Java API to create the SQLite database. I read the latest sources and in new versions (3.x) they seem to always use WebSQLite.

  1. Yes, both create a DB file, but the path to it will be different. In fact, you can open the same database from JavaScript code and Java code in your application.

  2. The same type of database. SQLite is its own C-layer that manages the file structure. In fact, you can also use this native C API from a native Android application.

  3. Cordoba / Phonegap uses SQLIte from the built-in support, if available (on Android, this).

  4. Yes, they stay there.

  5. Yes, there is a limit. Read more about here .

+8
source share

All Articles