Skip to content

Check liveness in PDO_ODBC #6805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion ext/pdo_odbc/odbc_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
* XXX: Should we be using SQL_ATTR_CONNECTION_DEAD? Procedural ODBC
* uses this check, but it might be problematic per #20298
Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think we should check for SQL_ATTR_CONNECTION_DEAD. ext/odbc likely doesn't do this, because SQLGetConnectAttr () is ODBC 3.0 and the ODBC 2.0 SQLGetConnectOption() doesn't support this attribute, but ext/odbc is still supposed to work with ODBC 2.0 (something we probably should have changed years ago). ext/pdo_odbc requires ODBC 3.0 anyway.

*/
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,
Expand All @@ -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 */
Expand Down