sqlite數據庫有必定概率出現損壞的狀況

如題,頭大,我用一些工程機測試時數據庫壞掉的時候會本身刪掉本身。。。。。。。。尤爲是舊的(android4.0)出現頻率還挺高的。修都沒的修。html

SQLite有一個很嚴重的缺點就是不提供Repair命令。
致使死亡提示database disk image is malformed
它的產生有不少種可能,好比,磁盤空間不足,還有就是寫入數據過程當中忽然掉電等。
官方對產生緣由的一些說明: http://www.sqlite.org/lockingv3.html#how_to_corruptjava

多線程操做也容易出現這種狀況。android

估計我那邊是由於多線程操做引發的。git

微信數據庫用的是sqllite數據庫,數據庫的名稱是EnMicroMsg.dbgithub

網上說密碼用手機的IMEI+UIN,而後取md5加密後的前幾位數字爲密碼,而後就能夠看數據庫的內容了。sql

微信把數據庫框架WCDB也開源了,https://github.com/Tencent/wcdb 地址在這裏數據庫

參考文檔:https://github.com/Tencent/wcdb/wikiwindows

有空要看看他們的框架。他們主要爲了就是下降數據庫損壞率。微信

 

另外,我也問了朋友,他們項目用的realm,數據量大的時候查找很是快,可是坑很是多,其中一個坑就是查出來的對象不能用intent傳遞,只能傳id。估計我這個項目先不換這個吧,畢竟查找少一些。數據條數很少。下個項目能夠試試。多線程

---------------------2018/3/8 補充------------------

通過新一輪線上錯誤收集,發現天天都會有幾回下面這個錯誤

android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1034)

java.sql.SQLException: Unable to run deleteById stmt on id 9295: DELETE FROM `inspect2_result` WHERE `generatedId` = ?
com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:25)
com.j256.ormlite.stmt.mapped.MappedDelete.deleteById(MappedDelete.java:75)
com.j256.ormlite.stmt.StatementExecutor.deleteById(StatementExecutor.java:542)
com.j256.ormlite.dao.BaseDaoImpl.deleteById(BaseDaoImpl.java:487)
com.iots.epo.inspect.dao.sys.PendingRequestDao.deleteByGeneratedId(PendingRequestDao.java:124)
com.iots.epo.inspect.service.HttpService$HttpRunnable.run(HttpService.java:439)
java.lang.Thread.run(Thread.java:818)\nCaused by: java.sql.SQLException: updating database failed: DELETE FROM `inspect2_result` WHERE `generatedId` = ?
com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:27)
com.j256.ormlite.android.AndroidDatabaseConnection.update(AndroidDatabaseConnection.java:313
com.j256.ormlite.android.AndroidDatabaseConnection.delete(AndroidDatabaseConnection.java:194)
com.j256.ormlite.stmt.mapped.MappedDelete.deleteById(MappedDelete.java:64)
... 5 more\nCaused by: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 1034)
android.database.sqlite.SQLiteConnection.nativeExecute(Native Method
android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:555
android.database.sqlite.SQLiteSession.execute(SQLiteSession.java:619)
android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:44)
com.j256.ormlite.android.AndroidDatabaseConnection.update(AndroidDatabaseConnection.java:311)
... 7 more\n

https://sqlite.org/rescode.html#ioerr_fstat  這裏查錯誤代碼,

(1034) SQLITE_IOERR_FSYNC

The SQLITE_IOERR_FSYNC error code is an extended error code for SQLITE_IOERR indicating an I/O error in the VFS layer while trying to flush previously written content out of OS and/or disk-control buffers and into persistent storage. In other words, this code indicates a problem with the fsync() system call in unix or the FlushFileBuffers() system call in windows.

仍是很困惑

相關文章
相關標籤/搜索