From: stronk7 Date: Tue, 28 Apr 2009 23:49:33 +0000 (+0000) Subject: MDL-14679 mssql fix - Fix boolean handling in mssql + set_field() without params. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0aa060602f269adb23b8649d68a5f7e0ad28b824;p=moodle.git MDL-14679 mssql fix - Fix boolean handling in mssql + set_field() without params. --- diff --git a/lib/dml/mssql_adodb_moodle_database.php b/lib/dml/mssql_adodb_moodle_database.php index 093e2de581..e673f42dc5 100644 --- a/lib/dml/mssql_adodb_moodle_database.php +++ b/lib/dml/mssql_adodb_moodle_database.php @@ -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