* @return mixed the specified value, or false if an error occured.
*/
function get_field($table, $return, $field1, $value1, $field2='', $value2='', $field3='', $value3='') {
+ global $CFG;
$select = where_clause($field1, $value1, $field2, $value2, $field3, $value3);
- return get_field_select($table, $return, $select);
+ return get_field_sql('SELECT ' . $return . ' FROM ' . $CFG->prefix . $table . ' ' . $select);
}
/**
*/
function get_field_select($table, $return, $select) {
global $CFG;
+ if ($select) {
+ $select = 'WHERE '. $select;
+ }
return get_field_sql('SELECT ' . $return . ' FROM ' . $CFG->prefix . $table . ' ' . $select);
}
$this->assertEqual(get_field($this->table, 'number + id', 'text', 'tadpole', 'id', 4), 108);
}
+ function test_get_field_select() {
+ $this->assertEqual(get_field_select($this->table, 'number', 'id = 1'), 101);
+ }
+
+ function test_get_field_sql() {
+ global $CFG;
+ $this->assertEqual(get_field_sql("SELECT number FROM {$CFG->prefix}$this->table WHERE id = 1"), 101);
+ }
+
function test_set_field() {
set_field($this->table, 'number', 12345, 'id', 1);
$this->assertEqual(get_field($this->table, 'number', 'id', 1), 12345);