On Fri, Jun 05, 2009 at 08:48:44AM +0100, Martin Evans wrote: > H.Merijn Brand wrote: > > On Thu, 4 Jun 2009 11:44:51 -0700 (GMT-07:00), Todd Zervas > > <[email protected]> wrote: > > > >> Do you have any thoughts on how DBD::Unify ought to return warnings? > >> Specifically I need to be able to detect "dirty reads" (SQLWARN = > >> -2022). Is the right DBI way to do this to have DBD::Unify update > >> SQLSTATE even when there is no error via the h->state method?
The $h->state method isn't meant just for errors. It should always return the value of SQLSTATE for drivers that support it. > > Did you read DBI::DBD? I have no ideas about this one. If it is not > > documented in DBI::DBD, the best (and only) place to ask is the devel > > mailing list, which I Cc'd > > Look at DBIh_SET_ERR_CHAR. In a quick glance at DBI::DBD I cannot find > the relevant information It's not in a very obvious place (patches welcome): http://search.cpan.org/~timb/DBI-1.608/lib/DBI/DBD.pm#The_dbd_drv_error_method > but the following is pulled from DBD::ODBC: > > if (SQL_SUCCEEDED(err_rc)) { > DBIh_SET_ERR_CHAR(h, imp_xxh, "", 1, ErrorMsg, sqlstate, Nullch); > } else { > DBIh_SET_ERR_CHAR(h, imp_xxh, Nullch, 1, ErrorMsg, sqlstate, Nullch); > } > > I believe it is the "" argument. From DBI docs: > > A driver may return 0 from err() to indicate a warning condition after a > method call. Similarly, a driver may return an empty string to indicate > a 'success with information' condition. In both these cases the value is > false but not undef. The errstr() and state() methods may be used to > retrieve extra information in these cases. Yeap. Use "" for success with information and "0" for warning (see also the PrintWarn attribute). Tim.
