diff --git a/src/crypto_impl.c b/src/crypto_impl.c index e5331f6..f73ee72 100644 --- a/src/crypto_impl.c +++ b/src/crypto_impl.c @@ -1359,11 +1359,11 @@ migrate: #endif CODEC_TRACE("renamed migration database %s to main database %s: %d\n", migrated_db_filename, db_filename, rc); - rc = sqlite3OsOpen(db->pVfs, migrated_db_filename, srcfile, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, &oflags); + rc = sqlite3OsOpen(db->pVfs, migrated_db_filename, srcfile, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_DB, &oflags); CODEC_TRACE("reopened migration database: %d\n", rc); if( rc!=SQLITE_OK ) goto handle_error; - rc = sqlite3OsOpen(db->pVfs, db_filename, destfile, SQLITE_OPEN_READWRITE, &oflags); + rc = sqlite3OsOpen(db->pVfs, db_filename, destfile, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_DB, &oflags); CODEC_TRACE("reopened main database: %d\n", rc); if( rc!=SQLITE_OK ) goto handle_error; diff --git a/test/crypto.test b/test/crypto.test index e900d1b..544a193 100644 --- a/test/crypto.test +++ b/test/crypto.test @@ -2098,11 +2098,43 @@ do_test migrate-3-0-database-to-current-format { execsql { PRAGMA key = 'testkey'; SELECT count(*) FROM sqlite_master; + PRAGMA journal_mode; } -} {1} +} {1 delete} db close file delete -force test.db +do_test migrate-wal-database-to-current { + file copy -force $sampleDir/sqlcipher-3.0-testkey.db test.db + sqlite_orig db test.db + set rc {} + + lappend rc [execsql { + PRAGMA key = 'testkey'; + PRAGMA cipher_page_size = 1024; PRAGMA kdf_iter = 64000; PRAGMA cipher_hmac_algorithm = HMAC_SHA1; PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1; + PRAGMA journal_mode = wal; + }] + db close + + sqlite_orig db test.db + lappend rc [execsql { + PRAGMA key = 'testkey'; + PRAGMA cipher_migrate; + PRAGMA journal_mode; + }] + db close + + sqlite_orig db test.db + lappend rc [execsql { + PRAGMA key = 'testkey'; + SELECT count(*) FROM sqlite_master; + PRAGMA journal_mode; + }] +} {wal {0 wal} {1 wal}} +db close +file delete -force test.db + + do_test key-database-by-name { sqlite_orig db test.db execsql {