]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14679 mssql fix - Fix boolean handling in mssql + set_field() without params.
authorstronk7 <stronk7>
Tue, 28 Apr 2009 23:49:33 +0000 (23:49 +0000)
committerstronk7 <stronk7>
Tue, 28 Apr 2009 23:49:33 +0000 (23:49 +0000)
lib/dml/mssql_adodb_moodle_database.php

index 093e2de581a1d8a99ec013e1baa9f253b78dfd0c..e673f42dc5522a150a15b9b3dc28b1189827a9e7 100644 (file)
@@ -201,6 +201,11 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
                 continue;
             }
             $column = $columns[$field];
+
+            if (is_bool($value)) { /// Always, convert boolean to int
+                $value = (int)$value;
+            }
+
             if ($column->meta_type == 'B') { /// BLOBs (IMAGE) columns need to be updated apart
                 if (!is_null($value)) {      /// If value not null, add it to the list of BLOBs to update later
                     $blobs[$field] = $value;
@@ -212,9 +217,6 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
                     $value = (string)$value;        /// cast to string
                 }
 
-            } else if (is_bool($value)) {
-                $value = (int)$value; // prevent "false" problems
-
             } else if ($value === '') {
                 if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
                     $value = 0; // prevent '' problems in numeric fields
@@ -269,6 +271,11 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
         }
 
     /// Arrived here, normal update (without BLOBs)
+
+        if (is_bool($newvalue)) { /// Always, convert boolean to int
+            $newvalue = (int)$newvalue;
+        }
+
         if (is_null($newvalue)) {
             $newfield = "$newfield = NULL";
         } else {
@@ -277,9 +284,6 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
                     $newvalue = (string)$newvalue;  /// cast to string in PHP
                 }
 
-            } else if (is_bool($newvalue)) {
-                $newvalue = (int)$newvalue; // prevent "false" problems
-
             } else if ($newvalue === '') {
                 if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
                     $newvalue = 0; // prevent '' problems in numeric fields
@@ -289,7 +293,8 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
             $newfield = "$newfield = ?";
             array_unshift($params, $newvalue); // add as first param
         }
-        $sql = "UPDATE {$this->prefix}$table SET $newfield WHERE $select";
+        $select = !empty($select) ? "WHERE $select" : '';
+        $sql = "UPDATE {$this->prefix}$table SET $newfield $select";
 
         $this->query_start($sql, $params, SQL_QUERY_UPDATE);
         $rs = $this->adodb->Execute($sql, $params);
@@ -327,6 +332,11 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
                 continue;
             }
             $column = $columns[$field];
+
+            if (is_bool($value)) { /// Always, convert boolean to int
+                $value = (int)$value;
+            }
+
             if ($column->meta_type == 'B') { /// BLOBs (IMAGE) columns need to be updated apart
                 if (!is_null($value)) {      /// If value not null, add it to the list of BLOBs to update later
                     $blobs[$field] = $value;
@@ -338,9 +348,6 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
                     $value = (string)$value;        /// cast to string
                 }
 
-            } else if (is_bool($value)) {
-                $value = (int)$value; // prevent "false" problems
-
             } else if ($value === '') {
                 if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
                     $value = 0; // prevent '' problems in numeric fields