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 #5307

Method to remove duplicate join declarations

Details

Request #5307Method to remove duplicate join declarations
Submitted2005-09-06 09:19 UTC
Fromtorsten dot roehr at gmx dot de
StatusSuspended
PackageDB_DataObject
PHP VersionIrrelevant
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2005-09-06 09:19 UTC] torsten dot roehr at gmx dot de

Description:
------------
When building an object with multiple join objects for a complex search form it may occur that joins may be added multiple times depending on the entered search form values.

As this is very hard to control in the application (a lot of nested if/else may be required) I would like to see the following method added:

Test script:
---------------
function removeDuplicateJoins()
{
if (!empty($this->_join)) {
$joins = explode("\n", $this->_join);
$joins = array_map('trim', $joins);
$joins = array_unique($joins);
$this->_join = implode("\n", $joins);
}
}

This will remove duplicate join declarations and needs to be called once in the find() method before building the query:

$this->removeDuplicateJoins();
$sql = 'SELECT ' .
$this->_query['data_select'] .
' FROM ' . ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table) . " " .
$this->_join .
$this->_query['condition'] . ' '.
$this->_query['group_by'] . ' '.
$this->_query['having'] . ' '.
$this->_query['order_by'] . ' ';

Thanks for having a look and best regards,

Torsten Roehr