From 5bbf18cd6feb7a63c28912f2ffe819a6351cdc94 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Mon, 19 Nov 2007 01:44:26 +0000 Subject: [PATCH] changed to get_recordset_sql because get_records forces the first element to be key --- lib/db/upgrade.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index d2bca4b253..5249bac505 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2594,22 +2594,25 @@ function xmldb_main_upgrade($oldversion=0) { GROUP BY userid, itemid HAVING COUNT( * ) >1"; // duplicates found - if ($dups = get_records_sql($SQL)) { - // for each set of userid, itemid - foreach ($dups as $dup) { - if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades - WHERE itemid = $dup->itemid AND userid = $dup->userid - ORDER BY timemodified DESC")) { - - $processed = 0; // keep the first one - foreach ($thisdups as $thisdup) { - if ($processed) { - // remove the duplicates - delete_records('grade_grades', 'id', $thisdup->id); + + if ($rs = get_recordset_sql($SQL)) { + if ($rs && $rs->RecordCount() > 0) { + while ($dup = rs_fetch_next_record($rs)) { + if ($thisdups = get_records_sql("SELECT id FROM {$CFG->prefix}grade_grades + WHERE itemid = $dup->itemid AND userid = $dup->userid + ORDER BY timemodified DESC")) { + + $processed = 0; // keep the first one + foreach ($thisdups as $thisdup) { + if ($processed) { + // remove the duplicates + delete_records('grade_grades', 'id', $thisdup->id); + } + $processed++; } - $processed++; } } + rs_close($rs); } } -- 2.39.5