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

[email protected] ("Roode, Eric")
Newsgroups perl.dbi.users
Message-ID <[email protected]>
On Tuesday, October 19, 2010 3:59 AM, Martin J. Evans wrote:

> All drivers I've tried this with report 2 things. The 23000 error
> for the insert of a null into a column which does not allow nulls
> (the tds_error packet) then a 01000 informational (tds_info) which
> states the statement has been terminated.
>
> However, it does not get around the fact that SQLExecute is
> returning SQL_SUCCESS_WITH_INFO with the broken driver. DBD::ODBC
> uses the SQLExecute return to determine if the execute was
> successful or not (as per the ODBC docs) and not the state of any
> error it sees when recovering details of the errors and
> informationals.
>
> I suppose this could be changed but it would need additional logic
> everywhere "if (SQL_SUCCEEDED(ret))" is called and some way of
> recording the states it has seen since the last ODBC call. I'm not
> keen on doing that and not only because the driver in this case is
> broken.

I agree; it hardly seems worthwhile.  This is what I put in place
as a workaround.  Does it look reasonable?

 $retval = $sth->execute(...);
 $sqlstate = $handle->state;
 if (   (!defined $retval)
        || (defined $sqlstate  &&  length $sqlstate
            &&  $sqlstate ne '00000'  &&  $sqlstate ne 'S1000'
            &&  substr($sqlstate,0,2) ne '01')
       )
    {
         ...handle error condition


-- Eric
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.