From abef50d0fdd694be84b711c5562c3085136ff3fa Mon Sep 17 00:00:00 2001 From: amillar Date: Fri, 31 May 2002 05:33:34 +0000 Subject: [PATCH] Error handling in biblio/biblioitem addition --- acqui.simple/marcimport.pl | 200 +++++++++++++++++++++---------------- 1 file changed, 112 insertions(+), 88 deletions(-) diff --git a/acqui.simple/marcimport.pl b/acqui.simple/marcimport.pl index 30f04ca5e5..3a793fd003 100755 --- a/acqui.simple/marcimport.pl +++ b/acqui.simple/marcimport.pl @@ -231,6 +231,7 @@ if (my $data=$input->param('uploadmarc')) { if ($input->param('insertnewrecord')) { + my $sth; my $isbn=$input->param('isbn'); my $issn=$input->param('issn'); my $lccn=$input->param('lccn'); @@ -241,8 +242,9 @@ if ($input->param('insertnewrecord')) { my $q_isbn=$dbh->quote((($isbn) || ('NIL'))); my $q_issn=$dbh->quote((($issn) || ('NIL'))); my $q_lccn=$dbh->quote((($lccn) || ('NIL'))); - my $sth=$dbh->prepare("insert into marcrecorddone values ($q_origisbn, $q_origissn, $q_origlccn, $q_origcontrolnumber)"); - $sth->execute; + + #my $sth=$dbh->prepare("insert into marcrecorddone values ($q_origisbn, $q_origissn, $q_origlccn, $q_origcontrolnumber)"); + #$sth->execute; my $sth=$dbh->prepare("select biblionumber,biblioitemnumber from biblioitems where issn=$q_issn or isbn=$q_isbn or lccn=$q_lccn"); $sth->execute; my $biblionumber=0; @@ -316,16 +318,19 @@ EOF \@additionalauthors ); - - - my $title=$input->param('title'); - print << "EOF"; - - - -
Record entered into database
$title has been entered into the database with biblionumber - $biblionumber and biblioitemnumber $biblioitemnumber
+ if ( $error ) { + print "

Error adding biblio item

$error\n"; + } else { + + my $title=$input->param('title'); + print << "EOF"; + + + +
Record entered into database
$title has been entered into the database with biblionumber + $biblionumber and biblioitemnumber $biblioitemnumber
EOF + } # if error } # if new record my $title=$input->param('title'); @@ -398,74 +403,85 @@ sub NewBiblioItem { "ISBN=$biblioitem->{isbn} \n" if $debug; # Make sure master biblio entry exists - $biblionumber=GetOrAddBiblio($dbh, $biblio); + ($biblionumber,$error)=GetOrAddBiblio($dbh, $biblio); - # Get next biblioitemnumber - $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems"); - $sth->execute; - ($biblioitemnumber) = $sth->fetchrow; - $biblioitemnumber++; - - print "
Next biblio item is $biblioitemnumber
\n" if $debug; - - $sth=$dbh->prepare("insert into biblioitems ( - biblioitemnumber, - biblionumber, - volume, - number, - itemtype, - isbn, - issn, - dewey, - subclass, - publicationyear, - publishercode, - volumedate, - volumeddesc, - illus, - pages, - notes, - size, - place, - lccn, - marc) - values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" ); + if ( ! $error ) { + # Get next biblioitemnumber + $sth=$dbh->prepare("select max(biblioitemnumber) from biblioitems"); + $sth->execute; + ($biblioitemnumber) = $sth->fetchrow; + $biblioitemnumber++; - $sth->execute( - $biblioitemnumber, - $biblionumber, - $biblioitem->{volume}, - $biblioitem->{number}, - $biblioitem->{itemtype}, - $biblioitem->{isbn}, - $biblioitem->{issn}, - $biblioitem->{dewey}, - $biblioitem->{subclass}, - $biblioitem->{publicationyear}, - $biblioitem->{publishercode}, - $biblioitem->{volumedate}, - $biblioitem->{volumeddesc}, - $biblioitem->{illus}, - $biblioitem->{pages}, - $biblioitem->{notes}, - $biblioitem->{size}, - $biblioitem->{place}, - $biblioitem->{lccn}, - $biblioitem->{marc} ); - - $sth=$dbh->prepare("insert into bibliosubject + print "
Next biblio item is $biblioitemnumber
\n" if $debug; + + $sth=$dbh->prepare("insert into biblioitems ( + biblioitemnumber, + biblionumber, + volume, + number, + itemtype, + isbn, + issn, + dewey, + subclass, + publicationyear, + publishercode, + volumedate, + volumeddesc, + illus, + pages, + notes, + size, + place, + lccn, + marc) + values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" ); + + $sth->execute( + $biblioitemnumber, + $biblionumber, + $biblioitem->{volume}, + $biblioitem->{number}, + $biblioitem->{itemtype}, + $biblioitem->{isbn}, + $biblioitem->{issn}, + $biblioitem->{dewey}, + $biblioitem->{subclass}, + $biblioitem->{publicationyear}, + $biblioitem->{publishercode}, + $biblioitem->{volumedate}, + $biblioitem->{volumeddesc}, + $biblioitem->{illus}, + $biblioitem->{pages}, + $biblioitem->{notes}, + $biblioitem->{size}, + $biblioitem->{place}, + $biblioitem->{lccn}, + $biblioitem->{marc} ) or $error.=$sth->errstr ; + + $sth=$dbh->prepare("insert into bibliosubject (biblionumber,subject) values (?, ? )" ); - foreach $subjectheading (@{$subjects} ) { - $sth->execute($biblionumber, $subjectheading); - } + foreach $subjectheading (@{$subjects} ) { + $sth->execute($biblionumber, $subjectheading) + or $error.=$sth->errstr ; + + } # foreach subject - $sth=$dbh->prepare("insert into additionalauthors + $sth=$dbh->prepare("insert into additionalauthors (biblionumber,author) values (?, ? )"); - foreach $additionalauthor (@{$addlauthors} ) { - $sth->execute($biblionumber, $additionalauthor); - } + foreach $additionalauthor (@{$addlauthors} ) { + $sth->execute($biblionumber, $additionalauthor) + or $error.=$sth->errstr ; + } # foreach author + + } else { + # couldn't get biblio + $biblionumber=''; + $biblioitemnumber=''; + + } # if no biblio error return ( $biblionumber, $biblioitemnumber, $error); @@ -486,6 +502,7 @@ sub GetOrAddBiblio { my $debug=1; my $sth; + my $error; #----- print "
Looking for biblio 
\n" if $debug; @@ -502,9 +519,15 @@ sub GetOrAddBiblio { } else { # Doesn't exist. Add new one. print "
Adding biblio
\n" if $debug; - $biblionumber=&newbiblio($biblio); - print "
Added with biblio number $biblionumber
\n" if $debug; - &newsubtitle($biblionumber,$biblio->{subtitle} ); + ($biblionumber,$error)=&newbiblio($biblio); + if ( $biblionumber ) { + print "
Added with biblio number=$biblionumber
\n" if $debug; + if ( $biblio->{subtitle} ) { + &newsubtitle($biblionumber,$biblio->{subtitle} ); + } # if subtitle + } else { + print "
Couldn't add biblio: $error
\n" if $debug; + } # if added } return $biblionumber; @@ -539,7 +562,7 @@ if ($input->param('newitem')) { print "Error: $error

\n"; } else { - print "Item added with barcode $barcode + print "Item added with barcode $barcode

\n"; } # if error } # if barcode exists @@ -548,6 +571,7 @@ if ($input->param('newitem')) { my $menu = $input->param('menu'); if ($file) { + my $sth; print "Main Menu


\n"; my $qisbn=$input->param('isbn'); my $qissn=$input->param('issn'); @@ -1021,12 +1045,12 @@ EOF my $q_issn=$dbh->quote((($issn) || ('NIL'))); my $q_lccn=$dbh->quote((($lccn) || ('NIL'))); my $q_controlnumber=$dbh->quote((($controlnumber) || ('NIL'))); - my $sth=$dbh->prepare("select * from marcrecorddone where isbn=$q_isbn or issn=$q_issn or lccn=$q_lccn or controlnumber=$q_controlnumber"); - $sth->execute; - my $donetext=''; - if ($sth->rows) { - $donetext="DONE"; - } + #my $sth=$dbh->prepare("select * from marcrecorddone where isbn=$q_isbn or issn=$q_issn or lccn=$q_lccn or controlnumber=$q_controlnumber"); + #$sth->execute; + #my $donetext=''; + #if ($sth->rows) { + # $donetext="DONE"; + #} $sth=$dbh->prepare("select * from biblioitems where isbn=$q_isbn or issn=$q_issn or lccn=$q_lccn"); $sth->execute; if ($sth->rows) { @@ -1109,12 +1133,12 @@ EOF my $q_issn=$dbh->quote((($issn) || ('NIL'))); my $q_lccn=$dbh->quote((($lccn) || ('NIL'))); my $q_controlnumber=$dbh->quote((($controlnumber) || ('NIL'))); - my $sth=$dbh->prepare("select * from marcrecorddone where isbn=$q_isbn or issn=$q_issn or lccn=$q_lccn or controlnumber=$q_controlnumber"); - $sth->execute; - my $donetext=''; - if ($sth->rows) { - $donetext="DONE"; - } + #my $sth=$dbh->prepare("select * from marcrecorddone where isbn=$q_isbn or issn=$q_issn or lccn=$q_lccn or controlnumber=$q_controlnumber"); + #$sth->execute; + #my $donetext=''; + #if ($sth->rows) { + # $donetext="DONE"; + #} $sth=$dbh->prepare("select * from biblioitems where isbn=$q_isbn or issn=$q_issn or lccn=$q_lccn"); $sth->execute; if ($sth->rows) { -- 2.39.5