PhoneGap 上的 SQLite 数据库
我想使用 PhoneGap 为 iPhone 实现 SQLite 数据库.我知道 iPhone 本机应用程序中的一些基础 SQLite 数据库.但是如何在PhoneGap中实现SQLite数据库呢?
I want to implement SQLite database for iPhone using PhoneGap. I know some basics SQLite database in iPhone native application. But how can I implement SQLite database in PhoneGap?
请务必记住,PhoneGap 是打包在浏览器组件中的网络应用.适用于移动 WebKit 的所有内容也将适用于 PhoneGap,PhoneGap 中的环境也与在桌面浏览器中打开 HTML 文件非常相似.
It's important to remember that PhoneGap is web apps packaged in a browser component. Everything that applies to mobile WebKit will apply to PhoneGap as well, and the environment in PhoneGap is also very similar to opening an HTML-file in a desktop browser.
您需要所谓的Web SQL 数据库".
You want what's called a 'Web SQL Database'.
http://www.w3.org/TR/webdatabase/
自撰写此答案以来,此规范已被标记为已弃用,现在依赖它已成为官方的 Bad Idea™.
This specification has been marked as deprecated since the writing of this answer and it's now an officially Bad Idea™ to depend on it.
实际上,它在大多数支持它的浏览器中都基于 SQLite,但它不会完全是 SQLite 实现.但它很接近.在 Chrome 或 Safari 中,您可以使用开发者工具查看其内容,查看资源"选项卡 -> 数据库(您想在使用 PhoneGap 之前在桌面浏览器上测试基本功能).
In reality, it's based on SQLite in most browsers that support it, but it won't be exactly the SQLite implementation. But it's close. In Chrome or Safari, you can go have a look at it's contents with your developer tools, look at the 'Resources' tab -> Databases (you want to test out basic functionality on a desktop browser before trying in PhoneGap).
它在 PhoneGap 中的工作方式与在桌面浏览器中完全相同.
It will work exactly the same in PhoneGap as in desktop browsers.
Web SQL 数据库是更广泛地称为本地存储"的一种实现.我认为关于该主题的最佳介绍文本可以在 Mark Pilgrim 的Dive into HTML5"中找到:
Web SQL databases are one implementations of what's more broadly referred to as "local storage". I think that the best introductionary text on that topic can be found in Mark Pilgrim's "Dive into HTML5":
http://diveintohtml5.info/storage.html
对于 PhoneGap 和桌面浏览器仍然一样有效.
Still just as valid for PhoneGap as for desktop browsers.