From 01e911b856483ed64b30cc777e39fb505d672159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kwa=C5=9Bnicki?= Date: Fri, 26 Aug 2022 13:08:39 +0200 Subject: [PATCH 1/2] fix: Patched SQL dialect issue LIMIT vs TOP in favor of Microsoft SQL Server --- classes/review.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/classes/review.php b/classes/review.php index 2a72a0d760..30713c30a0 100644 --- a/classes/review.php +++ b/classes/review.php @@ -85,6 +85,15 @@ public static function get_short_review_info_for_discussion(int $discussionid) { public static function get_first_review_post($moodleoverflowid, $afterpostid = null) { global $DB; + /* 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'; + } + $params = ['moodleoverflowid' => $moodleoverflowid]; $orderby = ''; $addwhere = ''; @@ -102,11 +111,11 @@ public static function get_first_review_post($moodleoverflowid, $afterpostid = n $params['notpostid'] = $afterpostid; } $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 $addwhere " . "ORDER BY $orderby p.discussion, p.id " . - 'LIMIT 1', + $limit, $params ); if ($record) { From d7160fe4121e59bae38fe72c991bcafcd4a3f818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Kwa=C5=9Bnicki?= Date: Fri, 26 Aug 2022 13:08:39 +0200 Subject: [PATCH 2/2] fix: Patched SQL dialect issue LIMIT vs TOP in favor of Microsoft SQL Server --- classes/review.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/classes/review.php b/classes/review.php index fa58c71e4a..3416c6f1a9 100644 --- a/classes/review.php +++ b/classes/review.php @@ -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) {