]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11432 eliminated majority of RecordCount uses, added several missing rs_close...
authorskodak <skodak>
Wed, 10 Oct 2007 12:19:27 +0000 (12:19 +0000)
committerskodak <skodak>
Wed, 10 Oct 2007 12:19:27 +0000 (12:19 +0000)
31 files changed:
admin/multilangupgrade.php
auth/db/auth.php
backup/backuplib.php
enrol/database/enrol.php
grade/lib.php
lib/accesslib.php
lib/authlib.php
lib/datalib.php
lib/db/mysql.php
lib/db/postgres7.php
lib/db/upgrade.php
lib/dmllib.php
lib/eventslib.php
lib/grade/grade_category.php
lib/grade/grade_grade.php
lib/grade/grade_item.php
lib/gradelib.php
lib/setuplib.php
lib/simpletestlib.php
mod/assignment/lib.php
mod/chat/lib.php
mod/data/lib.php
mod/forum/lib.php
mod/glossary/lib.php
mod/hotpot/db/update_to_v2.php
mod/hotpot/lib.php
mod/lesson/lib.php
mod/quiz/lib.php
mod/scorm/lib.php
question/format/coursetestmanager/format.php
user/index.php

index 705a80e7c33d7175cc4e79f13abbfd8900d2ad17..1ab04d54170e43817e83ae2fb9077fd72c8e406d 100644 (file)
@@ -56,7 +56,7 @@ foreach ($tables as $table) {
             if (in_array($data->type, array('text','mediumtext','longtext','varchar'))) {  // Text stuff only
                 // first find candidate records
                 $rs = get_recordset_sql("SELECT id, $column FROM $table WHERE $column LIKE '%</lang>%' OR $column LIKE '%<span lang=%'");
-                if ($rs and $rs->RecordCount() > 0) {
+                if ($rs) {
                     while (!$rs->EOF) {
                         $text = $rs->fields[$column];
                         $id   = $rs->fields['id'];
@@ -86,6 +86,7 @@ foreach ($tables as $table) {
                             execute_sql("UPDATE $table SET $column='$newtext' WHERE id=$id", false);
                         }
                     }
+                    rs_close($rs);
                 }
             }
         }
index e8b2e50c361cf1ec74f3cf54d9411de69b52612c..2da10f05bf9cf002d133863571e57a917cc5a513 100644 (file)
@@ -59,20 +59,23 @@ class auth_plugin_db extends auth_plugin_base {
             // don't track passwords
             $rs = $authdb->Execute("SELECT * FROM {$this->config->table}
                                      WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."' ");
-            $authdb->Close();
-
             if (!$rs) {
+                $authdb->Close();
                 print_error('auth_dbcantconnect','auth');
                 return false;
             }
 
-            if ( $rs->RecordCount() ) {
+            if ( !$rs->EOF ) {
+                $rs->Close();
+                $authdb->Close();
                 // user exists exterally
                 // check username/password internally
                 if ($user = get_record('user', 'username', $username, 'mnethostid', $CFG->mnet_localhost_id)) {
                     return validate_internal_user_password($user, $password);
                 }
             } else {
+                $rs->Close();
+                $authdb->Close();
                 // user does not exist externally
                 return false;
             }
@@ -89,16 +92,19 @@ class auth_plugin_db extends auth_plugin_base {
             $rs = $authdb->Execute("SELECT * FROM {$this->config->table}
                                 WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'
                                   AND {$this->config->fieldpass} = '".$this->ext_addslashes($extpassword)."' ");
-            $authdb->Close();
-
             if (!$rs) {
+                $authdb->Close();
                 print_error('auth_dbcantconnect','auth');
                 return false;
             }
 
-            if ($rs->RecordCount()) {
+            if (!$rs->EOF) {
+                $rs->Close();
+                $authdb->Close();
                 return true;
             } else {
+                $rs->Close();
+                $authdb->Close();
                 return false;
             }
 
@@ -171,7 +177,7 @@ class auth_plugin_db extends auth_plugin_base {
                 " FROM {$this->config->table}" .
                 " WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'";
             if ($rs = $authdb->Execute($sql)) {
-                if ( $rs->RecordCount() == 1 ) {
+                if ( !$rs->EOF ) {
                     $fields_obj = rs_fetch_record($rs);
                     foreach ($selectfields as $localname=>$externalname) {
                         $result[$localname] = $textlib->convert($fields_obj->{$localname}, $this->config->extencoding, 'utf-8');
@@ -391,9 +397,9 @@ class auth_plugin_db extends auth_plugin_base {
 
         if (!$rs) {
             print_error('auth_dbcantconnect','auth');
-        } else if ( $rs->RecordCount() ) {
+        } else if ( !$rs->EOF ) {
             // user exists exterally
-            $result = $rs->RecordCount();
+            $result = true;
         }
 
         $authdb->Close();
@@ -414,7 +420,7 @@ class auth_plugin_db extends auth_plugin_base {
 
         if (!$rs) {
             print_error('auth_dbcantconnect','auth');
-        } else if ( $rs->RecordCount() ) {
+        } else if ( !$rs->EOF ) {
             while ($rec = rs_fetch_next_record($rs)) {
                 array_push($result, $rec->username);
             }
index baba9672922b27960e03bd967f28d34ecfb09325..84beeac159c1b1f5377da94f8ba593bb18e0eff2 100644 (file)
                                           b.table_name = 'user'");
 
         //If we have users to backup
-        if ($users && $users->RecordCount()) {
+        if ($users && !rs_EOF($users)) {
             //Begin Users tag
             fwrite ($bf,start_tag("USERS",2,true));
             $counter = 0;
             //With every user
-            while ($user = $users->FetchNextObj()) {
+            while ($user = rs_fetch_next_record($users)) {
                 //Begin User tag
                 fwrite ($bf,start_tag("USER",3,true));
                 //Output all user data
             $status = true;
         }
 
+        if ($users) {
+            rs_close($users);
+        }
+
         return $status;
     }
 
index ef9a8af8f73480ae0a7305f0613f465a8816eb8f..dbd07282f7355ab5332c6ed00524d95c04d346e0 100644 (file)
@@ -78,16 +78,19 @@ function setup_enrolments(&$user) {
                 $existing = array();
             }
 
-            //error_log('[ENROL_DB] Found '.count($existing).' existing roles and '.$rs->RecordCount().' in external database');
 
-            if ($rs->RecordCount() > 0) {   // We found some courses
+            if (!$rs->EOF) {   // We found some courses
 
+                //$count = 0;
                 $courselist = array();
                 while ($fields_obj = rs_fetch_next_record($rs)) {         // Make a nice little array of courses to process
                     $courselist[] = $fields_obj->enrolremotecoursefield;
+                    //$count++;
                 }
                 rs_close($rs);
 
+                //error_log('[ENROL_DB] Found '.count($existing).' existing roles and '.$count.' in external database');
+
                 foreach ($courselist as $coursefield) {   /// Check the list of courses against existing
                     $course = get_record('course', $CFG->enrol_localcoursefield, $coursefield);
                     if (!is_object($course)) {
@@ -209,7 +212,7 @@ function sync_enrolments($role = null) {
         trigger_error($enroldb->ErrorMsg() .' STATEMENT: '. $sql);
         return false;
     }
-    if ( $rs->RecordCount() == 0 ) { // no courses! outta here...
+    if ( $rs->EOF ) { // no courses! outta here...
         return true;
     }
 
@@ -267,7 +270,7 @@ function sync_enrolments($role = null) {
             trigger_error($enroldb->ErrorMsg() .' STATEMENT: '. $sql);
             return false;
         }
-        if ( $crs->RecordCount() == 0 ) { // shouldn't happen, but cover all bases
+        if ( $crs->EOF ) { // shouldn't happen, but cover all bases
             continue;
         }
 
@@ -329,7 +332,7 @@ function sync_enrolments($role = null) {
                 trigger_error($db->ErrorMsg() .' STATEMENT: '. $sql);
                 return false;
             }
-            if ( $ers->RecordCount() == 0 ) { // if this returns empty, it means we don't have the student record.
+            if ( $ers->EOF ) { // if this returns empty, it means we don't have the student record.
                                               // should not happen -- but skip it anyway
                 trigger_error('weird! no user record entry?');
                 continue;
@@ -381,7 +384,7 @@ function sync_enrolments($role = null) {
         trigger_error($db->ErrorMsg() .' STATEMENT: '. $sql);
         return false;
     }
-    if ( $ers->RecordCount() > 0 ) {
+    if ( !$ers->EOF ) {
         while ($user_obj = rs_fetch_next_record($ers)) {
             $roleid     = $user_obj->roleid;
             $user       = $user_obj->userid;
index 90411cf231182cec68278e0c7066cb6a65c236c1..1da3b5f2cbcbf52e37683abf773afe683d9b69f3 100644 (file)
@@ -119,7 +119,7 @@ class graded_users_iterator {
      * @return mixed array of user info, all grades and feedback or null when no more users found
      */
     function next_user() {
-        if (!$this->users_rs or !$this->users_rs->RecordCount()) {
+        if (!$this->users_rs) {
             return false; // no users present
         }
 
@@ -200,7 +200,7 @@ class graded_users_iterator {
      */
     function _pop() {
         if (empty($this->gradestack)) {
-            if (!$this->grades_rs or !$this->grades_rs->RecordCount()) {
+            if (!$this->grades_rs) {
                 return NULL; // no grades present
             }
 
index 966518d9eb7728c0ed16acce9093c188a8e8022c..cff3c6245e55d59f5012db51f610799ece0a2b56 100755 (executable)
@@ -231,13 +231,11 @@ function get_role_access($roleid, $accessdata=NULL) {
                   AND ctx.contextlevel <= ".CONTEXT_COURSE."
             ORDER BY ctx.depth, ctx.path";
     if ($rs = get_recordset_sql($sql)) {
-        if ($rs->RecordCount()) {
-            while ($rd = rs_fetch_next_record($rs)) {
-                $k = "{$rd->path}:{$roleid}";
-                $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
-            }
-            unset($rd);
+        while ($rd = rs_fetch_next_record($rs)) {
+            $k = "{$rd->path}:{$roleid}";
+            $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
         }
+        unset($rd);
         rs_close($rs);
     }
 
@@ -271,13 +269,11 @@ function get_default_frontpage_role_access($roleid, $accessdata=NULL) {
             ORDER BY ctx.depth, ctx.path";             
             
     if ($rs = get_recordset_sql($sql)) {
-        if ($rs->RecordCount()) {
-            while ($rd = rs_fetch_next_record($rs)) {
-                $k = "{$rd->path}:{$roleid}";
-                $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
-            }
-            unset($rd);
+        while ($rd = rs_fetch_next_record($rs)) {
+            $k = "{$rd->path}:{$roleid}";
+            $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
         }
+        unset($rd);
         rs_close($rs);
     }
 
@@ -882,12 +878,10 @@ function get_user_courses_bycap($userid, $cap, $accessdata, $doanything, $sort='
                 ORDER BY ctx.depth";
         $rs = get_recordset_sql($sql);
         $catpaths = array();
-        if ($rs->RecordCount()) {
-            while ($catctx = rs_fetch_next_record($rs)) {
-                if ($catctx->path != '' 
-                    && has_capability_in_accessdata($cap, $catctx, $accessdata, $doanything)) {
-                    $catpaths[] = $catctx->path;
-                }
+        while ($catctx = rs_fetch_next_record($rs)) {
+            if ($catctx->path != '' 
+                && has_capability_in_accessdata($cap, $catctx, $accessdata, $doanything)) {
+                $catpaths[] = $catctx->path;
             }
         }
         rs_close($rs);
@@ -931,16 +925,14 @@ function get_user_courses_bycap($userid, $cap, $accessdata, $doanything, $sort='
     }
     $courses = array();
     $cc = 0; // keep count
-    if ($rs->RecordCount()) {
-        while ($c = rs_fetch_next_record($rs)) {
-            // build the context obj
-            $c = make_context_subobj($c);
-
-            if (has_capability_in_accessdata($cap, $c->context, $accessdata, $doanything)) {
-                $courses[] = $c;
-                if ($limit > 0 && $cc++ > $limit) {
-                    break;
-                }
+    while ($c = rs_fetch_next_record($rs)) {
+        // build the context obj
+        $c = make_context_subobj($c);
+
+        if (has_capability_in_accessdata($cap, $c->context, $accessdata, $doanything)) {
+            $courses[] = $c;
+            if ($limit > 0 && $cc++ > $limit) {
+                break;
             }
         }
     }
@@ -998,15 +990,13 @@ function get_context_users_byrole ($context, $roleid, $fields=NULL, $where=NULL,
     
     $users = array();
     $cc = 0; // keep count
-    if ($rs->RecordCount()) {
-        while ($u = rs_fetch_next_record($rs)) {
-            // build the context obj
-            $u = make_context_subobj($u);
+    while ($u = rs_fetch_next_record($rs)) {
+        // build the context obj
+        $u = make_context_subobj($u);
 
-            $users[] = $u;
-            if ($limit > 0 && $cc++ > $limit) {
-                break;
-            }
+        $users[] = $u;
+        if ($limit > 0 && $cc++ > $limit) {
+            break;
         }
     }
     rs_close($rs);
@@ -1071,10 +1061,8 @@ function get_context_users_bycap ($context, $capability='moodle/course:view', $f
             WHERE rc.capability = '$capability'
                   AND rc.contextid IN ($contexts)";
     $rs = get_recordset_sql($sql);
-    if ($rs->RecordCount()) {
-        while ($u = rs_fetch_next_record($rs)) {
-            $roles[] = $u->roleid;
-        }
+    while ($u = rs_fetch_next_record($rs)) {
+        $roles[] = $u->roleid;
     }
     rs_close($rs);
     $roles = implode(',', $roles);
@@ -1112,15 +1100,13 @@ function get_context_users_bycap ($context, $capability='moodle/course:view', $f
     
     $users = array();
     $cc = 0; // keep count
-    if ($rs->RecordCount()) {
-        while ($u = rs_fetch_next_record($rs)) {
-            // build the context obj
-            $u = make_context_subobj($u);
+    while ($u = rs_fetch_next_record($rs)) {
+        // build the context obj
+        $u = make_context_subobj($u);
 
-            $users[] = $u;
-            if ($limit > 0 && $cc++ > $limit) {
-                break;
-            }
+        $users[] = $u;
+        if ($limit > 0 && $cc++ > $limit) {
+            break;
         }
     }
     rs_close($rs);
@@ -1191,38 +1177,36 @@ function get_user_access_sitewide($userid) {
     $raparents = array();
     $lastseen  = '';
     if ($rs) {
-        if ($rs->RecordCount()) {
-            while ($ra = rs_fetch_next_record($rs)) {
-                // RAs leafs are arrays to support multi
-                // role assignments...
-                if (!isset($accessdata['ra'][$ra->path])) {
-                    $accessdata['ra'][$ra->path] = array();
-                }
-                // only add if is not a repeat caused
-                // by capability join...
-                // (this check is cheaper than in_array())
-                if ($lastseen !== $ra->path.':'.$ra->roleid) {
-                    $lastseen = $ra->path.':'.$ra->roleid;
-                    array_push($accessdata['ra'][$ra->path], $ra->roleid);
-                    $parentids = explode('/', $ra->path);
-                    array_shift($parentids); // drop empty leading "context"
-                    array_pop($parentids);   // drop _this_ context
-    
-                    if (isset($raparents[$ra->roleid])) {
-                        $raparents[$ra->roleid] = array_merge($raparents[$ra->roleid],
-                                                              $parentids);
-                    } else {
-                        $raparents[$ra->roleid] = $parentids;
-                    }
-                }
-                // Always add the roleded
-                if (!empty($ra->capability)) {
-                    $k = "{$ra->path}:{$ra->roleid}";
-                    $accessdata['rdef'][$k][$ra->capability] = $ra->permission;
+        while ($ra = rs_fetch_next_record($rs)) {
+            // RAs leafs are arrays to support multi
+            // role assignments...
+            if (!isset($accessdata['ra'][$ra->path])) {
+                $accessdata['ra'][$ra->path] = array();
+            }
+            // only add if is not a repeat caused
+            // by capability join...
+            // (this check is cheaper than in_array())
+            if ($lastseen !== $ra->path.':'.$ra->roleid) {
+                $lastseen = $ra->path.':'.$ra->roleid;
+                array_push($accessdata['ra'][$ra->path], $ra->roleid);
+                $parentids = explode('/', $ra->path);
+                array_shift($parentids); // drop empty leading "context"
+                array_pop($parentids);   // drop _this_ context
+
+                if (isset($raparents[$ra->roleid])) {
+                    $raparents[$ra->roleid] = array_merge($raparents[$ra->roleid],
+                                                          $parentids);
+                } else {
+                    $raparents[$ra->roleid] = $parentids;
                 }
             }
-            unset($ra);
+            // Always add the roleded
+            if (!empty($ra->capability)) {
+                $k = "{$ra->path}:{$ra->roleid}";
+                $accessdata['rdef'][$k][$ra->capability] = $ra->permission;
+            }
         }
+        unset($ra);
         rs_close($rs);
     }
 
@@ -1251,13 +1235,11 @@ function get_user_access_sitewide($userid) {
         $rs = get_recordset_sql($sql);
         unset($clauses);
 
-        if ($rs->RecordCount()) {
-            while ($rd = rs_fetch_next_record($rs)) {
-                $k = "{$rd->path}:{$rd->roleid}";
-                $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
-            }
-            unset($rd);
+        while ($rd = rs_fetch_next_record($rs)) {
+            $k = "{$rd->path}:{$rd->roleid}";
+            $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
         }
+        unset($rd);
         rs_close($rs);
     }
 
@@ -1284,13 +1266,11 @@ function get_user_access_sitewide($userid) {
             ORDER BY sctx.depth, sctx.path, ra.roleid";
 
     $rs = get_recordset_sql($sql);
-    if ($rs->RecordCount()) {
-        while ($rd = rs_fetch_next_record($rs)) {
-            $k = "{$rd->path}:{$rd->roleid}";
-            $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
-        }
-        unset($rd);
+    while ($rd = rs_fetch_next_record($rs)) {
+        $k = "{$rd->path}:{$rd->roleid}";
+        $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
     }
+    unset($rd);
     rs_close($rs);
 
     return $accessdata;
@@ -1370,14 +1350,12 @@ function get_user_access_bycontext($userid, $context, $accessdata=NULL) {
     // Read in the RAs
     //
     $localroles = array();
-    if ($rs->RecordCount()) {
-        while ($ra = rs_fetch_next_record($rs)) {
-            if (!isset($accessdata['ra'][$ra->path])) {
-                $accessdata['ra'][$ra->path] = array();
-            }
-            array_push($accessdata['ra'][$ra->path], $ra->roleid);
-            array_push($localroles,           $ra->roleid);
+    while ($ra = rs_fetch_next_record($rs)) {
+        if (!isset($accessdata['ra'][$ra->path])) {
+            $accessdata['ra'][$ra->path] = array();
         }
+        array_push($accessdata['ra'][$ra->path], $ra->roleid);
+        array_push($localroles,           $ra->roleid);
     }
     rs_close($rs);
 
@@ -1417,11 +1395,9 @@ function get_user_access_bycontext($userid, $context, $accessdata=NULL) {
             ORDER BY ctx.depth ASC, ctx.path DESC, rc.roleid ASC ";
 
     if ($rs = get_recordset_sql($sql)) {
-        if ($rs->RecordCount()) {
-            while ($rd = rs_fetch_next_record($rs)) {
-                $k = "{$rd->path}:{$rd->roleid}";
-                $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
-            }
+        while ($rd = rs_fetch_next_record($rs)) {
+            $k = "{$rd->path}:{$rd->roleid}";
+            $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
         }
         rs_close($rs);
     } else {
@@ -1490,11 +1466,9 @@ function get_role_access_bycontext($roleid, $context, $accessdata=NULL) {
             ORDER BY ctx.depth ASC, ctx.path DESC, rc.roleid ASC ";
 
     $rs = get_recordset_sql($sql);
-    if ($rs->RecordCount()) {
-        while ($rd = rs_fetch_next_record($rs)) {
-            $k = "{$rd->path}:{$roleid}";
-            $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
-        }
+    while ($rd = rs_fetch_next_record($rs)) {
+        $k = "{$rd->path}:{$roleid}";
+        $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
     }
     rs_close($rs);
 
@@ -1684,11 +1658,9 @@ function load_temp_role($context, $roleid, $accessdata) {
                   AND rc.roleid = {$roleid}
             ORDER BY ctx.depth, ctx.path";
     $rs = get_recordset_sql($sql);
-    if ($rs->RecordCount()) {
-        while ($rd = rs_fetch_next_record($rs)) {
-            $k = "{$rd->path}:{$roleid}";
-            $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
-        }
+    while ($rd = rs_fetch_next_record($rs)) {
+        $k = "{$rd->path}:{$roleid}";
+        $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
     }
     rs_close($rs);
 
@@ -2443,21 +2415,19 @@ function cleanup_contexts() {
               WHERE t.id IS NULL AND c.contextlevel = " . CONTEXT_GROUP . "
            ";
     if ($rs = get_recordset_sql($sql)) {
-        if ($rs->RecordCount()) {
-            begin_sql();
-            $tx = true;
-            while ($tx && $ctx = rs_fetch_next_record($rs)) {
-                $tx = $tx && delete_context($ctx->level, $ctx->instanceid);
-            }
-            rs_close($rs);
-            if ($tx) {
-                commit_sql();
-                return true;
-            }
-            rollback_sql();
-            return false;
+        begin_sql();
+        $tx = true;
+        while ($tx && $ctx = rs_fetch_next_record($rs)) {
+            $tx = $tx && delete_context($ctx->level, $ctx->instanceid);
         }
         rs_close($rs);
+        if ($tx) {
+            commit_sql();
+            return true;
+        }
+        rollback_sql();
+        return false;
+        rs_close($rs);
     }
     return true;
 }
@@ -3679,12 +3649,10 @@ function get_child_contexts($context) {
             ";
             $rs  = get_recordset_sql($sql);
             $records = array();
-            if ($rs->RecordCount()) {
-                while ($rec = rs_fetch_next_record($rs)) {
-                    $records[$rec->id] = $rec;
-                    $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
-                }
-             }
+            while ($rec = rs_fetch_next_record($rs)) {
+                $records[$rec->id] = $rec;
+                $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
+            }
             rs_close($rs);
             return $records;
         break;
@@ -3700,11 +3668,9 @@ function get_child_contexts($context) {
             ";
             $rs  = get_recordset_sql($sql);
             $records = array();
-            if ($rs->RecordCount()) {
-                while ($rec = rs_fetch_next_record($rs)) {
-                    $records[$rec->id] = $rec;
-                    $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
-                }
+            while ($rec = rs_fetch_next_record($rs)) {
+                $records[$rec->id] = $rec;
+                $context_cache[$rec->contextlevel][$rec->instanceid] = $rec;
             }
             rs_close($rs);
             return $records;
@@ -4094,11 +4060,10 @@ function get_assignable_roles ($context, $field="name") {
 
     $rs = get_recordset_sql($sql);
     $roles = array();
-    if ($rs->RecordCount()) {
-        while ($r = rs_fetch_next_record($rs)) {
-            $roles[$r->id] = $r->{$field};
-        }
+    while ($r = rs_fetch_next_record($rs)) {
+        $roles[$r->id] = $r->{$field};
     }
+    rs_close($rs);
     foreach ($roles as $roleid => $rolename) {
         $roles[$roleid] = strip_tags(format_string($rolename, true));
     }
index 355fdf3ec5c3490d36d3b6a0f156acf5ac389ff9..ca942381e04c9ea3b3bf3700dadf84b999ab1f8e 100644 (file)
@@ -205,6 +205,7 @@ class auth_plugin_base {
      * Checks if user exists in external db
      *
      * @param string $username (with system magic quotes)
+     * @return bool
      */
     function user_exists() {
         //override if needed
index fb84762ac4839086453e40e9a347ae7d1eccb8a8..93d40c40bca2494ce21e6aea61f51e89591dbb1d 100644 (file)
@@ -473,34 +473,29 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
     }
     $totalcount = 0;
 
-    if (!$limitnum) {
-        $limitnum = $rs->RecordCount();
-    }
-
     if (!$limitfrom) {
         $limitfrom = 0;
     }
 
     // iteration will have to be done inside loop to keep track of the limitfrom and limitnum
-    if ($rs->RecordCount()) {
-        while ($course = rs_fetch_next_record($rs)) {
-            $course = make_context_subobj($course);
-            if ($course->visible <= 0) {
-                // for hidden courses, require visibility check
-                if (has_capability('moodle/course:viewhiddencourses', $course->context)) {
-                    $totalcount++;
-                    if ($totalcount > $limitfrom && count($visiblecourses) < $limitnum) {
-                        $visiblecourses [] = $course;
-                    }
-                }
-            } else {
+    while ($course = rs_fetch_next_record($rs)) {
+        $course = make_context_subobj($course);
+        if ($course->visible <= 0) {
+            // for hidden courses, require visibility check
+            if (has_capability('moodle/course:viewhiddencourses', $course->context)) {
                 $totalcount++;
-                if ($totalcount > $limitfrom && count($visiblecourses) < $limitnum) {
+                if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) {
                     $visiblecourses [] = $course;
                 }
             }
+        } else {
+            $totalcount++;
+            if ($totalcount > $limitfrom && (!$limitnum or count($visiblecourses) < $limitnum)) {
+                $visiblecourses [] = $course;
+            }
         }
     }
+    rs_close($rs);
     return $visiblecourses;
 
 /**
@@ -706,44 +701,40 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a
 
         // This loop is fairly stupid as it stands - might get better
         // results doing an initial pass clustering RAs by path.
-        if ($rs->RecordCount()) {
-            while ($ra = rs_fetch_next_record($rs)) {
-                $user = new StdClass;
-                $user->id        = $ra->userid;    unset($ra->userid);
-                $user->firstname = $ra->firstname; unset($ra->firstname);
-                $user->lastname  = $ra->lastname;  unset($ra->lastname);
-                $ra->user = $user;
-                if ($ra->contextlevel == CONTEXT_SYSTEM) {
+        while ($ra = rs_fetch_next_record($rs)) {
+            $user = new StdClass;
+            $user->id        = $ra->userid;    unset($ra->userid);
+            $user->firstname = $ra->firstname; unset($ra->firstname);
+            $user->lastname  = $ra->lastname;  unset($ra->lastname);
+            $ra->user = $user;
+            if ($ra->contextlevel == CONTEXT_SYSTEM) {
+                foreach ($courses as $k => $course) {
+                    $courses[$k]->managers[] = $ra;
+                }
+            } elseif ($ra->contextlevel == CONTEXT_COURSECAT) {
+                if ($allcats === false) {
+                    // It always applies
                     foreach ($courses as $k => $course) {
                         $courses[$k]->managers[] = $ra;
                     }
-                } elseif ($ra->contextlevel == CONTEXT_COURSECAT) {
-                    if ($allcats === false) {
-                        // It always applies
-                        foreach ($courses as $k => $course) {
+                } else {
+                    foreach ($courses as $k => $course) {
+                        // Note that strpos() returns 0 as "matched at pos 0"
+                        if (strpos($course->context->path, $ra->path.'/')===0) {
+                            // Only add it to subpaths
                             $courses[$k]->managers[] = $ra;
                         }
-                    } else {
-                        foreach ($courses as $k => $course) {
-                            // Note that strpos() returns 0 as "matched at pos 0"
-                            if (strpos($course->context->path, $ra->path.'/')===0) {
-                                // Only add it to subpaths
-                                $courses[$k]->managers[] = $ra;
-                            }
-                        }
                     }
-                } else { // course-level
-                    if(!array_key_exists($ra->instanceid, $courses)) {
-                        //this course is not in a list, probably a frontpage course
-                        continue;
-                    }
-                    $courses[$ra->instanceid]->managers[] = $ra;
                 }
+            } else { // course-level
+                if(!array_key_exists($ra->instanceid, $courses)) {
+                    //this course is not in a list, probably a frontpage course
+                    continue;
+                }
+                $courses[$ra->instanceid]->managers[] = $ra;
             }
         }
-
-
-
+        rs_close($rs);
     }
 
     return $courses;
@@ -872,15 +863,13 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NUL
             $rs = get_recordset_sql($sql);
             $courses = array();
             $cc = 0; // keep count
-            if ($rs->RecordCount()) {
-                while ($c = rs_fetch_next_record($rs)) {
-                    // build the context obj
-                    $c = make_context_subobj($c);
+            while ($c = rs_fetch_next_record($rs)) {
+                // build the context obj
+                $c = make_context_subobj($c);
 
-                    $courses[$c->id] = $c;
-                    if ($limit > 0 && $cc++ > $limit) {
-                        break;
-                    }
+                $courses[$c->id] = $c;
+                if ($limit > 0 && $cc++ > $limit) {
+                    break;
                 }
             }
             rs_close($rs);
@@ -915,20 +904,18 @@ function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NUL
 
         // Using a temporary array instead of $cats here, to avoid a "true" result when isnull($cats) further down
         $categories = array();
-        if ($rs->RecordCount()) {
-            while ($course_cat = rs_fetch_next_record($rs)) {
-                // build the context obj
-                $course_cat = make_context_subobj($course_cat);
-                $categories[$course_cat->id] = $course_cat;
-            }
+        while ($course_cat = rs_fetch_next_record($rs)) {
+            // build the context obj
+            $course_cat = make_context_subobj($course_cat);
+            $categories[$course_cat->id] = $course_cat;
         }
+        rs_close($rs);
 
         if (!empty($categories)) {
             $cats = $categories;
         }
 
         unset($course_cat);
-        rs_close($rs);
     }
     //
     // Strangely, get_my_courses() is expected to return the
@@ -1383,7 +1370,7 @@ function fix_coursecategory_orphans() {
 
     $rs = get_recordset_sql($sql);
 
-    if ($rs->RecordCount()){ // we have some orphans
+    if (!rs_EOF($rs)) { // we have some orphans
 
         // the "default" category is the lowest numbered...
         $default   = get_field_sql("SELECT MIN(id)
@@ -1405,6 +1392,7 @@ function fix_coursecategory_orphans() {
             rollback_sql();
         }
     }
+    rs_close($rs);
 }
 
 /**
index ea2dcf4eae71868e82a698fe3cecaceee01ba36b..1259ed51f4c06c701cdd34485f01ff953fb57e4c 100644 (file)
@@ -1805,7 +1805,7 @@ function main_upgrade($oldversion=0) {
         modify_database('', "ALTER TABLE prefix_log_display ADD UNIQUE `moduleaction`(`module` , `action`)");
         
         // Insert the records back in, sans duplicates.
-        if ($rs && $rs->RecordCount() > 0) {
+        if ($rs) {
             while (!$rs->EOF) {
                 $sql = "INSERT INTO {$CFG->prefix}log_display ".
                             "VALUES('', '".$rs->fields['module']."', ".
@@ -1816,6 +1816,7 @@ function main_upgrade($oldversion=0) {
                 execute_sql($sql, false);
                 $rs->MoveNext();
             }
+            rs_close($rs);
         }
     }
     
index fdec2bcde1ccb46481219ba66219ad759f241e9f..5e483db467b45ac3a23e318141a672e0aa974da0 100644 (file)
@@ -1500,7 +1500,7 @@ function main_upgrade($oldversion=0) {
         modify_database('', 'CREATE INDEX prefix_log_display_moduleaction ON prefix_log_display (module,action)');
         
         // Insert the records back in, sans duplicates.
-        if ($rs && $rs->RecordCount() > 0) {
+        if ($rs) {
             while (!$rs->EOF) {
                 $sql = "INSERT INTO {$CFG->prefix}log_display ".
                             "VALUES('', '".$rs->fields['module']."', ".
@@ -1511,6 +1511,7 @@ function main_upgrade($oldversion=0) {
                 execute_sql($sql, false);
                 $rs->MoveNext();
             }
+            rs_close($rs);
         }
     }
     
index 7eb056cc4d2de77814daa838324ef071abf5a70e..ac8c0bd0859a5d175f2f5688e12ba7920ab8a512 100644 (file)
@@ -1289,13 +1289,11 @@ function xmldb_main_upgrade($oldversion=0) {
         if ($result) {
             require_once($CFG->libdir.'/db/upgradelib.php');
             if ($rs = get_recordset('course')) {
-                if ($rs->RecordCount() > 0) {
-                    while ($course = rs_fetch_next_record($rs)) {
-                        // this function uses SQL only, it must not be changed after 1.9 goes stable!!
-                        if (!upgrade_18_gradebook($course->id)) {
-                            $result = false;
-                            break;
-                        }
+                while ($course = rs_fetch_next_record($rs)) {
+                    // this function uses SQL only, it must not be changed after 1.9 goes stable!!
+                    if (!upgrade_18_gradebook($course->id)) {
+                        $result = false;
+                        break;
                     }
                 }
                 rs_close($rs);
@@ -1650,31 +1648,29 @@ function xmldb_main_upgrade($oldversion=0) {
         $tagrefs = array(); // $tagrefs[$oldtagid] = $newtagid
         if ($rs = get_recordset('tags')) {
             $db->debug = false;
-            if ($rs->RecordCount() > 0) {
-                while ($oldtag = rs_fetch_next_record($rs)) {
-                    $raw_normalized = clean_param($oldtag->text, PARAM_TAG);
-                    $normalized     = moodle_strtolower($raw_normalized);
-                    // if this tag does not exist in tag table yet
-                    if (!$newtag = get_record('tag', 'name', $normalized, '', '', '', '', 'id')) {
-                        $itag = new object();
-                        $itag->name         = $normalized;
-                        $itag->rawname      = $raw_normalized;
-                        $itag->userid       = $oldtag->userid;
-                        $itag->timemodified = time();
-                        $itag->descriptionformat = 0; // default format
-                        if ($oldtag->type == 'official') {
-                            $itag->tagtype  = 'official';
-                        } else {
-                            $itag->tagtype  = 'default';
-                        }
-
-                        if ($idx = insert_record('tag', $itag)) {
-                            $tagrefs[$oldtag->id] = $idx;
-                        }
-                    // if this tag is already used by tag table
+            while ($oldtag = rs_fetch_next_record($rs)) {
+                $raw_normalized = clean_param($oldtag->text, PARAM_TAG);
+                $normalized     = moodle_strtolower($raw_normalized);
+                // if this tag does not exist in tag table yet
+                if (!$newtag = get_record('tag', 'name', $normalized, '', '', '', '', 'id')) {
+                    $itag = new object();
+                    $itag->name         = $normalized;
+                    $itag->rawname      = $raw_normalized;
+                    $itag->userid       = $oldtag->userid;
+                    $itag->timemodified = time();
+                    $itag->descriptionformat = 0; // default format
+                    if ($oldtag->type == 'official') {
+                        $itag->tagtype  = 'official';
                     } else {
-                        $tagrefs[$oldtag->id] = $newtag->id;
+                        $itag->tagtype  = 'default';
                     }
+
+                    if ($idx = insert_record('tag', $itag)) {
+                        $tagrefs[$oldtag->id] = $idx;
+                    }
+                // if this tag is already used by tag table
+                } else {
+                    $tagrefs[$oldtag->id] = $newtag->id;
                 }
             }
             $db->debug = true;
@@ -1684,17 +1680,15 @@ function xmldb_main_upgrade($oldversion=0) {
         // fetch all the tag instances and migrate them as well
         if ($rs = get_recordset('blog_tag_instance')) {
             $db->debug = false;
-            if ($rs->RecordCount() > 0) {
-                while ($blogtag = rs_fetch_next_record($rs)) {
-                    if (array_key_exists($blogtag->tagid, $tagrefs)) {
-                        $tag_instance = new object();
-                        $tag_instance->tagid        = $tagrefs[$blogtag->tagid];
-                        $tag_instance->itemtype     = 'blog';
-                        $tag_instance->itemid       = $blogtag->entryid;
-                        $tag_instance->ordering     = 1; // does not matter much, because originally there was no ordering in blogs
-                        $tag_instance->timemodified = time();
-                        insert_record('tag_instance', $tag_instance);
-                    }
+            while ($blogtag = rs_fetch_next_record($rs)) {
+                if (array_key_exists($blogtag->tagid, $tagrefs)) {
+                    $tag_instance = new object();
+                    $tag_instance->tagid        = $tagrefs[$blogtag->tagid];
+                    $tag_instance->itemtype     = 'blog';
+                    $tag_instance->itemid       = $blogtag->entryid;
+                    $tag_instance->ordering     = 1; // does not matter much, because originally there was no ordering in blogs
+                    $tag_instance->timemodified = time();
+                    insert_record('tag_instance', $tag_instance);
                 }
             }
             $db->debug = true;
index 29051daafe4416d2af3fbd70ff6879d4eb3f19c9..ae0026bdb28e6a4bfa1bd561f8314ebd576b6bf2 100644 (file)
@@ -306,13 +306,18 @@ function record_exists_sql($sql) {
     $limitfrom = 0; /// Number of records to skip
     $limitnum  = 1; /// Number of records to retrieve
 
-    $rs = get_recordset_sql($sql, $limitfrom, $limitnum);
+    if (!$rs = get_recordset_sql($sql, $limitfrom, $limitnum)) {
+        return false;
+    }
 
-    if ($rs && $rs->RecordCount() > 0) {
-        return true;
+    if (rs_EOF($rs)) {
+        $result = false;
     } else {
-        return false;
+        $result = true;
     }
+
+    rs_close($rs);
+    return $result;
 }
 
 /**
@@ -698,7 +703,7 @@ function recordset_to_array($rs) {
 
     global $CFG;
 
-    if ($rs && $rs->RecordCount() > 0) {
+    if ($rs && !rs_EOF($rs)) {
     /// First of all, we are going to get the name of the first column
     /// to introduce it back after transforming the recordset to assoc array
     /// See http://docs.moodle.org/en/XMLDB_Problems, fetch mode problem.
@@ -939,7 +944,7 @@ function get_records_sql($sql, $limitfrom='', $limitnum='') {
 function recordset_to_menu($rs) {
     global $CFG;
     $menu = array();
-    if ($rs && $rs->RecordCount() > 0) {
+    if ($rs && !rs_EOF($rs)) {
         $keys = array_keys($rs->fields);
         $key0=$keys[0];
         $key1=$keys[1];
@@ -1155,7 +1160,7 @@ function get_fieldset_sql($sql) {
         return false;
     }
 
-    if ( $rs->RecordCount() > 0 ) {
+    if ( !rs_EOF($rs) ) {
         $keys = array_keys($rs->fields);
         $key0 = $keys[0];
         $results = array();
@@ -1170,8 +1175,10 @@ function get_fieldset_sql($sql) {
             array_walk($results, 'onespace2empty');
         }
         /// End of DIRTY HACK
+        rs_close($rs);
         return $results;
     } else {
+        rs_close($rs);
         return false;
     }
 }
index 81957a972749ec7f0002430c7fd7aed7b6876fb2..519ea6bf5f717b34e8e27ee1f9efc2e5f7bf71e6 100755 (executable)
@@ -345,18 +345,16 @@ function events_cron($eventname='') {
     }
 
     if ($rs = get_recordset_sql($sql)) {
-        if ($rs->RecordCount() > 0) {
-            while ($qhandler = rs_fetch_next_record($rs)) {
-                if (in_array($qhandler->handlerid, $failed)) {
-                    // do not try to dispatch any later events when one already failed
-                    continue;
-                }
-                $status = events_process_queued_handler($qhandler);
-                if ($status === false) {
-                    $failed[] = $qhandler->handlerid;
-                } else {
-                    $processed++;
-                }
+        while ($qhandler = rs_fetch_next_record($rs)) {
+            if (in_array($qhandler->handlerid, $failed)) {
+                // do not try to dispatch any later events when one already failed
+                continue;
+            }
+            $status = events_process_queued_handler($qhandler);
+            if ($status === false) {
+                $failed[] = $qhandler->handlerid;
+            } else {
+                $processed++;
             }
         }
         rs_close($rs);
index ee9c7bd5641c9c9c10e9942d90d0cd8ccf733fe0..7d0d33443ecbede7c8053af25c041aca74bc652b 100644 (file)
@@ -404,29 +404,27 @@ class grade_category extends grade_object {
 
         // group the results by userid and aggregate the grades for this user
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                $prevuser = 0;
-                $grade_values = array();
-                $excluded     = array();
-                $oldgrade     = null;
-                while ($used = rs_fetch_next_record($rs)) {
-                    if ($used->userid != $prevuser) {
-                        $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);
-                        $prevuser = $used->userid;
-                        $grade_values = array();
-                        $excluded     = array();
-                        $oldgrade     = null;
-                    }
-                    $grade_values[$used->itemid] = $used->finalgrade;
-                    if ($used->excluded) {
-                        $excluded[] = $used->itemid;
-                    }
-                    if ($this->grade_item->id == $used->itemid) {
-                        $oldgrade = $used;
-                    }
+            $prevuser = 0;
+            $grade_values = array();
+            $excluded     = array();
+            $oldgrade     = null;
+            while ($used = rs_fetch_next_record($rs)) {
+                if ($used->userid != $prevuser) {
+                    $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);
+                    $prevuser = $used->userid;
+                    $grade_values = array();
+                    $excluded     = array();
+                    $oldgrade     = null;
+                }
+                $grade_values[$used->itemid] = $used->finalgrade;
+                if ($used->excluded) {
+                    $excluded[] = $used->itemid;
+                }
+                if ($this->grade_item->id == $used->itemid) {
+                    $oldgrade = $used;
                 }
-                $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one
             }
+            $this->aggregate_grades($prevuser, $items, $grade_values, $oldgrade, $excluded);//the last one
             rs_close($rs);
         }
 
index 4385a801bbf026e199eab332fb66e89302f1e81a..a97e3c9887ea22907e3c1b65b25a5885f1a279ff 100644 (file)
@@ -340,12 +340,10 @@ class grade_grade extends grade_object {
         $now = time(); // no rounding needed, this is not supposed to be called every 10 seconds
 
         if ($rs = get_recordset_select('grade_grades', "itemid IN ($items_sql) AND locked = 0 AND locktime > 0 AND locktime < $now")) {
-            if ($rs->RecordCount() > 0) {
-                while ($grade = rs_fetch_next_record($rs)) {
-                    $grade_grade = new grade_grade($grade, false);
-                    $grade_grade->locked = time();
-                    $grade_grade->update('locktime');
-                }
+            while ($grade = rs_fetch_next_record($rs)) {
+                $grade_grade = new grade_grade($grade, false);
+                $grade_grade->locked = time();
+                $grade_grade->update('locktime');
             }
             rs_close($rs);
         }
index 0e29d2ba7dd63b5c10f6fc69a8fd21e8f161e6af..0882c71d684e08b10ea2f52adc31c11c8a11fc9c 100644 (file)
@@ -643,21 +643,19 @@ class grade_item extends grade_object {
             $rs = get_recordset('grade_grades', 'itemid', $this->id, '', $fields);
         }
         if ($rs) {
-            if ($rs->RecordCount() > 0) {
-                while ($grade_record = rs_fetch_next_record($rs)) {
-                    $grade = new grade_grade($grade_record, false);
+            while ($grade_record = rs_fetch_next_record($rs)) {
+                $grade = new grade_grade($grade_record, false);
 
-                    if (!empty($grade_record->locked) or !empty($grade_record->overridden)) {
-                        // this grade is locked - final grade must be ok
-                        continue;
-                    }
+                if (!empty($grade_record->locked) or !empty($grade_record->overridden)) {
+                    // this grade is locked - final grade must be ok
+                    continue;
+                }
 
-                    $grade->finalgrade = $this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
+                $grade->finalgrade = $this->adjust_raw_grade($grade->rawgrade, $grade->rawgrademin, $grade->rawgrademax);
 
-                    if ($grade_record->finalgrade !== $grade->finalgrade) {
-                        if (!$grade->update('system')) {
-                            $result = "Internal error updating final grade";
-                        }
+                if ($grade_record->finalgrade !== $grade->finalgrade) {
+                    if (!$grade->update('system')) {
+                        $result = "Internal error updating final grade";
                     }
                 }
             }
@@ -1515,30 +1513,28 @@ class grade_item extends grade_object {
 
         // group the grades by userid and use formula on the group
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                $prevuser = 0;
-                $grade_records   = array();
-                $oldgrade    = null;
-                while ($used = rs_fetch_next_record($rs)) {
-                    if ($used->userid != $prevuser) {
-                        if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
-                            $return = false;
-                        }
-                        $prevuser = $used->userid;
-                        $grade_records   = array();
-                        $oldgrade    = null;
-                    }
-                    if ($used->itemid == $this->id) {
-                        $oldgrade = $used;
+            $prevuser = 0;
+            $grade_records   = array();
+            $oldgrade    = null;
+            while ($used = rs_fetch_next_record($rs)) {
+                if ($used->userid != $prevuser) {
+                    if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
+                        $return = false;
                     }
-                    $grade_records['gi'.$used->itemid] = $used->finalgrade;
+                    $prevuser = $used->userid;
+                    $grade_records   = array();
+                    $oldgrade    = null;
                 }
-                if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
-                    $return = false;
+                if ($used->itemid == $this->id) {
+                    $oldgrade = $used;
                 }
+                $grade_records['gi'.$used->itemid] = $used->finalgrade;
+            }
+            if (!$this->use_formula($prevuser, $grade_records, $useditems, $oldgrade)) {
+                $return = false;
             }
-            rs_close($rs);
         }
+        rs_close($rs);
 
         return $return;
     }
index 80f8b06dec05fbff91d9a1da99b0e21fd1327807..c4494790097dbc35eeb4554863463d0e26609068 100644 (file)
@@ -1085,12 +1085,10 @@ function grade_cron() {
 
     // go through all courses that have proper final grades and lock them if needed
     if ($rs = get_recordset_sql($sql)) {
-        if ($rs->RecordCount() > 0) {
-            while ($item = rs_fetch_next_record($rs)) {
-                $grade_item = new grade_item($item, false);
-                $grade_item->locked = $now;
-                $grade_item->update('locktime');
-            }
+        while ($item = rs_fetch_next_record($rs)) {
+            $grade_item = new grade_item($item, false);
+            $grade_item->locked = $now;
+            $grade_item->update('locktime');
         }
         rs_close($rs);
     }
@@ -1105,12 +1103,10 @@ function grade_cron() {
 
     // go through all courses that have proper final grades and lock them if needed
     if ($rs = get_recordset_sql($sql)) {
-        if ($rs->RecordCount() > 0) {
-            while ($grade = rs_fetch_next_record($rs)) {
-                $grade_grade = new grade_grade($grade, false);
-                $grade_grade->locked = $now;
-                $grade_grade->update('locktime');
-            }
+        while ($grade = rs_fetch_next_record($rs)) {
+            $grade_grade = new grade_grade($grade, false);
+            $grade_grade->locked = $now;
+            $grade_grade->update('locktime');
         }
         rs_close($rs);
     }
index 6689f632218e80e54bde76b324d398a0e394d5a0..f93fa0ddb36b980efa1e3e0e8530f9c3883e2d1f 100644 (file)
@@ -175,7 +175,7 @@ function setup_is_unicodedb() {
     switch ($dbfamily) {
         case 'mysql':
             $rs = $db->Execute("SHOW VARIABLES LIKE 'character_set_database'");
-            if ($rs && $rs->RecordCount() > 0) {
+            if ($rs && !$rs->EOF) { // rs_EOF() not available yet
                 $records = $rs->GetAssoc(true);
                 $encoding = $records['character_set_database']['Value'];
                 if (strtoupper($encoding) == 'UTF8') {
@@ -186,7 +186,7 @@ function setup_is_unicodedb() {
         case 'postgres':
         /// Get PostgreSQL server_encoding value
             $rs = $db->Execute("SHOW server_encoding");
-            if ($rs && $rs->RecordCount() > 0) {
+            if ($rs && !$rs->EOF) { // rs_EOF() not available yet
                 $encoding = $rs->fields['server_encoding'];
                 if (strtoupper($encoding) == 'UNICODE' || strtoupper($encoding) == 'UTF8') {
                     $unicodedb = true;
@@ -200,7 +200,7 @@ function setup_is_unicodedb() {
         case 'oracle':
         /// Get Oracle DB character set value
             $rs = $db->Execute("SELECT parameter, value FROM nls_database_parameters where parameter = 'NLS_CHARACTERSET'");
-            if ($rs && $rs->RecordCount() > 0) {
+            if ($rs && !$rs->EOF) { // rs_EOF() not available yet
                 $encoding = $rs->fields['value'];
                 if (strtoupper($encoding) == 'AL32UTF8') {
                     $unicodedb = true;
index 7793878df9c8c8d16016a783b28dce005d773ff6..fc10e32a154cdec014fabf90cea165b4ae7e14da 100644 (file)
@@ -293,7 +293,7 @@ function remove_test_table($tablename, $db, $cascade = false) {
     
     if ($CFG->dbfamily == 'postgres') {
         $rs = $db->Execute("SELECT relname FROM pg_class WHERE relname = '{$tablename}_id_seq' AND relkind = 'S';");
-        if ($rs && $rs->RecordCount()) {
+        if ($rs && !rs_EOF($rs)) {
             _private_execute_sql("DROP SEQUENCE {$tablename}_id_seq;", $db);
         }
     }
index 5f583fc97afcb859e610d00f3e05948a007f28a4..99298c0478948ff5aec35769e26a87e938d66cad 100644 (file)
@@ -2117,12 +2117,10 @@ function assignment_update_grades($assignment=null, $userid=0, $nullifnone=true)
                   FROM {$CFG->prefix}assignment a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
                  WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                while ($assignment = rs_fetch_next_record($rs)) {
-                    assignment_grade_item_update($assignment);
-                    if ($assignment->grade != 0) {
-                        assignment_update_grades($assignment);
-                    }
+            while ($assignment = rs_fetch_next_record($rs)) {
+                assignment_grade_item_update($assignment);
+                if ($assignment->grade != 0) {
+                    assignment_update_grades($assignment);
                 }
             }
             rs_close($rs);
index f802cb154e62d3ebba91796759e44a389dc1cad6..22eee7ad8f7a6aa3dc2639bf6b0ca5c86949c9c2 100644 (file)
@@ -363,11 +363,12 @@ function chat_get_latest_message($chatid, $groupid=0) {
                                  ORDER BY timestamp DESC", 1)) {
         return false;
     }
-    if ($rs->RecordCount() == 1) {
-        return rs_fetch_record($rs);
-    } else {
-        return false;                 // Found no records
-    }
+
+    $result = rs_fetch_record($rs);
+
+    rs_close($result);
+
+    return $result;
 }
 
 
index 0f5c6465d2959291f2306042b5cc51cab00671a0..cc7543d4c4aa5cb27e8b16e8cf9db09611814bff 100755 (executable)
@@ -781,12 +781,10 @@ function data_update_grades($data=null, $userid=0, $nullifnone=true) {
                   FROM {$CFG->prefix}data d, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
                  WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                while ($data = rs_fetch_next_record($rs)) {
-                    data_grade_item_update($data);
-                    if ($data->assessed) {
-                        data_update_grades($data, 0, false);
-                    }
+            while ($data = rs_fetch_next_record($rs)) {
+                data_grade_item_update($data);
+                if ($data->assessed) {
+                    data_update_grades($data, 0, false);
                 }
             }
             rs_close($rs);
index 1b767567570c378243cc6ef8720c9d33be606215..eac525cba24b057d7d3a559ed56ef0e79061a919 100644 (file)
@@ -1168,12 +1168,10 @@ function forum_update_grades($forum=null, $userid=0, $nullifnone=true) {
                   FROM {$CFG->prefix}forum f, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
                  WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                while ($forum = rs_fetch_next_record($rs)) {
-                    forum_grade_item_update($forum);
-                    if ($forum->assessed) {
-                        forum_update_grades($forum, 0, false);
-                    }
+            while ($forum = rs_fetch_next_record($rs)) {
+                forum_grade_item_update($forum);
+                if ($forum->assessed) {
+                    forum_update_grades($forum, 0, false);
                 }
             }
             rs_close($rs);
index f84b668ac5a6a819a5c849b1002aadba3d4aeff7..512756dd4c8ba9303b97ee40b28a535e7e46f0c1 100644 (file)
@@ -358,12 +358,10 @@ function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
                   FROM {$CFG->prefix}glossary g, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
                  WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                while ($glossary = rs_fetch_next_record($rs)) {
-                    glossary_grade_item_update($glossary);
-                    if ($glossary->assessed) {
-                        glossary_update_grades($glossary, 0, false);
-                    }
+            while ($glossary = rs_fetch_next_record($rs)) {
+                glossary_grade_item_update($glossary);
+                if ($glossary->assessed) {
+                    glossary_update_grades($glossary, 0, false);
                 }
             }
             rs_close($rs);
index d5935b6410f0ff6f93ed15a7e860fdf88555f3bb..1632d4f0d60a6141e5ebd7a835d82d0132d7f112 100644 (file)
@@ -270,7 +270,7 @@ function hotpot_update_to_v2_1_2() {
         GROUP BY userid, hotpot
         HAVING COUNT(*)>1 AND MIN(status)=1
     ");
-    if ($rs && $rs->RecordCount()) {
+    if ($rs && !$rs->EOF) {
         $records = $rs->GetArray();
 
         // start message to browser
@@ -921,7 +921,7 @@ function hotpot_db_index_exists($table, $index, $feedback=false) {
     switch (strtolower($CFG->dbfamily)) {
         case 'mysql' : 
             $rs = $db->Execute("SHOW INDEX FROM `$table`");
-            if ($rs && $rs->RecordCount()>0) {
+            if ($rs && !$rs->EOF) {
                 $records = $rs->GetArray();
                 foreach ($records as $record) {
                     if (isset($record['Key_name']) && $record['Key_name']==$index) {
@@ -933,7 +933,7 @@ function hotpot_db_index_exists($table, $index, $feedback=false) {
         break;
         case 'postgres' :
             $rs = $db->Execute("SELECT relname FROM pg_class WHERE relname = '$index' AND relkind='i'");
-            if ($rs && $rs->RecordCount()>0) {
+            if ($rs && !$rs->EOF) {
                 $exists = true;
             }
         break;
@@ -1042,7 +1042,7 @@ function hotpot_db_object_exists($table, $field='', $feedback=false) {
     if (empty($rs) && debugging()) {
         notify($db->ErrorMsg()."<br /><br />$sql");
     }
-    return ($rs && $rs->RecordCount()>0);
+    return ($rs && !$rs->EOF);
 }
 function hotpot_db_remove_table($table, $feedback=true) {
     global $CFG;
@@ -1208,7 +1208,7 @@ function hotpot_db_update_field_type($table, $oldfield, $field, $type, $size, $u
             //    (except lib/adodb/drivers/adodb-postgre64-inc.php)
             $dbversion = '';
             $rs = $db->Execute("SELECT version()");
-            if ($rs && $rs->RecordCount()>0) {
+            if ($rs && !$rs->EOF) {
                 $records = $rs->GetArray();
                 if (preg_match('/\d+\.\d+/', $records[0][0], $matches)) {
                     $dbversion = $matches[0];
index a2379d2d38b105727475441e8ac5f597b63bd6ba..8d117767577eb771f4cacb49d740bd8bc9a15021 100644 (file)
@@ -1243,11 +1243,9 @@ function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
                   FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
                  WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=s.id";
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                while ($hotpot = rs_fetch_next_record($rs)) {
-                    hotpot_grade_item_update($hotpot);
-                    hotpot_update_grades($hotpot, 0, false);
-                }
+            while ($hotpot = rs_fetch_next_record($rs)) {
+                hotpot_grade_item_update($hotpot);
+                hotpot_update_grades($hotpot, 0, false);
             }
             rs_close($rs);
         }
index c7b4a0365b8667b8621b40d655a112bad21b07b6..43450948941520fedfc564ab4e5c4c747ac63f79 100644 (file)
@@ -392,12 +392,10 @@ function lesson_update_grades($lesson=null, $userid=0, $nullifnone=true) {
                   FROM {$CFG->prefix}lesson l, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
                  WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                while ($lesson = rs_fetch_next_record($rs)) {
-                    lesson_grade_item_update($lesson);
-                    if ($lesson->grade != 0) {
-                        lesson_update_grades($lesson, 0, false);
-                    }
+            while ($lesson = rs_fetch_next_record($rs)) {
+                lesson_grade_item_update($lesson);
+                if ($lesson->grade != 0) {
+                    lesson_update_grades($lesson, 0, false);
                 }
             }
             rs_close($rs);
index 08af5445756455bac29b083ccaf9ddf23f4c0c25..588c9bbe9bb7904ee9d798c7ab2c62a53c7b4729 100644 (file)
@@ -305,12 +305,10 @@ function quiz_update_grades($quiz=null, $userid=0, $nullifnone=true) {
                   FROM {$CFG->prefix}quiz a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
                  WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id";
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                while ($quiz = rs_fetch_next_record($rs)) {
-                    quiz_grade_item_update($quiz);
-                    if ($quiz->grade != 0) {
-                        quiz_update_grades($quiz, 0, false);
-                    }
+            while ($quiz = rs_fetch_next_record($rs)) {
+                quiz_grade_item_update($quiz);
+                if ($quiz->grade != 0) {
+                    quiz_update_grades($quiz, 0, false);
                 }
             }
             rs_close($rs);
index 035e9853d33e4899a3380e3a5a9379236c04255d..517812fca22b89e536fa1247f65229b4e93c77e6 100755 (executable)
@@ -475,11 +475,9 @@ function scorm_update_grades($scorm=null, $userid=0, $nullifnone=true) {
                   FROM {$CFG->prefix}scorm s, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
                  WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
         if ($rs = get_recordset_sql($sql)) {
-            if ($rs->RecordCount() > 0) {
-                while ($scorm = rs_fetch_next_record($rs)) {
-                    scorm_grade_item_update($scorm);
-                    scorm_update_grades($scorm, 0, false);
-                }
+            while ($scorm = rs_fetch_next_record($rs)) {
+                scorm_grade_item_update($scorm);
+                scorm_update_grades($scorm, 0, false);
             }
             rs_close($rs);
         }
index 295db1a4d88a3a32bf940714e6b7f70eb18fcd62..206a42d864031e546e3be82ce4327362ebcc0c0b 100755 (executable)
@@ -307,7 +307,7 @@ class qformat_coursetestmanager extends qformat_default {
         if (PHP_OS == "WINNT") {
             $ldb =& $this->connect_win($filename);
             $qset = $ldb->Execute("$sql");
-            if ( $qset->RecordCount() > 0 ) {
+            if ( !$qset->EOF ) {
                 $records = $qset->GetAssoc(true);
             } else {
                 $this->err("There were no records in the database.",$dsn);
@@ -341,7 +341,7 @@ class qformat_coursetestmanager extends qformat_default {
         if (PHP_OS == "WINNT") {
             $ldb =& $this->connect_win($filename);
             $qset = $ldb->Execute("$sql");
-            if ( $qset->RecordCount() > 0 ) {
+            if ( !$qset->EOF ) {
                 $records = $qset->GetArray(true);
                 foreach ($records as $record) {
                     $categories[$record[0]] = $record[0];
index dc2da43b304c874cbfa46053520708f86b7f1733..e137056f974c54c7a6c044b3acdae8836af0198c 100644 (file)
         $timeformat = get_string('strftimedate');
 
 
-        if ($userlist->RecordCount() > 0)  {
+        if ($userlist)  {
             while ($user = rs_fetch_next_record($userlist)) {
                 $user = make_context_subobj($user);
                 if ($user->hidden) {
 
     print_footer($course);
 
-
+    if ($userlist) {
+        rs_close($userlist);
+    }
 
 
 function get_lastaccess_sql($accesssince='') {