MDL-24028 cast all bools in DML params to integers 1/0; credit goes to Eloy Lafuente

This commit is contained in:
Petr Skoda 2010-09-03 15:44:11 +00:00
parent deb73728e7
commit 0e6e90516a
2 changed files with 30 additions and 0 deletions

View file

@ -632,6 +632,11 @@ abstract class moodle_database {
// convert table names
$sql = $this->fix_table_names($sql);
// cast booleans to 1/0 int
foreach ($params as $key => $value) {
$params[$key] = is_bool($value) ? (int)$value : $value;
}
// NICOLAS C: Fixed regexp for negative backwards lookahead of double colons. Thanks for Sam Marshall's help
$named_count = preg_match_all('/(?<!:):[a-z][a-z0-9_]*/', $sql, $named_matches); // :: used in pgsql casts
$dollar_count = preg_match_all('/\$[1-9][0-9]*/', $sql, $dollar_matches);