#48383 [Com]: PostgreSQL extension passes string param to int column when passed NULL of FALS

From: Date: Wed, 27 May 2009 01:19:17 +0000
Subject: #48383 [Com]: PostgreSQL extension passes string param to int column when passed NULL of FALS
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-137765@lists.php.net to get a copy of this message
ID: 48383 Comment by: sfrost at snowman dot net Reported By: joshwaihi at gmail dot com Status: Open Bug Type: PDO related Operating System: Ubuntu PHP Version: 5.2.9 New Comment: Based on what I've seen in gdb under Debian with php 5.2.9, this looks to be an issue where PHP believes it's an empty string, not a false boolean: (gdb) p *param $37 = {paramno = 0, name = 0x10dec80 ":id", namelen = 3, max_value_len = 0, parameter = 0x10deb10, param_type = PDO_PARAM_STR, driver_params = 0x0, driver_data = 0x0, stmt = 0x10dd398, is_param = 1} (gdb) p *param->parameter $38 = {value = {lval = 17684240, dval = 8.7371754568116058e-317, str = {val = 0x10dd710 "", len = 0}, ht = 0x10dd710, obj = {handle = 17684240, handlers = 0x0}}, refcount = 1, type = 6 '\006', is_ref = 0 '\0'} (gdb) If param->parameter was actually coming through as a IS_BOOL, the pdo_pgsql driver would act differently (it would translate it to a 't' or an 'f' respectively, which still isn't ideal since that would still break going into an integer column, but that's easily enough fixed by switching to '1' and '0', which PG will accept as booleans directly too). Previous Comments: ------------------------------------------------------------------------ [2009-05-25 10:52:53] joshwaihi at gmail dot com Description: ------------ When FALSE or NULL is passed to int column, PostgreSQL 8.3 fails with the following error: Invalid text representation: 7 ERROR: invalid input syntax for integer: "" It would seem the PDO postgreSQL driver is passing NULL and FALSE as a string. This is not however, the case for the MySQL Driver. Reproduce code: --------------- try { $dbh = new PDO('pgsql:dbname=test;', 'myUser'); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbh->query('CREATE TABLE test (id int not null, name text not null)'); $SQL = 'INSERT INTO test (id,name) VALUES (:id, :name)'; $query = $dbh->prepare($SQL); $query->execute(array(':id' => 0, ':name' => 'This will work')); $query->execute(array(':id' => FALSE, ':name' => 'This will not work')); } catch (Exception $e) { print $e->getMessage(); } $dbh->query('DROP TABLE test'); Expected result: ---------------- no output Actual result: -------------- SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48383&edit=1

« previous php.bugs (#137765) next »