From: tjhunt Date: Fri, 15 Dec 2006 18:23:31 +0000 (+0000) Subject: MDL-7926 - set_field_select function. Merged from MOODLE_17_STABLE. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=0dae5d33a76f37581205ec5f03bfcda1f5f895ae;p=moodle.git MDL-7926 - set_field_select function. Merged from MOODLE_17_STABLE. --- diff --git a/lib/dmllib.php b/lib/dmllib.php index e543ae08d8..6195658881 100644 --- a/lib/dmllib.php +++ b/lib/dmllib.php @@ -1027,9 +1027,7 @@ function get_fieldset_sql($sql) { */ function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $value2='', $field3='', $value3='') { - global $db, $CFG, $record_cache; - - if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; }; + global $CFG, $record_cache; // Clear record_cache based on the parameters passed (individual record or whole table) if (!empty($CFG->enablerecordcache)) { @@ -1054,6 +1052,40 @@ function set_field($table, $newfield, $newvalue, $field1, $value1, $field2='', $ $select = where_clause($field1, $value1, $field2, $value2, $field3, $value3); + return set_field_select($table, $newfield, $newvalue, $select, true); +} + +/** + * 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, $record_cache; + + if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++; }; + + if (!$localcall) { + if ($select) { + $select = 'WHERE ' . $select; + } + + // Clear record_cache based on the parameters passed (individual record or whole table) + if (!empty($CFG->enablerecordcache)) { + if (isset($record_cache[$table])) { + unset($record_cache[$table]); + } + } + } + $dataobject = new StdClass; $dataobject->{$newfield} = $newvalue; // Oracle DIRTY HACK -