From 51d791514fbafadab6bbe22e22a38b6e0644eb99 Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Wed, 23 Jan 2008 16:37:27 -0600 Subject: [PATCH] Removing replace statement as per bug 1546 Signed-off-by: Joshua Ferraro --- admin/mediatype.pl | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/admin/mediatype.pl b/admin/mediatype.pl index cbbd482c91..3d7a85e2f2 100755 --- a/admin/mediatype.pl +++ b/admin/mediatype.pl @@ -53,7 +53,7 @@ sub StringSearch { $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $sth=$dbh->prepare("Select * from mediatypetable where (description like ?) order by mediatypecode"); + my $sth=$dbh->prepare("SELECT * FROM mediatypetable WHERE (description LIKE ?) ORDER BY mediatypecode"); $sth->execute("$data[0]%"); my @results; while (my $data=$sth->fetchrow_hashref){ @@ -98,14 +98,14 @@ if ($op eq 'add_form') { my $dbh = C4::Context->dbh; my @itemtypesselected; if ($mediatypecode) { - my $sth=$dbh->prepare("select mediatypecode,description,itemtypecodes from mediatypetable where mediatypecode=?"); + my $sth=$dbh->prepare("SELECT mediatypecode,description,itemtypecodes FROM mediatypetable WHERE mediatypecode=?"); $sth->execute($mediatypecode); $data=$sth->fetchrow_hashref; $sth->finish; @itemtypesselected = split ( /\|/, $data->{'itemtypecodes'} ); } - my $sth=$dbh->prepare("select description,itemtype from itemtypes order by description"); + my $sth=$dbh->prepare("SELECT description,itemtype FROM itemtypes ORDER BY description"); $sth->execute; while (my ($description,$itemtype) = $sth->fetchrow) { $itemtypes .='dbh; my @itemtypecodesarray = $input->param('itemtypecodes'); my $itemtypecodes=join('|',@itemtypecodesarray); - my $sth=$dbh->prepare("replace mediatypetable (mediatypecode,description,itemtypecodes) values (?,?,?)"); - $sth->execute( + my $sth = $dbh->prepaer("SELECT * FROM mediatypetable WHERE mediatypecode = ?"); + $sth->execute($input->param('mediatypecode')); + if (my $data = $sth->fetchrow_hashref()){ + # row exists, so its a modify + $sth->finish(); + $sth = $dbh->prepare("UPDATE mediatypetable SET description=?, itemtypecodes=? WHERE mediatypecode =? "); + $sth->execute($input->param('description'),$itemtypecodes,$input->param('mediatypecode')); + $sth->finish(); + } + else { + # its an add + $sth->finish(); + $sth = $dbh->prepare("INSERT INTO mediattypetable (mediatypecode,description,itemtypecodes) VALUES (?,?,?)"); + $sth->execute( $input->param('mediatypecode'),$input->param('description'), $itemtypecodes ); - $sth->finish; + $sth->finish; + } print "Content-Type: text/html\n\n"; exit; # END $OP eq ADD_VALIDATE -- 2.39.5