Make the $enable parameter of odbc_autocommit() nullable (#11909)

Co-authored-by: George Peter Banyard <girgias@php.net>
This commit is contained in:
Máté Kocsis 2023-08-08 15:31:58 +02:00 committed by GitHub
parent ad18fbc836
commit 038b2ae254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 7 deletions

View File

@ -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

View File

@ -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 {}

View File

@ -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)

View File

@ -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);
}
}
/* }}} */

View File

@ -0,0 +1,25 @@
--TEST--
odbc_autocommit(): Basic test
--EXTENSIONS--
odbc
--SKIPIF--
<?php include 'skipif.inc'; ?>
--FILE--
<?php
include 'config.inc';
$conn = odbc_connect($dsn, $user, $pass);
var_dump(odbc_autocommit($conn, true));
var_dump(odbc_autocommit($conn, null));
var_dump(odbc_autocommit($conn, false));
var_dump(odbc_autocommit($conn));
?>
--EXPECTF--
bool(true)
int(1)
bool(true)
int(0)