Skip to content

Commit 038b2ae

Browse files
kocsismateGirgias
andauthoredAug 8, 2023
Make the $enable parameter of odbc_autocommit() nullable (#11909)
Co-authored-by: George Peter Banyard <girgias@php.net>
1 parent ad18fbc commit 038b2ae

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed
 

‎UPGRADING

+5
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ PHP 8.3 UPGRADE NOTES
278278
. mysqli_poll now raises a ValueError when the read nor error arguments are
279279
passed.
280280

281+
- ODBC
282+
. odbc_autocommit() now accepts null for the $enable parameter.
283+
Passing null has the same behaviour as passing only 1 parameter,
284+
namely indicating if the autocommit feature is enabled or not.
285+
281286
- PGSQL:
282287
. pg_fetch_object now raises a ValueError instead of an Exception when the
283288
constructor_args argument is non empty with the class not having

‎ext/odbc/odbc.stub.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ function odbc_field_scale($statement, int $field): int|false {}
425425
function odbc_field_num($statement, string $field): int|false {}
426426

427427
/** @param resource $odbc */
428-
function odbc_autocommit($odbc, bool $enable = false): int|bool {}
428+
function odbc_autocommit($odbc, ?bool $enable = null): int|bool {}
429429

430430
/** @param resource $odbc */
431431
function odbc_commit($odbc): bool {}

‎ext/odbc/odbc_arginfo.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ext/odbc/php_odbc.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -2553,22 +2553,23 @@ PHP_FUNCTION(odbc_autocommit)
25532553
RETCODE rc;
25542554
zval *pv_conn;
25552555
bool pv_onoff = 0;
2556+
bool pv_onoff_is_null = true;
25562557

2557-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|b", &pv_conn, &pv_onoff) == FAILURE) {
2558+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|b!", &pv_conn, &pv_onoff, &pv_onoff_is_null) == FAILURE) {
25582559
RETURN_THROWS();
25592560
}
25602561

25612562
if (!(conn = (odbc_connection *)zend_fetch_resource2(Z_RES_P(pv_conn), "ODBC-Link", le_conn, le_pconn))) {
25622563
RETURN_THROWS();
25632564
}
25642565

2565-
if (ZEND_NUM_ARGS() > 1) {
2566+
if (!pv_onoff_is_null) {
25662567
rc = SQLSetConnectOption(conn->hdbc, SQL_AUTOCOMMIT, pv_onoff ? SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF);
25672568
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
25682569
odbc_sql_error(conn, SQL_NULL_HSTMT, "Set autocommit");
25692570
RETURN_FALSE;
25702571
}
2571-
RETVAL_TRUE;
2572+
RETURN_TRUE;
25722573
} else {
25732574
SQLINTEGER status;
25742575

@@ -2577,7 +2578,7 @@ PHP_FUNCTION(odbc_autocommit)
25772578
odbc_sql_error(conn, SQL_NULL_HSTMT, "Get commit status");
25782579
RETURN_FALSE;
25792580
}
2580-
RETVAL_LONG((zend_long)status);
2581+
RETURN_LONG((zend_long)status);
25812582
}
25822583
}
25832584
/* }}} */
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
odbc_autocommit(): Basic test
3+
--EXTENSIONS--
4+
odbc
5+
--SKIPIF--
6+
<?php include 'skipif.inc'; ?>
7+
--FILE--
8+
<?php
9+
10+
include 'config.inc';
11+
12+
$conn = odbc_connect($dsn, $user, $pass);
13+
14+
var_dump(odbc_autocommit($conn, true));
15+
var_dump(odbc_autocommit($conn, null));
16+
17+
var_dump(odbc_autocommit($conn, false));
18+
var_dump(odbc_autocommit($conn));
19+
20+
?>
21+
--EXPECTF--
22+
bool(true)
23+
int(1)
24+
bool(true)
25+
int(0)

0 commit comments

Comments
 (0)
Failed to load comments.