Skip to content

Commit dd7f861

Browse files
cmb69NattyNarwhal
authored andcommitted
Avoid calling deprecated ODBC functions
`SQLGetConnectOption`, `SQLSetConnectOption` and `SQLSetStmtOption` are deprecated, so if ODBC 3 is available, we use `SQLSetConnectAttr`, `SQLGetConnectAttr`, and `SQLSetStmtAttr` instead. (This is based on GH-17556, but just assumes ODBC 3.x.)
1 parent 3324565 commit dd7f861

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ext/odbc/php_odbc.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ PHP_FUNCTION(odbc_prepare)
925925
/* Try to set CURSOR_TYPE to dynamic. Driver will replace this with other
926926
type if not possible.
927927
*/
928-
SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, ODBCG(default_cursortype));
928+
SQLSetStmtAttr(result->stmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) ODBCG(default_cursortype), 0);
929929
}
930930
} else {
931931
result->fetch_abs = 0;
@@ -1312,7 +1312,7 @@ PHP_FUNCTION(odbc_exec)
13121312
/* Try to set CURSOR_TYPE to dynamic. Driver will replace this with other
13131313
type if not possible.
13141314
*/
1315-
SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, ODBCG(default_cursortype));
1315+
SQLSetStmtAttr(result->stmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) ODBCG(default_cursortype), 0);
13161316
}
13171317
} else {
13181318
result->fetch_abs = 0;
@@ -2146,7 +2146,7 @@ bool odbc_sqlconnect(zval *zv, char *db, char *uid, char *pwd, int cur_opt, bool
21462146
}
21472147
#else
21482148
if (cur_opt != SQL_CUR_DEFAULT) {
2149-
rc = SQLSetConnectOption(link->connection->hdbc, SQL_ODBC_CURSORS, cur_opt);
2149+
rc = SQLSetConnectAttr(link->connection->hdbc, SQL_ATTR_ODBC_CURSORS, (SQLPOINTER) (intptr_t) cur_opt, 0);
21502150
if (rc != SQL_SUCCESS) { /* && rc != SQL_SUCCESS_WITH_INFO ? */
21512151
odbc_sql_error(link->connection, SQL_NULL_HSTMT, "SQLSetConnectOption");
21522152
return false;
@@ -2647,7 +2647,7 @@ PHP_FUNCTION(odbc_autocommit)
26472647
CHECK_ODBC_CONNECTION(conn);
26482648

26492649
if (!pv_onoff_is_null) {
2650-
rc = SQLSetConnectOption(conn->hdbc, SQL_AUTOCOMMIT, pv_onoff ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF);
2650+
rc = SQLSetConnectAttr(conn->hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER) (intptr_t) (pv_onoff ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF), 0);
26512651
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
26522652
odbc_sql_error(conn, SQL_NULL_HSTMT, "Set autocommit");
26532653
RETURN_FALSE;
@@ -2656,7 +2656,7 @@ PHP_FUNCTION(odbc_autocommit)
26562656
} else {
26572657
SQLINTEGER status;
26582658

2659-
rc = SQLGetConnectOption(conn->hdbc, SQL_AUTOCOMMIT, (PTR)&status);
2659+
rc = SQLGetConnectAttr(conn->hdbc, SQL_ATTR_AUTOCOMMIT, &status, SQL_IS_INTEGER, NULL);
26602660
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
26612661
odbc_sql_error(conn, SQL_NULL_HSTMT, "Get commit status");
26622662
RETURN_FALSE;
@@ -2758,7 +2758,7 @@ PHP_FUNCTION(odbc_setoption)
27582758
php_error_docref(NULL, E_WARNING, "Unable to set option for persistent connection");
27592759
RETURN_FALSE;
27602760
}
2761-
rc = SQLSetConnectOption(link->connection->hdbc, (unsigned short) pv_opt, pv_val);
2761+
rc = SQLSetConnectAttr(link->connection->hdbc, pv_opt, (SQLPOINTER) pv_val, 0);
27622762
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
27632763
odbc_sql_error(link->connection, SQL_NULL_HSTMT, "SetConnectOption");
27642764
RETURN_FALSE;
@@ -2772,7 +2772,7 @@ PHP_FUNCTION(odbc_setoption)
27722772
result = Z_ODBC_RESULT_P(pv_handle);
27732773
CHECK_ODBC_RESULT(result);
27742774

2775-
rc = SQLSetStmtOption(result->stmt, (unsigned short) pv_opt, pv_val);
2775+
rc = SQLSetStmtAttr(result->stmt, pv_opt, (SQLPOINTER) pv_val, 0);
27762776

27772777
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
27782778
odbc_sql_error(result->conn_ptr, result->stmt, "SetStmtOption");

0 commit comments

Comments
 (0)