From 75cec3d097a548e203b26d33dc68d974eae09f7b Mon Sep 17 00:00:00 2001 From: Eric Norris Date: Mon, 3 Aug 2020 21:29:18 -0400 Subject: [PATCH] Add PDO::checkLiveness method Exposes the driver's underlying pdo_dbh_check_liveness_func to PHP scripts that may want to check if a connection is still open. --- ext/pdo/pdo_dbh.c | 23 +++++++++++++++++++++++ ext/pdo/pdo_dbh.stub.php | 3 +++ ext/pdo/pdo_dbh_arginfo.h | 6 +++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index f172d44ea9379..c62c81028d599 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -1096,6 +1096,29 @@ PHP_METHOD(PDO, query) } /* }}} */ +/* {{{ Performs a liveness check */ +PHP_METHOD(PDO, checkLiveness) +{ + pdo_dbh_t *dbh = Z_PDO_DBH_P(ZEND_THIS); + + ZEND_PARSE_PARAMETERS_NONE(); + + PDO_CONSTRUCT_CHECK; + + if (!dbh->methods->check_liveness) { + zend_throw_exception_ex(php_pdo_get_exception(), 0, "This driver doesn't support checkLiveness"); + RETURN_THROWS(); + } + + if (dbh->methods->check_liveness(dbh) != FAILURE) { + RETURN_TRUE; + } + + PDO_HANDLE_DBH_ERR(); + RETURN_FALSE; +} +/* }}} */ + /* {{{ quotes string for use in a query. The optional paramtype acts as a hint for drivers that have alternate quoting styles. The default value is PDO_PARAM_STR */ PHP_METHOD(PDO, quote) { diff --git a/ext/pdo/pdo_dbh.stub.php b/ext/pdo/pdo_dbh.stub.php index bde46dd712e2f..c52967b0dba47 100644 --- a/ext/pdo/pdo_dbh.stub.php +++ b/ext/pdo/pdo_dbh.stub.php @@ -9,6 +9,9 @@ public function __construct(string $dsn, ?string $username = null, ?string $pass /** @return bool */ public function beginTransaction() {} + /** @return bool */ + public function checkLiveness() {} + /** @return bool */ public function commit() {} diff --git a/ext/pdo/pdo_dbh_arginfo.h b/ext/pdo/pdo_dbh_arginfo.h index 1057c54665274..444020cbdb8ff 100644 --- a/ext/pdo/pdo_dbh_arginfo.h +++ b/ext/pdo/pdo_dbh_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 36270d1418fc4ddd8f79018372b0ef00fb6f5889 */ + * Stub hash: 379b21e9f0e26c7095c7366fa1eac71388ba0014 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, dsn, IS_STRING, 0) @@ -11,6 +11,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_beginTransaction, 0, 0, 0) ZEND_END_ARG_INFO() +#define arginfo_class_PDO_checkLiveness arginfo_class_PDO_beginTransaction + #define arginfo_class_PDO_commit arginfo_class_PDO_beginTransaction #define arginfo_class_PDO_errorCode arginfo_class_PDO_beginTransaction @@ -59,6 +61,7 @@ ZEND_END_ARG_INFO() ZEND_METHOD(PDO, __construct); ZEND_METHOD(PDO, beginTransaction); +ZEND_METHOD(PDO, checkLiveness); ZEND_METHOD(PDO, commit); ZEND_METHOD(PDO, errorCode); ZEND_METHOD(PDO, errorInfo); @@ -77,6 +80,7 @@ ZEND_METHOD(PDO, setAttribute); static const zend_function_entry class_PDO_methods[] = { ZEND_ME(PDO, __construct, arginfo_class_PDO___construct, ZEND_ACC_PUBLIC) ZEND_ME(PDO, beginTransaction, arginfo_class_PDO_beginTransaction, ZEND_ACC_PUBLIC) + ZEND_ME(PDO, checkLiveness, arginfo_class_PDO_checkLiveness, ZEND_ACC_PUBLIC) ZEND_ME(PDO, commit, arginfo_class_PDO_commit, ZEND_ACC_PUBLIC) ZEND_ME(PDO, errorCode, arginfo_class_PDO_errorCode, ZEND_ACC_PUBLIC) ZEND_ME(PDO, errorInfo, arginfo_class_PDO_errorInfo, ZEND_ACC_PUBLIC)