From: skodak Date: Wed, 10 Oct 2007 12:19:27 +0000 (+0000) Subject: MDL-11432 eliminated majority of RecordCount uses, added several missing rs_close... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=03cedd62834549ea3a47275e1d151c06d3753616;p=moodle.git MDL-11432 eliminated majority of RecordCount uses, added several missing rs_close() - this should help improve perf on some platforms - Eloy says ;-) --- diff --git a/admin/multilangupgrade.php b/admin/multilangupgrade.php index 705a80e7c3..1ab04d5417 100644 --- a/admin/multilangupgrade.php +++ b/admin/multilangupgrade.php @@ -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 '%%' OR $column LIKE '%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); } } } diff --git a/auth/db/auth.php b/auth/db/auth.php index e8b2e50c36..2da10f05bf 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -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); } diff --git a/backup/backuplib.php b/backup/backuplib.php index baba967292..84beeac159 100644 --- a/backup/backuplib.php +++ b/backup/backuplib.php @@ -1147,12 +1147,12 @@ 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 @@ -1290,6 +1290,10 @@ $status = true; } + if ($users) { + rs_close($users); + } + return $status; } diff --git a/enrol/database/enrol.php b/enrol/database/enrol.php index ef9a8af8f7..dbd07282f7 100644 --- a/enrol/database/enrol.php +++ b/enrol/database/enrol.php @@ -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; diff --git a/grade/lib.php b/grade/lib.php index 90411cf231..1da3b5f2cb 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -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 } diff --git a/lib/accesslib.php b/lib/accesslib.php index 966518d9eb..cff3c6245e 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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)); } diff --git a/lib/authlib.php b/lib/authlib.php index 355fdf3ec5..ca942381e0 100644 --- a/lib/authlib.php +++ b/lib/authlib.php @@ -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 diff --git a/lib/datalib.php b/lib/datalib.php index fb84762ac4..93d40c40bc 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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); } /** diff --git a/lib/db/mysql.php b/lib/db/mysql.php index ea2dcf4eae..1259ed51f4 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -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); } } diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index fdec2bcde1..5e483db467 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -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); } } diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 7eb056cc4d..ac8c0bd085 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; diff --git a/lib/dmllib.php b/lib/dmllib.php index 29051daafe..ae0026bdb2 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -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; } } diff --git a/lib/eventslib.php b/lib/eventslib.php index 81957a9727..519ea6bf5f 100755 --- a/lib/eventslib.php +++ b/lib/eventslib.php @@ -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); diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index ee9c7bd564..7d0d33443e 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -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); } diff --git a/lib/grade/grade_grade.php b/lib/grade/grade_grade.php index 4385a801bb..a97e3c9887 100644 --- a/lib/grade/grade_grade.php +++ b/lib/grade/grade_grade.php @@ -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); } diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 0e29d2ba7d..0882c71d68 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -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; } diff --git a/lib/gradelib.php b/lib/gradelib.php index 80f8b06dec..c449479009 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -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); } diff --git a/lib/setuplib.php b/lib/setuplib.php index 6689f63221..f93fa0ddb3 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -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; diff --git a/lib/simpletestlib.php b/lib/simpletestlib.php index 7793878df9..fc10e32a15 100644 --- a/lib/simpletestlib.php +++ b/lib/simpletestlib.php @@ -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); } } diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 5f583fc97a..99298c0478 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -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); diff --git a/mod/chat/lib.php b/mod/chat/lib.php index f802cb154e..22eee7ad8f 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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; } diff --git a/mod/data/lib.php b/mod/data/lib.php index 0f5c6465d2..cc7543d4c4 100755 --- a/mod/data/lib.php +++ b/mod/data/lib.php @@ -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); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 1b76756757..eac525cba2 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -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); diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index f84b668ac5..512756dd4c 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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); diff --git a/mod/hotpot/db/update_to_v2.php b/mod/hotpot/db/update_to_v2.php index d5935b6410..1632d4f0d6 100644 --- a/mod/hotpot/db/update_to_v2.php +++ b/mod/hotpot/db/update_to_v2.php @@ -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()."

$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]; diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index a2379d2d38..8d11776757 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -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); } diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index c7b4a0365b..4345094894 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -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); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 08af544575..588c9bbe9b 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -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); diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 035e9853d3..517812fca2 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -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); } diff --git a/question/format/coursetestmanager/format.php b/question/format/coursetestmanager/format.php index 295db1a4d8..206a42d864 100755 --- a/question/format/coursetestmanager/format.php +++ b/question/format/coursetestmanager/format.php @@ -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]; diff --git a/user/index.php b/user/index.php index dc2da43b30..e137056f97 100644 --- a/user/index.php +++ b/user/index.php @@ -560,7 +560,7 @@ $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) { @@ -676,7 +676,9 @@ print_footer($course); - + if ($userlist) { + rs_close($userlist); + } function get_lastaccess_sql($accesssince='') {