From 94ea7044efc8cc394d7d32a241cc5508c88b1685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 8 Aug 2023 10:06:27 +0200 Subject: [PATCH 1/4] Make the $enable parameter of odbc_autocommit() nullable --- UPGRADING | 3 +++ ext/odbc/odbc.stub.php | 2 +- ext/odbc/odbc_arginfo.h | 4 ++-- ext/odbc/php_odbc.c | 5 +++-- ext/odbc/tests/odbc_autocommit_001.phpt | 27 +++++++++++++++++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 ext/odbc/tests/odbc_autocommit_001.phpt diff --git a/UPGRADING b/UPGRADING index f18c7118e921d..59e5424416e5b 100644 --- a/UPGRADING +++ b/UPGRADING @@ -278,6 +278,9 @@ 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. + - 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..f1ce62491812b 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,7 +2563,7 @@ 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"); diff --git a/ext/odbc/tests/odbc_autocommit_001.phpt b/ext/odbc/tests/odbc_autocommit_001.phpt new file mode 100644 index 0000000000000..0dc94c621a294 --- /dev/null +++ b/ext/odbc/tests/odbc_autocommit_001.phpt @@ -0,0 +1,27 @@ +--TEST-- +odbc_autocommit(): Basic test +--EXTENSIONS-- +odbc +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +int(0) +bool(true) +int(1) +bool(true) +int(0) From 483518d02c73550c711ccb0f8e9e66fbc05cdefd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 8 Aug 2023 13:42:51 +0200 Subject: [PATCH 2/4] [skip-ci] Update UPGRADING Co-authored-by: George Peter Banyard --- UPGRADING | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UPGRADING b/UPGRADING index 59e5424416e5b..963035200182b 100644 --- a/UPGRADING +++ b/UPGRADING @@ -280,6 +280,8 @@ PHP 8.3 UPGRADE NOTES - 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 From 98434f9bc0fade4803f6e53b7946ee7f3e3cec97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 8 Aug 2023 13:43:09 +0200 Subject: [PATCH 3/4] Update ext/odbc/tests/odbc_autocommit_001.phpt Co-authored-by: George Peter Banyard --- ext/odbc/tests/odbc_autocommit_001.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/odbc/tests/odbc_autocommit_001.phpt b/ext/odbc/tests/odbc_autocommit_001.phpt index 0dc94c621a294..e5b17a7cb13a4 100644 --- a/ext/odbc/tests/odbc_autocommit_001.phpt +++ b/ext/odbc/tests/odbc_autocommit_001.phpt @@ -11,8 +11,8 @@ include 'config.inc'; $conn = odbc_connect($dsn, $user, $pass); -var_dump(odbc_autocommit($conn)); var_dump(odbc_autocommit($conn, true)); +var_dump(odbc_autocommit($conn)); var_dump(odbc_autocommit($conn, null)); var_dump(odbc_autocommit($conn, false)); From b2fdfcba7a5f4c1cab9b8ed677a8d636563164a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 8 Aug 2023 13:46:10 +0200 Subject: [PATCH 4/4] Fixes --- ext/odbc/php_odbc.c | 4 ++-- ext/odbc/tests/odbc_autocommit_001.phpt | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/ext/odbc/php_odbc.c b/ext/odbc/php_odbc.c index f1ce62491812b..804e79b063636 100644 --- a/ext/odbc/php_odbc.c +++ b/ext/odbc/php_odbc.c @@ -2569,7 +2569,7 @@ PHP_FUNCTION(odbc_autocommit) odbc_sql_error(conn, SQL_NULL_HSTMT, "Set autocommit"); RETURN_FALSE; } - RETVAL_TRUE; + RETURN_TRUE; } else { SQLINTEGER status; @@ -2578,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 index e5b17a7cb13a4..6ae09736555c0 100644 --- a/ext/odbc/tests/odbc_autocommit_001.phpt +++ b/ext/odbc/tests/odbc_autocommit_001.phpt @@ -12,7 +12,6 @@ include 'config.inc'; $conn = odbc_connect($dsn, $user, $pass); var_dump(odbc_autocommit($conn, true)); -var_dump(odbc_autocommit($conn)); var_dump(odbc_autocommit($conn, null)); var_dump(odbc_autocommit($conn, false)); @@ -20,7 +19,6 @@ var_dump(odbc_autocommit($conn)); ?> --EXPECTF-- -int(0) bool(true) int(1) bool(true)