ID: 46508
Comment by: php at displague dot com
Reported By: marques at displague dot com
Status: Assigned
Bug Type: PDO related
PHP Version: 5.2.6
Assigned To: mysql
New Comment:
This should probably be the topic of another bug, but TINYINT doesn't
return a native_type (I'm guessing because TINY is used everywhere, but
not TINYINT - maybe another constant is needed).
mysql://u...@host/db> show columns from table like 'disable' \G;
*************************** 1. row ***************************
Field: disable
Type: tinyint(4)
Null: NO
Key:
Default: 0
Extra:
1 row in set (0.00 sec)
getColumnMeta (php 5.2.9) returns:
Array
(
[flags] => Array
(
[0] => not_null
)
[table] => promo_item
[name] => disable
[len] => 4
[precision] => 0
[pdo_type] => 2
)
native_type is missing.
Is there any chance this correction will make it into 5.2.x?
Previous Comments:
------------------------------------------------------------------------
[2008-11-07 16:24:52] [email protected]
Hi Marques, good observation! I've updated the patch. ;)
Thanks.
------------------------------------------------------------------------
[2008-11-07 16:02:59] marques at displague dot com
The values that are currently being reported may belong in the
getmetacolumn array member 'driver:decl_type' (per the getColumnMeta
documentation example).
------------------------------------------------------------------------
[2008-11-07 15:49:25] [email protected]
Patch: http://felipe.ath.cx/diff/bug46508.diff (5.3)
------------------------------------------------------------------------
[2008-11-06 15:05:57] marques at displague dot com
I put my expected and actual results in the wrong boxes.
The capitalized native_types are not what I would expect because they
are not php native types per the PHP documentation on types and the
getColumnMeta example.
------------------------------------------------------------------------
[2008-11-06 15:02:20] marques at displague dot com
Description:
------------
Using the pdo_mysql driver, when I do a getColumnMeta on an int(11)
NULL field, the native_type returned is 'LONG'. I expect 'integer'.
Also, the pdo_type returned on this column is PDO::PARAM_STR, not
PDO::PARAM_INT as I would expect.
http://php.net/manual/en/pdostatement.getcolumnmeta.php defines
native_type as "The PHP native type used to represent the column
value.". The example on that page shows a return value of 'integer'..
This would seem to mesh with the PHP types defined here:
http://php.net/manual/en/function.gettype.php
If this is just a documentation bug due to recent changes, perhaps
someone should consider leaving native_type intact as php native type,
and using 'type' or something for these new values.
Reproduce code:
---------------
// MySQL: create table `table` (`i` int default null, `s` varchar(32),
`b` text, `t` timestamp, `d` datetime);
$pdo= new PDO("mysql:host=localhost;dbname=somedb","user","pass");
$stmt=$pdo->query("SELECT * from `table` limit 0");
for($i=0;$i<5;$i++) print_r($stmt->getColumnMeta($i));
Expected result:
----------------
Array
(
[native_type] => LONG
[flags] => Array
(
)
[table] => table
[name] => i
[len] => 11
[precision] => 0
[pdo_type] => 1
)
Array
(
[native_type] => VAR_STRING
[flags] => Array
(
)
[table] => table
[name] => s
[len] => 32
[precision] => 0
[pdo_type] => 2
)
Array
(
[native_type] => BLOB
[flags] => Array
(
[0] => blob
)
[table] => table
[name] => b
[len] => 65535
[precision] => 0
[pdo_type] => 2
)
Array
(
[native_type] => TIMESTAMP
[flags] => Array
(
[0] => not_null
)
[table] => table
[name] => t
[len] => 19
[precision] => 0
[pdo_type] => 2
)
Array
(
[native_type] => DATETIME
[flags] => Array
(
)
[table] => table
[name] => d
[len] => 19
[precision] => 0
[pdo_type] => 2
)
Actual result:
--------------
Array
(
[native_type] => integer
[flags] => Array
(
)
[table] => table
[name] => i
[len] => 11
[precision] => 0
[pdo_type] => 1
)
Array
(
[native_type] => string
[flags] => Array
(
)
[table] => table
[name] => s
[len] => 32
[precision] => 0
[pdo_type] => 2
)
Array
(
[native_type] => string
[flags] => Array
(
[0] => blob
)
[table] => table
[name] => b
[len] => 65535
[precision] => 0
[pdo_type] => 2
)
Array
(
[native_type] => string
[flags] => Array
(
[0] => not_null
)
[table] => table
[name] => t
[len] => 19
[precision] => 0
[pdo_type] => 2
)
Array
(
[native_type] => string
[flags] => Array
(
)
[table] => table
[name] => d
[len] => 19
[precision] => 0
[pdo_type] => 2
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=46508&edit=1