diff --git a/NEWS b/NEWS index e42393462d83..c4985bb9fcb2 100644 --- a/NEWS +++ b/NEWS @@ -230,6 +230,10 @@ PHP NEWS . Fixed sodium_add() and sodium_increment() retaining stale string hashes and UTF-8 validity flags. (lacatoire) +- SQLite: + . Fixed bug GH-25809 (SQLite3::backup() returns true when the backup fails). + (Tomasz Kowalczyk) + - Standard: . Fixed bug GH-25474 (version_compare() treats large numeric parts as equal on 64-bit Windows). (lazerg, timwolla) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 19a226c1dca9..4d2c74891c9a 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1442,7 +1442,7 @@ PHP_METHOD(SQLite3, backup) rc = sqlite3_backup_finish(dbBackup); } else { - rc = sqlite3_errcode(source_obj->db); + rc = sqlite3_errcode(destination_obj->db); } if (rc != SQLITE_OK) { @@ -1453,7 +1453,7 @@ PHP_METHOD(SQLite3, backup) php_sqlite3_error(source_obj, rc, "Backup failed: source database is locked"); } else { - php_sqlite3_error(source_obj, rc, "Backup failed: %s", sqlite3_errmsg(source_obj->db)); + php_sqlite3_error(source_obj, rc, "Backup failed: %s", sqlite3_errmsg(destination_obj->db)); } RETURN_FALSE; } diff --git a/ext/sqlite3/tests/gh25809.phpt b/ext/sqlite3/tests/gh25809.phpt new file mode 100644 index 000000000000..33f4ad12279c --- /dev/null +++ b/ext/sqlite3/tests/gh25809.phpt @@ -0,0 +1,35 @@ +--TEST-- +GH-25809 (SQLite3::backup() returns true when the backup fails) +--EXTENSIONS-- +sqlite3 +--FILE-- +exec('CREATE TABLE t (a); INSERT INTO t VALUES (1)'); +$destination = new SQLite3(':memory:'); + +var_dump($source->backup($destination, 'main', 'nonexistent')); +var_dump($source->backup($destination, 'nonexistent', 'main')); + +$file = __DIR__ . '/gh25809.db'; +$writer = new SQLite3($file); +$writer->exec('CREATE TABLE z (a)'); +$writer->close(); +$readonly = new SQLite3($file, SQLITE3_OPEN_READONLY); +var_dump($source->backup($readonly)); + +?> +--CLEAN-- + +--EXPECTF-- +Warning: SQLite3::backup(): Backup failed: unknown database nonexistent in %s on line %d +bool(false) + +Warning: SQLite3::backup(): Backup failed: unknown database nonexistent in %s on line %d +bool(false) + +Warning: SQLite3::backup(): Backup failed: attempt to write a readonly database in %s on line %d +bool(false)