* @return array|bool Array of object instances or false if not found
*/
public static function fetch_all_helper($table, $classname, $params) {
+ global $DB; // Need to introspect DB here.
+
$instance = new $classname();
$classvars = (array)$instance;
$wheresql = array();
$newparams = array();
+ $columns = $DB->get_columns($table); // Cached, no worries.
+
foreach ($params as $var=>$value) {
if (!in_array($var, $instance->required_fields) and !array_key_exists($var, $instance->optional_fields)) {
continue;
}
+ if (!array_key_exists($var, $columns)) { // TODO: Should this throw a coding exception?
+ continue;
+ }
if (is_null($value)) {
$wheresql[] = " $var IS NULL ";
} else {
- $wheresql[] = " $var = ? ";
+ if ($columns[$var]->meta_type === 'X') {
+ // We have a text/clob column, use the cross-db method for its comparison.
+ $wheresql[] = ' ' . $DB->sql_compare_text($var) . ' = ' . $DB->sql_compare_text('?') . ' ';
+ } else {
+ // Other columns (varchar, integers...).
+ $wheresql[] = " $var = ? ";
+ }
$newparams[] = $value;
}
}