From 5d1331a5a227dc3344c0c810bb75ffc4fb587508 Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Sat, 16 Dec 2023 00:00:30 +0900 Subject: [PATCH 1/2] add pdo_firebird_check_liveness --- ext/pdo_firebird/firebird_driver.c | 18 ++++++- .../tests/persistent_connect.phpt | 47 +++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 ext/pdo_firebird/tests/persistent_connect.phpt diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index a4c1a67601dbb..d8832303272f4 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -1216,6 +1216,18 @@ static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) } /* }}} */ +#if FB_API_VER >= 30 +/* called by PDO to check liveness */ +static zend_result pdo_firebird_check_liveness(pdo_dbh_t *dbh) /* {{{ */ +{ + pdo_firebird_db_handle *H = (pdo_firebird_db_handle *)dbh->driver_data; + + /* fb_ping return 0 if the connection is alive */ + return fb_ping(H->isc_status, &H->db) ? FAILURE : SUCCESS; +} +/* }}} */ +#endif + /* called by PDO to retrieve driver-specific information about an error that has occurred */ static void pdo_firebird_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) /* {{{ */ { @@ -1254,7 +1266,11 @@ static const struct pdo_dbh_methods firebird_methods = { /* {{{ */ NULL, /* last_id not supported */ pdo_firebird_fetch_error_func, pdo_firebird_get_attribute, - NULL, /* check_liveness */ +#if FB_API_VER >= 30 + pdo_firebird_check_liveness, +#else + NULL, +#endif NULL, /* get driver methods */ NULL, /* request shutdown */ pdo_firebird_in_manually_transaction, diff --git a/ext/pdo_firebird/tests/persistent_connect.phpt b/ext/pdo_firebird/tests/persistent_connect.phpt new file mode 100644 index 0000000000000..1467bd31054a3 --- /dev/null +++ b/ext/pdo_firebird/tests/persistent_connect.phpt @@ -0,0 +1,47 @@ +--TEST-- +PDO_Firebird: persistent connect test +--EXTENSIONS-- +pdo_firebird +--SKIPIF-- + +--XLEAK-- +A bug in firebird causes a memory leak when calling `isc_attach_database()`. +See https://github.com/FirebirdSQL/firebird/issues/7849 +--FILE-- + true, + ], + ); + $stmt = $dbh->query('SELECT CURRENT_CONNECTION FROM RDB$DATABASE'); + $connId = $stmt->fetchColumn(); + $connIds[] = $connId; + echo "{$times} connection ID: {$connId}\n"; + + unset($dbh); + unset($stmt); + unset($connID); +} + +echo $connIds[0] === $connIds[1] ? "Same ID.\n" : "Different ID\n"; +?> +--EXPECTF-- +First connection ID: %d +Second connection ID: %d +Same ID. From 1b7f727085ae6647e674ef4d90ce5c97953a2b01 Mon Sep 17 00:00:00 2001 From: SakiTakamachi Date: Thu, 21 Dec 2023 00:36:10 +0900 Subject: [PATCH 2/2] [ci skip] UPGRADING --- UPGRADING | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UPGRADING b/UPGRADING index d7c640c3e2b23..ce83dc006b40f 100644 --- a/UPGRADING +++ b/UPGRADING @@ -223,6 +223,8 @@ PHP 8.4 UPGRADE NOTES Along with these, five constants (PDO::FB_TRANSACTION_ISOLATION_LEVEL, PDO::FB_READ_COMMITTED, PDO::FB_REPEATABLE_READ, PDO::FB_SERIALIZABLE, PDO::FB_WRITABLE_TRANSACTION) have been added. + . When using persistent connections, there is now a liveness check in the + constructor. - PDO_MYSQL: . getAttribute, enabled to get the value of ATTR_FETCH_TABLE_NAMES.