From 0bca64517cb65032e6af9be47e367679f8870c67 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 23 Jul 2013 07:57:55 +0000 Subject: [PATCH] fixed SQL error introduced by r43149: multiple identical rows --- etemplate/inc/class.so_sql.inc.php | 1 + etemplate/inc/class.so_sql_cf.inc.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/etemplate/inc/class.so_sql.inc.php b/etemplate/inc/class.so_sql.inc.php index f82f88e709..6ece3782d4 100644 --- a/etemplate/inc/class.so_sql.inc.php +++ b/etemplate/inc/class.so_sql.inc.php @@ -823,6 +823,7 @@ class so_sql */ function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) { + //error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')'); if ((int) $this->debug >= 4) echo "

so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')

\n"; // if extending class or instanciator set columns to search, convert string criteria to array diff --git a/etemplate/inc/class.so_sql_cf.inc.php b/etemplate/inc/class.so_sql_cf.inc.php index 17372dffcf..b55aa9bdf3 100644 --- a/etemplate/inc/class.so_sql_cf.inc.php +++ b/etemplate/inc/class.so_sql_cf.inc.php @@ -414,6 +414,7 @@ class so_sql_cf extends so_sql */ function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) { + //error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')'); if ($only_keys === false) { $only_keys = $this->table_name.'.*'; @@ -500,6 +501,8 @@ class so_sql_cf extends so_sql $col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col; } } + // add DISTINCT as by joining custom fields for search a row can be returned multiple times + $only_keys = array_values($only_keys); $only_keys[0] = 'DISTINCT '.$only_keys[0]; } else