Skip to content

Commit

Permalink
data MDL-24131 fixed numeric field names throwing db error. numeric f…
Browse files Browse the repository at this point in the history
…ield names are not good for DB->sql_like()
  • Loading branch information
nebgor committed Sep 16, 2010
1 parent 38015ff commit fdeb3e1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions mod/data/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1646,13 +1646,18 @@ function data_get_post_actions() {
function data_fieldname_exists($name, $dataid, $fieldid=0) {
global $CFG, $DB;

if(!is_numeric($name)) {
$like = $DB->sql_like('df.name', $name, false);
} else {
$like = "df.name = $name";
}
if ($fieldid) {
return $DB->record_exists_sql("SELECT * FROM {data_fields} df
WHERE ".$DB->sql_like('df.name', '?', false)." AND df.dataid = ?
AND ((df.id < ?) OR (df.id > ?))", array($name, $dataid, $fieldid, $fieldid));
WHERE ".$like." AND df.dataid = ?
AND ((df.id < ?) OR (df.id > ?))", array($dataid, $fieldid, $fieldid));
} else {
return $DB->record_exists_sql("SELECT * FROM {data_fields} df
WHERE ".$DB->sql_like('df.name', '?', false)." AND df.dataid = ?", array($name, $dataid));
WHERE ".$like." AND df.dataid = ?", array($dataid));
}
}

Expand Down

0 comments on commit fdeb3e1

Please sign in to comment.