Ed et all,
I've run into a strange problem with a Z3950 server that I wrote using
Indexdata's SimpleServer module. The Z-Server is for the Koha Library
System and I use a subroutine in Koha called MARCgetbiblio to generate
MARC records (MARCgetbiblio uses MARC::Record) that I put into a string
and send off to the Z-client via SimpleServer's built-in hash $args->{RECORD}.
Everything seemed to be working fine while I was using my copy of Bookwhere
as the Z-Client; but when I tried to use the Yaz client to connect to my
server I get the following error when retrieving the MARC records:
Z> show 1
Sent presentRequest (1+1).
Records: 1
[]Record type: USmarc
001
<!-- no separator at end of field -->
000
<!-- no separator at end of field -->
700
<!-- no separator at end of field -->
(...snip)
In fact, a number of Z-clients have this same problem when attempting to
retrieve records from my Z-Server.
When I print the string to the Z-Server log (which is printed on the
terminal that the server was executed from) the separators are also missing.
However, if I dump the MARC string into a file before it gets passed to the
SimpleServer hash, the seperators are there and a MARC-testing program called
dumpmarc.pl says that the records are fine. Also, I can see ^s in the file when
I open it in vi that aren't there in the Z-Server screen log.
The Z-Server can be reached at: koha.athenscounty.lib.oh.us:9999 (no database
name necessary).
Could it be that the encoding is somehow wrong? Is there something unique
about MARC separators?
I'm out of ideas...any suggestions? I've attached sample records in both
formats (with and without separators) as well as my fetch_handler code and
Koha's MARCgetbiblio subroutine.
Thanks,
Joshua Ferraro
Nelsonville Public Library
Record with separators:
00786 00265 00100070000000300050000700500170001200800410002901000130
00700200021000830350013001040900017001171000024001342450062001582500012002202600
05300232300003500285440002500320500003100345500002000376650003700396700002300433
942002500456952003900481^^128616^^ACLS^^20030516103009.0^^970724s1997 caua
001 0 eng d^^ ^_a97208359^^ ^_a1565922840 (pa.)^^ ^_a97208359^^ ^_c99
294^_d99294^^1 ^_aSchwartz, Randal L.^^10^_aLearning Perl /^_cRandal L. Schwartz
and Tom Christiansen.^^ ^_a2nd ed.^^ ^_aSebastopol, CA :^_bO'Reilly & Associa
tes,^_cc1997.^^ ^_axxix, 269 p. :^_bill. ;^_c24 cm.^^ 2^_aA Nutshell handbook.^
^ ^_a"Unix programming"--Cover.^^ ^_aIncludes index.^^ 0^_aPerl (Computer prog
ram language)^^1 ^_aChristiansen, Tom.^^ ^_aACLS^_cNF^_k005.133 Sc^^ ^_bAPL^_p
32000000095485^_r29.95^_u208596^^^]
Same record without separators:
00786 00265
001000700000003000500007005001700012008004100029010001300070020002100083035001300104090001700117100002400134245006200158250001200220260005300232300003500285440002500320500003100345500002000376650003700396700002300433942002500456952003900481128616ACLS20030516103009.0970724s1997
caua 001 0 eng d a97208359 a1565922840 (pa.) a97208359 c99294d992941
aSchwartz, Randal L.10aLearning Perl /cRandal L. Schwartz and Tom Christiansen. a2nd
ed. aSebastopol, CA :bO'Reilly & Associates,cc1997. axxix, 269 p. :bill. ;c24 cm.
2aA Nutshell handbook. a"Unix programming"--Cover. aIncludes index. 0aPerl (Computer
program language)1 aChristiansen, Tom. aACLScNFk005.133 Sc
bAPLp32000000095485r29.95u208596
Here's my Z-Server fetch_handler which calls the MARCgetbiblio subroutine
and then places the resulting MARC record into a string and passes it to
SimpleServer's hash function (and off it goes to the client).
sub fetch_handler {
my ($args) = @_;
# warn "in fetch_handler"; ## troubleshooting
my $offset = $args->{OFFSET};
$offset -= 1; ## $args->{OFFSET} starts on 0
## Set the bibid to be used
chomp (my $bibid = $bib_list[$offset]);
my $MARCRecord = &MARCgetbiblio($dbh,$bibid);
my $recordstring=$MARCRecord->as_usmarc();
## Print MARC record to the Z-Server log
print "here is my record: $recordstring\n";
## Dump MARC record to a file
use Data::Dumper;
Dumper $recordstring;
open (MARC, ">/root/marc.dump");
print MARC "$recordstring";
close MARC;
## Return the record string to the client
$args->{RECORD} = $recordstring;
}
Here's the MARCgetbiblio subroutine:
sub MARCgetbiblio {
# Returns MARC::Record of the biblio passed in parameter.
my ($dbh,$bibid)[EMAIL PROTECTED];
my $record = MARC::Record->new();
#---- TODO : the leader is missing
$record->leader(' ');
my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,su
bfieldcode,subfieldorder,subfieldvalue,valuebloblink
from marc_subfield_table
where bibid=? order by tag,tagorder,subfieldcod
e
");
my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield whe
re blobidlink=?");
$sth->execute($bibid);
my $prevtagorder=1;
my $prevtag='XXX';
my $previndicator;
my $field; # for >=10 tags
my $prevvalue; # for <10 tags
while (my $row=$sth->fetchrow_hashref) {
if ($row->{'valuebloblink'}) { #---- search blob if there is one
$sth2->execute($row->{'valuebloblink'});
my $row2=$sth2->fetchrow_hashref;
$sth2->finish;
$row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
}
if ($row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag
) {
$previndicator.=" ";
if ($prevtag <10) {
$record->add_fields((sprintf "%03s",$prevtag),$prevvalue
) unless $prevtag eq "XXX"; # ignore the 1st loop
} else {
$record->add_fields($field) unless $prevtag eq "
XXX";
}
undef $field;
$prevtagorder=$row->{tagorder};
$prevtag = $row->{tag};
$previndicator=$row->{tag_indicator};
if ($row->{tag}<10) {
$prevvalue = $row->{subfieldvalue};
} else {
$field = MARC::Field->new((sprintf "%03s",$prevt
ag), substr($row->{tag_indicator}.' ',0,1), substr($row->{tag_indicator}.' ',1
,1), $row->{'subfieldcode'}, $row->{'subfieldvalue'} );
}
} else {
if ($row->{tag} <10) {
$record->add_fields((sprintf "%03s",$row->{tag})
, $row->{'subfieldvalue'});
} else {
$field->add_subfields($row->{'subfieldcode'}, $r
ow->{'subfieldvalue'} );
}
$prevtag= $row->{tag};
$previndicator=$row->{tag_indicator};
}
}
# the last has not been included inside the loop... do it now !
if ($prevtag <10) {
$record->add_fields($prevtag,$prevvalue);
} else {
# my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
$record->add_fields($field);
}
return $record;
}