From: skodak Date: Sun, 1 Jun 2008 16:14:59 +0000 (+0000) Subject: MDL-14679 removed all instances of set_field_select() X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1c69b88529b3f9ef8930e52a952bdd55d66be72c;p=moodle.git MDL-14679 removed all instances of set_field_select() --- diff --git a/course/lib.php b/course/lib.php index 9d3bb8de4a..315d984c1f 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1548,8 +1548,12 @@ function rebuild_course_cache($courseid=0, $clearonly=false) { 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; diff --git a/lib/dmllib.php b/lib/dmllib.php index f25711b7fd..8223084bd8 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -452,3 +452,7 @@ function records_to_menu($records, $field1, $field2) { error('records_to_menu() removed'); } +function set_field_select($table, $newfield, $newvalue, $select, $localcall = false) { + error('set_field_select() removed'); +} + diff --git a/lib/dmllib_todo.php b/lib/dmllib_todo.php index f652e1fb72..df03d15291 100644 --- a/lib/dmllib_todo.php +++ b/lib/dmllib_todo.php @@ -728,81 +728,6 @@ function get_fieldset_sql($sql) { } } -/** - * 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() .'

'. 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 * diff --git a/lib/questionlib.php b/lib/questionlib.php index 6b6d03dbde..b538b0d274 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -713,13 +713,15 @@ function question_delete_activity($cm, $feedback=true) { * @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.