Skip to content

Commit e740f4f

Browse files
committed
Fix #37: MSSQL compatibility issue with filters
The ORDER BY clause is causing an error when searching changesets This fixes part 1° of the issue report
1 parent 3747c5a commit e740f4f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Source/Source.FilterAPI.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,18 @@ function __construct( $init = true ) {
6363
}
6464
}
6565

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

7076
$t_count_query = "SELECT COUNT(c.id) $t_query_tail";
71-
$t_full_query = "SELECT DISTINCT( c.id ), c.* $t_query_tail";
77+
$t_full_query = "SELECT DISTINCT( c.id ), c.* $t_query_tail $t_order";
7278

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

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

100+
/**
101+
* Processes the filter criteria to define the query join/where clause, order by
102+
* clause and parameters
103+
* @param string $p_filters
104+
* @param array $p_filter_params
105+
* @return array query join+where clause, order clause and parameters
106+
*/
94107
function Source_Process_Filters( $p_filters, $p_filter_params ) {
95108
$t_changeset_table = plugin_table( 'changeset', 'Source' );
96109
$t_repo_table = plugin_table( 'repository', 'Source' );
@@ -139,7 +152,7 @@ function Source_Process_Filters( $p_filters, $p_filter_params ) {
139152

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

142-
return array( "$t_join $t_where $t_order", $t_params );
155+
return array( "$t_join $t_where", $t_order, $t_params );
143156
}
144157

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

0 commit comments

Comments
 (0)