From: pop Date: Mon, 7 Jul 2003 10:59:33 +0000 (+0000) Subject: Zebra perl API following changes in zebraapi.c/.h (all functions returning X-Git-Tag: ZEBRA.1.3.12~21 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=8c703765dad3228649e340337b293f76603ca9de;p=idzebra-moved-to-github.git Zebra perl API following changes in zebraapi.c/.h (all functions returning an int status). Now it's compatible, but return status is not yet implemented in all case. --- diff --git a/perl/IDZebra.i b/perl/IDZebra.i index 2881661..0cf0ca7 100644 --- a/perl/IDZebra.i +++ b/perl/IDZebra.i @@ -289,11 +289,12 @@ void zebra_repository_show (ZebraHandle zh); If not, and match_criteria is provided, then sysno is guessed If not, and a record is provided, then sysno is got from there */ +%apply int *REFERENCE { int *sysno }; %name(insert_record) int zebra_insert_record (ZebraHandle zh, recordGroup *rGroup, const char *recordType, - int sysno, + int *sysno, const char *match, const char *fname, const char *buf, @@ -304,7 +305,7 @@ int zebra_insert_record (ZebraHandle zh, int zebra_update_record (ZebraHandle zh, recordGroup *rGroup, const char *recordType, - int sysno, + int *sysno, const char *match, const char *fname, const char *buf, @@ -315,7 +316,7 @@ int zebra_update_record (ZebraHandle zh, int zebra_delete_record (ZebraHandle zh, recordGroup *rGroup, const char *recordType, - int sysno, + int *sysno, const char *match, const char *fname, const char *buf, @@ -324,11 +325,13 @@ int zebra_delete_record (ZebraHandle zh, /* == Search (zebraapi.c) ================================================== */ - +%include "typemaps.i" +%apply int *REFERENCE { int *hits }; %name(search_PQF) int zebra_search_PQF (ZebraHandle zh, const char *pqf_query, - const char *setname); + const char *setname, + int *hits); /* == YAZ - query tools ==================================================== */ @@ -371,7 +374,8 @@ int zebra_deleleResultSet(ZebraHandle zh, int function, /* == Sort ================================================================= */ -int sort (ZebraHandle zh, +%name(sort) +int zebra_sort_by_specstr (ZebraHandle zh, ODR stream, const char *sort_spec, const char *output_setname, @@ -387,6 +391,10 @@ void zebra_scan_PQF (ZebraHandle zh, scanEntry *getScanEntry(ScanObj *so, int pos); +%typemap(in) int * (int dvalue); +%typemap(argout) int *; + + /* Admin functionality */ /* %name(admin_start) void zebra_admin_start (ZebraHandle zh); diff --git a/perl/IDZebra_wrap.c b/perl/IDZebra_wrap.c index eab4a79..cbf5b83 100644 --- a/perl/IDZebra_wrap.c +++ b/perl/IDZebra_wrap.c @@ -212,7 +212,7 @@ SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { * perl5.swg * * Perl5 runtime library - * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.18 2003-05-21 08:03:02 pop Exp $ + * $Header: /home/cvsroot/idis/perl/Attic/IDZebra_wrap.c,v 1.19 2003-07-07 10:59:33 pop Exp $ * ----------------------------------------------------------------------------- */ #define SWIGPERL @@ -4031,14 +4031,16 @@ XS(_wrap_insert_record) { ZebraHandle arg1 ; recordGroup *arg2 ; char *arg3 ; - int arg4 ; + int *arg4 ; char *arg5 ; char *arg6 ; char *arg7 ; int arg8 ; int arg9 ; int result; + int dvalue4 ; int argvi = 0; + SV * _saved[1] ; dXSARGS; if ((items < 9) || (items > 9)) { @@ -4058,7 +4060,18 @@ XS(_wrap_insert_record) { } if (!SvOK((SV*) ST(2))) arg3 = 0; else arg3 = (char *) SvPV(ST(2), PL_na); - arg4 = (int) SvIV(ST(3)); + { + SV *tempsv; + if (!SvROK(ST(3))) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV(ST(3)); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue4 = SvIV(tempsv); + arg4 = &dvalue4; + } if (!SvOK((SV*) ST(4))) arg5 = 0; else arg5 = (char *) SvPV(ST(4), PL_na); if (!SvOK((SV*) ST(5))) arg6 = 0; @@ -4067,10 +4080,16 @@ XS(_wrap_insert_record) { else arg7 = (char *) SvPV(ST(6), PL_na); arg8 = (int) SvIV(ST(7)); arg9 = (int) SvIV(ST(8)); + _saved[0] = ST(3); result = (int)zebra_insert_record(arg1,arg2,(char const *)arg3,arg4,(char const *)arg5,(char const *)arg6,(char const *)arg7,arg8,arg9); ST(argvi) = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result); + { + SV *tempsv; + tempsv = SvRV(_saved[0]); + sv_setiv(tempsv, (IV) *arg4); + } XSRETURN(argvi); fail: (void) _swigerr; @@ -4086,14 +4105,16 @@ XS(_wrap_update_record) { ZebraHandle arg1 ; recordGroup *arg2 ; char *arg3 ; - int arg4 ; + int *arg4 ; char *arg5 ; char *arg6 ; char *arg7 ; int arg8 ; int arg9 ; int result; + int dvalue4 ; int argvi = 0; + SV * _saved[1] ; dXSARGS; if ((items < 9) || (items > 9)) { @@ -4113,7 +4134,18 @@ XS(_wrap_update_record) { } if (!SvOK((SV*) ST(2))) arg3 = 0; else arg3 = (char *) SvPV(ST(2), PL_na); - arg4 = (int) SvIV(ST(3)); + { + SV *tempsv; + if (!SvROK(ST(3))) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV(ST(3)); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue4 = SvIV(tempsv); + arg4 = &dvalue4; + } if (!SvOK((SV*) ST(4))) arg5 = 0; else arg5 = (char *) SvPV(ST(4), PL_na); if (!SvOK((SV*) ST(5))) arg6 = 0; @@ -4122,10 +4154,16 @@ XS(_wrap_update_record) { else arg7 = (char *) SvPV(ST(6), PL_na); arg8 = (int) SvIV(ST(7)); arg9 = (int) SvIV(ST(8)); + _saved[0] = ST(3); result = (int)zebra_update_record(arg1,arg2,(char const *)arg3,arg4,(char const *)arg5,(char const *)arg6,(char const *)arg7,arg8,arg9); ST(argvi) = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result); + { + SV *tempsv; + tempsv = SvRV(_saved[0]); + sv_setiv(tempsv, (IV) *arg4); + } XSRETURN(argvi); fail: (void) _swigerr; @@ -4141,14 +4179,16 @@ XS(_wrap_delete_record) { ZebraHandle arg1 ; recordGroup *arg2 ; char *arg3 ; - int arg4 ; + int *arg4 ; char *arg5 ; char *arg6 ; char *arg7 ; int arg8 ; int arg9 ; int result; + int dvalue4 ; int argvi = 0; + SV * _saved[1] ; dXSARGS; if ((items < 9) || (items > 9)) { @@ -4168,7 +4208,18 @@ XS(_wrap_delete_record) { } if (!SvOK((SV*) ST(2))) arg3 = 0; else arg3 = (char *) SvPV(ST(2), PL_na); - arg4 = (int) SvIV(ST(3)); + { + SV *tempsv; + if (!SvROK(ST(3))) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV(ST(3)); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue4 = SvIV(tempsv); + arg4 = &dvalue4; + } if (!SvOK((SV*) ST(4))) arg5 = 0; else arg5 = (char *) SvPV(ST(4), PL_na); if (!SvOK((SV*) ST(5))) arg6 = 0; @@ -4177,10 +4228,16 @@ XS(_wrap_delete_record) { else arg7 = (char *) SvPV(ST(6), PL_na); arg8 = (int) SvIV(ST(7)); arg9 = (int) SvIV(ST(8)); + _saved[0] = ST(3); result = (int)zebra_delete_record(arg1,arg2,(char const *)arg3,arg4,(char const *)arg5,(char const *)arg6,(char const *)arg7,arg8,arg9); ST(argvi) = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result); + { + SV *tempsv; + tempsv = SvRV(_saved[0]); + sv_setiv(tempsv, (IV) *arg4); + } XSRETURN(argvi); fail: (void) _swigerr; @@ -4196,12 +4253,15 @@ XS(_wrap_search_PQF) { ZebraHandle arg1 ; char *arg2 ; char *arg3 ; + int *arg4 ; int result; + int dvalue4 ; int argvi = 0; + SV * _saved[1] ; dXSARGS; - if ((items < 3) || (items > 3)) { - SWIG_croak("Usage: search_PQF(zh,pqf_query,setname);"); + if ((items < 4) || (items > 4)) { + SWIG_croak("Usage: search_PQF(zh,pqf_query,setname,hits);"); } { ZebraHandle * argp; @@ -4214,10 +4274,28 @@ XS(_wrap_search_PQF) { else arg2 = (char *) SvPV(ST(1), PL_na); if (!SvOK((SV*) ST(2))) arg3 = 0; else arg3 = (char *) SvPV(ST(2), PL_na); - result = (int)zebra_search_PQF(arg1,(char const *)arg2,(char const *)arg3); + { + SV *tempsv; + if (!SvROK(ST(3))) { + SWIG_croak("expected a reference"); + } + tempsv = SvRV(ST(3)); + if (!SvIOK(tempsv)) { + SWIG_croak("expected a integer reference"); + } + dvalue4 = SvIV(tempsv); + arg4 = &dvalue4; + } + _saved[0] = ST(3); + result = (int)zebra_search_PQF(arg1,(char const *)arg2,(char const *)arg3,arg4); ST(argvi) = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result); + { + SV *tempsv; + tempsv = SvRV(_saved[0]); + sv_setiv(tempsv, (IV) *arg4); + } XSRETURN(argvi); fail: (void) _swigerr; @@ -4605,7 +4683,7 @@ XS(_wrap_sort) { } arg5[i] = NULL; } - result = (int)sort(arg1,arg2,(char const *)arg3,(char const *)arg4,(char const **)arg5); + result = (int)zebra_sort_by_specstr(arg1,arg2,(char const *)arg3,(char const *)arg4,(char const **)arg5); ST(argvi) = sv_newmortal(); sv_setiv(ST(argvi++), (IV) result); @@ -5280,11 +5358,9 @@ XS(_wrap_data1_nodetogr) { arg4 = *argp; } { - int i; - if (!SvIOK(ST(4))) - croak("Argument 5 is not an integer."); - i = SvIV(ST(4)); - arg5 = &i; + if (SWIG_ConvertPtr(ST(4), (void **) &arg5, SWIGTYPE_p_int,0) < 0) { + SWIG_croak("Type error in argument 5 of data1_nodetogr. Expected _p_int"); + } } result = (Z_GenericRecord *)data1_nodetogr(arg1,arg2,arg3,arg4,arg5); @@ -5402,11 +5478,9 @@ XS(_wrap_data1_nodetobuf) { } arg3 = (int) SvIV(ST(2)); { - int i; - if (!SvIOK(ST(3))) - croak("Argument 4 is not an integer."); - i = SvIV(ST(3)); - arg4 = &i; + if (SWIG_ConvertPtr(ST(3), (void **) &arg4, SWIGTYPE_p_int,0) < 0) { + SWIG_croak("Type error in argument 4 of data1_nodetobuf. Expected _p_int"); + } } result = (char *)data1_nodetobuf(arg1,arg2,arg3,arg4); @@ -6978,11 +7052,9 @@ XS(_wrap_data1_nodetomarc) { } arg4 = (int) SvIV(ST(3)); { - int i; - if (!SvIOK(ST(4))) - croak("Argument 5 is not an integer."); - i = SvIV(ST(4)); - arg5 = &i; + if (SWIG_ConvertPtr(ST(4), (void **) &arg5, SWIGTYPE_p_int,0) < 0) { + SWIG_croak("Type error in argument 5 of data1_nodetomarc. Expected _p_int"); + } } result = (char *)data1_nodetomarc(arg1,arg2,arg3,arg4,arg5); @@ -7029,11 +7101,9 @@ XS(_wrap_data1_nodetoidsgml) { } arg3 = (int) SvIV(ST(2)); { - int i; - if (!SvIOK(ST(3))) - croak("Argument 4 is not an integer."); - i = SvIV(ST(3)); - arg4 = &i; + if (SWIG_ConvertPtr(ST(3), (void **) &arg4, SWIGTYPE_p_int,0) < 0) { + SWIG_croak("Type error in argument 4 of data1_nodetoidsgml. Expected _p_int"); + } } result = (char *)data1_nodetoidsgml(arg1,arg2,arg3,arg4); @@ -7174,11 +7244,9 @@ XS(_wrap_data1_nodetosoif) { } arg3 = (int) SvIV(ST(2)); { - int i; - if (!SvIOK(ST(3))) - croak("Argument 4 is not an integer."); - i = SvIV(ST(3)); - arg4 = &i; + if (SWIG_ConvertPtr(ST(3), (void **) &arg4, SWIGTYPE_p_int,0) < 0) { + SWIG_croak("Type error in argument 4 of data1_nodetosoif. Expected _p_int"); + } } result = (char *)data1_nodetosoif(arg1,arg2,arg3,arg4); diff --git a/perl/lib/IDZebra/Session.pm b/perl/lib/IDZebra/Session.pm index 1283702..ea49deb 100644 --- a/perl/lib/IDZebra/Session.pm +++ b/perl/lib/IDZebra/Session.pm @@ -1,4 +1,4 @@ -# $Id: Session.pm,v 1.17 2003-05-21 08:03:02 pop Exp $ +# $Id: Session.pm,v 1.18 2003-07-07 10:59:33 pop Exp $ # # Zebra perl API header # ============================================================================= @@ -16,7 +16,7 @@ BEGIN { use IDZebra::ScanList; use IDZebra::RetrievalRecord; require Exporter; - our $VERSION = do { my @r = (q$Revision: 1.17 $ =~ /\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); } @@ -455,22 +455,30 @@ sub _update_args { sub insert_record { my ($self, %args) = @_; $self->checkzh; - return(IDZebra::insert_record($self->{zh}, - $self->_record_update_args(%args))); + 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 { @@ -517,7 +525,7 @@ sub _record_update_args { unless ($rectype) { $rectype=""; } - return ($rg, $rectype, $sysno, $match, $fname, $buff, $len, $force); + return ($rg, $rectype, \$sysno, $match, $fname, $buff, $len, $force); } # ----------------------------------------------------------------------------- @@ -615,9 +623,13 @@ sub _new_setname { sub _search_pqf { my ($self, $query, $setname) = @_; - my $hits = IDZebra::search_PQF($self->{zh}, + + my $hits = 0; + + my $res = IDZebra::search_PQF($self->{zh}, $query, - $setname); + $setname, + \$hits); my $rs = IDZebra::Resultset->new($self, name => $setname, diff --git a/perl/t/03_record_update.t b/perl/t/03_record_update.t index e34e844..762c78a 100644 --- a/perl/t/03_record_update.t +++ b/perl/t/03_record_update.t @@ -1,6 +1,6 @@ #!perl # ============================================================================= -# $Id: 03_record_update.t,v 1.5 2003-04-15 20:56:33 pop Exp $ +# $Id: 03_record_update.t,v 1.6 2003-07-07 10:59:33 pop Exp $ # # Perl API header # ============================================================================= @@ -14,7 +14,7 @@ BEGIN { use strict; use warnings; -use Test::More tests => 17; +use Test::More tests => 18; # ---------------------------------------------------------------------------- # Session opening and closing @@ -78,20 +78,21 @@ ok(($sysno < 0),"Inserted record got invalid sysno"); $sess->begin_trans; -$sysno = $sess->update_record(data => $rec2, - recordType => 'grs.perl.pod', - groupName => "demo1", - ); +my $sysno1 = $sess->update_record(data => $rec2, + recordType => 'grs.perl.pod', + groupName => "demo1", + ); -$sysno = $sess->update_record(data => $rec2, - recordType => 'grs.perl.pod', - groupName => "demo1", - ); +my $sysno2 = $sess->update_record(data => $rec2, + recordType => 'grs.perl.pod', + groupName => "demo1", + ); $stat = $sess->end_trans; ok(($stat->{inserted} == 0), "Inserted 0 records"); ok(($stat->{updated} == 1), "Updated $stat->{updated} records"); -ok(($sysno > 0),"Inserted got valid sysno"); +ok(($sysno1 > 0),"Updated record got valid sysno"); +ok(($sysno2 < 0),"Unupdated record got invalid sysno"); $sess->begin_trans; $sysno = $sess->delete_record(data => $rec3,