[development] using db_insert with big ints
Paolo Mainardi
paolomainardi at gmail.com
Tue Dec 28 20:28:14 UTC 2010
My advice is to use it that value like a varchar(N), in order to avoid any
kind of problems, obviously if you don't need to have some kind of
calculation behind it, but i don't think as this bigint field is a
facebook_id.
On Tue, Dec 28, 2010 at 8:28 PM, Andre Angelantoni <aangel at mac.com> wrote:
> When I use db_insert in D7 (RC3), drupal_write_record (the engine behind
> db_insert) allows ints, serials, and floats for numbers.
>
> If it sees int in the schema definition, it casts the number in PHP as an
> int before writing the record. Thus my facebook id of 100000412533411
> becomes much much smaller. I have D6 code that I'm bringing to D7, btw.
>
> In common.inc:
>
> // Type cast to proper datatype, except when the value is NULL and the
> // column allows this.
> //
> // MySQL PDO silently casts e.g. FALSE and '' to 0 when inserting the
> value
> // into an integer column, but PostgreSQL PDO does not. Also type cast
> NULL
> // when the column does not allow this.
> if (isset($object->$field) || !empty($info['not null'])) {
> if ($info['type'] == 'int' || $info['type'] == 'serial') {
> $fields[$field] = (int) $fields[$field]; // ****HERE***
> }
> elseif ($info['type'] == 'float') {
> $fields[$field] = (float) $fields[$field];
> }
> else {
> $fields[$field] = (string) $fields[$field];
> }
> }
>
> There doesn't appear to be a way to insert bigints using db_insert
>
> ...or am I completely missing something?
>
> -Andre'
>
>
--
Paolo Mainardi
CTO Twinbit
Blog: http://www.paolomainardi.com
-- Please consider the environment before printing this email --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101228/4778944d/attachment.html
More information about the development
mailing list