Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/sqlcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ static int sqlcipher_ctx_migrate(sqlite3 *db, sqlcipher_ctx *ctx) {
}

/* re-open the file handle to the main database */
rc = sqlite3OsOpen(db->pVfs, db_filename, destfile, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_DB, &oflags);
rc = sqlite3OsOpen(db->pVfs, db_filename, destfile, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_URI, &oflags);
if(rc != SQLITE_OK) {
sqlcipher_log(SQLCIPHER_LOG_DEBUG, SQLCIPHER_LOG_CORE, "%s: failed to reopen main database %s: %d", __func__, db_filename, rc);
goto handle_error;
Expand Down Expand Up @@ -2825,7 +2825,7 @@ static int sqlcipher_ctx_migrate(sqlite3 *db, sqlcipher_ctx *ctx) {
* so reopen it and re-initialize the sqlcipher_ctx so cleanup is not run against a closed file */
destfile = sqlite3PagerFile(sqlite3BtreePager(db->aDb[0].pBt));
if(destfile->pMethods == 0) { /* file is closed */
if((rc_cleanup = sqlite3OsOpen(db->pVfs, db_filename, destfile, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_DB, &oflags)) != SQLITE_OK) {
if((rc_cleanup = sqlite3OsOpen(db->pVfs, db_filename, destfile, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_URI, &oflags)) != SQLITE_OK) {
sqlcipher_log(SQLCIPHER_LOG_ERROR, SQLCIPHER_LOG_CORE, "%s: failed to re-open database file in error handler %s: %d", __func__, db_filename, rc_cleanup);
if(rc == SQLITE_OK) rc = rc_cleanup;
goto cleanup;
Expand Down
29 changes: 29 additions & 0 deletions test/sqlcipher-compatibility.test
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,20 @@ do_test migrate-failure-closed {
db close
file delete -force test.db

# the error handler keeps the URI parameters of the main database
do_test migrate-failure-closed-uri-filename {
file copy -force $sampleDir/sqlcipher-3.0-testkey.db test.db
sqlite_orig db file:test.db?psow=0
list [execsql {
PRAGMA key = 'testkey';
PRAGMA cipher_test_on = fail_migrate_closed;
PRAGMA cipher_migrate;
PRAGMA cipher_test_off = fail_migrate_closed;
}] [file_control_powersafe_overwrite db -1]
} {{ok 1} {0 0}}
db close
file delete -force test.db

# if a cipher_migrate that fails after the database migration has started
# should place the connection in a permanent error state
do_test migrate-failure-not-readable {
Expand Down Expand Up @@ -1480,6 +1494,21 @@ do_test migrate-quote-in-filename {
db close
file delete -force {"a test'ing--db".db} {"a test'ing--db".db-migrated}

# verify that cipher migrate keeps the URI parameters of the main database
foreach version {3.0 4.0} {
do_test migrate-uri-filename-$version {
file copy -force $sampleDir/sqlcipher-$version-testkey.db test.db
sqlite_orig db file:test.db?psow=0
list [execsql {
PRAGMA key = 'testkey';
PRAGMA cipher_migrate;
SELECT count(*) FROM t1;
}] [file_control_powersafe_overwrite db -1]
} {{ok 0 78536} {0 0}}
db close
file delete -force test.db
}

# verify escaping of database alias names in sqlcipher_export
do_test export-alias-quoting-1 {
sqlite_orig db test.db
Expand Down