global $COURSE, $DB;
if ($clearonly) {
- $courseselect = empty($courseid) ? "" : "id = $courseid";
- set_field_select('course', 'modinfo', null, $courseselect);
+ if (empty($courseid)) {
+ $courseselect = array();
+ } else {
+ $courseselect = array('id'=>$courseid);
+ }
+ $DB->set_field('course', 'modinfo', null, $courseselect);
// update cached global COURSE too ;-)
if ($courseid == $COURSE->id) {
$COURSE->modinfo = null;
}
}
-/**
- * Set a single field in every table row where the select statement evaluates to true.
- *
- * @uses $CFG
- * @uses $db
- * @param string $table The database table to be checked against.
- * @param string $newfield the field to set.
- * @param string $newvalue the value to set the field to.
- * @param string $select a fragment of SQL to be used in a where clause in the SQL call.
- * @param boolean $localcall Leave this set to false. (Should only be set to true by set_field.)
- * @return mixed An ADODB RecordSet object with the results from the SQL call or false.
- */
-function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) {
-
- global $db, $CFG;
-
- if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; };
-
- if (!$localcall) {
- if ($select) {
- $select = 'WHERE ' . $select;
- }
- }
-
- $dataobject = new StdClass;
- $dataobject->{$newfield} = $newvalue;
- // Oracle DIRTY HACK -
- if ($CFG->dbfamily == 'oracle') {
- oracle_dirty_hack($table, $dataobject); // Convert object to the correct "empty" values for Oracle DB
- $newvalue = $dataobject->{$newfield};
- }
- // End DIRTY HACK
-
-/// Under Oracle, MSSQL and PostgreSQL we have our own set field process
-/// If the field being updated is clob/blob, we use our alternate update here
-/// They will be updated later
- if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres') && !empty($select)) {
- /// Detect lobs
- $foundclobs = array();
- $foundblobs = array();
- db_detect_lobs($table, $dataobject, $foundclobs, $foundblobs);
- }
-
-/// Under Oracle, MSSQL and PostgreSQL, finally, update all the Clobs and Blobs present in the record
-/// if we know we have some of them in the query
- if (($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'postgres') && !empty($select) &&
- (!empty($foundclobs) || !empty($foundblobs))) {
- if (!db_update_lobs($table, $select, $foundclobs, $foundblobs)) {
- return false; //Some error happened while updating LOBs
- } else {
- return true; //Everrything was ok
- }
- }
-
-/// NULL inserts - introduced in 1.9
- if (is_null($newvalue)) {
- $update = "$newfield = NULL";
- } else {
- $update = "$newfield = '$newvalue'";
- }
-
-/// Arriving here, standard update
- $sql = 'UPDATE '. $CFG->prefix . $table .' SET '.$update.' '.$select;
- $rs = $db->Execute($sql);
- if (!$rs) {
- debugging($db->ErrorMsg() .'<br /><br />'. s($sql));
- if (!empty($CFG->dblogerror)) {
- $debug=array_shift(debug_backtrace());
- error_log("SQL ".$db->ErrorMsg()." in {$debug['file']} on line {$debug['line']}. STATEMENT: $sql");
- }
- return false;
- }
- return $rs;
-}
-
/**
* Delete one or more records from a table
*
* @param integer $newcategory the id of the category to move to.
*/
function question_move_questions_to_category($questionids, $newcategory) {
+ global $DB;
+
$result = true;
// Move the questions themselves.
- $result = $result && set_field_select('question', 'category', $newcategory, "id IN ($questionids)");
+ $result = $result && $DB->set_field_select('question', 'category', $newcategory, "id IN ($questionids)");
// Move any subquestions belonging to them.
- $result = $result && set_field_select('question', 'category', $newcategory, "parent IN ($questionids)");
+ $result = $result && $DB->set_field_select('question', 'category', $newcategory, "parent IN ($questionids)");
// TODO Deal with datasets.