diff --git a/phpgwapi/inc/class.egw_db.inc.php b/phpgwapi/inc/class.egw_db.inc.php index 697e20d5af..4ea9b07d07 100644 --- a/phpgwapi/inc/class.egw_db.inc.php +++ b/phpgwapi/inc/class.egw_db.inc.php @@ -1537,7 +1537,7 @@ */ function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False) { - if ($this->Debug) echo "
db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app')
\n"; + if ($this->Debug) echo "db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')
\n"; if (!$table_def) $table_def = $this->get_table_definitions($app,$table); if (is_array($cols)) @@ -1557,6 +1557,54 @@ if ($this->Debug) echo "sql='$sql'
"; + if ($line === false && $file === false) // call by union, to return the sql rather then run the query + { + return $sql; + } + return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows); + } + + /** + * Does a union over multiple selects + * + * @author RalfBeckerdb::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)
\n"; + + $sql = array(); + foreach($selects as $select) + { + $sql[] = call_user_func_array(array($this,'select'),array( + $select['table'], + $select['cols'], + $select['where'], + false, // line + false, // file + false, // offset + $select['append'], + $select['app'], + 0, // num_rows, + $select['join'], + $select['table_def'], + )); + } + $sql = count($sql) > 1 ? '(' . implode(")\nUNION\n(",$sql).')' : $sql[0]; + + if ($order_by) $sql .= "\nORDER BY ".$order_by; + + if ($this->Debug) echo "sql='$sql'
"; + return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows); } }