Skip to content

PostgreSQL 19.0 compatibility - #419

Open
alikon wants to merge 6 commits into
joomla-framework:4.x-devfrom
alikon:patch-3
Open

alikon wants to merge 6 commits into
joomla-framework:4.x-devfrom
alikon:patch-3

Conversation

@alikon

@alikon alikon commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Pull Request for Issue #418

Summary of Changes

Conditionally set standard_conforming_strings based on PostgreSQL version.

Testing Instructions

Use joomla with PostgreSQL 19.0

Documentation Changes Required

Conditionally set standard_conforming_strings based on PostgreSQL version.
@Nubro01

Nubro01 commented Nov 19, 2026

Copy link
Copy Markdown

Thanks for picking this up. I tested this approach on PostgreSQL 19.0 with a copy of a Joomla 6.2.0 site, and found a problem with it.

Skipping SET standard_conforming_strings = off makes the site load again on 19: front end, login and backend all worked. But PgsqlDriver::escape() is unchanged, and it still escapes as if the setting were off:

$text = str_replace("'", "''", (string) $text);
return addcslashes($text, "\000\n\r\\\032");

With standard_conforming_strings = on, which is the only option on PostgreSQL 19, backslashes inside '...' are literal. So any value that goes through quote()/escape() and contains a newline, carriage return or backslash is stored differently:

-- what escape() produces for "line1<LF>line2 dir\sub":
SELECT '[' || 'line1\nline2 dir\\sub' || ']';

-- PostgreSQL 18, standard_conforming_strings = off (current behaviour):
[line1
line2 dir\sub]

-- PostgreSQL 19 (always on), with this PR:
[line1\nline2 dir\\sub]

So the page renders, but data written through quote() gets a literal \n where a newline was meant, and backslashes are doubled. Queries that use bound parameters are not affected.

I think the escaping has to change together with the SET. Some options:

  • When standard_conforming_strings is on, only double the single quotes in escape(), and drop the addcslashes() part.
  • Or emit E'...' literals from quote() while keeping the current escape().
  • Or delegate to PDO::quote(), which uses libpq's escaping and respects the server setting.

Since PostgreSQL has defaulted to on since 9.1, the first option would also let the driver drop the SET ... = off for all versions. That would need a check that nothing else in the CMS builds SQL that relies on backslash escapes.

Tested with Joomla 6.2.0, joomla/database 4.0.0, PHP 8.5.12, PostgreSQL 19.0 (PGDG packages, Debian 12 arm64).

@alikon

alikon commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the feedback
i've made an override of the escape()

@richard67

Copy link
Copy Markdown
Contributor

@alikon PHPstan is not happy with is_int and is_float, see the PHPstan errors shown here: https://github.com/joomla-framework/database/pull/419/changes . I think he/she/it is right, these methods check for the data type, not if a string is numeric or not. Maybe you can use is_numeric instead and check for the dot if so?

@alikon

alikon commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@richard67 let me 1st make happy the Unit tests, after i'll look at PHPstan

@alikon alikon changed the title Update connection settings for PostgreSQL 19.0 compatibility PostgreSQL 19.0 compatibility Nov 20, 2026
Added messages for impossible type checks in PgsqlDriver.php
@richard67

richard67 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

@alikon To add it to the baseline file is not right. Please check the PHP documentation, e.g. for ìs_int`: https://www.php.net/manual/en/function.is-int.php

Note:

To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric().

Example #1 is_int() example

<?php
$values = array(23, "23", 23.5, "23.5", null, true, false);
foreach ($values as $value) {
    echo "is_int(";
    var_export($value);
    echo ") = ";
    var_dump(is_int($value));
}
?>

The above example will output:

is_int(23) = bool(true)
is_int('23') = bool(false)
...

@alikon

alikon commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@richard67 there are already there for PDOdriver

message: '#^Call to function is_float\(\) with string will always evaluate to false\.$#'
identifier: function.impossibleType
count: 1
path: src/Pdo/PdoDriver.php
-
message: '#^Call to function is_int\(\) with string will always evaluate to false\.$#'
identifier: function.impossibleType
count: 1
path: src/Pdo/PdoDriver.php

the goal of this pr is to make joomla run with postgresql 19.0

room for another pr imho

@richard67

Copy link
Copy Markdown
Contributor

Hmm, not nice, but ok, old issue, has to be fixed separately.

@richard67

Copy link
Copy Markdown
Contributor

@alikon PHPstan fails:

Run ./vendor/bin/phpstan --error-format=github
Note: Using configuration file /__w/database/database/phpstan.neon.

In NeonCachedFileReader.php line 46:
                                                                               
  Error while loading /__w/database/database/phpstan-baseline.neon: Invalid combination of tabs and spaces on line 381, column 9.                         

Have you updated that file manually?

On a development environment with composer, you can use ./vendor/bin/phpstan -b to recreate that file (after having run composer install once so that PHPstan is available).

@teoberi

teoberi commented Nov 21, 2026 •

Copy link
Copy Markdown

Thanks, this is worth testing after Joomla 6.2.1 release!

@teoberi

teoberi commented Nov 25, 2026 •

Copy link
Copy Markdown

I have tested this PR on a Joomla 6.2.1 site running on PostgreSQL 19, and everything works as expected.

Test Results

  • Connection & Core Navigation: Frontend, backend login, and general navigation work without the non-standard string literals are not supported error.
  • String Escaping (escape()): Tested saving and editing articles containing raw newlines (\n), Windows file paths with backslashes (C:\Users\Admin\Documents\file.txt), and single quotes (') inside a <pre> block. All characters were stored and retrieved accurately without doubled backslashes or literal \n strings.
  • Bulk Operations: Ran the Smart Search (Finder) indexer across existing site content and categories, indexing completed cleanly with no database warnings or errors.

Environment

  • Joomla: 6.2.1
  • PostgreSQL: 19.0
  • PHP: 8.5.13

Thanks for the fix!

PS
PHP 8.6.0 awaits Joomla support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants