Bug #48724 [PATCH]: getColumnMeta() doesn't return native_type for BIT, TINYINT and YEAR

From: Date: Fri, 13 Apr 2012 12:06:15 +0000
Subject: Bug #48724 [PATCH]: getColumnMeta() doesn't return native_type for BIT, TINYINT and YEAR
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-169536@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48724&edit=1

 ID:                 48724
 Patch added by:     tony2001@php.net
 Reported by:        an0nym at narod dot ru
 Summary:            getColumnMeta() doesn't return native_type for BIT,
                     TINYINT and YEAR
 Status:             Open
 Type:               Bug
 Package:            PDO related
 Operating System:   *
 PHP Version:        5.3.0
 Block user comment: N
 Private report:     N

 New Comment:

The following patch has been added/updated:

Patch Name: fix-bug-48724.patch
Revision:   1334318775
URL:        https://bugs.php.net/patch-display.php?bug=48724&patch=fix-bug-48724.patch&revision=1334318775


Previous Comments:
------------------------------------------------------------------------
[2009-07-03 16:57:28] uw@php.net

You are free to patch it. 

Bye.

------------------------------------------------------------------------
[2009-07-03 16:30:12] an0nym at narod dot ru

Poor MySQLi developers... they've managed to solve this problem without 
specification. 

Poor you... you've spent sooo many time for nothing developing this 
function, which works in 35 of 38 cases - this stuff has no 
specification! Wait for a specification - you have a good excuse! 

Bye.

------------------------------------------------------------------------
[2009-07-03 16:17:20] uw@php.net

You are free to write a patch. 

I refuse to work on stuff that has no specification and which may go into any direction. That
typically ends up in a backwards compatibility nightmare, which in particular for an abstraction
like PDO makes no sense to me.

The patch may be rather simple. But watch out for different values returned by different MySQL
versions.

------------------------------------------------------------------------
[2009-07-03 15:39:20] an0nym at narod dot ru

> libmysql and mysqlnd behave the same way. If this is decided to be
considered as a bug it is not a mysqlnd bug. 
I agree. This is not a libmysql or mysqlnd bug. This is a PDO (or 
PDO_MySQL) bug.

------------------------------------------------------------------------
[2009-07-03 15:31:27] an0nym at narod dot ru

Tell me then, why MySQLi is OK with all the types while PDO is not? 
Nevertheless, it is not just OK, but it is EQUAL in behaviour for all 
the types except TINYINT, BIT and YEAR. 

Don't tell me, please, MySQLi type and PDO native type refer to 
different things. I'm almost sure they don't. At least they shouldn't. 

<?php $PDO=new 
PDO('mysql:host=localhost;dbname=test','anyone','anyone');
$PDO->exec("CREATE TABLE test(
	 tinyint TINYINT NOT NULL
	,smallint SMALLINT NOT NULL
	,mediumint MEDIUMINT NOT NULL
	,int INT NOT NULL
	,bigint BIGINT NOT NULL
	,decimal DECIMAL NOT NULL
	,float FLOAT NOT NULL
	,double DOUBLE NOT NULL
	,bit BIT(1) NOT NULL
	,date DATE NOT NULL
	,datetime DATETIME NOT NULL
	,timestamp TIMESTAMP NOT NULL
	,time TIME NOT NULL
	,year YEAR NOT NULL
	,char CHAR(1) NOT NULL
	,varchar VARCHAR(1) NOT NULL
	,tinytext TINYTEXT NOT NULL
	,text TEXT NOT NULL
	,mediumtext MEDIUMTEXT NOT NULL
	,longtext LONGTEXT NOT NULL
	,binary BINARY(1) NOT NULL
	,varbinary VARBINARY(1) NOT NULL
	,tinyblob TINYBLOB NOT NULL
	,mediumblob MEDIUMBLOB NOT NULL
	,blob BLOB NOT NULL
	,longblob LONGBLOB NOT NULL
	,enum ENUM('') NOT NULL
	,set SET('') NOT NULL)");
$PDO->exec('INSERT INTO test(tinyint) VALUES(0)');
$PDO_statement=$PDO->query('SELECT * FROM test');
$PDO_fields=array();
for($i=0,$n=$PDO_statement->columnCount();$i<$n;++$i){
	$PDO_fields[]=$PDO_statement->getColumnMeta($i);
}
$MySQLi=new mysqli('localhost','anyone','anyone','test');
$MySQLi_result=$MySQLi->query('SELECT * FROM test');
$MySQLi_fields=$MySQLi_result->fetch_fields();
$bug_fields=array();
for($i=0,$n=count($PDO_fields);$i<$n;++$i){
	if(!isset($PDO_fields[$i]['native_type'])
		 or 
constant('MYSQLI_TYPE_'.$PDO_fields[$i]['native_type'])!=$MySQLi_field
s[$i]->type){
		$bug_fields[]=$PDO_fields[$i]['name'];
	}
}
var_dump($bug_fields);
$PDO->exec('DROP TABLE test'); ?>

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


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=48724


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


Thread (14 messages)

« previous php.bugs (#169536) next »