Skip to content

Commit 249b88a

Browse files
authored
fix: getVersion() for OCI8 and SQLSRV drivers (#9471)
* fix: getVersion() for OCI8 driver when no connection is established * phpstan - regenerate baseline * fix: SQLSRV getVersion() when no connection is established
1 parent 99be151 commit 249b88a

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

system/Database/OCI8/Connection.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,14 @@ public function getVersion(): string
193193
return $this->dataCache['version'];
194194
}
195195

196-
if (! $this->connID || ($versionString = oci_server_version($this->connID)) === false) {
196+
if ($this->connID === false) {
197+
$this->initialize();
198+
}
199+
200+
if (($versionString = oci_server_version($this->connID)) === false) {
197201
return '';
198202
}
203+
199204
if (preg_match('#Release\s(\d+(?:\.\d+)+)#', $versionString, $match)) {
200205
return $this->dataCache['version'] = $match[1];
201206
}

system/Database/SQLSRV/Connection.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,15 @@ public function getVersion(): string
561561
return $this->dataCache['version'];
562562
}
563563

564-
if (! $this->connID || ($info = sqlsrv_server_info($this->connID)) === []) {
564+
if (! $this->connID) {
565565
$this->initialize();
566566
}
567567

568-
return isset($info['SQLServerVersion']) ? $this->dataCache['version'] = $info['SQLServerVersion'] : false;
568+
if (($info = sqlsrv_server_info($this->connID)) === []) {
569+
return '';
570+
}
571+
572+
return isset($info['SQLServerVersion']) ? $this->dataCache['version'] = $info['SQLServerVersion'] : '';
569573
}
570574

571575
/**

tests/system/Database/Live/GetVersionTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ final class GetVersionTest extends CIUnitTestCase
2929

3030
public function testGetVersion(): void
3131
{
32+
if ($this->db->DBDriver === 'MySQLi') {
33+
$this->db->mysqli = false;
34+
}
35+
36+
$this->db->connID = false;
37+
3238
$version = $this->db->getVersion();
3339

3440
$this->assertMatchesRegularExpression('/\A\d+(\.\d+)*\z/', $version);

user_guide_src/source/changelogs/v4.6.1.rst

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Bugs Fixed
3333
- **CURLRequest:** Fixed an issue where multiple header sections appeared in the CURL response body during multiple redirects from the target server.
3434
- **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.
3535
- **Database:** Fixed a bug in ``Postgre`` and ``SQLite3`` handlers where composite unique keys were not fully taken into account for ``upsert`` type of queries.
36+
- **Database:** Fixed a bug in the ``OCI8`` and ``SQLSRV`` drivers where ``getVersion()`` returned an empty string when the database connection was not yet established.
3637

3738
See the repo's
3839
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

utils/phpstan-baseline/property.notFound.neon

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 58 errors
1+
# total 59 errors
22

33
parameters:
44
ignoreErrors:
@@ -42,6 +42,11 @@ parameters:
4242
count: 2
4343
path: ../../tests/system/Database/BaseConnectionTest.php
4444

45+
-
46+
message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$mysqli\.$#'
47+
count: 1
48+
path: ../../tests/system/Database/Live/GetVersionTest.php
49+
4550
-
4651
message: '#^Access to an undefined property CodeIgniter\\Database\\BaseConnection\:\:\$foundRows\.$#'
4752
count: 2

0 commit comments

Comments
 (0)