[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] CVS: koha/C4 Reserves2.pm,1.35,1.36
From: |
MJ Ray |
Subject: |
[Koha-cvs] CVS: koha/C4 Reserves2.pm,1.35,1.36 |
Date: |
Mon, 15 Dec 2003 08:07:38 -0800 |
Update of /cvsroot/koha/koha/C4
In directory sc8-pr-cvs1:/tmp/cvs-serv24769/C4
Modified Files:
Reserves2.pm
Log Message:
DBI call fix for bug 662
Index: Reserves2.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Reserves2.pm,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -r1.35 -r1.36
*** Reserves2.pm 28 Oct 2003 19:34:05 -0000 1.35
--- Reserves2.pm 15 Dec 2003 16:07:36 -0000 1.36
***************
*** 111,114 ****
--- 111,115 ----
# redundancy. Wouldn't it be better to have a @clauses array, add
# one or two clauses as necessary, then join(" AND ", @clauses) ?
+ # FIXME: not keen on quote() and interpolation either, but it looks safe
if ($bib ne ''){
$bib = $dbh->quote($bib);
***************
*** 149,162 ****
# FIXME - What is this if-statement doing? How do constraints
work?
if ($data->{'constrainttype'} eq 'o') {
! my $conquery = "SELECT biblioitemnumber FROM
reserveconstraints
WHERE biblionumber = ?
AND borrowernumber = ?
! AND reservedate = ?";
! my $csth=$dbh->prepare($conquery);
! # FIXME - Why use separate variables for this?
! my $bibn = $data->{'biblionumber'};
! my $born = $data->{'borrowernumber'};
! my $resd = $data->{'reservedate'};
! $csth->execute($bibn, $born, $resd);
my ($bibitemno) = $csth->fetchrow_array;
$csth->finish;
--- 150,158 ----
# FIXME - What is this if-statement doing? How do constraints
work?
if ($data->{'constrainttype'} eq 'o') {
! my $csth=$dbh->prepare("SELECT biblioitemnumber FROM
reserveconstraints
WHERE biblionumber = ?
AND borrowernumber = ?
! AND reservedate =
?");
! $csth->execute($data->{'biblionumber'},
$data->{'borrowernumber'}, $data->{'reservedate'});
my ($bibitemno) = $csth->fetchrow_array;
$csth->finish;
***************
*** 297,311 ****
if (($item and $borr) and (not $biblio)) {
# removing a waiting reserve record....
- $item = $dbh->quote($item);
- $borr = $dbh->quote($borr);
# update the database...
! # FIXME - Use $dbh->do()
! my $query = "update reserves set cancellationdate = now(),
found = Null,
priority = 0
! where itemnumber = $item
! and borrowernumber = $borr";
! my $sth = $dbh->prepare($query);
! $sth->execute;
$sth->finish;
}
--- 293,303 ----
if (($item and $borr) and (not $biblio)) {
# removing a waiting reserve record....
# update the database...
! my $sth = $dbh->prepare("update reserves set cancellationdate = now(),
found = Null,
priority = 0
! where itemnumber = ?
! and borrowernumber = ?");
! $sth->execute($item,$borr);
$sth->finish;
}
***************
*** 313,329 ****
# removing a reserve record....
- my $q_biblio = $dbh->quote($biblio);
- $borr = $dbh->quote($borr);
# get the prioritiy on this record....
my $priority;
{
! my $query = "SELECT priority FROM reserves
! WHERE biblionumber = $q_biblio
! AND borrowernumber = $borr
AND cancellationdate is NULL
! AND (found <> 'F' or found is NULL)";
! my $sth=$dbh->prepare($query);
! $sth->execute;
($priority) = $sth->fetchrow_array;
$sth->finish;
--- 305,318 ----
# removing a reserve record....
# get the prioritiy on this record....
my $priority;
{
! my $sth=$dbh->prepare("SELECT priority FROM reserves
! WHERE biblionumber = ?
! AND borrowernumber = ?
AND cancellationdate is NULL
! AND (found <> 'F' or found is NULL)");
! $sth->execute($biblio,$borr);
($priority) = $sth->fetchrow_array;
$sth->finish;
***************
*** 332,344 ****
# update the database, removing the record...
{
! my $query = "update reserves set cancellationdate = now(),
found = Null,
priority = 0
! where biblionumber = $q_biblio
! and borrowernumber = $borr
and cancellationdate is NULL
! and (found <> 'F' or found is NULL)";
! my $sth = $dbh->prepare($query);
! $sth->execute;
$sth->finish;
}
--- 321,332 ----
# update the database, removing the record...
{
! my $sth = $dbh->prepare("update reserves set cancellationdate = now(),
found = Null,
priority = 0
! where biblionumber = ?
! and borrowernumber = ?
and cancellationdate is NULL
! and (found <> 'F' or found is NULL)");
! $sth->execute($biblio,$borr);
$sth->finish;
}
***************
*** 412,428 ****
foreach my $rec (@$reserves) {
if ($rec->{'priority'} > $priority) {
! # FIXME - Rewrite this without so much duplication and
! # redundancy
! my $newpr = $rec->{'priority'}; $newpr = $dbh->quote($newpr -
1);
! my $nbib = $rec->{'biblionumber'}; $nbib = $dbh->quote($nbib);
! my $nbor = $rec->{'borrowernumber'}; $nbor = $dbh->quote($nbor);
! my $nresd = $rec->{'reservedate'}; $nresd = $dbh->quote($nresd);
! my $query = "UPDATE reserves SET priority = $newpr
! WHERE biblionumber = $nbib
! AND borrowernumber = $nbor
! AND reservedate = $nresd";
! #warn $query;
! my $sth = $dbh->prepare($query);
! $sth->execute;
$sth->finish;
}
--- 400,408 ----
foreach my $rec (@$reserves) {
if ($rec->{'priority'} > $priority) {
! my $sth = $dbh->prepare("UPDATE reserves SET priority = ?
! WHERE biblionumber = ?
! AND borrowernumber = ?
! AND reservedate = ?");
!
$sth->execute($rec->{'priority'},$rec->{'biblionumber'},$rec->{'borrowernumber'},$rec->{'reservedate'});
$sth->finish;
}
***************
*** 434,441 ****
my ($item, $borr) = @_;
my $dbh = C4::Context->dbh;
- $item = $dbh->quote($item);
- $borr = $dbh->quote($borr);
# get priority and biblionumber....
! my $query = "SELECT reserves.priority as priority,
reserves.biblionumber as biblionumber,
reserves.branchcode as branchcode,
--- 414,419 ----
my ($item, $borr) = @_;
my $dbh = C4::Context->dbh;
# get priority and biblionumber....
! my $sth = $dbh->prepare("SELECT reserves.priority as priority,
reserves.biblionumber as biblionumber,
reserves.branchcode as branchcode,
***************
*** 443,465 ****
FROM reserves,items
WHERE reserves.biblionumber = items.biblionumber
! AND items.itemnumber = $item
! AND reserves.borrowernumber = $borr
AND reserves.cancellationdate is NULL
! AND (reserves.found <> 'F' or reserves.found is NULL)";
! my $sth = $dbh->prepare($query);
! $sth->execute;
my $data = $sth->fetchrow_hashref;
$sth->finish;
my $biblio = $data->{'biblionumber'};
my $timestamp = $data->{'timestamp'};
- my $q_biblio = $dbh->quote($biblio);
- my $q_timestamp = $dbh->quote($timestamp);
# update reserves record....
! $query = "UPDATE reserves SET priority = 0, found = 'W', itemnumber =
$item
! WHERE borrowernumber = $borr
! AND biblionumber = $q_biblio
! AND timestamp = $q_timestamp";
! $sth = $dbh->prepare($query);
! $sth->execute;
$sth->finish;
# now fix up the remaining priorities....
--- 421,439 ----
FROM reserves,items
WHERE reserves.biblionumber = items.biblionumber
! AND items.itemnumber = ?
! AND reserves.borrowernumber = ?
AND reserves.cancellationdate is NULL
! AND (reserves.found <> 'F' or reserves.found is
NULL)");
! $sth->execute($item,$borr);
my $data = $sth->fetchrow_hashref;
$sth->finish;
my $biblio = $data->{'biblionumber'};
my $timestamp = $data->{'timestamp'};
# update reserves record....
! $sth = $dbh->prepare("UPDATE reserves SET priority = 0, found = 'W',
itemnumber = ?
! WHERE borrowernumber = ?
! AND biblionumber = ?
! AND timestamp = ?");
! $sth->execute($item,$borr,$biblio,$timestamp);
$sth->finish;
# now fix up the remaining priorities....
***************
*** 473,492 ****
my ($borr)address@hidden;
my $dbh = C4::Context->dbh;
- $borr = $dbh->quote($borr);
my @itemswaiting;
! my $query = "SELECT * FROM reserves
! WHERE borrowernumber = $borr
AND reserves.found = 'W'
! AND cancellationdate is NULL";
! my $sth = $dbh->prepare($query);
! $sth->execute();
! # FIXME - Use 'push'
! my $cnt=0;
if (my $data=$sth->fetchrow_hashref) {
! $itemswaiting[$cnt] =$data;
! $cnt ++;
}
$sth->finish;
! return ($cnt,address@hidden);
}
--- 447,461 ----
my ($borr)address@hidden;
my $dbh = C4::Context->dbh;
my @itemswaiting;
! my $sth = $dbh->prepare("SELECT * FROM reserves
! WHERE borrowernumber = ?
AND reserves.found = 'W'
! AND cancellationdate is NULL");
! $sth->execute($borr);
if (my $data=$sth->fetchrow_hashref) {
! push(@itemswaiting,$data);
}
$sth->finish;
! return (scalar(@itemswaiting),address@hidden);
}
***************
*** 514,518 ****
my ($bibitem,$biblio)address@hidden;
my $dbh = C4::Context->dbh;
! my $query = "SELECT reserves.biblionumber AS biblionumber,
reserves.borrowernumber AS borrowernumber,
reserves.reservedate AS reservedate,
--- 483,487 ----
my ($bibitem,$biblio)address@hidden;
my $dbh = C4::Context->dbh;
! my $sth=$dbh->prepare("SELECT reserves.biblionumber AS
biblionumber,
reserves.borrowernumber AS borrowernumber,
reserves.reservedate AS reservedate,
***************
*** 533,548 ****
OR reserves.constrainttype='a' )
AND reserves.cancellationdate is NULL
! AND (reserves.found <> 'F' or reserves.found is NULL)";
! my $sth=$dbh->prepare($query);
$sth->execute($biblio, $bibitem);
- # FIXME - $i is unnecessary and bogus
- my $i=0;
my @results;
while (my $data=$sth->fetchrow_hashref){
! $results[$i]=$data; # FIXME - Use push
! $i++;
}
$sth->finish;
! return($i,@results);
}
--- 502,513 ----
OR reserves.constrainttype='a' )
AND reserves.cancellationdate is NULL
! AND (reserves.found <> 'F' or reserves.found is NULL)");
$sth->execute($biblio, $bibitem);
my @results;
while (my $data=$sth->fetchrow_hashref){
! push(@results,$data);
}
$sth->finish;
! return(scalar(@results),@results);
}
***************
*** 563,581 ****
# print $fee;
my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
! my $updquery = "insert into accountlines
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
values
! ($borrnum,$nextacctno,now(),$fee,'Reserve Charge - $title','Res',$fee)";
! my $usth = $dbh->prepare($updquery);
! $usth->execute;
$usth->finish;
}
#if ($const eq 'a'){
! my $query="insert into reserves
(borrowernumber,biblionumber,reservedate,branchcode,constrainttype,priority,reservenotes)
! values
!
('$borrnum','$biblionumber','$resdate','$branch','$const','$priority','$notes')";
! my $sth = $dbh->prepare($query);
! $sth->execute();
$sth->finish;
#}
--- 528,543 ----
# print $fee;
my $nextacctno = &getnextacctno($env,$borrnum,$dbh);
! my $usth = $dbh->prepare("insert into accountlines
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding)
values
! (?,?,now(),?,?,'Res',?)");
! $usth->execute($borrnum,$nextacctno,$fee,'Reserve Charge - $title',$fee);
$usth->finish;
}
#if ($const eq 'a'){
! my $sth = $dbh->prepare("insert into reserves
(borrowernumber,biblionumber,reservedate,branchcode,constrainttype,priority,reservenotes)
! values (?,?,?,?,?,?,?)");
!
$sth->execute($borrnum,$biblionumber,$resdate,$branch,$const,$priority,$notes);
$sth->finish;
#}
***************
*** 585,595 ****
while ($i < $numitems) {
my $biblioitem = @$bibitems[$i];
! my $query = "insert into
reserveconstraints
(borrowernumber,biblionumber,reservedate,biblioitemnumber)
! values
! ('$borrnum','$biblionumber','$resdate','$biblioitem')";
! my $sth = $dbh->prepare($query);
! $sth->execute();
$sth->finish;
$i++;
--- 547,555 ----
while ($i < $numitems) {
my $biblioitem = @$bibitems[$i];
! my $sth = $dbh->prepare("insert into
reserveconstraints
(borrowernumber,biblionumber,reservedate,biblioitemnumber)
! values (?,?,?,?)");
! $sth->execute($borrnum,$biblionumber,$resdate,$biblioitem);
$sth->finish;
$i++;
***************
*** 609,616 ****
my $dbh = C4::Context->dbh;
my $const = lc substr($constraint,0,1);
! my $query = "SELECT * FROM borrowers,categories
WHERE (borrowernumber = ?)
! AND (borrowers.categorycode = categories.categorycode)";
! my $sth = $dbh->prepare($query);
$sth->execute($borrnum);
my $data = $sth->fetchrow_hashref;
--- 569,575 ----
my $dbh = C4::Context->dbh;
my $const = lc substr($constraint,0,1);
! my $sth = $dbh->prepare("SELECT * FROM borrowers,categories
WHERE (borrowernumber = ?)
! AND (borrowers.categorycode = categories.categorycode)");
$sth->execute($borrnum);
my $data = $sth->fetchrow_hashref;
***************
*** 622,629 ****
# first find biblioitem records
my @biblioitems;
! my $query1 = "SELECT * FROM biblio,biblioitems
WHERE (biblio.biblionumber = ?)
! AND (biblio.biblionumber = biblioitems.biblionumber)";
! my $sth1 = $dbh->prepare($query1);
$sth1->execute($biblionumber);
while (my $data1=$sth1->fetchrow_hashref) {
--- 581,587 ----
# first find biblioitem records
my @biblioitems;
! my $sth1 = $dbh->prepare("SELECT * FROM biblio,biblioitems
WHERE (biblio.biblionumber = ?)
! AND (biblio.biblionumber = biblioitems.biblionumber)");
$sth1->execute($biblionumber);
while (my $data1=$sth1->fetchrow_hashref) {
***************
*** 657,670 ****
while ($x < $cntitemsfound) {
my $bitdata = $biblioitems[$x];
! my $query2 = "SELECT * FROM items
! WHERE biblioitemnumber = ?";
! my $sth2 = $dbh->prepare($query2);
$sth2->execute($bitdata->{'biblioitemnumber'});
while (my $itdata=$sth2->fetchrow_hashref) {
! my $query3 = "SELECT * FROM issues
WHERE itemnumber = ?
! AND returndate IS NULL";
!
! my $sth3 = $dbh->prepare($query3);
$sth3->execute($itdata->{'itemnumber'});
if (my $isdata=$sth3->fetchrow_hashref) {
--- 615,625 ----
while ($x < $cntitemsfound) {
my $bitdata = $biblioitems[$x];
! my $sth2 = $dbh->prepare("SELECT * FROM items
! WHERE biblioitemnumber = ?");
$sth2->execute($bitdata->{'biblioitemnumber'});
while (my $itdata=$sth2->fetchrow_hashref) {
! my $sth3 = $dbh->prepare("SELECT * FROM issues
WHERE itemnumber = ?
! AND returndate IS NULL");
$sth3->execute($itdata->{'itemnumber'});
if (my $isdata=$sth3->fetchrow_hashref) {
***************
*** 676,681 ****
}
if ($allissued == 0) {
! my $rquery = "SELECT * FROM reserves WHERE biblionumber = ?";
! my $rsth = $dbh->prepare($rquery);
$rsth->execute($biblionumber);
if (my $rdata = $rsth->fetchrow_hashref) {
--- 631,635 ----
}
if ($allissued == 0) {
! my $rsth = $dbh->prepare("SELECT * FROM reserves WHERE biblionumber =
?");
$rsth->execute($biblionumber);
if (my $rdata = $rsth->fetchrow_hashref) {
***************
*** 693,701 ****
my ($env,$bornumber,$dbh)address@hidden;
my $nextaccntno = 1;
! my $query = "select * from accountlines
! where (borrowernumber = '$bornumber')
! order by accountno desc";
! my $sth = $dbh->prepare($query);
! $sth->execute;
if (my $accdata=$sth->fetchrow_hashref){
$nextaccntno = $accdata->{'accountno'} + 1;
--- 647,654 ----
my ($env,$bornumber,$dbh)address@hidden;
my $nextaccntno = 1;
! my $sth = $dbh->prepare("select * from accountlines
! where (borrowernumber = ?)
! order by accountno desc");
! $sth->execute($bornumber);
if (my $accdata=$sth->fetchrow_hashref){
$nextaccntno = $accdata->{'accountno'} + 1;
***************
*** 710,745 ****
my ($rank,$biblio,$borrower,$del,$branch)address@hidden;
my $dbh = C4::Context->dbh;
- my $query="Update reserves ";
if ($del == 0){
! $query.="set priority='$rank',branchcode='$branch' where
! biblionumber=$biblio and borrowernumber=$borrower";
} else {
! $query="Select * from reserves where biblionumber=$biblio and
! borrowernumber=$borrower";
! my $sth=$dbh->prepare($query);
! $sth->execute;
my $data=$sth->fetchrow_hashref;
! $sth->finish;
! $query="Select * from reserves where biblionumber=$biblio and
! priority > '$data->{'priority'}' and cancellationdate is NULL
! order by priority";
! my $sth2=$dbh->prepare($query) || die $dbh->errstr;
! $sth2->execute || die $sth2->errstr;
! while (my $data=$sth2->fetchrow_hashref){
$data->{'priority'}--;
! $query="Update reserves set priority=$data->{'priority'} where
! biblionumber=$data->{'biblionumber'} and
! borrowernumber=$data->{'borrowernumber'}";
! my $sth3=$dbh->prepare($query);
! $sth3->execute || die $sth3->errstr;
! $sth3->finish;
! }
! $sth2->finish;
! $query="update reserves set cancellationdate=now() where
biblionumber=$biblio
! and borrowernumber=$borrower";
}
- my $sth=$dbh->prepare($query);
- $sth->execute;
- $sth->finish;
}
--- 663,694 ----
my ($rank,$biblio,$borrower,$del,$branch)address@hidden;
my $dbh = C4::Context->dbh;
if ($del == 0){
! my $sth = $dbh->prepare("Update reserves set priority=?,branchcode=? where
! biblionumber=? and borrowernumber=?");
! $sth->execute($rank,$branch,$biblio,$borrower);
! $sth->finish();
} else {
! my $sth=$dbh->prepare("Select * from reserves where biblionumber=? and
! borrowernumber=?");
! $sth->execute($biblio,$borrower);
my $data=$sth->fetchrow_hashref;
! $sth->finish();
! $sth=$dbh->prepare("Select * from reserves where biblionumber=? and
! priority > ? and cancellationdate is NULL
! order by priority") || die $dbh->errstr;
! $sth->execute($biblio,$data->{'priority'}) || die $sth->errstr;
! while (my $data=$sth->fetchrow_hashref){
$data->{'priority'}--;
! my $sth3=$dbh->prepare("Update reserves set priority=?
! where biblionumber=? and borrowernumber=?");
!
$sth3->execute($data->{'priority'},$data->{'biblionumber'},$data->{'borrowernumber'})
|| die $sth3->errstr;
! $sth3->finish();
! }
! $sth->finish();
! $sth=$dbh->prepare("update reserves set cancellationdate=now() where
biblionumber=?
! and borrowernumber=?");
! $sth->execute($biblio,$borrower);
! $sth->finish;
}
}
***************
*** 752,770 ****
my $dbh = C4::Context->dbh;
if ($rank eq "del") {
! my $query = "UPDATE reserves SET cancellationdate=now()
WHERE biblionumber = ?
AND borrowernumber = ?
AND cancellationdate is NULL
! AND (found <> 'F' or found is NULL)";
! my $sth=$dbh->prepare($query);
$sth->execute($biblio, $borrower);
$sth->finish;
} else {
! my $query = "UPDATE reserves SET priority = ? ,branchcode = ?,
itemnumber = NULL, found = NULL
WHERE biblionumber = ?
AND borrowernumber = ?
AND cancellationdate is NULL
! AND (found <> 'F' or found is NULL)";
! my $sth=$dbh->prepare($query);
$sth->execute($rank, $branch, $biblio, $borrower);
$sth->finish;
--- 701,717 ----
my $dbh = C4::Context->dbh;
if ($rank eq "del") {
! my $sth=$dbh->prepare("UPDATE reserves SET cancellationdate=now()
WHERE biblionumber = ?
AND borrowernumber = ?
AND cancellationdate is NULL
! AND (found <> 'F' or found is NULL)");
$sth->execute($biblio, $borrower);
$sth->finish;
} else {
! my $sth=$dbh->prepare("UPDATE reserves SET priority = ? ,branchcode =
?, itemnumber = NULL, found = NULL
WHERE biblionumber = ?
AND borrowernumber = ?
AND cancellationdate is NULL
! AND (found <> 'F' or found is NULL)");
$sth->execute($rank, $branch, $biblio, $borrower);
$sth->finish;
***************
*** 776,786 ****
my ($biblio,$bor,$date,$timestamp)address@hidden;
my $dbh = C4::Context->dbh;
! my $query="Select * from reserveconstraints,biblioitems where
reserveconstraints.biblioitemnumber=biblioitems.biblioitemnumber
! and reserveconstraints.biblionumber=$biblio and
reserveconstraints.borrowernumber
! = $bor and reserveconstraints.reservedate='$date' and
! reserveconstraints.timestamp=$timestamp";
! my $sth=$dbh->prepare($query);
! $sth->execute;
my $data=$sth->fetchrow_hashref;
$sth->finish;
--- 723,732 ----
my ($biblio,$bor,$date,$timestamp)address@hidden;
my $dbh = C4::Context->dbh;
! my $sth=$dbh->prepare("Select * from reserveconstraints,biblioitems where
reserveconstraints.biblioitemnumber=biblioitems.biblioitemnumber
! and reserveconstraints.biblionumber=? and reserveconstraints.borrowernumber
! = ? and reserveconstraints.reservedate=? and
! reserveconstraints.timestamp=?");
! $sth->execute($biblio,$bor,$date,$timestamp);
my $data=$sth->fetchrow_hashref;
$sth->finish;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Koha-cvs] CVS: koha/C4 Reserves2.pm,1.35,1.36,
MJ Ray <=