PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject » Bug #750

possibility to do distinct for select and count

Details

Submitted2004-02-13 10:41 UTC
Frompear at daniu dot de
Assignedalan_k
StatusClosed
PackageDB_DataObject
PHP Version4.3.4
OSWin XP
Roadmaps(Not assigned)

Comments

[2004-02-13 10:41 UTC] pear at daniu dot de

Description:
------------
I would like to be able to do distinct selects and counts

my suggestion is:

changing function find to:

function find($n = false, $distinct = false) //ext. by $distinct
...
if ($distinct){
$this->_query('SELECT DISTINCT ' .
$this->_query['data_select'] .
' FROM ' . $this->__table . " " .
$this->_join .
$this->_query['condition'] . ' '.
$this->_query['group_by'] . ' '.
$this->_query['having'] . ' '.
$this->_query['order_by'] . ' '.

$this->_query['limit']); // is select
}
else{
$this->_query('SELECT ' .
$this->_query['data_select'] .
' FROM ' . $this->__table . " " .
$this->_join .
$this->_query['condition'] . ' '.
$this->_query['group_by'] . ' '.
$this->_query['having'] . ' '.
$this->_query['order_by'] . ' '.

$this->_query['limit']); // is select
}

count() the same way.

I don't know whether this is the way of doing things in Pear but it works for me and I would like to see it in PEAR as it is a bit dangerous to exchange the function as it won't get updated upon a change in the real function.

probably you would prefer something like
$db->distinct();

PS.: wouldn't it be nicer to be able to post "request for features" instead of bug reports? I always feel like murmoring about good code just because i would like to make it even better :-)

[2004-02-16 10:21 UTC] pear at daniu dot de

Hi!

Yes - there might come up a problem in certain cases:

if (soandso)
selectAdd('foo');
if (something else)
selectAdd('bar');
if (yet something else)
selectAdd('baz')

where to put the Distinct here? I cannot know which one is the first select statement. so I would need a selectAdd() that does not add a "," in the end so that I could do selectAdd('DISTINCT') - or ... put the distinct in any other way.

OK - to be honest - this is very special - but might happen even though probably not without possibilities for workarounds.