commit 723ddb28151dc6a5294f17c84dfb90156e6a679e
Author: fowlerj <fowlerj@bd254432-7d39-4477-bd56-4e64f646bcf9>
Date:   Mon Mar 10 06:53:44 2008 +0000

    lib/statslib: added 'FROM DUAL' phrases to stats stages that require it
    
    
    git-svn-id: https://moodledev.usq.edu.au/repos/dev/dev19/trunk@410 bd254432-7d39-4477-bd56-4e64f646bcf9

diff --git a/lib/statslib.php b/lib/statslib.php
index b768d37..a012734 100644
--- a/lib/statslib.php
+++ b/lib/statslib.php
@@ -165,6 +165,7 @@ function stats_cron_daily($maxdays=1) {
         }
         stats_daily_progress('1');
 
+        // USQ JF MOOD-988: added 'FROM DUAL'
         $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)
 
                 SELECT 'logins' AS stattype, $nextmidnight AS timeend, ".SITEID." as courseid, 0,
@@ -173,7 +174,8 @@ function stats_cron_daily($maxdays=1) {
                                       WHERE s1.stattype = 'logins' AND timeend = $nextmidnight), 0) AS stat1,
                        (SELECT COUNT('x')
                           FROM {$CFG->prefix}stats_user_daily s2
-                         WHERE s2.stattype = 'logins' AND timeend = $nextmidnight) AS stat2";
+                         WHERE s2.stattype = 'logins' AND timeend = $nextmidnight) AS stat2
+                FROM DUAL";
 
         if ($logspresent and !execute_sql($sql, false)) {
             $failed = true;
@@ -273,6 +275,7 @@ function stats_cron_daily($maxdays=1) {
         stats_daily_progress('6');
 
     /// frontapge(==site) enrolments total
+        // USQ JF MOOD-988: added 'FROM DUAL'
         $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)
 
                 SELECT 'enrolments', $nextmidnight, ".SITEID.", 0,
@@ -282,7 +285,8 @@ function stats_cron_daily($maxdays=1) {
                        (SELECT COUNT(DISTINCT u.id)
                           FROM {$CFG->prefix}user u
                                JOIN {$CFG->prefix}log l ON l.userid = u.id
-                         WHERE u.deleted = 0 AND $timesql) AS stat2";
+                         WHERE u.deleted = 0 AND $timesql) AS stat2
+                FROM DUAL";
 
         if ($logspresent and !execute_sql($sql, false)) {
             $failed = true;
@@ -309,6 +313,7 @@ function stats_cron_daily($maxdays=1) {
             }
             stats_daily_progress('8');
 
+            // USQ JF MOOD-988: added 'FROM DUAL'
             $sql = "INSERT INTO {$CFG->prefix}stats_daily (stattype, timeend, courseid, roleid, stat1, stat2)
 
                     SELECT 'enrolments', $nextmidnight, ".SITEID.", $defaultfproleid,
@@ -318,7 +323,8 @@ function stats_cron_daily($maxdays=1) {
                            (SELECT COUNT(DISTINCT u.id)
                               FROM {$CFG->prefix}user u
                                    JOIN {$CFG->prefix}log l ON l.userid = u.id
-                             WHERE u.deleted = 0 AND $timesql) AS stat2";
+                             WHERE u.deleted = 0 AND $timesql) AS stat2
+                    FROM DUAL";
 
             if ($logspresent and !execute_sql($sql, false)) {
                 $failed = true;
@@ -334,6 +340,7 @@ function stats_cron_daily($maxdays=1) {
 
 
     /// individual user stats (including not-logged-in) in each course, this is slow - reuse this data if possible
+        // USQ JF MOOD-988: added 'FROM DUAL'
         $sql = "INSERT INTO {$CFG->prefix}stats_user_daily (stattype, timeend, courseid, userid, statsreads, statswrites)
 
                 SELECT 'activity' AS stattype, $nextmidnight AS timeend, d.courseid, d.userid,
@@ -351,7 +358,7 @@ function stats_cron_daily($maxdays=1) {
                           FROM {$CFG->prefix}user u, {$CFG->prefix}log l
                          WHERE u.id = l.userid AND $timesql
                        UNION
-                        SELECT 0 AS userid, ".SITEID." AS courseid) d";
+                        SELECT 0 AS userid, ".SITEID." AS courseid FROM DUAL) d";
                         // can not use group by here because pg can not handle it :-(
 
         if ($logspresent and !execute_sql($sql, false)) {
@@ -576,6 +583,7 @@ function stats_cron_weekly() {
 
         execute_sql($sql, false);
 
+        // USQ JF MOOD-988: added 'FROM DUAL'
         $sql = "INSERT INTO {$CFG->prefix}stats_weekly (stattype, timeend, courseid, roleid, stat1, stat2)
 
                 SELECT 'logins' AS stattype, $nextstartweek AS timeend, ".SITEID." as courseid, 0,
@@ -584,7 +592,8 @@ function stats_cron_weekly() {
                                   WHERE s1.stattype = 'logins' AND timeend = $nextstartweek), 0) AS nstat1,
                        (SELECT COUNT('x')
                           FROM {$CFG->prefix}stats_user_weekly s2
-                         WHERE s2.stattype = 'logins' AND timeend = $nextstartweek) AS nstat2";
+                         WHERE s2.stattype = 'logins' AND timeend = $nextstartweek) AS nstat2
+                FROM DUAL";
 
         execute_sql($sql, false);
 
@@ -697,6 +706,7 @@ function stats_cron_monthly() {
 
         execute_sql($sql, false);
 
+        // USQ JF MOOD-988: added 'FROM DUAL'
         $sql = "INSERT INTO {$CFG->prefix}stats_monthly (stattype, timeend, courseid, roleid, stat1, stat2)
 
                 SELECT 'logins' AS stattype, $nextstartmonth AS timeend, ".SITEID." as courseid, 0,
@@ -705,7 +715,8 @@ function stats_cron_monthly() {
                                   WHERE s1.stattype = 'logins' AND timeend = $nextstartmonth), 0) AS nstat1,
                        (SELECT COUNT('x')
                           FROM {$CFG->prefix}stats_user_monthly s2
-                         WHERE s2.stattype = 'logins' AND timeend = $nextstartmonth) AS nstat2";
+                         WHERE s2.stattype = 'logins' AND timeend = $nextstartmonth) AS nstat2
+                FROM DUAL";
 
         execute_sql($sql, false);
 
