From 7770a9545292d628afd2be4f58f86da5c9139619 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 30 Nov 2013 21:31:21 +0000 Subject: [PATCH] Disallow subtraction on unsigned columns: MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit When you use subtraction between integer values where one is of type UNSIGNED, the result is unsigned unless the NO_UNSIGNED_SUBTRACTION SQL mode is enabled. See Section 12.10, “Cast Functions and Operators”. --- inc/db/lib-mysql3.php | 3 +++ inc/db/lib-mysqli.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/inc/db/lib-mysql3.php b/inc/db/lib-mysql3.php index 24fb6e42c8..fd86300e36 100644 --- a/inc/db/lib-mysql3.php +++ b/inc/db/lib-mysql3.php @@ -231,6 +231,9 @@ function sqlConnectToDatabase ($host, $login, $password, $file, $line) { `character_set_connection`='utf8', `character_set_database`='utf8', `character_set_server`='utf8'", $file . ':' . __FUNCTION__, $line . ':' . __LINE__); + + // Disallow subtraction for unsigned columns + sqlQuery("SET `sql_mode`='NO_UNSIGNED_SUBTRACTION'", $file . ':' . __FUNCTION__, $line . ':' . __LINE__); } // END - if // Return the resource diff --git a/inc/db/lib-mysqli.php b/inc/db/lib-mysqli.php index 27798e9bb2..9a1be87301 100644 --- a/inc/db/lib-mysqli.php +++ b/inc/db/lib-mysqli.php @@ -218,6 +218,9 @@ function sqlConnectToDatabase ($host, $login, $password, $file, $line) { `character_set_connection`='utf8', `character_set_database`='utf8', `character_set_server`='utf8'", $file . ':' . __FUNCTION__, $line . ':' . __LINE__); + + // Disallow subtraction for unsigned columns + sqlQuery("SET `sql_mode`='NO_UNSIGNED_SUBTRACTION'", $file . ':' . __FUNCTION__, $line . ':' . __LINE__); } // END - if // Any errors encountered? -- 2.39.5