Skip to content

Commit

Permalink
Fix #37: MSSQL compatibility issue with filters
Browse files Browse the repository at this point in the history
The ORDER BY clause is causing an error when searching changesets

This fixes part 1° of the issue report
  • Loading branch information
dregad committed Dec 7, 2012
1 parent 3747c5a commit e740f4f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions Source/Source.FilterAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,18 @@ function __construct( $init = true ) {
}
}

/**
* Retrieves the data based on current filter
* @param int $p_page page to display; defaults to 1, use null for all pages
* @param int $p_limit number of records per page, defaults to 25
* @return array containing list of changesets and number of records
*/
function find( $p_page=1, $p_limit=25 ) {
list( $t_filters, $t_filter_params ) = Source_Twomap( 'Source_Process_FilterOption', $this->filters );
list ( $t_query_tail, $t_params ) = Source_Process_Filters( $t_filters, $t_filter_params );
list( $t_query_tail, $t_order, $t_params ) = Source_Process_Filters( $t_filters, $t_filter_params );

$t_count_query = "SELECT COUNT(c.id) $t_query_tail";
$t_full_query = "SELECT DISTINCT( c.id ), c.* $t_query_tail";
$t_full_query = "SELECT DISTINCT( c.id ), c.* $t_query_tail $t_order";

$t_count = db_result( db_query_bound( $t_count_query, $t_params ) );

Expand All @@ -91,6 +97,13 @@ function find( $p_page=1, $p_limit=25 ) {
}
}

/**
* Processes the filter criteria to define the query join/where clause, order by
* clause and parameters
* @param string $p_filters
* @param array $p_filter_params
* @return array query join+where clause, order clause and parameters
*/
function Source_Process_Filters( $p_filters, $p_filter_params ) {
$t_changeset_table = plugin_table( 'changeset', 'Source' );
$t_repo_table = plugin_table( 'repository', 'Source' );
Expand Down Expand Up @@ -139,7 +152,7 @@ function Source_Process_Filters( $p_filters, $p_filter_params ) {

$t_order = 'ORDER BY c.timestamp DESC';

return array( "$t_join $t_where $t_order", $t_params );
return array( "$t_join $t_where", $t_order, $t_params );
}

function Source_Process_FilterOption( $key, $option ) {
Expand Down Expand Up @@ -604,4 +617,3 @@ function Source_Date_Select( $p_name, $p_selected=null ) {
print_day_option_list( $t_selected[2] );
echo '</select> ';
}

0 comments on commit e740f4f

Please sign in to comment.