This will allow smoother imports as occasional Message-ID
duplicates happen and the best we can do is ignore the
second one.
sub mid_insert {
my ($self, $mid) = @_;
my $dbh = $self->{dbh};
- use constant MID_INSERT => 'INSERT INTO msgmap (mid) VALUES (?)';
- my $sth = $self->{mid_insert} ||= $dbh->prepare(MID_INSERT);
+ my $sql = 'INSERT OR IGNORE INTO msgmap (mid) VALUES (?)';
+ my $sth = $self->{mid_insert} ||= $dbh->prepare($sql);
$sth->bind_param(1, $mid);
- $sth->execute;
+ return if $sth->execute == 0;
$dbh->last_insert_id(undef, undef, 'msgmap', 'num');
}
}
$@ = undef;
-eval { $d->mid_insert('a@b') };
-ok($@, 'error raised when attempting duplicate message ID');
-
+my $ret = $d->mid_insert('a@b');
+is($ret, undef, 'duplicate mid_insert in undef result');
+is($d->num_for('a@b'), $mid2num{'a@b'}, 'existing number not clobbered');
foreach my $n (keys %num2mid) {
is($d->mid_for($n), $num2mid{$n}, "num:$n maps correctly");