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:
tjhunt
2006-08-17 16:28:29 +00:00
parent b9c3d818fe
commit cfa27f4472
2 changed files with 14 additions and 1 deletions
+5 -1
View File
@@ -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);
}
+9
View File
@@ -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);