Android 2.3開始採用Sqlite 3.7,而SQLite 3.7開始引入WAL Mode(Write Ahead Log),一種新的事務控制機制,
所以我們會在系統的簡訊與連絡人的資料庫下看到.db-wal的檔案格式,。
引入的目的是為了保證資料庫中的一致性,避免程式發生崩潰的時候也能保證資料庫的一致性。所以,這就是為什麼
第3方的程式有時能夠正常讀到連絡人的資料,有時卻讀不到的原因,使用者遇到這種情況,最好重啟下機器。
WAL檔案格式的詳細說明見: http://www.sqlite.org/fileformat2.html
其中提到:
A WAL file consists of a header followed by zero or more "frames". Each frame records the revised content of a single page from the database file. All changes to the database are recorded by writing frames into the WAL. Transactions commit when a frame is written that contains a commit marker. A single WAL can and usually does record multiple transactions. Periodically, the content of the WAL is transferred back into the database file in an operation called a "checkpoint".
A single WAL file can be reused multiple times. In other words, the WAL can fill up with frames and then be checkpointed and then new frames can overwrite the old ones. A WAL always grows from beginning toward the end. Checksums and counters attached to each frame are used to determine which frames within the WAL are valid and which are leftovers from prior checkpoints.