-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: PostgreSQL getVersion() logic #7488
fix: PostgreSQL getVersion() logic #7488
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove below code in phpstan-baseline.neon.dist
-
message: "#^Strict comparison using \\=\\=\\= between array<string, int|string|null> and false will always evaluate to false\\.$#"
count: 1
path: system/Database/Postgre/Connection.php
By the way, Following step how to create PR in https://github.com/codeigniter4/CodeIgniter4/blob/develop/contributing/pull_request.md#php-style Dont forget signing your commit |
7ee8775
to
8064aab
Compare
@marekmosna Almost there! Could you follow the suggestion from #7488 (review) to fix the PHPStan error? |
$this->initialize(); | ||
} | ||
|
||
$pgVersion = pg_version($this->connID); | ||
|
||
return isset($pgVersion['server']) ? $this->dataCache['version'] = $pgVersion['server'] : false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface is public function getVersion(): string;
. So false
should not be returned.
98362e6
to
efbf68c
Compare
efbf68c
to
3292e43
Compare
$this->initialize(); | ||
} | ||
|
||
return isset($pgVersion['server']) ? $this->dataCache['version'] = $pgVersion['server'] : false; | ||
$pgVersion = pg_version($this->connID); | ||
$this->dataCache['version'] = $pgVersion['server'] ?? 'PostgreSQL 7.4 or lower'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getVersion()
returns the version number like '12.1'
, and the number should be used with version_compare()
Is it impossible to get the version number 7.4 or lower?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pg_version() returns an array with the client, protocol and server version. Protocol and server versions are only available if PHP was compiled with PostgreSQL 7.4 or later.
https://www.php.net/manual/en/function.pg-version.php#refsect1-function.pg-version-description
There is no version requirement in the docs:
https://codeigniter4.github.io/CodeIgniter4/intro/requirements.html#supported-databases
But PostgreSQL 11 will stop receiving fixes on November 9, 2023.
https://www.postgresql.org/about/news/postgresql-153-148-1311-1215-and-1120-released-2637/
@codeigniter4/core-team @codeigniter4/database-team
Do we need to support versions prior to 7.4?
Why don't we add (version 7.4 and above only)
in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PostgreSQL 7.4 seems too old, it seems it need to be documented in docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getVersion() returns the version number like '12.1', and the number should be used with version_compare()
that was the question in the related issue #7488
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no $pgVersion['server']
, we should return an empty string.
Adding a note (version 7.4 and above only)
is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sent a PR: #7507
$this->initialize(); | ||
} | ||
|
||
return isset($pgVersion['server']) ? $this->dataCache['version'] = $pgVersion['server'] : false; | ||
$pgVersion = pg_version($this->connID); | ||
$this->dataCache['version'] = $pgVersion['server'] ?? 'PostgreSQL 7.4 or lower'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->dataCache['version'] = $pgVersion['server'] ?? 'PostgreSQL 7.4 or lower'; | |
$this->dataCache['version'] = $pgVersion['server'] ?? ''; |
@marekmosna It seems there is no test code for |
3292e43
to
4c6e4ec
Compare
I'm sorry @kenjis but I'm not a php developer so I can't |
@marekmosna Okay, I got it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@codeigniter4/database-team Is this okay? |
Good point. I think we should filter out the version. |
$this->initialize(); | ||
} | ||
|
||
return isset($pgVersion['server']) ? $this->dataCache['version'] = $pgVersion['server'] : false; | ||
$pgVersion = pg_version($this->connID); | ||
$this->dataCache['version'] = $pgVersion['server'] ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->dataCache['version'] = $pgVersion['server'] ?? ''; | |
$this->dataCache['version'] = isset($pgVersion['server']) ? | |
preg_match('/^(\d+\.\d+)/', $pgVersion['server'], $matches) ? $matches[1] : '' : | |
''; | |
This should work if we deal with something like 15.3 (Debian 15.3-1.pgdg110+1)
- as Kenjis pointed out earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will take care of it in #7509
Description
Fixes #7484
Fixies logic of PostgreSQL getVersion() method.