在 iOS 应用中实现 sqlite3_busy_timeout() [英] Implementing sqlite3_busy_timeout() in an iOS app
问题描述
我有一个使用 Sqlite3 作为数据库的 iOS 应用程序.该应用是多线程的.
I have a iOS app that uses Sqlite3 as the database. The app is multithreading.
我想确保应用程序不会从一个线程到另一个线程获取 SQlite 数据锁.我认为 sqlite3_busy_timeout() 可能是答案.
I want to make sure the app doesn't get SQlite data locks from one thread to another. I think sqlite3_busy_timeout() might be the answer.
我的问题是我把 sqlite3_busy_timeout() 放在哪里?我在 appdelegate 中打开到 sqlite 的连接.我应该在打开sqlite连接后立即放置sqlite3_busy_timeout(),还是每次执行数据调用时都需要放置.
My question is where do I put sqlite3_busy_timeout()? I open the connection to sqlite in the appdelegate. Should I put the sqlite3_busy_timeout() right after I open the sqlite connection, or do I need to put in every time I execute data call.
感谢您的帮助.
推荐答案
为什么不改用事务?这将确保表插入以原子方式完成.
why not use transactions instead? this will ensure table inserts are done atomically.
开始交易;
INSERT INTO "t1" VALUES(1, 'This is sample data', 3, NULL);
INSERT INTO "t1" VALUES(2, 'More sample data', 6, NULL);
INSERT INTO "t1" VALUES(3, 'And a little more', 9, NULL);
COMMIT;
这篇关于在 iOS 应用中实现 sqlite3_busy_timeout()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!