window.openDatabase()和window.sqlitePlugin.openDatabase()函数之间的区别? [英] difference between window.openDatabase() and window.sqlitePlugin.openDatabase() functions?

查看:2160
本文介绍了window.openDatabase()和window.sqlitePlugin.openDatabase()函数之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用科尔多瓦版本3.x和
Android版本2.x到4.x版。

我很纳闷:


  1. 我的理解是正确的,在默认情况下所有的Andr​​oid设备都用于创建SQLite数据库一个​​SQLite程序/接口?

  2. 请上述两个数据库函数调用创建在设备中的SQLite数据库?

  3. 如果以上的答案是,然后就上述两个函数调用创建什么类型的数据库?

  4. 如果答案是,然后是 window.sqlite.openDatabase()各地函数包装 window.openDatabase ()

  5. 由呼叫持续创建的数据库?也就是说,关闭并重新打开科尔多瓦打包应用程序后,现有的数据?

  6. 是否有一个最大可通过上述两种方法创建的数据库大小?


解决方案

  1. 的WebSQL window.openDatabase )是德precated的网络标准。但是,在大多数桌面和移动浏览器。大多数浏览器实现使用SQLite的规范。在Android中,浏览器和网页视图支持的WebSQL,因为与当地奇巧存储和从第一届的版本存储,并且还沿着IndexedDB的。

然后我们有一个独立的Andr​​oid SQLite的支持是从的Java API作为其主要的持久性机制之一。

科尔多瓦是特殊的。该应用程序在运行网页视图,因此应该使用的WebSQL,但在Android的插件覆盖API和植入到窗口对象可能默认为不同的实现,而不是浏览器A​​PI的新功能。

因此​​,在科尔多瓦的应用程序,一旦它被加载,当你调用的openDatabase 你实际上是调用一个新的函数,科尔多瓦已放置在窗口对象覆盖旧标准一。从科尔多瓦文档


  

有些设备已经提供了该规范的实现。这些设备的内置支持,而不使用与科尔多瓦的实现来代替。对于不具备存储设备的支持,科尔多瓦的实施应符合W3C规范兼容。


这报价不明确,并在文档不再。对于内置他们的意思内置的web视图的WebSQL支持。我联系的文档都老了,从2.x版。在这些版本中,只有科尔多瓦默认为自定义实现,如果web视图不支持的WebSQL(我认为这从未发生过),或者如果设备受到的错误16175 。默认的实现包括对使用使用的Java API来创建一个SQLite数据库中的 Storage.java 插件。我一直在阅读最近来源并在更新(3。 x)的版本,他们似乎可以用WebSQLite始终。

<醇开始=2>
  • 是既建立DB文件,但其路径将有所不同。事实上,你可以打开JavaScript的code相同的数据库,并在你的应用在Java code。


  • 同类型DB的。 SQLite是一个管理文件结构本地C层。事实上,你也可以使用此本机C API从原生Android应用程序。


  • 科尔多瓦/ PhoneGap的使用SQLite从内置的支持(如果可用)(在Android中它是)。


  • 是的,他们呆在那里。


  • 是的,有限制。检查<一href=\"http://stackoverflow.com/questions/3482635/what-is-a-maximum-size-of-sqlite-database-on-android\">here获取更多信息。


  • Using Cordova version 3.x and Android version 2.x to 4.x.

    I am wondering:

    1. Is my understanding correct that all android devices by default have an sqlite program/interface for creating sqlite database?
    2. Do both the above database function calls create a sqlite database in the device?
    3. If the above answer is no, then what type of Database do both the above function calls create?
    4. If the answer is yes, then is window.sqlite.openDatabase() function wrapper around window.openDatabase()?
    5. Are the databases created by the call persistent? That is, is the data available after closing and reopening the cordova packaged apps?
    6. Is there a maximum the database size that can be created by the above two methods?

    解决方案

    1. WebSQL (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.

    1. 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.

    2. 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.

    3. Cordova / Phonegap use SQLIte from the built-in support if available (in Android it is).

    4. Yes, they stay there.

    5. Yes, there's a limit. Check here for more info.

    这篇关于window.openDatabase()和window.sqlitePlugin.openDatabase()函数之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆