← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1742: [database] Only cast MySQL's BIGINT to PHP integers on 64bit

 

------------------------------------------------------------
revno: 1742
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Tue 2010-01-05 21:45:41 +0100
message:
  [database] Only cast MySQL's BIGINT to PHP integers on 64bit
  
  ... and leave it as a string on 32 bit platforms, so that no
  information is silently lost. Fixes bug #503538.
modified:
  database/backend-mysql-old.lib.php
  database/backend-mysql.lib.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.
=== modified file 'database/backend-mysql-old.lib.php'
--- database/backend-mysql-old.lib.php	2009-07-20 20:41:56 +0000
+++ database/backend-mysql-old.lib.php	2010-01-05 20:45:41 +0000
@@ -238,6 +238,10 @@
 			switch ($type)
 			{
 				case 'int':
+					/* Issue: this doesn't work for BIGINTs on 32 bits
+					 * platforms, but there is no way to find out when this
+					 * happens (both have a 'int' field type). :(  The solution
+					 * is to use MySQLi instead. */
 					$value = (int) $value;
 					break;
 

=== modified file 'database/backend-mysql.lib.php'
--- database/backend-mysql.lib.php	2009-07-21 18:22:09 +0000
+++ database/backend-mysql.lib.php	2010-01-05 20:45:41 +0000
@@ -247,12 +247,19 @@
 				case MYSQLI_TYPE_TINY:
 				case MYSQLI_TYPE_SHORT:
 				case MYSQLI_TYPE_LONG:
-				case MYSQLI_TYPE_LONGLONG:
 				case MYSQLI_TYPE_INT24:
 				case MYSQLI_TYPE_YEAR:
 					$value = (int) $value;
 					break;
 
+				case MYSQLI_TYPE_LONGLONG:
+					/* Only cast BIGINTs on 64 bit platforms that can actually
+					   hold the values in an integer data type. */
+					if (PHP_INT_SIZE >= 8)
+						$value = (int) $value;
+
+					break;
+
 				case MYSQLI_TYPE_FLOAT:
 				case MYSQLI_TYPE_DOUBLE:
 					$value = (float) $value;