NOBUG: Normalise generated param names so we can safely use sql_xxx() helper functions everywhere.

This commit is contained in:
Eloy Lafuente 2010-03-22 18:06:59 +00:00
parent cea304d432
commit cd6d352396

View file

@ -485,9 +485,10 @@ abstract class moodle_database {
$where[] = "$key IS NULL"; $where[] = "$key IS NULL";
} else { } else {
if ($allowed_types & SQL_PARAMS_NAMED) { if ($allowed_types & SQL_PARAMS_NAMED) {
$where[] = "$key = :$key"; $normkey = trim(preg_replace('/[^a-zA-Z0-9-_]/', '_', $key), '-_'); // Need to normalize key names
$params[$key] = $value; $where[] = "$key = :$normkey"; // because they can contain, originally,
} else { $params[$normkey] = $value; // spaces and other forbiden chars when
} else { // using sql_xxx() functions and friends.
$where[] = "$key = ?"; $where[] = "$key = ?";
$params[] = $value; $params[] = $value;
} }