X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=perl%2Flib%2FIDZebra%2FSession.pm;h=a98a2326df5bb6017eb0b64eb75abd6768339c1d;hp=258ffc5bdf30bb30504e3690e095f7deeb36187a;hb=52551bf774d771a0422a401946fd0c5ee3788f34;hpb=2ebb686ca09ee2e128f4db3fb418d4846991b6a0 diff --git a/perl/lib/IDZebra/Session.pm b/perl/lib/IDZebra/Session.pm index 258ffc5..a98a232 100644 --- a/perl/lib/IDZebra/Session.pm +++ b/perl/lib/IDZebra/Session.pm @@ -1,4 +1,4 @@ -# $Id: Session.pm,v 1.14 2003-03-12 17:08:53 pop Exp $ +# $Id: Session.pm,v 1.15 2003-03-13 04:25:18 pop Exp $ # # Zebra perl API header # ============================================================================= @@ -15,7 +15,7 @@ BEGIN { use IDZebra::ScanList; use IDZebra::RetrievalRecord; require Exporter; - our $VERSION = do { my @r = (q$Revision: 1.14 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; + our $VERSION = do { my @r = (q$Revision: 1.15 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; our @ISA = qw(IDZebra::Logger Exporter); our @EXPORT = qw (TRANS_RW TRANS_RO); } @@ -451,6 +451,12 @@ sub _update_args { # ----------------------------------------------------------------------------- # Per record update # ----------------------------------------------------------------------------- +sub insert_record { + my ($self, %args) = @_; + $self->checkzh; + return(IDZebra::insert_record($self->{zh}, + $self->_record_update_args(%args))); +} sub update_record { my ($self, %args) = @_; @@ -540,7 +546,7 @@ sub cql2pqf { 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); @@ -950,15 +956,36 @@ where sysno in itself is sufficient to identify the record 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 member of the record group, or in the I 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 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 I1> 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 method: + + $sysno = $sess->insert_record(data => $rec1, + recordType => 'grs.perl.pod', + groupName => "demo1"); -B 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 setting). =head1 DATABASE SELECTION