$self->{acpClass} = Fieldmapper::class_for_hint('acp');
$self->{sreClass} = Fieldmapper::class_for_hint('sre');
+ # Make an arrayref of shortname ids if the library option was
+ # specified:
+ $self->{libs} = [];
+ if ($Marque::config->option_value('library')) {
+ # This is done not only for speed, but to prevent SQL injection.
+ my $sth = $self->{handle}->prepare('select id from actor.org_unit where shortname=any(?::text[])');
+ if ($sth->execute($Marque::config->option_value('library'))) {
+ my $r = $sth->fetchall_arrayref();
+ my @ids = map {$_->[0]} @{$r};
+ $self->{libs} = \@ids;
+ $sth->finish();
+ }
+ }
+
bless $self, $class;
return $self;
}
# query.
my $acn_joined = 0;
# Join to the acn table as needed for the library option.
- if ($Marque::config->option_value('library')) {
+ if (@{$self->{libs}}) {
$acn_joined = 1;
$from .= <<ACN_JOIN;
join $acnTable on $acnTable.record = $breTable.id
and $acnTable.deleted = 'f'
-join (select id from actor.org_unit where shortname in (
+and $acnTable.owning_lib in (
ACN_JOIN
-
- $from .= join(',',
- map {"'$_'"} @{$Marque::config->option_value('library')});
- $from .= ") aou on $acnTable.owning_lib = aou.id";
+ $from .= join(',', @{$self->{libs}}) . ")";
}
if ($Marque::config->option_value('items')) {
$Marque::config->option_value('format'));
};
if ($@) {
- print STDERR "Error in authority record " . $bre->id() . "\n";
+ print STDERR "Error in bibliograpic record " . $bre->id() . "\n";
print STDERR "$@\n";
import MARC::File::XML; # Reset SAX Parser.
return $self->next();
my $query = "select " . join(',', $self->{acnClass}->real_fields());
$query .= "\nfrom " . $self->{acnClass}->Table();
$query .= "\nwhere record = ? and deleted = 'f'";
- if ($Marque::config->option_value('library')) {
+ if (@{$self->{libs}}) {
$query .= "\nand owning_lib in (";
- $query .= "select id from actor.org_unit where shortname in (";
- $query .= join(',', map {"'$_'"} @{$Marque::config->option_value('library')});
- $query .= "))";
+ $query .= join(',', @{$self->{libs}}) . ")";
}
$self->{acnHandle} = $self->{handle}->prepare($query);
}