aqorders.listprice,
aqorders.rrp,
aqorders.ecost
- FROM aqorders,aqbasket
+ FROM aqorders
+ LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno
LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber
- WHERE aqbasket.basketno=aqorders.basketno
+ WHERE
AND aqbasket.booksellerid=?
AND aqorders.booksellerinvoicenumber LIKE \"$code\"
AND aqorders.datereceived= \'$datereceived\'";
my ( $biblionumber, $type ) = @_;
my $dbh = C4::Context->dbh;
my $query = "SELECT *,items.notforloan as itemnotforloan
- FROM items, biblio, biblioitems
+ FROM items
+ LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
+ LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
LEFT JOIN itemtypes on biblioitems.itemtype = itemtypes.itemtype
WHERE items.biblionumber = ?
- AND biblioitems.biblioitemnumber = items.biblioitemnumber
- AND biblio.biblionumber = items.biblionumber
ORDER BY items.dateaccessioned desc
";
my $sth = $dbh->prepare($query);
my $datedue = '';
my $isth = $dbh->prepare(
"SELECT issues.*,borrowers.cardnumber,borrowers.surname,borrowers.firstname
- FROM issues, borrowers
+ FROM issues LEFT JOIN borrowers ON issues.borrowernumber=borrowers.borrowernumber
WHERE itemnumber = ?
- AND returndate IS NULL
- AND issues.borrowernumber=borrowers.borrowernumber"
+ AND returndate IS NULL"
);
$isth->execute( $data->{'itemnumber'} );
if ( my $idata = $isth->fetchrow_hashref ) {
my ( $itemnumber ) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
- "SELECT * FROM biblio,items,biblioitems
- WHERE items.itemnumber = ?
- AND biblio.biblionumber = items.biblionumber
- AND biblioitems.biblioitemnumber = items.biblioitemnumber"
+ "SELECT * FROM items
+ LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
+ LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
+ WHERE items.itemnumber = ?"
);
$sth->execute($itemnumber);
$marcxml =~ s/\x1f//g;
$marcxml =~ s/\x1d//g;
$marcxml =~ s/\x0f//g;
- $marcxml =~ s/\x0c//g;
+ $marcxml =~ s/\x0c//g;
# warn $marcxml;
my $record = MARC::Record->new();
- $record = MARC::Record::new_from_xml( $marcxml, "utf8",C4::Context->preference('marcflavour')) if $marcxml;
+
+ $record = eval {MARC::Record::new_from_xml( $marcxml, "utf8",C4::Context->preference('marcflavour'))} if ($marcxml);
+ if ($@) {warn $@;}
# $record = MARC::Record::new_from_usmarc( $marc) if $marc;
return $record;
}
if ( $branch ne '' ) {
$strsth = "
SELECT *
- FROM aqbookfund,aqbudget
- WHERE aqbookfund.bookfundid=aqbudget.bookfundid
- AND startdate<now()
+ FROM aqbookfund
+ LEFT JOIN aqbudget ON aqbookfund.bookfundid=aqbudget.bookfundid
+ WHERE startdate<now()
AND enddate>now()
AND (aqbookfund.branchcode='' OR aqbookfund.branchcode= ? )
GROUP BY aqbookfund.bookfundid ORDER BY bookfundname";
else {
$strsth = "
SELECT *
- FROM aqbookfund,
- aqbudget
- WHERE aqbookfund.bookfundid=aqbudget.bookfundid
- AND startdate<now()
+ FROM aqbookfund
+ LEFT JOIN aqbudget ON aqbookfund.bookfundid=aqbudget.bookfundid
+ WHERE startdate<now()
AND enddate>now()
GROUP BY aqbookfund.bookfundid ORDER BY bookfundname
";
# Find the last 3 people who borrowed this item.
$sth2 = $dbh->prepare(
- "SELECT * FROM issues, borrowers
+ "SELECT * FROM issues
LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber
WHERE itemnumber = ?
AND returndate IS NOT NULL
if ($modulename eq "catalogue"){
$strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
$strsth .= "biblio.biblionumber, biblio.title, biblio.author" ;#if ($modulename eq "acqui.simple");
- $strsth .= " FROM borrowers,action_logs ";
- $strsth .= ",biblio " ;#if ($modulename eq "acqui.simple");
+ $strsth .= " FROM action_logs LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user";
+ $strsth .= " LEFT JOIN biblio ON action_logs.object=biblio.biblionumber " ;#if ($modulename eq "acqui.simple");
- $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
- $strsth .=" AND action_logs.module = 'cataloguing' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
+ $strsth .=" WHERE action_logs.module = 'cataloguing' ";# if ($modulename eq "acqui.simple");
if (@filters) {
foreach my $filter (@filters) {
if ($filter->{name} =~ /user/) {
}
}
} elsif ($modulename eq "acqui") {
- $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
- $strsth .= "biblio.biblionumber, biblio.title, biblio.author" ;#if ($modulename eq "acqui.simple");
- $strsth .= "FROM borrowers,action_logs ";
- $strsth .= ",biblio " ;#if ($modulename eq "acqui.simple");
-
- $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
- $strsth .= "AND action_logs.module = 'cataloguing' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
+ $strsth=qq|select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
+ biblio.biblionumber, biblio.title, biblio.author
+ FROM action_logs LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user
+ LEFT JOIN biblio ON action_logs.object=biblio.biblionumber
+ WHERE action_logs.module = 'cataloguing' |;# if ($modulename eq "acqui.simple");
if (@filters){
foreach my $filter (@filters){
if ($filter->{name} =~ /user/){
}
}
} elsif ($modulename eq "members"){
- $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
- $strsth .= "bor2.cardnumber, bor2.surname, bor2.firstname, bor2.userid,";
- $strsth .= "FROM borrowers,action_logs,borrowers as bor2 ";
-
- $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
- $strsth .= "AND action_logs.module = 'members' AND action_logs.object=bor2.borrowernumber ";# if ($modulename eq "acqui.simple");
+ $strsth=qq|SELECT action_logs.timestamp, action_logs.action, action_logs.info,
+ borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
+ bor2.cardnumber, bor2.surname, bor2.firstname, bor2.userid
+ FROM action_logs LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user LEFT JOIN borrowers as bor2 ON action_logs.object=bor2.borrowernumber
+ WHERE action_logs.module = 'members' |;# if ($modulename eq "acqui.simple");
if (@filters){
foreach my $filter (@filters){
if ($filter->{name} =~ /user/){
my $dbh = C4::Context->dbh;
my $count = 0;
my $query =
-"Select *,items.timestamp AS itemstimestamp from issues,biblio,items,biblioitems
- where borrowernumber=? and
- items.biblioitemnumber=biblioitems.biblioitemnumber and
- items.itemnumber=issues.itemnumber and
- items.biblionumber=biblio.biblionumber order by $order";
+ "Select *,items.timestamp AS itemstimestamp from
+ issues
+ LEFT JOIN items on items.itemnumber=issues.itemnumber
+ LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
+ LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
+ where borrowernumber=?
+ order by $order";
if ( $limit != 0 ) {
$query .= " limit $limit";
}
# large chunk of older issues data put into table oldissues
# to speed up db calls for issuing items
if ( C4::Context->preference("ReadingHistory") ) {
- my $query2 = "SELECT * FROM oldissues,biblio,items,biblioitems
+ my $query2 = "SELECT * FROM oldissues
+ LEFT JOIN items ON items.itemnumber=oldissues.itemnumber
+ LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
+ LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
WHERE borrowernumber=?
- AND items.biblioitemnumber=biblioitems.biblioitemnumber
- AND items.itemnumber=oldissues.itemnumber
- AND items.biblionumber=biblio.biblionumber
ORDER BY $order";
if ( $limit != 0 ) {
$limit = $limit - $count;
my @overdueitems;
my $count = 0;
my $sth = $dbh->prepare(
- "SELECT * FROM issues,biblio,biblioitems,items
- WHERE items.biblioitemnumber = biblioitems.biblioitemnumber
- AND items.biblionumber = biblio.biblionumber
- AND issues.itemnumber = items.itemnumber
- AND issues.borrowernumber = ?
+ "SELECT * FROM issues
+ LEFT JOIN items ON issues.itemnumber = items.itemnumber
+ LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
+ LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
+ WHERE issues.borrowernumber = ?
AND issues.returndate is NULL
AND issues.date_due < ?"
);
# I think this else-clause deals with the case where we're adding
# a new fine.
my $sth4 = $dbh->prepare(
- "select title from biblio,items where items.itemnumber=?
- and biblio.biblionumber=items.biblionumber"
+ "select title from biblio LEFT JOIN items ON biblio.biblionumber=items.biblionumber where items.itemnumber=?"
);
$sth4->execute($itemnum);
my $title = $sth4->fetchrow_hashref;
my ($borrowernumber) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
- "Select * from borrowers,categories where
- borrowernumber=? and
-borrowers.categorycode=categories.categorycode"
+ "SELECT * from borrowers
+ LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
+ WHERE borrowernumber=?"
);
$sth->execute($borrowernumber);
my $data = $sth->fetchrow_hashref;
sub CheckExistantNotifyid {
my($borrowernumber,$date_due) = @_;
my $dbh = C4::Context->dbh;
- my $query = qq|SELECT notify_id FROM issues,accountlines
+ my $query = qq|SELECT notify_id FROM accountlines
+ LEFT JOIN issues ON issues.itemnumber= accountlines.itemnumber
WHERE accountlines.borrowernumber =?
- AND issues.itemnumber= accountlines.itemnumber
AND date_due = ?|;
my $sth=$dbh->prepare($query);
$sth->execute($borrowernumber,$date_due);
accountlines.notify_level,
items.location,
accountlines.amountoutstanding
- FROM issues,borrowers,biblio,biblioitems,itemtypes,items,branches,accountlines
+ FROM accountlines
+ LEFT JOIN issues ON issues.itemnumber = accountlines.itemnumber AND issues.borrowernumber = accountlines.borrowernumber
+ LEFT JOIN borrowers ON borrowers.borrowernumber = accountlines.borrowernumber
+ LEFT JOIN items ON items.itemnumber = issues.itemnumber
+ LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
+ LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=items.biblioitemnumber
+ LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
+ LEFT JOIN branches ON branches.branchcode = issues.branchcode
WHERE ( issues.returndate is null)
AND ( accountlines.amountoutstanding != '0.000000')
AND ( accountlines.accounttype = 'FU')
- AND ( issues.borrowernumber = accountlines.borrowernumber )
- AND ( issues.itemnumber = accountlines.itemnumber )
- AND ( borrowers.borrowernumber = issues.borrowernumber )
- AND ( biblio.biblionumber = biblioitems.biblionumber )
- AND ( biblioitems.biblionumber = items.biblionumber )
- AND ( itemtypes.itemtype = biblioitems.itemtype )
- AND ( items.itemnumber = issues.itemnumber )
- AND ( branches.branchcode = issues.branchcode )
AND (issues.branchcode = ?)
AND (issues.date_due <= NOW())
ORDER BY borrowers.surname
accountlines.notify_level,
items.location,
accountlines.amountoutstanding
- FROM issues,borrowers,biblio,biblioitems,itemtypes,items,branches,accountlines
+ FROM accountlines
+ LEFT JOIN issues ON issues.itemnumber = accountlines.itemnumber AND issues.borrowernumber = accountlines.borrowernumber
+ LEFT JOIN borrowers ON borrowers.borrowernumber = accountlines.borrowernumber
+ LEFT JOIN items ON items.itemnumber = issues.itemnumber
+ LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
+ LEFT JOIN biblioitems ON biblioitems.biblioitemnumber=items.biblioitemnumber
+ LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
+ LEFT JOIN branches ON branches.branchcode = issues.branchcode
WHERE ( issues.returndate is null )
AND ( accountlines.amountoutstanding != '0.000000')
AND ( accountlines.accounttype = 'FU')
- AND ( issues.borrowernumber = accountlines.borrowernumber )
- AND ( issues.itemnumber = accountlines.itemnumber )
- AND ( borrowers.borrowernumber = issues.borrowernumber )
- AND ( biblio.biblionumber = biblioitems.biblionumber )
- AND ( biblioitems.biblionumber = items.biblionumber )
- AND ( itemtypes.itemtype = biblioitems.itemtype )
- AND ( items.itemnumber = issues.itemnumber )
- AND ( branches.branchcode = issues.branchcode )
AND (issues.branchcode = ? AND items.location = ?)
AND (issues.date_due <= NOW())
ORDER BY borrowers.surname
my $dbh = C4::Context->dbh;
my $const = lc substr( $constraint, 0, 1 );
my $query = qq/
- SELECT * FROM borrowers,categories
+ SELECT * FROM borrowers
+ LEFT JOIN categories ON borrowers.categorycode = categories.categorycode
WHERE borrowernumber = ?
- AND borrowers.categorycode = categories.categorycode
/;
my $sth = $dbh->prepare($query);
$sth->execute($borrowernumber);
# first find biblioitem records
my @biblioitems;
my $sth1 = $dbh->prepare(
- "SELECT * FROM biblio,biblioitems
- WHERE (biblio.biblionumber = ?)
- AND (biblio.biblionumber = biblioitems.biblionumber)"
+ "SELECT * FROM biblio LEFT JOIN biblioitems on biblio.biblionumber = biblioitems.biblionumber
+ WHERE (biblio.biblionumber = ?)"
);
$sth1->execute($biblionumber);
while ( my $data1 = $sth1->fetchrow_hashref ) {
# Look up the item by itemnumber
my $query = "
SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
- FROM items, biblioitems, itemtypes
- WHERE items.biblioitemnumber = biblioitems.biblioitemnumber
- AND biblioitems.itemtype = itemtypes.itemtype
- AND itemnumber=$qitem
+ FROM items
+ LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
+ LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
+ WHERE itemnumber=$qitem
";
$sth = $dbh->prepare($query);
}
# Look up the item by barcode
my $query = "
SELECT items.biblionumber, items.biblioitemnumber, itemtypes.notforloan
- FROM items, biblioitems, itemtypes
+ FROM items
+ LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber
+ LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
WHERE items.biblioitemnumber = biblioitems.biblioitemnumber
AND biblioitems.itemtype = itemtypes.itemtype
AND barcode=$qbc
if ($supplierid) {
my $query = qq|
SELECT name,title,planneddate,serialseq,serial.subscriptionid
- FROM subscription, serial, biblio
+ FROM subscription
+ LEFT JOIN serial ON subscription.subscriptionid = serial.subscriptionid
+ LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
- WHERE subscription.subscriptionid = serial.subscriptionid
- AND ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3)
+ WHERE ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3)
AND subscription.aqbooksellerid=$supplierid
- AND biblio.biblionumber = subscription.biblionumber
ORDER BY title
|;
$sth = $dbh->prepare($query);
else {
my $query = qq|
SELECT name,title,planneddate,serialseq,serial.subscriptionid
- FROM subscription, serial, biblio
+ FROM subscription
+ LEFT JOIN serial ON subscription.subscriptionid = serial.subscriptionid
+ LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber
LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id
- WHERE subscription.subscriptionid = serial.subscriptionid
- AND ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3)
- AND biblio.biblionumber = subscription.biblionumber
+ WHERE ((planneddate < now() AND serial.STATUS =1) OR serial.STATUS = 3)
ORDER BY title
|;
$sth = $dbh->prepare($query);
my $subscription = GetSubscription($subscriptionid);
my $query = qq|
SELECT *
- FROM biblio,biblioitems
- WHERE biblio.biblionumber=biblioitems.biblionumber
- AND biblio.biblionumber=?
+ FROM biblio
+ LEFT JOIN biblioitems ON biblio.biblionumber=biblioitems.biblionumber
+ WHERE biblio.biblionumber=?
|;
my $sth = $dbh->prepare($query);
$sth->execute( $subscription->{biblionumber} );
sub DelIssue {
my ( $dataissue) = @_;
my $dbh = C4::Context->dbh;
- ### TODO Add itemdeletion. Should be in a pref ?
+ ### TODO Add itemdeletion. Would need to get itemnumbers. Should be in a pref ?
+
my $query = qq|
DELETE FROM serial
WHERE serialid= ?
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
"SELECT serialid, serial.subscriptionid, aqbooksellerid
- FROM serial, subscription
- WHERE serial.subscriptionid = subscription.subscriptionid
- AND serialid = ?
+ FROM serial
+ LEFT JOIN subscription ON serial.subscriptionid = subscription.subscriptionid
+ WHERE serialid = ?
"
);
$sth->execute($serialid);
my ($subscriptionid) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
-"SELECT count(routingid) routingids FROM subscriptionroutinglist, subscription
- WHERE subscription.subscriptionid = subscriptionroutinglist.subscriptionid
- AND subscription.subscriptionid = ? ORDER BY ranking ASC
+"SELECT count(routingid) routingids FROM subscription LEFT JOIN subscriptionroutinglist
+ ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
+ WHERE subscription.subscriptionid = ? ORDER BY ranking ASC
"
);
$sth->execute($subscriptionid);
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
"SELECT routingid, borrowernumber,
- ranking, biblionumber FROM subscriptionroutinglist, subscription
- WHERE subscription.subscriptionid = subscriptionroutinglist.subscriptionid
- AND subscription.subscriptionid = ? ORDER BY ranking ASC
+ ranking, biblionumber
+ FROM subscription
+ LEFT JOIN subscriptionroutinglist ON subscription.subscriptionid = subscriptionroutinglist.subscriptionid
+ WHERE subscription.subscriptionid = ? ORDER BY ranking ASC
"
);
$sth->execute($subscriptionid);
my ($barcode) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare(
- "Select * from items,biblioitems where barcode=?
- and items.biblioitemnumber=biblioitems.biblioitemnumber"
+ "Select * from items LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
+ WHERE barcode=?"
);
$sth->execute($barcode);
my $data = $sth->fetchrow_hashref;
my ( $time, $time2, $spreadsheet ) = @_;
$time2 = $time unless $time2;
my $dbh = C4::Context->dbh;
- my $query = "SELECT * FROM statistics,borrowers
- WHERE statistics.borrowernumber= borrowers.borrowernumber
- AND (statistics.type='payment' OR statistics.type='writeoff') ";
+ my $query = "SELECT * FROM statistics
+ LEFT JOIN borrowers ON statistics.borrowernumber= borrowers.borrowernumber
+ WHERE (statistics.type='payment' OR statistics.type='writeoff') ";
if ( $time eq 'today' ) {
$query = $query . " AND datetime = now()";
}
else {
my $query = qq |
SELECT count(*)
- FROM suggestions,borrowers
+ FROM suggestions LEFT JOIN borrowers ON borrowers.borrowernumber=suggestions.suggestedby
WHERE status=?
- AND borrowers.borrowernumber=suggestions.suggestedby
AND (borrowers.branchcode='' OR borrowers.branchcode =?)
|;
$sth = $dbh->prepare($query);