Skip to content
Snippets Groups Projects
Commit 41aa26b1 authored by Marek Szuba's avatar Marek Szuba
Browse files

ChecksumParser: increment checksum_xref_id BEFORE use

The initial value of the variable $counter is set to the highest
checksum_xref.checksum_xref_id found if the table in question is not
empty, or 0 if it is. This causes problems if $counter is only
incremented after each use in the input-file loop:
 - for a non-empty table the parser would attempt to re-use an existing
   value of checksum_xref_id for the first entry read from the input
   file. checksum_xref_id is the primary key of checksum_xref so its
   values have to be unique, therefore "LOAD DATA" silently discards the
   offending row;
 - for an empty table we lose one input row as well but it is the SECOND
   rather than the first one. Reason: 0 is not a valid value for
   auto_increment fields in MySQL, resulting in the first row being
   inserted with the first allowed ID value of 1 - which brings us back
   to the previous scenario when "LOAD DATA" attempts to insert the
   second row.

Incrementing $counter before use ought to address both forms of the
problem.
parent d3f22cfa
No related branches found
No related tags found
3 merge requests!457Patch to support longer assembly names in the mapping session table.,!402Prevent ChecksumParser from losing one xref per input file,!402Prevent ChecksumParser from losing one xref per input file
......@@ -71,7 +71,13 @@ sub _transfer_contents {
while(my $line = <$input_fh>) {
chomp $line;
my ($upi, $checksum) = split(/\s+/, $line);
my @output = ($counter++, $source_id, $upi, $checksum);
# Use an ID one higher than the last. Obvious? Perhaps - except before
# the commit adding this comment the code only incremented $counter
# AFTER using it.
$counter += 1;
my @output = ($counter, $source_id, $upi, $checksum);
print $output_fh join("\t", @output);
print $output_fh "\n";
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment