in reply to Re^4: DBI not erroring out on Insert
in thread DBI not erroring out on Insert

No. I do not think that this is worth a comment in the DBI pod.

For folks who want to know some super details, I say "go for it!". The DBI code is actually so complex that I cannot say that x or y or even z is completely true.

The DBI code is written in such a way that it does "work as advertised". Yes, we can talk about details, but I think that it would be a huge mistake to change things without careful consideration.

So, having said that, I would be happy to work on the DBI.

Replies are listed 'Best First'.
Re^6: DBI not erroring out on Insert
by mje (Curate) on Sep 15, 2011 at 18:44 UTC

    In actual fact it is possible for the connect to fail but connect not to die and no error to be output but you have to go out of your way to do it. You have to call connect properly but with RaiseError => 0 and PrintError => 0.

    I:\svn\dbd-odbc\trunk>perl -le "use DBI; my $h = eval {DBI->connect('d +bi:ODBC:in validsn', 'fred', 'fred', {RaiseError => 0, PrintError => 0})}; print +'error' . $@ if $@;print $h->ping;" Can't call method "ping" on an undefined value at -e line 1.

    If you do not disable RaiseError (legitimately) but disable PrintError then connect will not die as RaiseError is off by default and no error will be output:

    I:\svn\dbd-odbc\trunk>perl -le "use DBI; my $h = eval {DBI->connect('d +bi:ODBC:in validsn', 'fred', 'fred', {PrintError => 0})}; print 'error' . $@ if $ +@;print $h ->ping;" Can't call method "ping" on an undefined value at -e line 1.

    So for the connect method you should always set RaiseError and be sure connect is called correctly or test the return status of connect. To be honest, I'd be surprised to see a call to connect without a check for the return status but I've been surprised before.