From 79da766afcbb87807de07f218a4b697eae768249 Mon Sep 17 00:00:00 2001 From: michalsn Date: Fri, 28 Feb 2025 15:41:48 +0100 Subject: [PATCH 1/3] fix: getVersion() for OCI8 driver when no connection is established --- system/Database/OCI8/Connection.php | 7 ++++++- tests/system/Database/Live/GetVersionTest.php | 6 ++++++ user_guide_src/source/changelogs/v4.6.1.rst | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index b6078febd030..67921d2c13f8 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -193,9 +193,14 @@ public function getVersion(): string return $this->dataCache['version']; } - if (! $this->connID || ($versionString = oci_server_version($this->connID)) === false) { + if ($this->connID === false) { + $this->initialize(); + } + + if (($versionString = oci_server_version($this->connID)) === false) { return ''; } + if (preg_match('#Release\s(\d+(?:\.\d+)+)#', $versionString, $match)) { return $this->dataCache['version'] = $match[1]; } diff --git a/tests/system/Database/Live/GetVersionTest.php b/tests/system/Database/Live/GetVersionTest.php index 73da7c07071d..93678e3b8356 100644 --- a/tests/system/Database/Live/GetVersionTest.php +++ b/tests/system/Database/Live/GetVersionTest.php @@ -29,6 +29,12 @@ final class GetVersionTest extends CIUnitTestCase public function testGetVersion(): void { + if ($this->db->DBDriver === 'MySQLi') { + $this->db->mysqli = false; + } + + $this->db->connID = false; + $version = $this->db->getVersion(); $this->assertMatchesRegularExpression('/\A\d+(\.\d+)*\z/', $version); diff --git a/user_guide_src/source/changelogs/v4.6.1.rst b/user_guide_src/source/changelogs/v4.6.1.rst index 9a5ea391d4f3..65a5b5071516 100644 --- a/user_guide_src/source/changelogs/v4.6.1.rst +++ b/user_guide_src/source/changelogs/v4.6.1.rst @@ -33,6 +33,7 @@ Bugs Fixed - **CURLRequest:** Fixed an issue where multiple header sections appeared in the CURL response body during multiple redirects from the target server. - **Cors:** Fixed a bug in the Cors filter that caused the appropriate headers to not be added when another filter returned a response object in the ``before`` filter. - **Database:** Fixed a bug in ``Postgre`` and ``SQLite3`` handlers where composite unique keys were not fully taken into account for ``upsert`` type of queries. +- **Database:** Fixed a bug in the ``OCI8`` driver where ``getVersion()`` returned an empty string when the database connection was not yet established. See the repo's `CHANGELOG.md `_ From 7945a48dde68c8bc65067524b87858aa8faffa2b Mon Sep 17 00:00:00 2001 From: michalsn Date: Fri, 28 Feb 2025 15:53:07 +0100 Subject: [PATCH 2/3] phpstan - regenerate baseline --- utils/phpstan-baseline/property.notFound.neon | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/phpstan-baseline/property.notFound.neon b/utils/phpstan-baseline/property.notFound.neon index 4d31a18bf6b7..9c0dfe2005a3 100644 --- a/utils/phpstan-baseline/property.notFound.neon +++ b/utils/phpstan-baseline/property.notFound.neon @@ -1,4 +1,4 @@ -# total 58 errors +# total 59 errors parameters: ignoreErrors: @@ -42,6 +42,11 @@ parameters: count: 2 path: ../../tests/system/Database/BaseConnectionTest.php + - + message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$mysqli\.$#' + count: 1 + path: ../../tests/system/Database/Live/GetVersionTest.php + - message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$foundRows\.$#' count: 2 From f4d8a022eb3b56bc8a09725c2e9f7cf64f79962e Mon Sep 17 00:00:00 2001 From: michalsn Date: Fri, 28 Feb 2025 16:15:21 +0100 Subject: [PATCH 3/3] fix: SQLSRV getVersion() when no connection is established --- system/Database/SQLSRV/Connection.php | 8 ++++++-- user_guide_src/source/changelogs/v4.6.1.rst | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index c8e1e3fbee12..7ef4f31901d1 100644 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -561,11 +561,15 @@ public function getVersion(): string return $this->dataCache['version']; } - if (! $this->connID || ($info = sqlsrv_server_info($this->connID)) === []) { + if (! $this->connID) { $this->initialize(); } - return isset($info['SQLServerVersion']) ? $this->dataCache['version'] = $info['SQLServerVersion'] : false; + if (($info = sqlsrv_server_info($this->connID)) === []) { + return ''; + } + + return isset($info['SQLServerVersion']) ? $this->dataCache['version'] = $info['SQLServerVersion'] : ''; } /** diff --git a/user_guide_src/source/changelogs/v4.6.1.rst b/user_guide_src/source/changelogs/v4.6.1.rst index 65a5b5071516..7b35ad9faabc 100644 --- a/user_guide_src/source/changelogs/v4.6.1.rst +++ b/user_guide_src/source/changelogs/v4.6.1.rst @@ -33,7 +33,7 @@ Bugs Fixed - **CURLRequest:** Fixed an issue where multiple header sections appeared in the CURL response body during multiple redirects from the target server. - **Cors:** Fixed a bug in the Cors filter that caused the appropriate headers to not be added when another filter returned a response object in the ``before`` filter. - **Database:** Fixed a bug in ``Postgre`` and ``SQLite3`` handlers where composite unique keys were not fully taken into account for ``upsert`` type of queries. -- **Database:** Fixed a bug in the ``OCI8`` driver where ``getVersion()`` returned an empty string when the database connection was not yet established. +- **Database:** Fixed a bug in the ``OCI8`` and ``SQLSRV`` drivers where ``getVersion()`` returned an empty string when the database connection was not yet established. See the repo's `CHANGELOG.md `_