Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292997

drupal_write_record() cast wrong type for unsigned int and big int value

$
0
0

I have encountered this problem when I try to save big int value by drupal_write_record().

I have defined a field as unsigned big int in the schema, meaning in MySQL I can save value ranging from 0 to 4294967295.

In php, integer value is ranging from -2147483648 to 2147483647.

When I want to save a value like 3453966699, it actually belongs to float type but can be saved as unsigned int(10) not to mention bigint.

But in the drupal_write_record(), all int type including normal and big will be forced to cast to int type.

<?php
     
if ($info['type'] == 'int'|| $info['type'] == 'serial') {
       
$fields[$field] = (int) $fields[$field];
      }
?>

So (int) 3453966699 will become -841000597

Can we make it work with unsigned int and big int?

<?php
     
if ($info['type'] == 'int'|| $info['type'] == 'serial') {
        if (
$info['unsigned'] || $info['size'] == 'big') {
         
$fields[$field] = (float) $fields[$field];
        }
        else {
         
$fields[$field] = (int) $fields[$field];
        }
      }
?>

Viewing all articles
Browse latest Browse all 292997

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>