]> git.mjollnir.org Git - moodle.git/commitdiff
fix SQL query that didn't work in PG (bug 4989)
authorgbateson <gbateson>
Wed, 29 Mar 2006 05:14:49 +0000 (05:14 +0000)
committergbateson <gbateson>
Wed, 29 Mar 2006 05:14:49 +0000 (05:14 +0000)
mod/hotpot/db/update_to_v2.php

index 14b386aa2b0d3c41f303db2eb41c36f6f60802df..39c5170e16796c8f7d3e46f03a6dcd4ed95d9321 100644 (file)
@@ -58,32 +58,38 @@ function hotpot_update_to_v2_1_6() {
 function hotpot_update_to_v2_1_2() {\r
        global $CFG, $db;\r
        $ok = true;\r
-       // hotpot_attempts: make sure there is only one "in progress" attempt by each user on each hotpot (and it must be the most recent attempt)\r
-       // get info about attempts (grouped by user and hotpot)\r
-       //      countrecords : number of attempts in the group\r
-       //      maxtimestart : most recent timestart in the group\r
-       //      minstatus    : minimum status in the group\r
-       // (groups with only one attempt, or no "in progess" attempt are ignored)\r
-       $records = get_records_sql("\r
-               SELECT id, userid, hotpot, COUNT(*) as countrecords, MAX(timestart) AS maxtimestart, MIN(status) as minstatus\r
+\r
+       // save and switch off SQL message echo\r
+       $debug = $db->debug;\r
+       $db->debug = false;\r
+\r
+       // extract info about attempts by each user on each hotpot (cases where \r
+       // the user has only one attempt, or no "in progess" attempt are ignored)\r
+       $rs = $db->Execute("\r
+               SELECT userid, hotpot, COUNT(*), MIN(status)\r
                FROM {$CFG->prefix}hotpot_attempts\r
                GROUP BY userid, hotpot\r
-               HAVING countrecords > 1 AND minstatus=1\r
+               HAVING COUNT(*)>1 AND MIN(status)=1\r
        ");\r
-       if ($records) {\r
-               // save and switch off SQL message echo\r
-               $debug = $db->debug;\r
-               $db->debug = false;\r
+       if ($rs && $rs->RecordCount()) {\r
+               $records = $rs->GetArray();\r
+\r
+               // start message to browser\r
                print "adjusting status of ".count($records)." &quot;in progress&quot; attempts ... ";\r
+\r
+               // loop through records\r
                foreach ($records as $record) {\r
+\r
                        // get all attempts by this user at this hotpot\r
                        $attempts = get_records_sql("\r
                                SELECT id, userid, hotpot, score, timestart, timefinish, status \r
                                FROM {$CFG->prefix}hotpot_attempts \r
-                               WHERE userid = $record->userid AND hotpot=$record->hotpot\r
+                               WHERE userid = ".$record['userid']." AND hotpot=".$record['hotpot']."\r
                                ORDER BY timestart DESC, id DESC\r
                        ");\r
+\r
                        unset($previous_timestart);\r
+\r
                        foreach ($attempts as $attempt) {\r
                                // if this attempt has a status of "in progress" and is not \r
                                // the most recent one in the group, set the status to "abandoned"\r
@@ -102,11 +108,15 @@ function hotpot_update_to_v2_1_2() {
                                $previous_timestart = $attempt->timestart;\r
                        } // end foreach $attempts\r
                } // end foreach $records\r
+\r
+               // finish message to browser\r
                print $ok ? get_string('success') : 'failed';\r
                print "<br />\n";\r
-               // restore SQL message echo setting\r
-               $db->debug = $debug;\r
        }\r
+\r
+       // restore SQL message echo setting\r
+       $db->debug = $debug;\r
+\r
        return $ok;\r
 }\r
 function hotpot_update_to_v2_1() {\r