From dbbaf0fe61d285bf8d3566ca560e2b79be50d274 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 21 Apr 2011 14:32:37 +0000 Subject: [PATCH] * PostgreSQL/Addressbook: fixed SQL error when listing account, groups or querying birthdays --- addressbook/inc/class.addressbook_sql.inc.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/addressbook/inc/class.addressbook_sql.inc.php b/addressbook/inc/class.addressbook_sql.inc.php index db2ce5580a..d1921fb13f 100644 --- a/addressbook/inc/class.addressbook_sql.inc.php +++ b/addressbook/inc/class.addressbook_sql.inc.php @@ -363,15 +363,25 @@ class addressbook_sql extends so_sql_cf foreach($all_matches as $matches) { $table = ''; - if (strpos($matches[1],'.') === false) + $column = $matches[1]; + if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; + if (strpos($column,'.') === false) { - $table = ($matches[1] == $this->extra_value ? $this->extra_table : $this->table_name).'.'; + $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; + if (in_array($column, $this->db_cols)) + { + $table .= '.'; + } + else + { + $table = ''; + } } - $extra_cols[] = $table.$matches[1].' '.$matches[2]; + $extra_cols[] = $table.$column.' '.$matches[2]; //_debug_array($matches); if (!empty($order_by) && $table) // postgres requires explizit order by { - $order_by = str_replace($matches[0],$table.$matches[0],$order_by); + $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); } } //_debug_array($order_by); _debug_array($extra_cols);