diff --git a/cgi-bin/CATS/ApiJudge.pm b/cgi-bin/CATS/ApiJudge.pm index d3ccb3ac8..6cd098073 100644 --- a/cgi-bin/CATS/ApiJudge.pm +++ b/cgi-bin/CATS/ApiJudge.pm @@ -158,6 +158,23 @@ sub insert_req_details { print_json({ ok => 1 }); } +sub get_input_hash { + bad_judge and return -1; + my ($p) = @_; + + print_json({ hash => CATS::JudgeDB::get_input_hash($p->{problem_id}, $p->{test_rank}) }); +} + +sub save_input_hash { + bad_judge and return -1; + my ($p) = @_; + + CATS::JudgeDB::save_input_hash( + $p->{problem_id}, $p->{test_rank}, $p->{hash}}); + + print_json({ ok => 1 }); +} + sub save_input_test_data { bad_judge and return -1; my ($p) = @_; diff --git a/cgi-bin/CATS/Problem/Storage.pm b/cgi-bin/CATS/Problem/Storage.pm index bdf2f70b8..fe83039c2 100644 --- a/cgi-bin/CATS/Problem/Storage.pm +++ b/cgi-bin/CATS/Problem/Storage.pm @@ -442,8 +442,8 @@ sub insert_problem_content { $c = $dbh->prepare(q~ INSERT INTO tests ( problem_id, rank, input_validator_id, generator_id, param, std_solution_id, in_file, out_file, - points, gen_group - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)~ + points, gen_group, in_file_hash + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)~ ); for (sort { $a->{rank} <=> $b->{rank} } values %{$problem->{tests}}) { @@ -457,6 +457,7 @@ sub insert_problem_content { $c->bind_param(8, $_->{out_file}, { ora_type => 113 }); $c->bind_param(9, $_->{points}); $c->bind_param(10, $_->{gen_group}); + $c->bind_param(11, $_->{hash}); $c->execute or $self->error("Can not add test $_->{rank}: $dbh->errstr"); $self->note("Test $_->{rank} added"); diff --git a/cgi-bin/CATS/Router.pm b/cgi-bin/CATS/Router.pm index fe31ee2f1..f6929de38 100644 --- a/cgi-bin/CATS/Router.pm +++ b/cgi-bin/CATS/Router.pm @@ -271,6 +271,17 @@ $api_judge_routes = { ], api_judge_delete_req_details => [ \&CATS::ApiJudge::delete_req_details, req_id => integer, ], api_judge_insert_req_details => [ \&CATS::ApiJudge::insert_req_details, params => str, ], + api_judge_get_input_hash => [ + \&CATS::ApiJudge::get_input_hash, + problem_id => integer, + test_rank => integer, + ], + api_judge_save_input_hash => [ + \&CATS::ApiJudge::save_input_hash, + problem_id => integer, + test_rank => integer, + hash => undef, + ], api_judge_save_input_test_data => [ \&CATS::ApiJudge::save_input_test_data, problem_id => integer, diff --git a/sql/interbase/init_relations.sql b/sql/interbase/init_relations.sql index 0573c073c..0d81d53f8 100755 --- a/sql/interbase/init_relations.sql +++ b/sql/interbase/init_relations.sql @@ -281,7 +281,8 @@ CREATE TABLE tests ( out_file BLOB, /* For generated answer, length = min(out_file_size, save_answer_prefix). */ out_file_size INTEGER, /* Size of generated answer, else NULL. */ points INTEGER, - gen_group INTEGER + gen_group INTEGER, + in_file_hash VARCHAR(100) DEFAULT NULL ); CREATE TABLE testsets ( diff --git a/sql/interbase/migrations/20180226-tests-hash.sql b/sql/interbase/migrations/20180226-tests-hash.sql new file mode 100644 index 000000000..3d4a6b656 --- /dev/null +++ b/sql/interbase/migrations/20180226-tests-hash.sql @@ -0,0 +1,2 @@ +ALTER TABLE tests + ADD in_file_hash VARCHAR(100) DEFAULT NULL;