MDL-14679 mssql fix - Fix boolean handling in mssql + set_field() without params.

This commit is contained in:
stronk7 2009-04-28 23:49:33 +00:00
parent c94882ffa2
commit 0aa060602f

View file

@ -201,6 +201,11 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
continue; continue;
} }
$column = $columns[$field]; $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 ($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 if (!is_null($value)) { /// If value not null, add it to the list of BLOBs to update later
$blobs[$field] = $value; $blobs[$field] = $value;
@ -212,9 +217,6 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
$value = (string)$value; /// cast to string $value = (string)$value; /// cast to string
} }
} else if (is_bool($value)) {
$value = (int)$value; // prevent "false" problems
} else if ($value === '') { } else if ($value === '') {
if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') { if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
$value = 0; // prevent '' problems in numeric fields $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) /// Arrived here, normal update (without BLOBs)
if (is_bool($newvalue)) { /// Always, convert boolean to int
$newvalue = (int)$newvalue;
}
if (is_null($newvalue)) { if (is_null($newvalue)) {
$newfield = "$newfield = NULL"; $newfield = "$newfield = NULL";
} else { } else {
@ -277,9 +284,6 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
$newvalue = (string)$newvalue; /// cast to string in PHP $newvalue = (string)$newvalue; /// cast to string in PHP
} }
} else if (is_bool($newvalue)) {
$newvalue = (int)$newvalue; // prevent "false" problems
} else if ($newvalue === '') { } else if ($newvalue === '') {
if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') { if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
$newvalue = 0; // prevent '' problems in numeric fields $newvalue = 0; // prevent '' problems in numeric fields
@ -289,7 +293,8 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
$newfield = "$newfield = ?"; $newfield = "$newfield = ?";
array_unshift($params, $newvalue); // add as first param 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); $this->query_start($sql, $params, SQL_QUERY_UPDATE);
$rs = $this->adodb->Execute($sql, $params); $rs = $this->adodb->Execute($sql, $params);
@ -327,6 +332,11 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
continue; continue;
} }
$column = $columns[$field]; $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 ($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 if (!is_null($value)) { /// If value not null, add it to the list of BLOBs to update later
$blobs[$field] = $value; $blobs[$field] = $value;
@ -338,9 +348,6 @@ class mssql_adodb_moodle_database extends adodb_moodle_database {
$value = (string)$value; /// cast to string $value = (string)$value; /// cast to string
} }
} else if (is_bool($value)) {
$value = (int)$value; // prevent "false" problems
} else if ($value === '') { } else if ($value === '') {
if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') { if ($column->meta_type == 'I' or $column->meta_type == 'F' or $column->meta_type == 'N') {
$value = 0; // prevent '' problems in numeric fields $value = 0; // prevent '' problems in numeric fields