MDL-40266 improve emulate_bound_params() for mssql driver

Looping over large numbers of items with array_shift() is expensive.
Reverse the array and fetch items from the top of the pile.

Credit goes to Martin Langhoff for original mysqli fix.
This commit is contained in:
Petr Škoda 2013-07-01 08:52:03 +02:00
parent b983901d48
commit 7aed7f46ab

View file

@ -709,8 +709,8 @@ class sqlsrv_native_moodle_database extends moodle_database {
return $sql; return $sql;
} }
// ok, we have verified sql statement with ? and correct number of params // ok, we have verified sql statement with ? and correct number of params
$parts = explode('?', $sql); $parts = array_reverse(explode('?', $sql));
$return = array_shift($parts); $return = array_pop($parts);
foreach ($params as $param) { foreach ($params as $param) {
if (is_bool($param)) { if (is_bool($param)) {
$return .= (int)$param; $return .= (int)$param;
@ -730,7 +730,7 @@ class sqlsrv_native_moodle_database extends moodle_database {
$return .= "N'$param'"; $return .= "N'$param'";
} }
$return .= array_shift($parts); $return .= array_pop($parts);
} }
return $return; return $return;
} }