]> git.mjollnir.org Git - moodle.git/commitdiff
Fix bug in new function get_field_select(), and this time add a unittest to see if...
authortjhunt <tjhunt>
Thu, 17 Aug 2006 16:28:29 +0000 (16:28 +0000)
committertjhunt <tjhunt>
Thu, 17 Aug 2006 16:28:29 +0000 (16:28 +0000)
lib/datalib.php
lib/simpletest/testdatalib.php

index 6a216d8bb8021938869101ff0ff7b9dd28ae65e3..ae3de5228a1add8ce9b53cfacadbafbc0f1e8003 100644 (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);
 }
 
index bb3a89e9e516dc82ae07d286884f426e7be6006b..f7fcec230cce14d8421b00ee86f7c86fe8158671 100644 (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);