Skip to content

Commit

Permalink
Fix querying zero projects
Browse files Browse the repository at this point in the history
Fix the new api functions, to support the case when a user doesn't have
any accessible project. In this case the filter query can't be built, so
fix returning empty values.

Affected functions were introduced in relation to Issues #20424, #21072.
  • Loading branch information
cproensa authored and dregad committed Aug 27, 2016
1 parent b3511d2 commit 4d16012
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/database_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1314,3 +1314,13 @@ function db_mysql_fix_utf8( $p_string ) {
$p_string
);
}

/**
* Creates an empty record set, compatible with db_query() result
* This object can be used when a query can't be performed, or is not needed,
* and still want to return an empty result as a transparent return value.
* @return \ADORecordSet_empty
*/
function db_empty_result() {
return new ADORecordSet_empty();
}
11 changes: 11 additions & 0 deletions core/filter_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,10 @@ function filter_unique_query_clauses( array $p_query_clauses ) {
* @return integer
*/
function filter_get_bug_count( array $p_query_clauses ) {
# If query caluses is an empty array, the query can't be created
if( empty( $p_query_clauses ) ) {
return 0;
}
$p_query_clauses = filter_unique_query_clauses( $p_query_clauses );
$t_select_string = 'SELECT Count( DISTINCT {bug}.id ) as idcnt ';
$t_from_string = ' FROM ' . implode( ', ', $p_query_clauses['from'] );
Expand Down Expand Up @@ -1163,6 +1167,13 @@ function filter_get_bug_rows_filter( $p_project_id = null, $p_user_id = null ) {
* @return IteratorAggregate|boolean adodb result set or false if the query failed.
*/
function filter_get_bug_rows_result( array $p_query_clauses, $p_count = null, $p_offset = null ) {
# if the query can't be formed, there are no results
if( empty( $p_query_clauses ) ) {
# reset the db_param stack that was initialized by "filter_get_bug_rows_query_clauses()"
db_param_pop();
return db_empty_result();
}

if( null === $p_count ) {
$t_count = -1;
} else {
Expand Down
7 changes: 7 additions & 0 deletions core/history_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ function history_get_range_result_filter( $p_filter, $p_start_time = null, $p_en
# Note: filter_get_bug_rows_query_clauses() calls db_param_push();
$t_query_clauses = filter_get_bug_rows_query_clauses( $p_filter, null, null, null );

# if the query can't be formed, there are no results
if( empty( $t_query_clauses ) ) {
# reset the db_param stack that was initialized by "filter_get_bug_rows_query_clauses()"
db_param_pop();
return db_empty_result();
}

$t_select_string = 'SELECT DISTINCT {bug}.id ';
$t_from_string = ' FROM ' . implode( ', ', $t_query_clauses['from'] );
$t_join_string = count( $t_query_clauses['join'] ) > 0 ? implode( ' ', $t_query_clauses['join'] ) : ' ';
Expand Down

0 comments on commit 4d16012

Please sign in to comment.