Bug #78596 [Opn->Ana]: getColumnMeta() doesn't return native_type for JSON
| From: | requinix@php.net | Date: | Wed, 25 Sep 2019 15:48:56 +0000 |
| Subject: | Bug #78596 [Opn->Ana]: getColumnMeta() doesn't return native_type for JSON | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222913@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78596&edit=1
ID: 78596
Updated by: requinix@php.net
Reported by: phpbug at discosucks dot it
Summary: getColumnMeta() doesn't return native_type for JSON
-Status: Open
+Status: Analyzed
Type: Bug
Package: PDO MySQL
Operating System: linux
PHP Version: 7.2.22
Block user comment: N
Private report: N
New Comment:
PHP is testing for the field type (reported by MySQL) using a variety of #defined FIELD_TYPE_*
constants:
https://github.com/php/php-src/blob/PHP-7.2.22/ext/pdo_mysql/mysql_statement.c#L781
https://dev.mysql.com/doc/dev/mysql-server/latest/mysql__com_8h.html
(Ctrl+F)
Note there is no constant for JSON. No constant means PHP can't identify the type.
However those FIELD_TYPEs are aliases for MYSQL_TYPE_* constants:
https://dev.mysql.com/doc/dev/mysql-server/latest/field__types_8h.html
In that list there is a JSON type; it's documented as "used for replication only" but
it seems like other projects are using it.
https://github.com/search?q=%22MYSQL_TYPE_JSON%22&type=Commits
Perhaps pdo_mysql should switch to using the MYSQL_TYPEs?
Previous Comments:
------------------------------------------------------------------------
[2019-09-25 14:23:29] phpbug at discosucks dot it
Description:
------------
PDOStatement::getColumnMeta() doesn't return native_type for JSON type columns (i suppose it
should be "string").
Test script:
---------------
$DB=new PDO('mysql:host=localhost;dbname=test','user','pass');
$DB->exec('CREATE TABLE
test (a JSON)');
$DB->exec("INSERT INTO test VALUES('[]')");
$statement=$DB->query('SELECT a FROM test');
$meta=$statement->getColumnMeta(0);
var_dump(isset($meta['native_type']));
Expected result:
----------------
bool(true)
Actual result:
--------------
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78596&edit=1