-
-if ( not $noaction) {
- if ( $mybranch ) { #yep, we received a specific branch to work on.
- $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
- my $query=qq|UPDATE borrowers
- SET guarantorid ='0',
- categorycode =?
- WHERE dateofbirth<=?
- AND dateofbirth!='0000-00-00'
- AND branchcode=?
- AND categorycode IN (select categorycode from categories where category_type='C' and categorycode=?)|;
- my $sth=$dbh->prepare($query);
- my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat ) or die "can't execute";
- if ($res eq '0E0') { print "No patrons updated\n";
- } else { print "Updated $res patrons\n"; }
- } else { # branch was not supplied, processing all branches
- $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
- my $query=qq|UPDATE borrowers
- SET guarantorid ='0',
- categorycode =?
- WHERE dateofbirth<=?
- AND dateofbirth!='0000-00-00'
- AND categorycode IN (select categorycode from categories where category_type='C' and categorycode=?)|;
- my $sth=$dbh->prepare($query);
- my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat ) or die "can't execute";
- if ($res eq '0E0') { print "No patrons updated\n";
- } else { print "Updated $res patrons\n"; }
- }
-} else {
- my $birthday;
- if ( $mybranch ) {
- $verbose and print "Displaying patrons that would be updated from $fromcat to $tocat from $mybranch\n";
- my $query=qq|SELECT firstname,
- surname,
- cardnumber,
- dateofbirth
- FROM borrowers
- WHERE dateofbirth<=?
- AND dateofbirth!='0000-00-00'
- AND branchcode=?
- AND categorycode IN (select categorycode from categories where category_type='C' and categorycode=?)|;
- my $sth=$dbh->prepare( $query );
- $sth->execute( $itsyourbirthday, $mybranch, $fromcat )
- or die "Couldn't execute statement: " . $sth->errstr;
- while ( my @res = $sth->fetchrow_array()) {
- my $firstname = $res[0];
- my $surname = $res[1];
- my $barcode = $res[2];
- $birthday = $res[3];
- print "$firstname $surname $barcode $birthday\n";
- }
- } else {
- $verbose and print "Displaying patrons that would be updated from $fromcat to $tocat.\n";
- my $query=qq|SELECT firstname,
- surname,
- cardnumber,
- dateofbirth
- FROM borrowers
- WHERE dateofbirth<=?
- AND dateofbirth!='0000-00-00'
- AND categorycode IN (select categorycode from categories where category_type='C' and categorycode=?)|;
- my $sth=$dbh->prepare( $query );
- $sth->execute( $itsyourbirthday, $fromcat )
- or die "Couldn't execute statement: " . $sth->errstr;
- while ( my @res = $sth->fetchrow_array()) {
- my $firstname = $res[0];
- my $surname = $res[1];
- my $barcode = $res[2];
- $birthday = $res[3];
- print "$firstname $surname $barcode $birthday\n";
- }
- }
- $sth->finish( );
+if ( not $noaction ) {
+ if ($mybranch) { #yep, we received a specific branch to work on.
+ $verbose and print "Looking for patrons of $mybranch to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
+ my $query = qq|
+ UPDATE borrowers
+ SET guarantorid ='0',
+ categorycode = ?
+ WHERE dateofbirth <= ?
+ AND dateofbirth != '0000-00-00'
+ AND branchcode = ?
+ AND categorycode IN (
+ SELECT categorycode
+ FROM categories
+ WHERE category_type = 'C'
+ AND categorycode = ?
+ )|;
+ my $sth = $dbh->prepare($query);
+ my $res = $sth->execute( $tocat, $itsyourbirthday, $mybranch, $fromcat )
+ or die "can't execute";
+
+ if ( $res eq '0E0' ) {
+ print "No patrons updated\n";
+ }
+ else {
+ print "Updated $res patrons\n";
+ }
+ }
+ else { # branch was not supplied, processing all branches
+ $verbose and print "Looking in all branches for patrons to update from $fromcat to $tocat that were born before $itsyourbirthday\n";
+ my $query = qq|
+ UPDATE borrowers
+ SET guarantorid = '0',
+ categorycode = ?
+ WHERE dateofbirth <= ?
+ AND dateofbirth!='0000-00-00'
+ AND categorycode IN (
+ SELECT categorycode
+ FROM categories
+ WHERE category_type = 'C'
+ AND categorycode = ?
+ )|;
+ my $sth = $dbh->prepare($query);
+ my $res = $sth->execute( $tocat, $itsyourbirthday, $fromcat )
+ or die "can't execute";
+
+ if ( $res eq '0E0' ) {
+ print "No patrons updated\n";
+ }
+ else {
+ print "Updated $res patrons\n";
+ }
+ }
+}
+else {
+ my $birthday;
+ if ($mybranch) {
+ $verbose and print "Displaying patrons that would be updated from $fromcat to $tocat from $mybranch\n";
+ my $query = qq|
+ SELECT firstname,
+ surname,
+ cardnumber,
+ dateofbirth
+ FROM borrowers
+ WHERE dateofbirth <= ?
+ AND dateofbirth != '0000-00-00'
+ AND branchcode = ?
+ AND categorycode IN (
+ SELECT categorycode
+ FROM categories
+ WHERE category_type = 'C'
+ AND categorycode = ?
+ )
+ |;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $itsyourbirthday, $mybranch, $fromcat )
+ or die "Couldn't execute statement: " . $sth->errstr;
+
+ while ( my @res = $sth->fetchrow_array() ) {
+ my $firstname = $res[0];
+ my $surname = $res[1];
+ my $barcode = $res[2];
+ $birthday = $res[3];
+ print "$firstname $surname $barcode $birthday\n";
+ }
+ }
+ else {
+ $verbose and print "Displaying patrons that would be updated from $fromcat to $tocat.\n";
+ my $query = qq|
+ SELECT firstname,
+ surname,
+ cardnumber,
+ dateofbirth
+ FROM borrowers
+ WHERE dateofbirth <= ?
+ AND dateofbirth != '0000-00-00'
+ AND categorycode IN (
+ SELECT categorycode
+ FROM categories
+ WHERE category_type = 'C'
+ AND categorycode = ?
+ )
+ |;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $itsyourbirthday, $fromcat )
+ or die "Couldn't execute statement: " . $sth->errstr;
+
+ while ( my @res = $sth->fetchrow_array() ) {
+ my $firstname = $res[0];
+ my $surname = $res[1];
+ my $barcode = $res[2];
+ $birthday = $res[3];
+ print "$firstname $surname $barcode $birthday\n";
+ }
+ }