Skip to content

Commit 94284df

Browse files
committed
Fix phpGH-20122: getColumnMeta() for JSON-column in MySQL
While at it, also add VECTOR. Closes phpGH-20143.
1 parent 94625a0 commit 94284df

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ PHP NEWS
2929
- MySQLnd:
3030
. Fixed bug GH-8978 (SSL certificate verification fails (port doubled)).
3131
(nielsdos)
32+
. Fixed bug GH-20122 (getColumnMeta() for JSON-column in MySQL). (nielsdos)
3233

3334
- Opcache:
3435
. Fixed bug GH-20081 (access to uninitialized vars in preload_load()).

ext/mysqli/tests/mysqli_fetch_field_types.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ require_once 'skipifconnectfailure.inc';
9494
MYSQLI_TYPE_NEWDATE => 'MYSQLI_TYPE_NEWDATE - TODO add testing',
9595
MYSQLI_TYPE_INTERVAL => 'MYSQLI_TYPE_INTERVAL - TODO add testing',
9696
MYSQLI_TYPE_GEOMETRY => 'MYSQLI_TYPE_GEOMETRY - TODO add testing',
97+
MYSQLI_TYPE_JSON => array('JSON', '[]'),
9798
);
9899

99100
$datatypes[MYSQLI_TYPE_NEWDECIMAL] = array('DECIMAL', '1.1');

ext/pdo_mysql/mysql_statement.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,12 @@ static char *type_to_name_native(int type) /* {{{ */
748748
PDO_MYSQL_NATIVE_TYPE_NAME(DATE)
749749
#ifdef FIELD_TYPE_NEWDATE
750750
PDO_MYSQL_NATIVE_TYPE_NAME(NEWDATE)
751+
#endif
752+
#ifdef FIELD_TYPE_VECTOR
753+
PDO_MYSQL_NATIVE_TYPE_NAME(VECTOR)
754+
#endif
755+
#ifdef FIELD_TYPE_JSON
756+
PDO_MYSQL_NATIVE_TYPE_NAME(JSON)
751757
#endif
752758
PDO_MYSQL_NATIVE_TYPE_NAME(TIME)
753759
PDO_MYSQL_NATIVE_TYPE_NAME(DATETIME)

ext/pdo_mysql/tests/gh20122.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
GH-20122 (getColumnMeta() for JSON-column in MySQL)
3+
--EXTENSIONS--
4+
pdo
5+
pdo_mysql
6+
--SKIPIF--
7+
<?php
8+
require __DIR__ . '/config.inc';
9+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10+
PDOTest::skip();
11+
?>
12+
--FILE--
13+
<?php
14+
require __DIR__ . '/config.inc';
15+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
16+
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
17+
18+
$db->exec('CREATE TABLE test (bar JSON)');
19+
$db->exec('INSERT INTO test VALUES("[]")');
20+
21+
$stmt = $db->query('SELECT * from test');
22+
$meta = $stmt->getColumnMeta(0);
23+
24+
// Note: JSON is an alias for LONGTEXT on MariaDB!
25+
echo $meta['native_type'], "\n";
26+
?>
27+
--CLEAN--
28+
<?php
29+
require __DIR__ . '/mysql_pdo_test.inc';
30+
MySQLPDOTest::dropTestTable();
31+
?>
32+
--EXPECTF--
33+
%r(JSON|LONGTEXT)%r

0 commit comments

Comments
 (0)