Print

Print


Hi Nate,

I've just started playing around with this a bit myself, although I have
to confess that it's quite recent and a hack.  But here's what I've been
doing.

Due to consortium issues and the like here's the track I'm taking.  I'm
using Perl, since I haven't yet started playing with Ruby.  I know, I
know, lame ;).

First, I run a query to grab the bib ids/mfhd ids of some groups of
records that I'm interested in.  I'm going for a smaller set probably,
since our whole collection is rather large.  Then I run it through a small
script that runs a query (where $recordtype = BIB or MFHD)

my $qry  = "SELECT ".$recordtype."_DATA.".$recordtype."_id,
record_segment, "
   . "seqnum FROM UIUDB.".$recordtype."_DATA "
   . "  WHERE ".$recordtype."_DATA.".$recordtype."_ID = ? "
   . "  ORDER BY seqnum ASC " ;


with the ? set to the id.  The results are merged into one string.  This
is used to create a MARC::Record object.  I add this to a MARC::File::XML
object.

I have in some notes that I need to pad out the bib records when using
this method, but I'm not sure why.  I'm not currently duing that
and it hasn't caused any issues yet.

That's it ;).  Gives me some nice marcxml.  And I haven't tested it at all
yet, just started playing around with it.


I've included some of the code below.  Like I said, I just came up with
this really quickly, haven't had a chance to really test it heavily yet.


use strict;
use DBI;
use MARC::Record;
use MARC::file::XML;
use Getopt::Std;

# set the database connection options
#removed :P

my %opts;

getopt('ft',\%opts);

my $recordtype="BIB";
if (uc($opts{'t'}) eq "MFHD" ) {
   $recordtype="MFHD";
}

#need to change so can take from command line
if ($opts{'f'}) {
open(IDS,"< ".$opts{'f'}) or die "must set -f input ids";
}

my $qry  = "SELECT ".$recordtype."_DATA.".$recordtype."_id,
record_segment, "
   . "seqnum FROM UIUDB.".$recordtype."_DATA "
   . "  WHERE ".$recordtype."_DATA.".$recordtype."_ID = ? "
   . "  ORDER BY seqnum ASC " ;
my $sth = $dbh->prepare($qry) or die "preparing SQL query $qry.";


my $file = MARC::File::XML->out( $recordtype.'records.xml'  );



while (<IDS>) {
   chomp;
   s/ *$//;
   s/^ *//;
   my $id = $_;
   my $MARC = "";


   $sth->execute($id);
   while (my ($rec_id, $recseg, $seqnum) = $sth->fetchrow_array) {
     $MARC .= $recseg ;
     #not sure that the below is needed...there is some
     #sort of issue with the "last" record, maybe?
     #  $MARC .= ' ' x (990-length($recseg)); # Pad each segment to 990
chars.
   }


   $sth->finish;

   my $record = MARC::Record->new_from_usmarc($MARC);
   $file->write($record);



}

$file->close();



Jonathan T. Gorman
Research Information Specialist
University of Illinois at Champaign-Urbana
216 Main Library - MC522
1408 West Gregory Drive
Urbana, IL 61801
Phone: (217) 244-4688