Skip to content

Commit eaf990b

Browse files
Merge pull request #55 from Vidalia/master
Added support for MSSQL databases
2 parents 88ee156 + c29cf17 commit eaf990b

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

classes/privacy/data_export_helper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,10 @@ protected static function export_all_posts_in_discussion($userid, \context $cont
157157
INNER JOIN {moodleoverflow_posts} p ON p.discussion = d.id
158158
LEFT JOIN {moodleoverflow_read} fr ON fr.postid = p.id AND fr.userid = :readuserid
159159
LEFT JOIN {moodleoverflow_ratings} rat ON rat.id = (
160-
SELECT id FROM {moodleoverflow_ratings} ra
160+
SELECT MAX(id) FROM {moodleoverflow_ratings} ra
161161
WHERE ra.postid = p.id OR ra.userid = :ratinguserid
162-
LIMIT 1
163162
)
164-
WHERE d.id = :discussionid
163+
WHERE d.id = :discussionid
165164
";
166165
$params = [
167166
'discussionid' => $discussionid,

classes/ratings.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ public static function moodleoverflow_add_rating($moodleoverflow, $postid, $rati
140140
// Get other ratings in the discussion.
141141
$sql = "SELECT *
142142
FROM {moodleoverflow_ratings}
143-
WHERE discussionid = $discussion->id AND rating = $rating
144-
LIMIT 1";
145-
$otherrating = $DB->get_record_sql($sql);
143+
WHERE discussionid = ? AND rating = ?";
144+
$otherrating = $DB->get_record_sql($sql, [ $discussion->id, $rating ]);
146145

147146
// If there is an old rating, update it. Else create a new rating record.
148147
if ($otherrating) {
@@ -347,10 +346,9 @@ public static function moodleoverflow_user_rated($postid, $userid = null) {
347346
// Get the rating.
348347
$sql = "SELECT firstrated, rating
349348
FROM {moodleoverflow_ratings}
350-
WHERE userid = $userid AND postid = $postid AND (rating = 1 OR rating = 2)
351-
LIMIT 1";
349+
WHERE userid = ? AND postid = ? AND (rating = 1 OR rating = 2)";
352350

353-
return ($DB->get_record_sql($sql));
351+
return ($DB->get_record_sql($sql, [ $userid, $postid ]));
354352
}
355353

356354
/**
@@ -390,9 +388,9 @@ public static function moodleoverflow_get_ratings_by_discussion($discussionid, $
390388
(SELECT COUNT(rating) FROM {moodleoverflow_ratings} WHERE postid=p.id AND rating = 3) AS issolved,
391389
(SELECT COUNT(rating) FROM {moodleoverflow_ratings} WHERE postid=p.id AND rating = 4) AS ishelpful
392390
FROM {moodleoverflow_posts} p
393-
WHERE p.discussion = $discussionid
391+
WHERE p.discussion = ?
394392
GROUP BY p.id";
395-
$votes = $DB->get_records_sql($sql);
393+
$votes = $DB->get_records_sql($sql, [ $discussionid ]);
396394

397395
// A single post is requested.
398396
if ($postid) {
@@ -596,9 +594,8 @@ private static function moodleoverflow_check_old_rating($postid, $userid, $oldra
596594
// Get the normal rating.
597595
$sql = "SELECT *
598596
FROM {moodleoverflow_ratings}
599-
WHERE userid = $userid AND postid = $postid AND (rating = 1 OR rating = 2)
600-
LIMIT 1";
601-
$rating['normal'] = $DB->get_record_sql($sql);
597+
WHERE userid = ? AND postid = ? AND (rating = 1 OR rating = 2)";
598+
$rating['normal'] = $DB->get_record_sql($sql, [ $userid, $postid ]);
602599

603600
// Return the rating if it is requested.
604601
if ($oldrating == RATING_DOWNVOTE OR $oldrating == RATING_UPVOTE) {
@@ -608,9 +605,8 @@ private static function moodleoverflow_check_old_rating($postid, $userid, $oldra
608605
// Get the solved rating.
609606
$sql = "SELECT *
610607
FROM {moodleoverflow_ratings}
611-
WHERE userid = $userid AND postid = $postid AND rating = 3
612-
LIMIT 1";
613-
$rating['solved'] = $DB->get_record_sql($sql);
608+
WHERE userid = ? AND postid = ? AND rating = 3";
609+
$rating['solved'] = $DB->get_record_sql($sql, [ $userid, $postid ]);
614610

615611
// Return the rating if it is requested.
616612
if ($oldrating == RATING_SOLVED) {
@@ -620,9 +616,8 @@ private static function moodleoverflow_check_old_rating($postid, $userid, $oldra
620616
// Get the helpful rating.
621617
$sql = "SELECT *
622618
FROM {moodleoverflow_ratings}
623-
WHERE userid = $userid AND postid = $postid AND rating = 4
624-
LIMIT 1";
625-
$rating['helpful'] = $DB->get_record_sql($sql);
619+
WHERE userid = ? AND postid = ? AND rating = 4";
620+
$rating['helpful'] = $DB->get_record_sql($sql, [ $userid, $postid ]);
626621

627622
// Return the rating if it is requested.
628623
if ($oldrating == RATING_HELPFUL) {

0 commit comments

Comments
 (0)