Doc #81173 [Com]: Fatal error. PHP7-8 PG Prepared statement name collision

[email protected] ("kachalin dot alexey at gmail dot com") Wed, 24 May 2023 17:33:09 +0000
Newsgroups php.doc.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=81173&edit=1

 ID:                 81173
 Comment by:         kachalin dot alexey at gmail dot com
 Reported by:        kachalin dot alexey at gmail dot com
 Summary:            Fatal error. PHP7-8 PG Prepared statement name
                     collision
 Status:             Open
 Type:               Documentation Problem
 Package:            PostgreSQL related
 Operating System:   any
 PHP Version:        8.0.7
 Block user comment: N
 Private report:     N

 New Comment:

Well, it not a bug. Please close this issue.
An application programmer should truncate and secure a prepared SQL statements names.
To know the which value was used at compilation time for NAMEDATALEN use SQL
show max_identifier_length;


Previous Comments:
------------------------------------------------------------------------
[2022-12-28 06:01:39] marlynrasavong at gmail dot com

the missing index notification is a relatively low-severity warning.
(https://www.c4yourself.ltd/)github.com

------------------------------------------------------------------------
[2021-06-21 18:18:19] [email protected]

Adding this info to the PHP documentation should not hurt,
although it is not particulary about prepared statements, but
rather about identifiers in general.

------------------------------------------------------------------------
[2021-06-21 18:09:05] kachalin dot alexey at gmail dot com

Okay, I understood.

Maybe be it's good idea to add a notice in PHP documentation, something like "The prepared statement name can be truncated. Default limit set to 63 character."
At least people will be aware about the limit. How do you think?

In some cases prepared statment warning don't showed, but can returns a malformed data.
The prepared statement 'SELECT 222 as result_1' returns 111. No warrning, no error.

<?php

$host = '';
$db   = '';
$port = '';// 5432
$user = '';
$pass = '';


$connectString = "host=$host port=$port dbname=$db user=$user password=$pass";
$pg_pconnect = pg_pconnect($connectString);

$string63 = '5c6b58ebdd4464734a57a87431ba24b38d2e49ae5c6b58ebdd4464734a57a87';
//$string63 = 'smallLenthSQL';// Uncoment for expected result.

$sqlPreparedNameA = $string63 . '_A';
$sqlPreparedNameB = $string63 . '_B';
$sqlPreparedBodyA = 'SELECT 111 as result_1';
$sqlPreparedBodyB = 'SELECT 222 as result_1';

$pg_prepareA = pg_prepare($pg_pconnect, $sqlPreparedNameA, $sqlPreparedBodyA);
$pg_prepareA = pg_prepare($pg_pconnect, $sqlPreparedNameB, $sqlPreparedBodyB);

$pg_executeA = pg_execute($pg_pconnect, $sqlPreparedNameA, []);
$pg_executeB = pg_execute($pg_pconnect, $sqlPreparedNameB, []);

$resultA     = pg_fetch_all($pg_executeA);
$resultB     = pg_fetch_all($pg_executeB);

var_dump($resultA);
var_dump($resultB);

------------------------------------------------------------------------
[2021-06-21 09:49:56] [email protected]

Yes, that is a general limitation of PostgreSQL[1], and there is
nothing we can do about it.  If you need to have longer
identifiers, increase the value of NAMEDATALEN.

[1] <https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS>

------------------------------------------------------------------------
[2021-06-19 20:12:07] [email protected]

I don't see anything in ext/pgsql or libpq, source or documentation, that says prepared statement names are limited to 63/64 characters. This may be a server-side limitation.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=81173


--
Edit this bug report at https://bugs.php.net/bug.php?id=81173&edit=1