Ads 468x60px

##EasyReadMore##

08 9月, 2016

sqlite 使用 sqlite3_prepare 會停住 (threadsafe )

最近使用 sqlite3_prepare 會掛點
後來才爬文到 sqlite 會有 threadsafe 的問題
不能在同一時間兩個 thread 同時使用

見下文:
By "threadsafe" we mean that you can use different SQLite database connections in different threads at the same time. It has never been safe to use the same database connection simultaneously in multiple threads. If you use the sqlite3_prepare() API to create prepared statements, each prepared statement is considered to be a part of the database connection from which it was derived. So you cannot run two prepared statements originating from the same database connection in different threads at the same time.

解法:

參照 pthread_mutex_lock 的用法
 [C] 互斥鎖 pthread_mutex_lock sample - http://goo.gl/9cvUnL

本來有想過將 database 讀出來放到 linklist ,以減少開 database 的機會
但其實當資料庫成功被開啟後也會先暫存在記憶體中
所以是一樣的道理

objective c - sqlite3_prepare_v2 exc_bad_access - Stack Overflow - http://goo.gl/hkbBft


使用 SQLite 資料庫 - http://goo.gl/GqTI1d

3 由於sqlite支持純記憶體資料庫,把所有庫放在記憶體中。可以結合上述兩種需求。即從大庫查詢(或導出)部分數據,在記憶體中進行統計。

powershell玩轉sqlite資料庫_ZenDei技術網路在線 - http://goo.gl/3o4SfS

0 意見:

張貼留言

 
Blogger Templates