Skip to content
Permalink
Browse files

MDL-27696 do not use placeholders in GROUP BY because pg does no like…

… that
  • Loading branch information...
skodak committed Jul 19, 2011
1 parent 27b4936 commit fc7224bac7f4b3296e7450e93c23d19016a0d92f
Showing with 12 additions and 14 deletions.
  1. +12 −14 lib/datalib.php
@@ -1844,15 +1844,13 @@ function get_logs_usercourse($userid, $courseid, $coursestart) {
$params['courseid'] = $courseid;
}
$params['userid'] = $userid;
$params['coursestart1'] = $coursestart;
$params['coursestart2'] = $coursestart;
$params['coursestart3'] = $coursestart;
$$coursestart = (int)$coursestart; // note: unfortunately pg complains if you use name parameter or column alias in GROUP BY
return $DB->get_records_sql("SELECT FLOOR((time - :coursestart1)/". DAYSECS .") AS day, COUNT(*) AS num
return $DB->get_records_sql("SELECT FLOOR((time - $coursestart)/". DAYSECS .") AS day, COUNT(*) AS num
FROM {log}
WHERE userid = :userid
AND time > :coursestart2 $courseselect
GROUP BY FLOOR((time - :coursestart3)/". DAYSECS .")", $params);
AND time > $coursestart $courseselect
GROUP BY FLOOR((time - $coursestart)/". DAYSECS .")", $params);
}
/**
@@ -1868,20 +1866,20 @@ function get_logs_usercourse($userid, $courseid, $coursestart) {
function get_logs_userday($userid, $courseid, $daystart) {
global $DB;
$params = array($daystart, $userid, $daystart);
$params = array('userid'=>$userid);
$courseselect = '';
if ($courseid) {
$courseselect = "AND course = ?";
$params[] = $courseid;
$courseselect = "AND course = :courseid";
$params['courseid'] = $courseid;
}
$params[] = $daystart;
$daystart = (int)$daystart; // note: unfortunately pg complains if you use name parameter or column alias in GROUP BY
return $DB->get_records_sql("SELECT FLOOR((time - ?)/". HOURSECS .") AS hour, COUNT(*) AS num
return $DB->get_records_sql("SELECT FLOOR((time - $daystart)/". HOURSECS .") AS hour, COUNT(*) AS num
FROM {log}
WHERE userid = ?
AND time > ? $courseselect
GROUP BY FLOOR((time - ?)/". HOURSECS .") ", $params);
WHERE userid = :userid
AND time > $daystart $courseselect
GROUP BY FLOOR((time - $daystart)/". HOURSECS .") ", $params);
}
/**

0 comments on commit fc7224b

Please sign in to comment.
You can’t perform that action at this time.