views:

301

answers:

1

Hi,

the players:

  1. 64bit linux with
  2. php 5 (ZendFramework 1.10.2)
  3. PostgreSQL 8.3
  4. Doctrine 1.2

Via a Flash/Flex client i get an 8byte integer value.
the field in the database is an BIGINT (8 byte)

PHP_INT_SIZE show that system supports 8byte integer.

printing out the value in the code as it is and as intval() leads to this:

Plain:  1269452776100  
intval: 1269452776099  

float rounding failure ?

but what really driving me nuts is

ERROR: invalid input syntax for integer: "1269452776099.000000"'

when i try to use it in a query. like:

Doctrine_Core::getTable('table')->findBy('external_id',$external_id);

or

Doctrine_Core::getTable('table')->findBy('external_id',intval($external_id));

How i am supposed to handle this ? or how can i give doctrine a floating point number which it should use on a bigint field ?

Any help is much appreciated!
TIA

EDIT:

from the model:

    $this->hasColumn('external_id', 'integer', 8, array(
     'type' => 'integer',
     'length' => 8,
     'fixed' => false,
     'unsigned' => false,
     'notnull' => false,
     'primary' => false,
     ));

Database field is bigint 8 bytes.

EDIT2: http://bugs.php.net/bug.php?id=48924 seems to be the root of the problem

+1  A: 

As you have already mentioned, you hit this bug.

To work around it, pass the parameter as a string and make sure it's converted to a BIGINT on the database side:

$q = Doctrine_Query::create();
$q->from('table AS t')
  ->where("t.external_id = CAST(:external_id AS BIGINT)", array(':external_id'  => $external_id))
  ->limit(1);
$result = $q->execute();
Quassnoi