mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-23 00:13:35 +01:00
"bugfix: not_unique() method was not working with unique indexes over multiple columns and was not testing the primary keys, with is also unique"
This commit is contained in:
parent
ead39f58a6
commit
b6be2fb249
@ -223,9 +223,16 @@ class so_sql
|
||||
{
|
||||
$this->autoinc_id = $col;
|
||||
}
|
||||
if (in_array($name,$this->table_def['uc']))
|
||||
foreach($this->table_def['uc'] as $k => $uni_index)
|
||||
{
|
||||
$this->db_uni_cols[$col] = $name;
|
||||
if (is_array($uni_index) && in_array($name,$uni_index))
|
||||
{
|
||||
$this->db_uni_cols[$k][$col] = $name;
|
||||
}
|
||||
elseif($name === $uni_index)
|
||||
{
|
||||
$this->db_uni_cols[$col] = $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -362,10 +369,24 @@ class so_sql
|
||||
{
|
||||
foreach($this->db_uni_cols as $db_col => $col)
|
||||
{
|
||||
if ($this->data[$col] != '')
|
||||
if (!is_array($col) && $this->data[$col] != '')
|
||||
{
|
||||
$query[$db_col] = $this->data[$col];
|
||||
}
|
||||
elseif(is_array($col))
|
||||
{
|
||||
$q = array();
|
||||
foreach($col as $db_c => $c)
|
||||
{
|
||||
if ($this->data[$col] == '')
|
||||
{
|
||||
$q = null;
|
||||
break;
|
||||
}
|
||||
$q[$db_c] = $this->data[$c];
|
||||
}
|
||||
if ($q) $query += $q;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$query) // no unique key in keys, lets try everything else
|
||||
@ -918,7 +939,7 @@ class so_sql
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if values for unique keys are unique
|
||||
* Check if values for unique keys and the primary keys are unique are unique
|
||||
*
|
||||
* @param array $data data-set to check, defaults to $this->data
|
||||
* @return int 0: all keys are unique, 1: first key not unique, 2: ...
|
||||
@ -930,9 +951,21 @@ class so_sql
|
||||
$data = $this->data;
|
||||
}
|
||||
$n = 1;
|
||||
foreach($this->db_uni_cols as $db_col => $col)
|
||||
foreach(array_merge($this->db_uni_cols,array($this->db_key_cols)) as $db_col => $col)
|
||||
{
|
||||
if (list($other) = $this->search(array($db_col => $data[$col]),false,'','','',false,'AND',false,null,''))
|
||||
if (is_array($col))
|
||||
{
|
||||
$query = array();
|
||||
foreach($col as $db_c => $c)
|
||||
{
|
||||
$query[$db_c] = $data[$c];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = array($db_col => $data[$col]);
|
||||
}
|
||||
if (list($other) = $this->search($query,false,'','','',false,'AND',false,null,''))
|
||||
{
|
||||
foreach($this->db_key_cols as $db_key_col => $key_col)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user