LHowell has asked for the wisdom of the Perl Monks concerning the following question:

Hey Perl Monks, I am really stuck! I have a Perl program that executes the following code snippet:
$InsertIntoMetar = <<SQL; REPLACE INTO Metar SELECT *,NULL FROM Deduped_Metars_No_Errors a; SQL .............. $sth = $dbh->prepare($InsertIntoMetar) or die "Can't prepare $InsertIntoMetar: $dbh->errstr\n"; $rv = $sth->execute + ##Insert into production Metar table. or die "can't execute the query: $sth->errstr";
The script dies with the following on the command line:
can't execute the query: DBI:: st=HASH(0x1a07924)-> errstr at Load_Met +ar_New1.pl line 600. Line 600 is the line that contains the $rv = $ +sth->execute shown above.
The interesting thing is that I can cut and paste the SQL contained in the prepare portion of the $LoadIntoMetar into a SQLYog window and it executes just fine!! Thoughts Anyone?

Replies are listed 'Best First'.
Re: Strange Execute Issue from PERL
by Corion (Patriarch) on May 07, 2011 at 14:01 UTC

    What else do you expect?

    As an idea, consider changing your code to:

    ... $rv = $sth->execute ##Insert into production Metar table. or die "can't execute the query: " . $sth->errstr; # ^^^^^^^

    That way, you'll see what your DBD things is the error cause and what it gives you as error message.

      I can not see what it is taht you are suggesting that I change my code to. It isn't being displayed in the reply!

        You currently have:

        $rv = $sth->execute or die "can't execute the query: $sth->errstr";

        I suggest that you change it into

        $rv = $sth->execute or die "can't execute the query: " . $sth->errstr;

        ... so that you see the actual error message from your database driver.

        If you look at the error message you got until now, you see DBI:: st=HASH(0x1a07924)-> errstr in there, which is much less informative than the actual return value of ->errstr.