[development] using db_insert with big ints

David Cohen drupal at dave-cohen.com
Tue Dec 28 21:22:16 UTC 2010


Is Drupal's db layer so weak that users must change their database
schema in order to use it?

Is that acceptable?

Sounds like a bug to me.

-Dave


On Tue, 28 Dec 2010 21:28 +0100, "Paolo Mainardi"
<paolomainardi at gmail.com> wrote:
> 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 --
> 


More information about the development mailing list