my $err = $!;
-d $d or die "$d not created: $err";
}
- my $f = "$d/msgmap.sqlite3";
+ new_file($class, "$d/msgmap.sqlite3", $writable);
+}
+
+sub new_file {
+ my ($class, $f, $writable) = @_;
+
my $dbh = DBI->connect("dbi:SQLite:dbname=$f",'','', {
AutoCommit => 1,
RaiseError => 1,
$self;
}
+# n.b. invoked directly by scripts/xhdr-num2mid
sub meta_accessor {
my ($self, $key, $value) = @_;
use constant {
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');
}
'val VARCHAR(255) NOT NULL)');
}
+# used by NNTP.pm
sub id_batch {
my ($self, $num, $cb) = @_;
my $dbh = $self->{dbh};
$nr;
}
+# only used for mapping external serial numbers (e.g. articles from gmane)
+# see scripts/xhdr-num2mid for usage
+sub mid_set {
+ my ($self, $num, $mid) = @_;
+ my $sth = $self->{mid_set} ||= do {
+ my $sql = 'INSERT OR IGNORE INTO msgmap (num, mid) VALUES (?,?)';
+ $self->{dbh}->prepare($sql);
+ };
+ $sth->execute($num, $mid);
+}
+
1;