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 3 commits
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
17 changes: 16 additions & 1 deletion ext/pdo_odbc/odbc_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,21 @@ 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;
SQLUINTEGER dead;
pdo_odbc_db_handle *H = (pdo_odbc_db_handle *)dbh->driver_data;

/* ODBC 3.5; procedural ODBC uses SQLGetInfo read only instead */
Copy link
Member

Choose a reason for hiding this comment

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

Oh, you're right, SQL_ATTR_CONNECTION_DEAD is ODBC 3.5. We may need a fallback for ODBC 3.0 (maybe just not checking the liveliness there is okay).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm not having much luck with the Db2i driver on Linux; it reconnects, but dead returns both SQL_SUCCESS and dead == 0 (SQL_CD_FALSE). (And a segfault at the end, but I can only assume that might be my fault for running bleeding-edge Fedora.) I can try it on i directly too, but it's the same codebase on both.

If drivers can't report their dead status reliably, maybe using SQLGetInfo only or to verify if the driver is correct would work.

ret = SQLGetConnectAttr(H->dbc, SQL_ATTR_CONNECTION_DEAD, &dead, 0, NULL);

if (ret != SQL_SUCCESS || dead == SQL_CD_TRUE) {
return FAILURE;
}
return SUCCESS;
}

static const struct pdo_dbh_methods odbc_methods = {
odbc_handle_closer,
odbc_handle_preparer,
Expand All @@ -384,7 +399,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