Re: There's an error, but $sth->execute returns -1

[email protected] ("Martin J. Evans")
Newsgroups perl.dbi.users
Message-ID <[email protected]>
  On 15/10/2010 22:20, Roode, Eric wrote:
> Hello all,
>
>
>
> DBI docs says that statement handle method execute() returns undef on
> error.  I have found a situation where that does not hold.  Was hoping
> someone could help me out, maybe there's a workaround.
>
You need to read further down that entry where it says:

"If the number of rows affected is not known, then |execute| returns -1."

Admittedly, in your case it looks like an error from the driver error 
message but it did not return an error so perhaps you stopped when you 
saw undef for error.

>
>
> First, I'm running ActiveState Perl 5.10.0 on Windows 7, connecting to a
> SQL Server 2000 database on a different machine.  I have DBI version
> 1.613, and DBD::ODBC version 1.24.
>
>
>
> In a nutshell, here is what happens.  I connect to the database, using
> the ODBC driver, and setting RaiseError to 1 and PrintError to 0.  I
> prepare a statement which calls a procedure.  I bind parameters to the
> statement (some input, some output, various types), I call execute().
>
>
>
> There's a problem with one of the parameters; because of that, the
> stored procedure tries to insert a null value into a column that does
> not accept nulls.  So SQL Server gives an error ("Cannot insert the
> value NULL into column 'enabled'"), and the DBI system stores this
> string in errstr.  However, the execute() method returns -1, which is
> what it would return on success.  Also, no error is thrown (I have the
> $sth->execute call wrapped in an eval, and $@ is empty afterward).
>
>
>
> You can see the definition of the table and the stored procedure at
> http://nopaste.gamedev.pl/?id=8272.
>
> The Perl code that demonstrates the problem is at
> http://nopaste.gamedev.pl/?id=8273.
>
> And the DBD trace output is at http://nopaste.gamedev.pl/?id=8274.
>
>
>
> I hope someone can shed some light on what's going on here.  Should I
> check errstr and ignore the return value? Thanks in advance.
>
> Eric
>
>
>

Martin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.