[development] using db_insert with big ints

nan wich nan_wich at bellsouth.net
Tue Dec 28 21:30:51 UTC 2010


'size' => 'big',
 
Nancy
 
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.




________________________________
From: Andre Angelantoni <aangel at mac.com>
To: development at drupal.org
Sent: Tue, December 28, 2010 2:28:32 PM
Subject: [development] using db_insert with big ints

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'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20101228/0f355506/attachment-0001.html 


More information about the development mailing list