On Thu, Sep 09, 2004 at 11:31:42AM -0700, Henri Asseily wrote: > I need to know when I execute() a statement if the error is a > connectivity error or something else. > From the DBI docs: > > Perform whatever processing is necessary to execute the prepared > statement. An "undef" is returned if an error occurs. A successful > "execute" always returns true regardless of the number of rows > affected, ... > > Is it possible, in a database-agnostic fashion, to know whether an > undef returned value for execute() means that the DB connection is > problematic, as opposed to another perfectly valid error such as a SQL > syntax error or primary key constraint error?
No. You'd need to parse $h->errstr etc. Though if the driver sets $h->state that would make life easier, but you'd be trusting it'll do that reasonably for all the error condiitons you're interested in. > Right now I simply follow up with a "select 1" and see if the returned > value is undef. If so, then the db connection is at fault. Anything > more subtle than this? No, that probably best since $dbh->ping may actually trigger a reconnect for some drivers (eg mysql). Tim.
