[Rt-devel] SearchBuilder 1.45: multi-table selects with order-by
clause
Jason Wong
jasoncw.wong at gmail.com
Wed Mar 14 21:04:58 EDT 2007
Hi,
I'm using the SearchBuilder to perform a query that performs a left
join between two tables and then orders the columns ("order by"
clause). Until recently, version 1.32 of the SearchBuilder was being
used and the query worked as expected. However, version 1.45 of the
module no longer generates the "order by" clause.
I compared the source code of the two versions and found where the
difference was being caused:
1.32:
sub BuildSelectQuery {
my $self = shift;
# The initial SELECT or SELECT DISTINCT is decided later
my $QueryString = $self->_BuildJoins . " ";
$QueryString .= $self->_WhereClause . " "
if ( $self->_isLimited > 0 );
# DISTINCT query only required for multi-table selects
if ($self->_isJoined) {
$self->_DistinctQuery(\$QueryString, $self->Table);
} else {
$QueryString = "SELECT main.* FROM $QueryString";
}
$QueryString .= ' ' . $self->_GroupClause . ' ';
$QueryString .= ' ' . $self->_OrderClause . ' ';
$self->_ApplyLimits(\$QueryString);
return($QueryString)
}
-----------------------------------------------------------------
1.45:
sub BuildSelectQuery {
my $self = shift;
# The initial SELECT or SELECT DISTINCT is decided later
my $QueryString = $self->_BuildJoins . " ";
$QueryString .= $self->_WhereClause . " "
if ( $self->_isLimited > 0 );
# DISTINCT query only required for multi-table selects
if ($self->_isJoined) {
$self->_DistinctQuery(\$QueryString);
} else {
$QueryString = "SELECT main.* FROM $QueryString";
$QueryString .= $self->_GroupClause;
$QueryString .= $self->_OrderClause;
}
$self->_ApplyLimits(\$QueryString);
return($QueryString)
}
-----------------------------------------------------------------
The difference is that the $self->_GroupClause and $self->_OrderClause
clauses are no longer appended to the query string if there's a join.
(I also checked the SearchBuilder 1.48 source; the BuildSelectQuery
function is the same as the 1.45 source.) Is this the intended
behavior?
Thanks,
Jason
More information about the Rt-devel
mailing list