mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
MDL-60976 dml: Optimise replace_all_text()
Avoid updating fields that do not match the search string.
This commit is contained in:
parent
109aa07648
commit
1c06098b6b
@ -2402,21 +2402,25 @@ abstract class moodle_database {
|
||||
|
||||
// Enclose the column name by the proper quotes if it's a reserved word.
|
||||
$columnname = $this->get_manager()->generator->getEncQuoted($column->name);
|
||||
|
||||
$searchsql = $this->sql_like($columnname, '?');
|
||||
$searchparam = '%'.$this->sql_like_escape($search).'%';
|
||||
|
||||
$sql = "UPDATE {".$table."}
|
||||
SET $columnname = REPLACE($columnname, ?, ?)
|
||||
WHERE $columnname IS NOT NULL";
|
||||
WHERE $searchsql";
|
||||
|
||||
if ($column->meta_type === 'X') {
|
||||
$this->execute($sql, array($search, $replace));
|
||||
$this->execute($sql, array($search, $replace, $searchparam));
|
||||
|
||||
} else if ($column->meta_type === 'C') {
|
||||
if (core_text::strlen($search) < core_text::strlen($replace)) {
|
||||
$colsize = $column->max_length;
|
||||
$sql = "UPDATE {".$table."}
|
||||
SET $columnname = " . $this->sql_substr("REPLACE(" . $columnname . ", ?, ?)", 1, $colsize) . "
|
||||
WHERE $columnname IS NOT NULL";
|
||||
WHERE $searchsql";
|
||||
}
|
||||
$this->execute($sql, array($search, $replace));
|
||||
$this->execute($sql, array($search, $replace, $searchparam));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user