Checksum for SQLite database?

I would like to know if the SQLite database file has been updated in any way. How can I implement this?

The first solution that I think of compares checksums, but in fact I have no experience with checksums.

+3
source share
3 answers

According to http://www.sqlite.org/fileformat.html, SQLite3 supports file change countera byte 24..27database file. It does not depend on the time the file changed, which, for example, can change after recovery or rollback the binary file, while nothing has changed:

$ sqlite3 test.sqlite 'create table test ( test )'
$ od --skip-bytes 24 --read-bytes=4 -tx1  test.sqlite | sed -n '1s/[^[:space:]]*[[:space:]]//p' | tr -d ' '
00000001
$ sqlite3 test.sqlite "insert into test values ( 'hello world');"
$ od --skip-bytes 24 --read-bytes=4 -tx1  test.sqlite | sed -n '1s/[^[:space:]]*[[:space:]]//p' | tr -d ' '
00000002
$ sqlite3 test.sqlite "delete from test;"
$ od --skip-bytes 24 --read-bytes=4 -tx1  test.sqlite | sed -n '1s/[^[:space:]]*[[:space:]]//p' | tr -d ' '
00000003
$ sqlite3 test.sqlite "begin exclusive; insert into test values (1); rollback;"
$ od --skip-bytes 24 --read-bytes=4 -tx1  test.sqlite | sed -n '1s/[^[:space:]]*[[:space:]]//p' | tr -d ' '
00000003

, "", (.dump), INSERT (, ). .

+6

.

, OS?

+1

sqlite ( ), , , (, , , ), 100 ( ) http://www.sqlite.org/fileformat.html

24..27 SQlite doc :

24..27 4
. , , 32- , ,

After some testing, a message appears stating that the file change counter does not increase during the database transaction, but contains only select statements, which is the behavior you want in case you complete the selection in the transaction and complete the transaction.

+1
source

Source: https://habr.com/ru/post/1784336/


All Articles