-# $Id: Session.pm,v 1.13 2003-03-05 13:55:22 pop Exp $
+# $Id: Session.pm,v 1.18 2003-07-07 10:59:33 pop Exp $
#
# Zebra perl API header
# =============================================================================
use strict;
use warnings;
+use Carp;
BEGIN {
use IDZebra;
use IDZebra::ScanList;
use IDZebra::RetrievalRecord;
require Exporter;
- our $VERSION = do { my @r = (q$Revision: 1.13 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+ our $VERSION = do { my @r = (q$Revision: 1.18 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
our @ISA = qw(IDZebra::Logger Exporter);
our @EXPORT = qw (TRANS_RW TRANS_RO);
}
}
sub _selectRecordGroup {
my ($self, $rg) = @_;
+
my $r = IDZebra::set_group($self->{zh}, $rg);
my $dbName;
unless ($dbName = $rg->{databaseName}) {
}
my %tmp;
-
my $changed = 0;
foreach my $db (@databases) {
- next if ($self->{databases}{$db});
$tmp{$db}++;
+ next if ($self->{databases}{$db});
$changed++;
}
# -----------------------------------------------------------------------------
# Per record update
# -----------------------------------------------------------------------------
+sub insert_record {
+ my ($self, %args) = @_;
+ $self->checkzh;
+ my @args = $self->_record_update_args(%args);
+ my $stat = IDZebra::insert_record($self->{zh}, @args);
+ my $sysno = $args[2]; $stat = -1 * $stat if ($stat > 0);
+ return $stat ? $stat : $$sysno;
+ if ($stat) { return ($stat); } else { return $sysno};
+}
sub update_record {
my ($self, %args) = @_;
$self->checkzh;
- return(IDZebra::update_record($self->{zh},
- $self->_record_update_args(%args)));
+ my @args = $self->_record_update_args(%args);
+ my $stat = IDZebra::update_record($self->{zh}, @args);
+ my $sysno = $args[2]; $stat = -1 * $stat if ($stat > 0);
+ return $stat ? $stat : $$sysno;
+ if ($stat) { return ($stat); } else { return $$sysno};
}
sub delete_record {
my ($self, %args) = @_;
$self->checkzh;
- return(IDZebra::delete_record($self->{zh},
- $self->_record_update_args(%args)));
+ my @args = $self->_record_update_args(%args);
+ my $stat = IDZebra::delete_record($self->{zh}, @args);
+ my $sysno = $args[2]; $stat = -1 * $stat if ($stat > 0);
+ return $stat ? $stat : $$sysno;
}
+
sub _record_update_args {
my ($self, %args) = @_;
my $match = $args{match} ? $args{match} : "";
my $rectype = $args{recordType} ? $args{recordType} : "";
my $fname = $args{file} ? $args{file} : "<no file>";
+ my $force = $args{force} ? $args{force} : 0;
my $buff;
delete ($args{recordType});
delete ($args{file});
delete ($args{data});
+ delete ($args{force});
my $rg = $self->_makeRecordGroup(%args);
unless ($rectype) {
$rectype="";
}
- return ($rg, $rectype, $sysno, $match, $fname, $buff, $len);
+ return ($rg, $rectype, \$sysno, $match, $fname, $buff, $len, $force);
}
# -----------------------------------------------------------------------------
my $res = "\0" x 2048;
my $r = IDZebra::cql2pqf($self->{cql_ct}, $cqlquery, $res, 2048);
if ($r) {
- carp ("Error transforming CQL query: '$cqlquery', status:$r");
+# carp ("Error transforming CQL query: '$cqlquery', status:$r");
}
$res=~s/\0.+$//g;
return ($res,$r);
sub _search_pqf {
my ($self, $query, $setname) = @_;
- my $hits = IDZebra::search_PQF($self->{zh},
- $self->{odr_input},
- $self->{odr_output},
+
+ my $hits = 0;
+
+ my $res = IDZebra::search_PQF($self->{zh},
$query,
- $setname);
+ $setname,
+ \$hits);
my $rs = IDZebra::Resultset->new($self,
name => $setname,
# ============================================================================
-
__END__
=head1 NAME
This case the record is extracted, and if already exists, located in the database, then deleted...
- $sysno = $sess->delete_record(data => $rec1,
+ $sysno = $sess->update_record(data => $rec1,
match => $myid,
recordType => 'grs.perl.pod',
groupName => "demo1");
-Don't try this at home! This case, the record identifier string (which is normally generated according to the rules set in recordId directive of zebra.cfg) is provided directly....
+Don't try this at home! This case, the record identifier string (which is normally generated according to the rules set in I<recordId> member of the record group, or in the I<recordId> parameter) is provided directly.... Looks much better this way:
+
+ $sysno = $sess->update_record(data => $rec1,
+ databaseName => 'books',
+ recordId => '(bib1,ISBN)',
+ recordType => 'grs.perl.pod',
+ flagStoreData => 1,
+ flagStoreKeys => 1);
+
+You can notice, that it's not necessary to define a record group in zebra.cfg: you can do it "on the fly" in your code.
+
+B<Important:> Note, that one record can be updated only once within a transaction - all subsequent updates are skipped. If you'd like to override this feature, use the I<force=E<gt>1> flag:
+
+ $sysno = $sess->update_record(data => $rec1,
+ recordType => 'grs.perl.pod',
+ groupName => "demo1",
+ force => 1);
+
+If you don't like to update the record, if it alerady exists, use the I<insert_record> method:
+ $sysno = $sess->insert_record(data => $rec1,
+ recordType => 'grs.perl.pod',
+ groupName => "demo1");
-B<Important:> Note, that one record can be updated only once within a transaction - all subsequent updates are skipped.
+In this case, sysno will be -1, if the record could not be added, because there was already one in the database, with the same record identifier (generated according to the I<recordId> setting).
=head1 DATABASE SELECTION