Fix bug in new function get_field_select(), and this time add a unittest to see if the new function works!
This commit is contained in:
+5
-1
@@ -946,8 +946,9 @@ function get_records_sql_menu($sql) {
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -961,6 +962,9 @@ function get_field($table, $return, $field1, $value1, $field2='', $value2='', $f
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +172,15 @@ class datalib_test extends prefix_changing_test_case {
|
||||
$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);
|
||||
|
||||
Reference in New Issue
Block a user