* Addressbook: fixed PostgeSQL error when searching or showing accounts

This commit is contained in:
Ralf Becker 2011-03-20 12:37:22 +00:00
parent 3684567a53
commit c492c57e2f
2 changed files with 19 additions and 13 deletions

View File

@ -27,7 +27,7 @@ class addressbook_sql extends so_sql_cf
/**
* join to show only active account (and not already expired ones)
*/
const ACOUNT_ACTIVE_JOIN = ' LEFT JOIN egw_accounts ON egw_addressbook.account_id=egw_accounts.account_id';
const ACCOUNT_ACTIVE_JOIN = ' LEFT JOIN egw_accounts ON egw_addressbook.account_id=egw_accounts.account_id';
/**
* filter to show only active account (and not already expired ones)
* UNIX_TIMESTAMP(NOW()) gets replaced with value of time() in the code!
@ -328,7 +328,14 @@ class addressbook_sql extends so_sql_cf
$join .= " JOIN $this->ab2list_table ON $this->table_name.contact_id=$this->ab2list_table.contact_id AND list_id=".(int)$filter['list'];
unset($filter['list']);
}
if ($join)
// add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin)
if (!$owner && substr($this->account_repository,0,3) == 'sql' &&
strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter))
{
$join .= self::ACCOUNT_ACTIVE_JOIN;
$filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER);
}
if ($join || $criteria && is_string($criteria)) // search also adds a join for custom fields!
{
switch(gettype($only_keys))
{
@ -368,13 +375,6 @@ class addressbook_sql extends so_sql_cf
//_debug_array($order_by);
}
}
// add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin)
if (!$owner && substr($this->account_repository,0,3) == 'sql' &&
strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter))
{
$join .= self::ACOUNT_ACTIVE_JOIN;
$filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER);
}
$rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false!

View File

@ -1081,16 +1081,22 @@ class so_sql
{
return array();
}
// Concat all fields to be searched together, so the conditions operate across the whole record
foreach($search_cols as $col)
{
if($this->table_def['fd'][$col] && in_array($this->table_def['fd'][$col]['type'], $numeric_types))
$col_name = $col;
$table = $this->table_name;
if (strpos($col,'.') !== false)
{
list($table,$col_name) = explode('.',$col);
}
$table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true,$table);
if ($table_def['fd'][$col_name] && in_array($table_def['fd'][$col_name]['type'], $numeric_types))
{
$numeric_columns[] = $col;
continue;
}
$columns[] = "CAST(COALESCE($col,'') AS char)";
$columns[] = sprintf($this->db->capabilities[egw_db::CAPABILITY_CAST_AS_VACHAR],"COALESCE($col,'')");
}
if($columns)
{