Skip to content

Fix GH-25809: SQLite3::backup() returns true when the backup fails - #25810

Open
thunderer wants to merge 2 commits into
php:PHP-8.4from
thunderer:fix/sqlite3-backup-error
Open

thunderer wants to merge 2 commits into
php:PHP-8.4from
thunderer:fix/sqlite3-backup-error

Conversation

@thunderer

Copy link
Copy Markdown
Contributor

Fixes GH-25809.

When sqlite3_backup_init() fails, SQLite stores the error in the destination connection, and after a failed sqlite3_backup_step() the message is also there. SQLite3::backup() read both from the source connection, so it returned true for a nonexistent database name and reported "not an error" for other failures. Read the error code and message from the destination connection instead.

The open PR #21326 (Pdo\Sqlite::backup()) uses the same pattern.

When sqlite3_backup_init() fails, SQLite stores the error in the
destination connection, and a failed backup step leaves its message there
too. SQLite3::backup() read both from the source connection, so it
returned true for a nonexistent database name and reported "not an error"
for other failures. Read them from the destination connection.
Comment thread ext/sqlite3/tests/gh25809.phpt Outdated
var_dump($source->backup($destination, 'nonexistent', 'main'));

$file = __DIR__ . '/gh25809.db';
@unlink($file);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: --CLEAN-- already removes the file; this @unlink() can go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants