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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking to see if data is already loaded 1

Status
Not open for further replies.

jcarrott

Programmer
May 28, 2009
130
US
I am trying to test a table for a entry to see if it is there before I write the record.

Code:
        $st2 = $dbh->prepare("SELECT * FROM procure.INVOICE_BLT WHERE
            company = '" . $vCompstr . "' and
            vendor  = '" . $vVendor . "' and
            invoice = '" . $vInvoice . "'")
            or die "Couldn't prepare statment 2: " . $dbh->errstr;
        my @dat2;
        my $r2 = $st2->execute
            or die "Couldn't execute statement 2: " . $st2->errstr;

        if (length(errstr) eq 0) {
            print leaInv $sLine;
            $query = "INSERT INTO procure.INVOICE_BLT (company, vendor,
                      invoice) VALUES
                      ('"."$vCompstr"."',
                       '"."$vVendor"."',
                       '"."$vInvoice"."')";
            $dbh->do($query) or die "DBI::errstr";
            }

This code is failing to work. I thought that if the record was not found I would have an error, so errstr would be longer than 0.

Is there a better way to check if a record is found?
 
I changed the if to

Code:
if ($st2->rows == 0) {

[\code]

Now I execute the if and write the record every time.

I was trying to make sure I did not add duplicates.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top