[development] using db_insert with big ints

Andre Angelantoni aangel at mac.com
Tue Dec 28 19:28:32 UTC 2010

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?


More information about the development mailing list