[php-src] master: Check liveness in PDO_ODBC

From: Date: Mon, 26 Apr 2021 11:03:07 +0000
Subject: [php-src] master: Check liveness in PDO_ODBC
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-115818@lists.php.net to get a copy of this message
Author: Calvin Buckley (NattyNarwhal) Committer: Nikita Popov (nikic) Date: 2021-04-26T13:03:07+02:00 Commit: https://github.com/php/php-src/commit/28a66b3f02aca7ef7be0c662dfebed619460aeff Raw diff: https://github.com/php/php-src/commit/28a66b3f02aca7ef7be0c662dfebed619460aeff.diff Check liveness in PDO_ODBC PDO drivers allow for it, and procedural ODBC has its own facility for it, but PDO_ODBC doesn't. If a connection is severed (for example, on IBM i, ending a databse job, or killing the network connection elsewhere), a persistent connection could get stuck. This adapts the procedural ODBC code to PDO for handling connection liveness, so PDO can reconnect if needed. A discussion about the method to check liveness is linked; this might not be the best method, but it's what procedural ODBC uses, so it's consistent. Closes GH-6805. Changed paths: M ext/pdo_odbc/odbc_driver.c Diff: diff --git a/ext/pdo_odbc/odbc_driver.c b/ext/pdo_odbc/odbc_driver.c index 790ee8785163..9d493accd349 100644 --- a/ext/pdo_odbc/odbc_driver.c +++ b/ext/pdo_odbc/odbc_driver.c @@ -372,6 +372,26 @@ static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val) return 0; } +static zend_result odbc_handle_check_liveness(pdo_dbh_t *dbh) +{ + RETCODE ret; + UCHAR d_name[32]; + SQLSMALLINT len; + pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data; + + /* + * SQL_ATTR_CONNECTION_DEAD is tempting, but only in ODBC 3.5, + * and not all drivers implement it properly + */ + ret = SQLGetInfo(H->dbc, SQL_DATA_SOURCE_READ_ONLY, d_name, + sizeof(d_name), &len); + + if (ret != SQL_SUCCESS || len == 0) { + return FAILURE; + } + return SUCCESS; +} + static const struct pdo_dbh_methods odbc_methods = { odbc_handle_closer, odbc_handle_preparer, @@ -384,7 +404,7 @@ static const struct pdo_dbh_methods odbc_methods = { NULL, /* last id */ pdo_odbc_fetch_error_func, odbc_handle_get_attr, /* get attr */ - NULL, /* check_liveness */ + odbc_handle_check_liveness, /* check_liveness */ NULL, /* get_driver_methods */ NULL, /* request_shutdown */ NULL, /* in transaction, use PDO's internal tracking mechanism */

« previous php.cvs (#115818) next »