diff --git a/UPGRADING b/UPGRADING index f18c7118e921d..963035200182b 100644 --- a/UPGRADING +++ b/UPGRADING @@ -278,6 +278,11 @@ PHP 8.3 UPGRADE NOTES . mysqli_poll now raises a ValueError when the read nor error arguments are passed. +- ODBC + . odbc_autocommit() now accepts null for the $enable parameter. + Passing null has the same behaviour as passing only 1 parameter, + namely indicating if the autocommit feature is enabled or not. + - PGSQL: . pg_fetch_object now raises a ValueError instead of an Exception when the constructor_args argument is non empty with the class not having diff --git a/ext/odbc/odbc.stub.php b/ext/odbc/odbc.stub.php index 444978837eed1..9606a38633f34 100644 --- a/ext/odbc/odbc.stub.php +++ b/ext/odbc/odbc.stub.php @@ -425,7 +425,7 @@ function odbc_field_scale($statement, int $field): int|false {} function odbc_field_num($statement, string $field): int|false {} /** @param resource $odbc */ -function odbc_autocommit($odbc, bool $enable = false): int|bool {} +function odbc_autocommit($odbc, ?bool $enable = null): int|bool {} /** @param resource $odbc */ function odbc_commit($odbc): bool {} diff --git a/ext/odbc/odbc_arginfo.h b/ext/odbc/odbc_arginfo.h index a29e33cc65c36..574d829daad42 100644 --- a/ext/odbc/odbc_arginfo.h +++ b/ext/odbc/odbc_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: c7d91d30503ac09c8610ce86846c36123b87f62a */ + * Stub hash: 0417b68a519527b0ee916bad75116ffe4a3ad304 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_close_all, 0, 0, IS_VOID, 0) ZEND_END_ARG_INFO() @@ -126,7 +126,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_odbc_autocommit, 0, 1, MAY_BE_LONG|MAY_BE_BOOL) ZEND_ARG_INFO(0, odbc) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 0, "false") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, enable, _IS_BOOL, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_odbc_commit, 0, 1, _IS_BOOL, 0) diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index a26a1a43c692e..804e79b063636 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -2553,8 +2553,9 @@ PHP_FUNCTION(odbc_autocommit) RETCODE rc; zval *pv_conn; bool pv_onoff = 0; + bool pv_onoff_is_null = true; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|b", &pv_conn, &pv_onoff) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|b!", &pv_conn, &pv_onoff, &pv_onoff_is_null) == FAILURE) { RETURN_THROWS(); } @@ -2562,13 +2563,13 @@ PHP_FUNCTION(odbc_autocommit) RETURN_THROWS(); } - if (ZEND_NUM_ARGS() > 1) { + if (!pv_onoff_is_null) { rc = SQLSetConnectOption(conn->hdbc, SQL_AUTOCOMMIT, pv_onoff ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF); if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) { odbc_sql_error(conn, SQL_NULL_HSTMT, "Set autocommit"); RETURN_FALSE; } - RETVAL_TRUE; + RETURN_TRUE; } else { SQLINTEGER status; @@ -2577,7 +2578,7 @@ PHP_FUNCTION(odbc_autocommit) odbc_sql_error(conn, SQL_NULL_HSTMT, "Get commit status"); RETURN_FALSE; } - RETVAL_LONG((zend_long)status); + RETURN_LONG((zend_long)status); } } /* }}} */ diff --git a/ext/odbc/tests/odbc_autocommit_001.phpt b/ext/odbc/tests/odbc_autocommit_001.phpt new file mode 100644 index 0000000000000..6ae09736555c0 --- /dev/null +++ b/ext/odbc/tests/odbc_autocommit_001.phpt @@ -0,0 +1,25 @@ +--TEST-- +odbc_autocommit(): Basic test +--EXTENSIONS-- +odbc +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true) +int(1) +bool(true) +int(0)