Skip to content
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

fix: getVersion() for OCI8 and SQLSRV drivers #9471

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion system/Database/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
6 changes: 6 additions & 0 deletions tests/system/Database/Live/GetVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ final class GetVersionTest extends CIUnitTestCase

public function testGetVersion(): void
{
if ($this->db->DBDriver === 'MySQLi') {
Copy link
Member

Choose a reason for hiding this comment

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

This should can use if ($this->db instanceof \CodeIgniter\Database\MySQLi\Connection)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but since this type of comparison is widely used in our tests, I personally find it more readable. However, if others prefer the change, I'm happy to update it.

Copy link
Member

Choose a reason for hiding this comment

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

The benefit of instanceof is phpstan will be fixed for no property notice

$this->db->mysqli = false;
}

$this->db->connID = false;

$version = $this->db->getVersion();

$this->assertMatchesRegularExpression('/\A\d+(\.\d+)*\z/', $version);
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelogs/v4.6.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 the ``OCI8`` driver where ``getVersion()`` returned an empty string when the database connection was not yet established.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
Expand Down
7 changes: 6 additions & 1 deletion utils/phpstan-baseline/property.notFound.neon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# total 58 errors
# total 59 errors

parameters:
ignoreErrors:
Expand Down Expand Up @@ -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
Expand Down
Loading