Bug #44597 [Com]: [PATCH] Postgres driver does not prepare booleans correctly

From: Date: Thu, 24 Jul 2014 15:44:11 +0000
Subject: Bug #44597 [Com]: [PATCH] Postgres driver does not prepare booleans correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186801@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=44597&edit=1 ID: 44597 Comment by: marcello dot nuccio at gmail dot com Reported by: kenaniah at gmail dot com Summary: [PATCH] Postgres driver does not prepare booleans correctly Status: No Feedback Type: Bug Package: PDO related Operating System: Red Hat 4.1.1 PHP Version: 5.2.6 Block user comment: N Private report: N New Comment: As a workaround, I use the following expression to pass boolean values: $boolvar ?: 'false' Very hackish, but that's the best workaround I have found. Previous Comments: ------------------------------------------------------------------------ [2013-10-15 11:54:25] php-bugs at lists dot php dot net No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. ------------------------------------------------------------------------ [2013-08-20 18:04:11] mike@php.net Please try using this snapshot: http://snaps.php.net/php5.4-latest.tar.gz For Windows: http://windows.php.net/snapshots/ Seems to work correctly in recent versions. ------------------------------------------------------------------------ [2010-10-12 12:20:14] ddebernardy at yahoo dot com I'm in agreement with the last commenter. The PGSQL driver handles booleans that are typecast as integers properly, but not the actual booleans. These really ought to work out of the box. ------------------------------------------------------------------------ [2009-10-05 06:08:33] kenaniah at gmail dot com *Sjoerd My apologies on the incorrect spelling. ------------------------------------------------------------------------ [2009-10-05 06:07:07] kenaniah at gmail dot com In response to sjored, I believe there is huge disagreement over that issue, and I can personally speak for many of my colleagues in saying that. While I understand the repercussions of the patch, I would also like to point out that the example cited depends on buggy functionality in the first place. For that reason alone, I humbly submit that such a case should not be considered when weighing the implementation of the patch. On the second point, I believe we have another difference of opinion. All DBMSs perform their own casting on query parameters to match internal data types. For example, certain DBs honor the *string* 'False' as a boolean value, whereas a simple boolean cast performed in PHP would result in the said parameter evaluating to TRUE. In addition, other transformations may be applied to a passed parameter based on localization, custom data types, complex data types, etc. which vary from vendor to vendor and schema to schema. The role of PDO should be to transparently forward parameters to queries via their respective PHP and PDO-recognized data types. Now concerning the third point: PHP is a loosely-typed language. There is beauty in being able to provide mixed parameters to functions. There is nothing wrong with allowing a "mixed" parameter to be passed to a query either. Most DBs operate perfectly fine when receiving mixed parameters, and rightfully throw an error when something is amiss. Passing 'True', TRUE, or 1 to a boolean database field is perfectly acceptable in many systems. And concerning your last statement: PHP should never under any circumstance attempt to think for the programmer. I expect a database abstraction layer to pass parameters along transparently *because* it is an abstraction layer. A programming language is not smarter than the one who implements it, and it is impossible to mitigate an error in logic. Rather, it is better for an error to be returned in order so that the erroneous logic be corrected, as their may be an even greater issue at hand. In closing, I believe that the implementation of a patch for this issue would be more inline with the general philosophy and design patterns that govern PHP than the current functionality today, to the point that I maintain my position that the current functionality is in fact buggy. I merely ask that PDO -- true to the form and function of an abstraction layer -- would pass parameters along in their respective data types without casting them to "string" of all things. I thank everyone who has participated in this issue thus far (especially sjored for the patch submitted), and am looking forward to this issue being resolved in an upcoming release. ------------------------------------------------------------------------ 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=44597 -- Edit this bug report at https://bugs.php.net/bug.php?id=44597&edit=1

« previous php.bugs (#186801) next »