def CountFlowResults(self,
                       client_id,
                       flow_id,
                       with_tag=None,
                       with_type=None,
                       cursor=None):
    """Counts flow results of a given flow using given query options."""
    query = ("SELECT COUNT(*) "
             "FROM flow_results "
             "FORCE INDEX (flow_results_by_client_id_flow_id_timestamp) "
             "WHERE client_id = %s AND flow_id = %s ")
    args = [db_utils.ClientIDToInt(client_id), db_utils.FlowIDToInt(flow_id)]

    if with_tag is not None:
      query += "AND tag = %s "
      args.append(with_tag)

    if with_type is not None:
      query += "AND type = %s "
      args.append(with_type)

    cursor.execute(query, args)
    return cursor.fetchone()[0]
Counts flow results of a given flow using given query options.