Skip to content

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

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

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/odbc/odbc.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
4 changes: 2 additions & 2 deletions ext/odbc/odbc_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions ext/odbc/php_odbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2553,22 +2553,23 @@ 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();
}

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

if (ZEND_NUM_ARGS() > 1) {
if (!pv_onoff_is_null) {
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit, but can you change the RETVAL_TRUE to RETURN_TRUE

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;

Expand All @@ -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);
}
}
/* }}} */
Expand Down
25 changes: 25 additions & 0 deletions ext/odbc/tests/odbc_autocommit_001.phpt
Original file line number Diff line number Diff line change
@@ -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)