Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Patched SQL dialect issue LIMIT vs TOP in favor of Microsoft SQL Server #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions classes/review.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,20 @@ public static function get_first_review_post($moodleoverflowid, $afterpostid = n
$addwhere = ' AND p.id != :notpostid ';
$params['notpostid'] = $afterpostid;
}
/* Handle different SQL dialects in favor of Microsoft SQL Server */
if (is_a($DB, 'sqlsrv_native_moodle_database')) {
$top = 'TOP 1';
$limit = '';
} else {
$top = '';
$limit = 'LIMIT 1';
}
$record = $DB->get_record_sql(
'SELECT p.id as postid, p.discussion as discussionid FROM {moodleoverflow_posts} p ' .
"SELECT $top p.id as postid, p.discussion as discussionid FROM {moodleoverflow_posts} p " .
'JOIN {moodleoverflow_discussions} d ON d.id = p.discussion ' .
"WHERE p.reviewed = 0 AND d.moodleoverflow = :moodleoverflowid AND p.created < :reviewtime $addwhere " .
"ORDER BY $orderby p.discussion, p.id " .
'LIMIT 1',
$limit,
$params
);
if ($record) {
Expand Down