Skip to content

Add Pdo\Sqlite::backup() - #21326

Open
ndossche wants to merge 1 commit into
php:masterfrom
ndossche:fix-21323
Open

ndossche wants to merge 1 commit into
php:masterfrom
ndossche:fix-21323

Conversation

@ndossche

@ndossche ndossche commented Mar 1, 2026

Copy link
Copy Markdown
Member

No description provided.

@ndossche ndossche linked an issue Mar 1, 2026 that may be closed by this pull request
@ndossche
ndossche marked this pull request as ready for review March 1, 2026 21:26
@bohwaz

bohwaz commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Is there anything blocking this? It would be great to have it in next major PHP :)

@ndossche

ndossche commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

The lack of reviews is blocking this... :/

@bohwaz

bohwaz commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

The lack of reviews is blocking this... :/

:'-(

@ndossche
ndossche requested a review from LamentXU123 November 6, 2026 18:16
@devnexen

devnexen commented Nov 6, 2026

Copy link
Copy Markdown
Member

I may be tired, but seems there is a typo (it s a faithful port of the original not nora's fault).
see here.

If an error occurs within sqlite3_backup_init(D,N,S,M), then NULL is returned and an error code and error message are stored in the destination [database connection](https://www.sqlite.org/c3ref/sqlite3.html) D

@LamentXU123 LamentXU123 left a comment

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.

Perhaps ?

diff --git a/ext/pdo_sqlite/pdo_sqlite.c b/ext/pdo_sqlite/pdo_sqlite.c
--- a/ext/pdo_sqlite/pdo_sqlite.c
+++ b/ext/pdo_sqlite/pdo_sqlite.c
@@ -23,6 +23,7 @@
 #include "ext/standard/info.h"
 #include "SAPI.h"
 #include "ext/pdo/php_pdo.h"
+#include "ext/pdo/php_pdo_error.h"
 #include "ext/pdo/php_pdo_driver.h"
 #include "php_pdo_sqlite.h"
 #include "php_pdo_sqlite_int.h"
@@ -381,6 +382,7 @@
 	pdo_sqlite_db_handle *destination_db_handle = dbh->driver_data;
 	dbh = Z_PDO_DBH_P(ZEND_THIS);
 	PDO_CONSTRUCT_CHECK;
+	PDO_DBH_CLEAR_ERR();
 	pdo_sqlite_db_handle *source_db_handle = dbh->driver_data;
 
 	sqlite3_backup *dbBackup = sqlite3_backup_init(destination_db_handle->db, destination_dbname, source_db_handle->db, source_dbname);
@@ -393,7 +395,7 @@
 		/* Release resources allocated by sqlite3_backup_init(). */
 		rc = sqlite3_backup_finish(dbBackup);
 	} else {
-		rc = sqlite3_errcode(source_db_handle->db);
+		rc = sqlite3_errcode(destination_db_handle->db);
 	}
 
 	if (rc != SQLITE_OK) {
@@ -403,7 +405,7 @@
 			pdo_raise_impl_error(dbh, NULL, "HY000", "Backup failed: source database is locked");
 		} else {
 			char *message;
-			spprintf(&message, 0, "Backup failed: %s", sqlite3_errmsg(source_db_handle->db));
+			spprintf(&message, 0, "Backup failed: %s", sqlite3_errmsg(destination_db_handle->db));
 			pdo_raise_impl_error(dbh, NULL, "HY000", message);
 			efree(message);
 		}

@kocsismate kocsismate left a comment •

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.

LGTM, I compared the logic with SQLite3::backup and I found no difference.

UPDATE: actually should be approved once David's and Weilin's comments are addressed in some way or another

PDO_CONSTRUCT_CHECK;
pdo_sqlite_db_handle *destination_db_handle = dbh->driver_data;
dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;

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 (since it's a preexisting problem):The double calls to the same macro with different dbh is really ugly

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.

PDO\SQLite: add support for backup API

5 participants