-# $Id: Session.pm,v 1.21 2004-09-09 14:12:10 adam Exp $
+# $Id: Session.pm,v 1.23 2004-09-15 14:11:06 heikki Exp $
#
# Zebra perl API header
# =============================================================================
use IDZebra::ScanList;
use IDZebra::RetrievalRecord;
require Exporter;
- our $VERSION = do { my @r = (q$Revision: 1.21 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+ our $VERSION = do { my @r = (q$Revision: 1.23 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
our @ISA = qw(IDZebra::Logger Exporter);
our @EXPORT = qw (TRANS_RW TRANS_RO);
}
# -----------------------------------------------------------------------------
# Per record update
# -----------------------------------------------------------------------------
+sub _get_data_buff {
+ my %args=@_;
+ my $buff;
+ if ($args{data}) {
+ $buff = $args{data};
+ }
+ elsif ($args{file}) {
+ CORE::open (F, $args{file}) || warn ("Cannot open $args{file}");
+ $buff = join('',(<F>));
+ CORE::close (F);
+ }
+ return $buff;
+}
+
sub insert_record {
my ($self, %args) = @_;
$self->checkzh;
- my @args = $self->_record_update_args(%args);
- my $stat = IDZebra::insert_record($self->{zh}, @args);
- # ADAM: rg no longer part of vector
- print STDERR "\nsub insert_record stat=$stat sys=${$args[1]}\n";
- return $stat;
+ my $rectype = $args{recordType} ? $args{recordType} : "";
+ my $fname = $args{file} ? $args{file} : "<no file>";
+ my $force = $args{force} ? $args{force} : 0;
+ my $buff =_get_data_buff(%args);
+ if (!$buff) { die ("insert_record needs a {data} or a {file}");}
+ my $len = length($buff);
+ my @args = ($rectype, 0, "", $fname, $buff, $len, $force);
+ my @ret = IDZebra::insert_record($self->{zh}, @args);
+ return @ret; # returns ($status, $sysno)
}
sub update_record {
my ($self, %args) = @_;
$self->checkzh;
- my @args = $self->_record_update_args(%args);
- my $stat = IDZebra::update_record($self->{zh}, @args);
- # ADAM: rg no longer part of vector
- my $sysno = $args[1]; $stat = -1 * $stat if ($stat > 0);
- return $stat ? $stat : $$sysno;
+ my $sysno = $args{sysno} ? $args{sysno} : 0;
+ 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 =_get_data_buff(%args);
+ if (!$buff) { die ("update_record needs a {data} or a {file}");}
+ my $len = length($buff);
+ my @args = ($rectype, $sysno, $match, $fname, $buff, $len, $force);
+ my @ret = IDZebra::update_record($self->{zh}, @args);
+ return @ret; # ($status, $sysno)
}
sub delete_record {
+# can delete by sysno, or by given match string, or by extracting keys
+# from the record itself...
my ($self, %args) = @_;
$self->checkzh;
- my @args = $self->_record_update_args(%args);
- my $stat = IDZebra::delete_record($self->{zh}, @args);
- # ADAM: rg no longer part of vector
- my $sysno = $args[1]; $stat = -1 * $stat if ($stat > 0);
+ my $sysno = $args{sysno} ? $args{sysno} : 0;
+ 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 =_get_data_buff(%args);
+ my $len=0;
+ if ($buff) {$len= length($buff)};
+ my @args = ($rectype, $sysno, $match, $fname, $buff, $len, $force);
+ my @ret = IDZebra::delete_record($self->{zh}, @args);
+ return @ret;
}
sub _record_update_args {
my ($self, %args) = @_;
- my $dummysysno=0;
- my $sysno = $args{sysno} ? $args{sysno} : \$dummysysno;
+ my $sysno = $args{sysno} ? $args{sysno} : 0;
my $match = $args{match} ? $args{match} : "";
my $rectype = $args{recordType} ? $args{recordType} : "";
my $fname = $args{file} ? $args{file} : "<no file>";
$setname,
\@setnames);
+
my $errCode = $self->errCode;
my $errString = $self->errString;
$sess->update(path => 'lib');
my $s1=$sess->update_record(data => $rec1,
- recordType => 'grs.perl.pod',
- groupName => "demo1",
+ recordType => 'grs.perl.pod'
);
my $stat = $sess->end_trans;