+sub contest_list { _add_names _query('contest_list_sth')->hashes }
+
+sub contest_entry { _add_names _query(contest_entry_sth => $_[0])->hash }
+
+sub contest_has_problem { _query('contest_has_problem_sth', @_[0, 1])->flat }
+
+sub job_list {
+ my (%args) = @_;
+ $args{page} = int ($args{page} // 1);
+ my %where = (
+ maybe contest => $args{contest},
+ maybe owner => $args{owner},
+ maybe problem => $args{problem},
+ maybe result => $args{result},
+ );
+ $where{private} = 0 unless $args{private};
+
+ my $rows = $db->select('job_entry', 'COUNT(*)', \%where)->list;
+ my $pages = int (($rows + JOBS_PER_PAGE - 1) / JOBS_PER_PAGE);
+ my ($stmt, @bind) = $db->abstract->select('job_entry', '*', \%where, {-desc => 'id'});
+ my $jobs = _add_names $db->query("$stmt LIMIT " . JOBS_PER_PAGE . ' OFFSET ' . ($args{page} - 1) * JOBS_PER_PAGE, @bind)->hashes;
+ my $pageinfo = {
+ current_page => $args{page},
+ last_page => $pages,
+ ($args{page} - 1) ? (previous_page => $args{page} - 1) : (),
+ ($args{page} < $pages) ? (next_page => $args{page} + 1) : (),
+ };
+ wantarray ? ($jobs, $pageinfo) : $jobs;
+}