anewt-developers team mailing list archive
-
anewt-developers team
-
Mailing list archive
-
Message #00288
[Branch ~uws/anewt/anewt.uws] Rev 1799: [database] MySQL: cast BIGINT when it is <= PHP_INT_MAX
------------------------------------------------------------
revno: 1799
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt
timestamp: Tue 2010-10-26 20:58:01 +0200
message:
[database] MySQL: cast BIGINT when it is <= PHP_INT_MAX
Cast BIGINT values into real integers if the result fits in
a regular integer. This makes things like the value of
COUNT(*) in a SQL query that sometimes returns BIGINT values
(even though the actual value easily fits in an integer)
work as expected.
Before this change, PHP_INT_SIZE was consulted, resulting in
casting only on 64-bits platforms, which is not really
useful.
modified:
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.lib.php'
--- database/backend-mysql.lib.php 2010-03-31 18:57:08 +0000
+++ database/backend-mysql.lib.php 2010-10-26 18:58:01 +0000
@@ -255,14 +255,15 @@
$value = (int) $value;
break;
+ /* BIGINT: Only cast when the integer type can actually hold the
+ * values in an integer type. PHP_INT_MAX is different on 32-bit
+ * and 64-bit platforms. */
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)
+ if ($value <= PHP_INT_MAX)
$value = (int) $value;
+
break;
-
/* Common string types (VARCHAR) */
case MYSQLI_TYPE_VAR_STRING:
break;