mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-14679 mssql fix - Fix boolean handling in mssql + set_field() without params.
This commit is contained in:
parent
c94882ffa2
commit
0aa060602f
1 changed files with 17 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue