Skip to content

Commit 2fa7dc6

Browse files
authored
fix: Patched SQL dialect issue LIMIT vs TOP in favor of Microsoft SQL Server (#101)
* fix: Patched SQL dialect issue LIMIT vs TOP in favor of Microsoft SQL Server
1 parent 81c3e1e commit 2fa7dc6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

classes/review.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ public static function get_first_review_post($moodleoverflowid, $afterpostid = n
107107
$addwhere = ' AND p.id != :notpostid ';
108108
$params['notpostid'] = $afterpostid;
109109
}
110+
/* Handle different SQL dialects in favor of Microsoft SQL Server */
111+
if (is_a($DB, 'sqlsrv_native_moodle_database')) {
112+
$top = 'TOP 1';
113+
$limit = '';
114+
} else {
115+
$top = '';
116+
$limit = 'LIMIT 1';
117+
}
110118
$record = $DB->get_record_sql(
111-
'SELECT p.id as postid, p.discussion as discussionid FROM {moodleoverflow_posts} p ' .
119+
"SELECT $top p.id as postid, p.discussion as discussionid FROM {moodleoverflow_posts} p " .
112120
'JOIN {moodleoverflow_discussions} d ON d.id = p.discussion ' .
113121
"WHERE p.reviewed = 0 AND d.moodleoverflow = :moodleoverflowid AND p.created < :reviewtime $addwhere " .
114122
"ORDER BY $orderby p.discussion, p.id " .
115-
'LIMIT 1',
123+
$limit,
116124
$params
117125
);
118126
if ($record) {

0 commit comments

Comments
 (0)