数据库操作线程安全吗? [英] Are Database operations thread safe?

查看:146
本文介绍了数据库操作线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的iPhone应用程序中使用sqlite。

I am using sqlite in my iPhone app.

我有一些数据库操作,我必须在两个表中插入不同的数据(意味着没有数据依赖)。我可以在单独的线程中执行这两个操作。而每个表中的插入操作不止一个。所以我在一个while循环也这样做。

I have some database operations, in which I have to insert into two tables different data(means there is no data-dependency). Can I perform these two operations in seperate thread. While the insert operation in each table are more than one. So I am doing this in a while loop also.

推荐答案

SQLite本身可以构建为线程安全的(对于v3.3.1或更高版本, c $ c> SQLITE_THREADSAFE defined)。您可以通过调用 sqlite_threadsafe()验证。

SQLite itself can be built to be thread-safe (for v3.3.1 or later, if it is compiled with SQLITE_THREADSAFE defined). You can verify this by calling sqlite_threadsafe().

我建议您仔细阅读以下内容:

I suggest you read the following carefully:

  • SQLite FAQ on threading

即使SQLite是线程安全的,您也可以重新访问您的设计。有多个线程写入数据库可能不是理想的,可以重新设计以避免完全需要。

Even if SQLite is thread-safe, you may wish to revisit your design. Having multiple threads write to the database is probably not ideal, and it may be possible to redesign to avoid the requirement altogether.

这篇关于数据库操作线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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