Skip to content
Open
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: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
35 changes: 35 additions & 0 deletions ext/sqlite3/tests/gh25809.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
GH-25809 (SQLite3::backup() returns true when the backup fails)
--EXTENSIONS--
sqlite3
--FILE--
<?php

$source = new SQLite3(':memory:');
$source->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--
<?php
@unlink(__DIR__ . '/gh25809.db');
?>
--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)
Loading