Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl failed because of DBI delete with 3 where values 1

Status
Not open for further replies.

jcarrott

Programmer
May 28, 2009
130
US
I am trying to do a delete, I have done the select and I am finished working with this record. I need to get rid of it.

This is my code. I have tried ';', 'and', ','

Code:
## delete the line from procure.RECPO2

        $dbh->do("DELETE FROM procure.RECPO2 WHERE
              po_number = '" . $vPO . "';
              requester = '" . $vReqName . "';
              req_num   = '" . $vSourDoc . "'")
              or die "Couldn't delete line: " . $dbh->errstr;

The error is trying to read the second where value.
Is there a way to get the record I want and delete it?
 
I just had an and at the end.

Code:
## delete the line from procure.RECPO2

        $dbh->do("DELETE FROM procure.RECPO2 WHERE
              po_number = '" . $vPO . "' and
              requester = '" . $vReqName . "' and
              req_num   = '" . $vSourDoc . "'")
              or die "Couldn't delete line: " . $dbh->errstr;

        }

I thought because I had concatienated the single quote I could just say 'and' then have the next value.
 
I forgot to include the error for the 'and'

Code:
DBD::Oracle::db do failed: ORA-00904: "REQUESTER": invalid identifier (DBD ERROR
: error possibly near <*> indicator at char 77 in 'DELETE FROM procure.RECPO2 WH
ERE
                          po_number = '       1608501' and
                          <*>requester = 'FERRARO' and
                          req_num   = '915053'') [for Statement "DELETE FROM pro
cure.RECPO2 WHERE
                          po_number = '       1608501' and
                          requester = 'FERRARO' and
                          req_num   = '915053'"] at reqNote2_sh line 116.
Couldn't delete line: ORA-00904: "REQUESTER": invalid identifier (DBD ERROR: err
or possibly near <*> indicator at char 77 in 'DELETE FROM procure.RECPO2 WHERE
                          po_number = '       1608501' and
                          <*>requester = 'FERRARO' and
                          req_num   = '915053'') at reqNote2_sh line 116.
 
I droped the requester and it worked,

$dbh->do("DELETE FROM procure.RECPO2 WHERE
po_number = '" . $vPO . "' and
req_num = '" . $vSourDoc . "'")
or die "Couldn't delete line: " . $dbh->errstr;
 
Rather than trying to build up the statement by catenating the pieces together, you may find it easier (and more secure) to use a prepared statement and then execute it
Perl:
my $sql_delete = 'DELETE FROM procure.RECPO2 WHERE po_number = ?
   AND requester = ? AND req_num = ?;';
my $sth = $dbh->prepare($sql_delete);
$sth->execute($vPO, $vReqName, $vSourDoc);
Note: not tested...

And although it is just a matter of personal taste and/or site coding standards, the Hungarian notation on the variable names is a bit clunky and smacks of VB...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top