iPhone中的Sqlite3数据库被锁定 - 如何避免? [英] Sqlite3 database in iPhone gets locked - how to avoid?

查看:156
本文介绍了iPhone中的Sqlite3数据库被锁定 - 如何避免?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Sqlite3数据库上执行搜索的查询。除了使用阅读器阅读之外什么都不做。
对于每个找到的匹配,它调用UI的回调来更新结果视图。

I have a query that performs a search on an Sqlite3 DB. It does nothing but read using a reader. For each found match it calls a callback to the UI which updates a result view.

当这个搜索正在运行时,我点击了UI中的一个按钮将在新线程中执行一些其他操作。最后它应该删除搜索控制器的视图并显示一个新的控制器。

While this search is running, I hit a button in the UI which will perform some other action in a new thread. In the end it is supposed to remove the search controller's view and show a new controller.

然而,在某些时候触发的动作想要写入数据库。它只是挂起,最终我会看到数据库被锁定的异常。

However, at some point the the triggered action wants to write to the databse. And there it just hangs and eventually I will see an exception that the DB is locked.

有趣的是,搜索阅读器也没有继续,这是一个僵局。

Interesting is also, that the search reader does not continue either, it is a deadlock.

我是否必须以某种特殊方式打开数据库以支持多线程使用?连接的构造函数是什么?

Do I have to open the database in some special way to support multithreaded usage? What would the constructor for the connection be?

推荐答案

MonoTouch 5.1+提供了 API ,让您选择与SQLite一起使用的线程模型。

MonoTouch 5.1+ provides an API to let you select the threading model to be used with SQLite.

SqliteConnection.SetConfig (SQLiteConfig.MultiThread);

这映射到某些连接选项

更新:如果你是使用早期版本的MonoTouch(例如介于4.2和5.0.x之间),您可以使用附加到错误报告的二进制文件#652 (按照说明进行操作)或将补丁(p / invoke和enum)复制粘贴到您自己的应用程序中。

UPDATE: If you're using an earlier version of MonoTouch (e.g. between 4.2 and 5.0.x) you can use the binary attached to the bug report #652 (follow the instructions) or copy-paste the patch (p/invoke and enum) inside your own application.

这篇关于iPhone中的Sqlite3数据库被锁定 - 如何避免?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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