mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 16:03:47 +01:00
* Addressbook: fixed PostgeSQL error when searching or showing accounts
This commit is contained in:
parent
58328235b0
commit
c34c52cacf
@ -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!
|
||||
|
@ -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_VARCHAR],"COALESCE($col,'')");
|
||||
}
|
||||
if($columns)
|
||||
{
|
||||
@ -1165,7 +1171,8 @@ class so_sql
|
||||
if($wildcard == '')
|
||||
{
|
||||
// Token has a wildcard from user, use LIKE
|
||||
$numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) LIKE " .
|
||||
$numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) " .
|
||||
$this->db->capabilities['case_insensitive_like'] . ' ' .
|
||||
$GLOBALS['egw']->db->quote(str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$token)) . ')';
|
||||
}
|
||||
else
|
||||
|
@ -222,6 +222,14 @@ class egw_db
|
||||
* DB requires varchar columns to be truncated to the max. size (eg. Postgres)
|
||||
*/
|
||||
const CAPABILITY_REQUIRE_TRUNCATE_VARCHAR = 'require_truncate_varchar';
|
||||
/**
|
||||
* How to cast a column to varchar: CAST(%s AS varchar)
|
||||
*
|
||||
* MySQL requires to use CAST(%s AS char)!
|
||||
*
|
||||
* Use as: $sql = sprintf($GLOBALS['egw']->db->capabilities[egw_db::CAPABILITY_CAST_AS_VARCHAR],$expression);
|
||||
*/
|
||||
const CAPABILITY_CAST_AS_VARCHAR = 'cast_as_varchar';
|
||||
/**
|
||||
* default capabilities will be changed by method set_capabilities($ado_driver,$db_version)
|
||||
*
|
||||
@ -240,6 +248,7 @@ class egw_db
|
||||
self::CAPABILITY_CLIENT_ENCODING => false,
|
||||
self::CAPABILITY_CASE_INSENSITIV_LIKE => 'LIKE',
|
||||
self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR => false,
|
||||
self::CAPABILITY_CAST_AS_VARCHAR => 'CAST(%s AS varchar)',
|
||||
);
|
||||
|
||||
var $prepared_sql = array(); // sql is the index
|
||||
@ -348,6 +357,7 @@ class egw_db
|
||||
switch($this->Type) // convert to ADO db-type-names
|
||||
{
|
||||
case 'pgsql':
|
||||
$this->query_log = '/tmp/pgsql-query.log';
|
||||
$type = 'postgres'; // name in ADOdb
|
||||
// create our own pgsql connection-string, to allow unix domain soccets if !$Host
|
||||
$Host = "dbname=$this->Database".($this->Host ? " host=$this->Host".($this->Port ? " port=$this->Port" : '') : '').
|
||||
@ -498,6 +508,7 @@ class egw_db
|
||||
$this->capabilities[self::CAPABILITY_UNION] = (float) $db_version >= 4.0;
|
||||
$this->capabilities[self::CAPABILITY_NAME_CASE] = 'preserv';
|
||||
$this->capabilities[self::CAPABILITY_CLIENT_ENCODING] = (float) $db_version >= 4.1;
|
||||
$this->capabilities[self::CAPABILITY_CAST_AS_VARCHAR] = 'CAST(%s AS char)';
|
||||
break;
|
||||
|
||||
case 'postgres':
|
||||
|
Loading…
Reference in New Issue
Block a user