jenkins-bot has submitted this change and it was merged.

Change subject: Database: Behave correctly when inserting booleans
......................................................................


Database: Behave correctly when inserting booleans

Pretty much everything seems to assume that PHP booleans should be
converted to 0/1: MySQL does this implicitly thanks to the lack of
strict mode by default, while PostgreSQL and Sqlite (and Mssql) do it
explicitly.

The addition of MySQL strict mode for unit tests in Ib2873913 exposed
the assumption in the case of MySQL by making some extension unit tests
fail. So let's make casting bool to int the default behavior of
Database::addQuotes().

This also cleans up the phpdoc for Database::addQuotes() to properly
reflect all the supported types that can be passed to it.

Change-Id: I13d0e402fa676bc27c345e8ac12f363ebc627f6a
---
M includes/db/DatabaseMssql.php
M includes/libs/rdbms/database/Database.php
M includes/libs/rdbms/database/DatabasePostgres.php
M includes/libs/rdbms/database/DatabaseSqlite.php
M includes/libs/rdbms/database/IDatabase.php
5 files changed, 10 insertions(+), 8 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php
index 00fb800..eb061d8 100644
--- a/includes/db/DatabaseMssql.php
+++ b/includes/db/DatabaseMssql.php
@@ -1085,8 +1085,8 @@
        }
 
        /**
-        * @param string|Blob $s
-        * @return string
+        * @param string|int|null|bool|Blob $s
+        * @return string|int
         */
        public function addQuotes( $s ) {
                if ( $s instanceof MssqlBlob ) {
diff --git a/includes/libs/rdbms/database/Database.php 
b/includes/libs/rdbms/database/Database.php
index 9993277..7e80221 100644
--- a/includes/libs/rdbms/database/Database.php
+++ b/includes/libs/rdbms/database/Database.php
@@ -2001,6 +2001,8 @@
                }
                if ( $s === null ) {
                        return 'NULL';
+               } elseif ( is_bool( $s ) ) {
+                       return (int)$s;
                } else {
                        # This will also quote numeric values. This should be 
harmless,
                        # and protects against weird problems that occur when 
they really
diff --git a/includes/libs/rdbms/database/DatabasePostgres.php 
b/includes/libs/rdbms/database/DatabasePostgres.php
index e79b28b..69488af 100644
--- a/includes/libs/rdbms/database/DatabasePostgres.php
+++ b/includes/libs/rdbms/database/DatabasePostgres.php
@@ -1232,8 +1232,8 @@
        }
 
        /**
-        * @param null|bool|Blob $s
-        * @return int|string
+        * @param string|int|null|bool|Blob $s
+        * @return string|int
         */
        function addQuotes( $s ) {
                if ( is_null( $s ) ) {
diff --git a/includes/libs/rdbms/database/DatabaseSqlite.php 
b/includes/libs/rdbms/database/DatabaseSqlite.php
index 6614898..2281f23 100644
--- a/includes/libs/rdbms/database/DatabaseSqlite.php
+++ b/includes/libs/rdbms/database/DatabaseSqlite.php
@@ -783,8 +783,8 @@
        }
 
        /**
-        * @param Blob|string $s
-        * @return string
+        * @param string|int|null|bool|Blob $s
+        * @return string|int
         */
        function addQuotes( $s ) {
                if ( $s instanceof Blob ) {
diff --git a/includes/libs/rdbms/database/IDatabase.php 
b/includes/libs/rdbms/database/IDatabase.php
index 25e5912..29a32f5 100644
--- a/includes/libs/rdbms/database/IDatabase.php
+++ b/includes/libs/rdbms/database/IDatabase.php
@@ -1015,8 +1015,8 @@
        /**
         * Adds quotes and backslashes.
         *
-        * @param string|Blob $s
-        * @return string
+        * @param string|int|null|bool|Blob $s
+        * @return string|int
         */
        public function addQuotes( $s );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/312052
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I13d0e402fa676bc27c345e8ac12f363ebc627f6a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: Parent5446 <tylerro...@gmail.com>
Gerrit-Reviewer: Skizzerz <skizz...@skizzerz.net>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to