从 Web Worker 和主浏览器线程访问相同的 Web SQL 数据库
我在 google 上搜索了很多,但无法确定我是否应该能够从主 ui 线程和网络工作者访问相同的 websql 数据库。
我使用异步 API,因为我相信这是唯一为 Web Worker 和主 ui 线程实现的 API。
基本上,当两个线程针对同一数据库同时执行事务时,我会遇到问题。 SQLite 支持以受控方式访问数据库的多个线程,因此这应该是可能的。
有人这样做过吗?
I have googled quite a bit and cannot find out whether I should be able to access the same websql database from the main ui thread and a web worker.
I am using the async api since I believe this is the only API that has been implemented for both the web worker and the main ui thread.
Basically I get issues when both threads execute a transaction concurrently against the same database. SQLite supports multiple threads accessing a db in a controlled way so it should be possible.
Has anyone done this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Webworkers 的功能相当有限。您无法访问 websql 数据库或 localStorage。唯一的解决方法是将消息发送到处理更新的主窗口。
编辑:
这里是可用的网络工作人员功能的链接:
https://developer.mozilla.org /en/DOM/Worker/Functions_available_to_workers
Webworkers are quite limit in their features. You can't access a websql database or localStorage. The only work-around would be to send messages to the main-window which handles the updates.
EDIT:
Here is a link to the available webworker functions:
https://developer.mozilla.org/en/DOM/Worker/Functions_available_to_workers
查看 SQLite FAQ,有一个 SQLite 线程安全吗? 问题涉及 SQLITE_THREADSAFE 编译时选项。请参阅 SQLite 的编译选项。
然后,在核心函数部分。 org/lang.html" rel="nofollow">SQL 对于 SQLite 的理解,有一个
sqlite_compileoption_get(N)
函数:我认为你可以编写一个 SQLite 语句并从 JavaScript 调用来查看 PRAGMAcompile_options;已设置。
Looking at the SQLite FAQ, there is a Is SQLite threadsafe? question that refers to a SQLITE_THREADSAFE compile time option. See Compilation Options For SQLite.
Then, in the core functions section of SQL As Understood By SQLite, there is a
sqlite_compileoption_get(N)
function:I think you could write an SQLite statement and call from your JavaScript to see how PRAGMA compile_options; was set.
在 Chrome 上(在版本 29 上测试),您现在可以访问 webSql,只是不要使用
window
而是使用
另外,在调用
executeSql
时,请务必记录错误消息在第二个回调函数中。这有助于查看错误所在。
On Chrome (tested on ver 29), you can now have access the webSql, just don't use
window
instead use
Also when calling
executeSql
be sure to log the error message in the second callback function.This is helpful to see where the error is.