# 2010 January 7
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements utility functions for SQLite library.
#
# This file attempts to restore the header of a journal.
# This may be useful for rolling-back the last committed
# transaction from a recovered journal.
#
package require sqlite3
set parm_error 0
set fix_chksums 0
set dump_pages 0
set db_name ""
for
if
# is there a way to determine this?
set sectsz 512
# Copy file $from into $to
#
# Execute some SQL
#
# Perform a test
#
# Calc checksum nonce from journal page data.
#
# Calc checksum from journal page data.
#
# Print journal page data in hex dump form
#
# Setup for the tests. Make a backup copy of the files.
#
if
if
copy_file $db_name $db_name.org
copy_file $jrnl_name $jrnl_name.org
set db_fsize
set db_pgsz
set db_npage
set jrnl_fsize
set jrnl_npage
# calculate checksum nonce for first page
set nonce
# verify all the pages in the journal use the same nonce
for
# verify all the page numbers in the journal
for
# dump page data
if
# write the 8 byte magic string
hexio_write $jrnl_name 0 d9d505f920a163d7
# write -1 for number of records
hexio_write $jrnl_name 8 ffffffff
# write 00 for checksum nonce
hexio_write $jrnl_name 12
# write page count
hexio_write $jrnl_name 16
# write sector size
hexio_write $jrnl_name 20
# write page size
hexio_write $jrnl_name 24
# check the integrity of the database with the patched journal
sqlite3 db $db_name
do_test restore_jrnl-1.0
db close