#403840: convert boolean to integer in the database layer to maximize the portability of our database statements.

From: Damien Tournoud <damien@tournoud.net>


---
 database/database.inc       |   15 +++++++++++++--
 database/pgsql/database.inc |    2 +-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git includes/database/database.inc includes/database/database.inc
index e80d429..a85358f 100644
--- includes/database/database.inc
+++ includes/database/database.inc
@@ -570,7 +570,7 @@ abstract class DatabaseConnection extends PDO {
         $stmt->execute(NULL, $options);
       }
       else {
-        $modified = $this->expandArguments($query, $args);
+        $modified = $this->prepareArguments($query, $args);
         $stmt = $this->prepareQuery($query, !$modified);
         $stmt->execute($args, $options);
       }
@@ -620,7 +620,7 @@ abstract class DatabaseConnection extends PDO {
    * @return
    *   TRUE if the query was modified, FALSE otherwise.
    */
-  protected function expandArguments(&$query, &$args) {
+  protected function prepareArguments(&$query, &$args) {
     $modified = FALSE;
 
     foreach ($args as $key => $data) {
@@ -655,10 +655,21 @@ abstract class DatabaseConnection extends PDO {
       }
     }
 
+    // Finally, cast boolean arguments to int to maximize the portability
+    // or our database statements.
+    $args = array_map(array($this, 'convertBooleanArgument'), $args);
+
     return $modified;
   }
 
   /**
+   * Helper function for array_walk() to convert boolean arguments to int.
+   */
+  protected function convertBooleanArgument($value) {
+    return is_bool($value) ? (int) $value : $value;
+  }
+
+  /**
    * Prepare and return a SELECT query object with the specified ID.
    *
    * @see SelectQuery
diff --git includes/database/pgsql/database.inc includes/database/pgsql/database.inc
index bf14ad3..c187652 100644
--- includes/database/pgsql/database.inc
+++ includes/database/pgsql/database.inc
@@ -64,7 +64,7 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
         $stmt->execute(NULL, $options);
       }
       else {
-        $modified = $this->expandArguments($query, $args);
+        $modified = $this->prepareArguments($query, $args);
         $stmt = $this->prepareQuery($query, !$modified);
         $stmt->execute($args, $options);
       }
