/** * Creates and executes a query for the history rows related to bugs matched by the provided filter * @param array $p_filter Filter array * @param integer $p_start_time The start time to filter by, or null for all. * @param integer $p_end_time The end time to filter by, or null for all. * @param string $p_history_order The sort order. * @return database result to pass into history_get_event_from_row(). */ function history_get_range_result_filter($p_filter, $p_start_time = null, $p_end_time = null, $p_history_order = null) { if ($p_history_order === null) { $t_history_order = config_get('history_order'); } else { $t_history_order = $p_history_order; } # 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']) : ' '; $t_where_string = ' WHERE ' . implode(' AND ', $t_query_clauses['project_where']); if (count($t_query_clauses['where']) > 0) { $t_where_string .= ' AND ( '; $t_where_string .= implode($t_query_clauses['operator'], $t_query_clauses['where']); $t_where_string .= ' ) '; } $t_query = 'SELECT * FROM {bug_history} JOIN' . ' ( ' . $t_select_string . $t_from_string . $t_join_string . $t_where_string . ' ) B' . ' ON {bug_history}.bug_id=B.id'; $t_params = $t_query_clauses['where_values']; $t_where = array(); if ($p_start_time !== null) { $t_where[] = 'date_modified >= ' . db_param(); $t_params[] = $p_start_time; } if ($p_end_time !== null) { $t_where[] = 'date_modified < ' . db_param(); $t_params[] = $p_end_time; } if (count($t_where) > 0) { $t_query .= ' WHERE ' . implode(' AND ', $t_where); } $t_query .= ' ORDER BY {bug_history}.date_modified ' . $t_history_order . ', {bug_history}.id ' . $t_history_order; $t_result = db_query($t_query, $t_params); return $t_result; }
/** * Creates a sql query with the supplied filter query clauses, and returns the unprocessed result set opbject * * Note: The parameter $p_pop_param can be used as 'false' to keep db_params in the stack, * if the same query clauses object is reused for several queries. In that case a db_param_pop() * should be used manually when required. * This is the case when "filter_get_bug_count" is used followed by "filter_get_bug_rows_result" * @param array $p_query_clauses Array of query clauses * @param integer $p_count The number of rows to return * -1 or null indicates default query (no limits) * @param integer $p_offset Offset query results for paging (number of rows) * -1 or null indicates default query (no offset) * @param boolean $p_pop_param Whether to pop DB params from the stack * @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, $p_pop_param = true) { # if the query can't be formed, there are no results if (empty($p_query_clauses)) { if ($p_pop_param) { # reset the db_param stack, this woould have been done by db_query if executed db_param_pop(); } return db_empty_result(); } if (null === $p_count) { $t_count = -1; } else { $t_count = $p_count; } if (null === $p_offset) { $t_offset = -1; } else { $t_offset = $p_offset; } $t_query_clauses = $p_query_clauses; $t_select_string = 'SELECT DISTINCT ' . implode(', ', $t_query_clauses['select']); $t_from_string = ' FROM ' . implode(', ', $t_query_clauses['from']); $t_order_string = ' ORDER BY ' . implode(', ', $t_query_clauses['order']); $t_join_string = count($t_query_clauses['join']) > 0 ? implode(' ', $t_query_clauses['join']) : ' '; $t_where_string = ' WHERE ' . implode(' AND ', $t_query_clauses['project_where']); if (count($t_query_clauses['where']) > 0) { $t_where_string .= ' AND ( '; $t_where_string .= implode($t_query_clauses['operator'], $t_query_clauses['where']); $t_where_string .= ' ) '; } $t_result = db_query($t_select_string . $t_from_string . $t_join_string . $t_where_string . $t_order_string, $t_query_clauses['where_values'], $t_count, $t_offset, $p_pop_param); return $t_result; }