php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81550 getColumnMeta should also return org_table and org_column
Submitted: 2021-10-21 17:31 UTC Modified: 2021-10-26 19:12 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: daniel dot garcia dot fidalgo at gmail dot com Assigned:
Status: Open Package: PDO MySQL
PHP Version: next minor OS: CentOS 7
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-10-21 17:31 UTC] daniel dot garcia dot fidalgo at gmail dot com
Description:
------------
getColumnMeta() function returns aliases of tables and fields instead of the base names.

Test script:
---------------
Original query:

SELECT 
	FormuId AS FormuId__FormId__V, 
	Formdate AS Formdate__Date__v, 
	GROUP_CONCAT(FieldValue ORDER BY id_sysformdb) AS Contact__v 
FROM 
	Sysformdb AS F 
WHERE 
	(F.Fieldname = 'frm_fld_Name' OR 
	 F.Fieldname = 'frm_fld_Lastname' OR 
	 F.FieldName = 'frm_fld_E-mail') 
GROUP BY 
	FormuId 
ORDER BY 
	id_sysformdb 
DESC LIMIT 50

getColumnMeta() returned data:

array(7) { ["native_type"]=> string(6) "STRING" ["pdo_type"]=> int(2) ["flags"]=> array(0) { } ["table"]=> string(1) "F" ["name"]=> string(9) "FormId__V" ["len"]=> int(30) ["precision"]=> int(0) }

array(7) { ["native_type"]=> string(9) "TIMESTAMP" ["pdo_type"]=> int(2) ["flags"]=> array(0) { } ["table"]=> string(1) "F" ["name"]=> string(7) "Date__v" ["len"]=> int(19) ["precision"]=> int(0) }

array(7) { ["native_type"]=> string(4) "BLOB" ["pdo_type"]=> int(2) ["flags"]=> array(1) { [0]=> string(4) "blob" } ["table"]=> string(0) "" ["name"]=> string(10) "Contact__v" ["len"]=> int(50331645) ["precision"]=> int(0) } 


Expected result:
----------------
The base name of tables and fields is expected as named in the db schema

Actual result:
--------------
The aliased names as set in the query are returned.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-25 13:54 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-10-25 13:54 UTC] cmb@php.net
> The aliased names as set in the query are returned.

Right.  And the documentation states[1]:

| The name of this column as returned by the database.

So where's the problem?

[1] <https://www.php.net/manual/en/pdostatement.getcolumnmeta.php#refsect1-pdostatement.getcolumnmeta-returnvalues>
 [2021-10-25 15:31 UTC] requinix@php.net
See MYSQL_FIELD in https://dev.mysql.com/doc/c-api/8.0/en/c-api-data-structures.html

Looking at this from the feature request view, what about adding the original table (org_table) and column names (org_name) to the array?

Not sure how it applies to other drivers, like pdo_pgsql/PostgreSQL seems to do identifiers instead of names, but the original names could be one more of PDO's "...if supported by the driver" features.

At the least there does seem to be some precedent for driver-specific values in the returned array: pdo_pgsql adds a "pgsql:table_oid" to the array. So pdo_mysql could potentially do "mysql:org_name/org_table" if it had to.
 [2021-10-25 16:31 UTC] cmb@php.net
-Summary: getColumnMeta returns aliases of tables and fields instead of the base names. +Summary: getColumnMeta should also return org_table and org_column -Status: Feedback +Status: Open -PHP Version: 7.3.31 +PHP Version: next minor -Assigned To: cmb +Assigned To:
 [2021-10-25 16:31 UTC] cmb@php.net
> Looking at this from the feature request view, […]

While this ticket is categorized as feature request, the OP looks
more like a bug report.  Anyhow, let's treat it as feature
request.

> […] what about adding the original table (org_table) and column
> names (org_name) to the array?

I'd be fine with this, but this should probably be discussed on
the internals mailing list and might need an RFC[1], because it is
unclear what exactly should be returned by getColumnMeta().

[1] <https://wiki.php.net/rfc/howto>
 [2021-10-25 16:36 UTC] daniel dot garcia dot fidalgo at gmail dot com
-Summary: getColumnMeta should also return org_table and org_column +Summary: getColumnMeta returns aliases of tables and fields instead of the base names. -Status: Open +Status: Assigned -PHP Version: next minor +PHP Version: 7.3.31
 [2021-10-25 16:36 UTC] daniel dot garcia dot fidalgo at gmail dot com
From the getColumnMeta() manual:

name	The name of this column as returned by the database.
table	The name of this column's table as returned by the database.

The alias is indeed the name of the column returned by the SQL statement, not the database. The database knows nothing about the aliases, they are higher level information set by the user in the very same query.

The alias is already accessible via the query returned data, what is the point in returning the same via a function that promises meta-information?.
 [2021-10-25 17:22 UTC] requinix@php.net
-Summary: getColumnMeta returns aliases of tables and fields instead of the base names. +Summary: getColumnMeta should also return org_table and org_column -Status: Assigned +Status: Open -PHP Version: 7.3.31 +PHP Version: next minor
 [2021-10-25 17:22 UTC] requinix@php.net
> The database knows nothing about the aliases,

The database server absolutely does know about the aliases. Look at the link I gave earlier.
 [2021-10-26 17:44 UTC] daniel dot garcia dot fidalgo at gmail dot com
How come the DB know about the aliases when they do not exist up until the programmer sets the query and runs it.

That is user set information and thus aliases are not in the DB schema and can't be known about on advance for the same reason that I can't predict the future.

You may be talking about the database engine or database server, who knows about them only after having processed the query and never before.
 [2021-10-26 19:12 UTC] requinix@php.net
That's why I said "server".

> The database server absolutely does know about the aliases.

This is relevant because it is *the server* that builds the statement and column metadata.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC