diff --git a/addressbook/inc/class.addressbook_sql.inc.php b/addressbook/inc/class.addressbook_sql.inc.php index ce86346ec9..0ad0b93934 100644 --- a/addressbook/inc/class.addressbook_sql.inc.php +++ b/addressbook/inc/class.addressbook_sql.inc.php @@ -357,18 +357,25 @@ class addressbook_sql extends so_sql_cf // fall through } // postgres requires that expressions in order by appear in the columns of a distinct select - if ($this->db->Type != 'mysql' && preg_match("/([a-zA-Z_.]+)<>''/",$order_by,$matches)) + if ($this->db->Type != 'mysql' && preg_match_all("/([a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)/u",$order_by,$all_matches,PREG_SET_ORDER)) { if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); - $table = $matches[1] == $this->extra_value ? $this->extra_table : $this->table_name; - $extra_cols[] = $table.'.'.$matches[1]; - $extra_cols[] = $table.'.'.$matches[1]."<>''"; - //_debug_array($matches[1]); - if (!empty($order_by) && $matches[1] != 'extra_order.contact_value' && stripos($matches[1],'.')===false) // postgres requires explizit order by + foreach($all_matches as $matches) { - $order_by = str_replace($matches[1],'egw_addressbook.'.$matches[1],$order_by); + $table = ''; + if (strpos($matches[1],'.') === false) + { + $table = ($matches[1] == $this->extra_value ? $this->extra_table : $this->table_name).'.'; + } + $extra_cols[] = $table.$matches[1]; + $extra_cols[] = $table.$matches[0]; + //_debug_array($matches); + if (!empty($order_by) && $table) // postgres requires explizit order by + { + $order_by = str_replace($matches[0],$table.$matches[0],$order_by); + } } - //_debug_array($order_by); + //_debug_array($order_by); _debug_array($extra_cols); } } $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);