in reply to Re^2: DBI not erroring out on Insert
in thread DBI not erroring out on Insert
The code in DBI's connect() related to RaiseError:
Ok, fair enough. If RaiseError is true, then the DBI croaks on an error.unless ( $attr->{HandleError} && $attr->{HandleError}->($msg, $drh, $dbh)) { Carp::croak($msg) if $attr->{RaiseError}; Carp::carp ($msg) if $attr->{PrintError}; }
I was pondering a different question. I was wondering what happens if connect() fails because the arguments supplied are are of wrong number or type - in a more general case, what happens if the arg list is such that the DBI connect cannot recognize that RaiseError is intended to be 'on'? That case is handled by this DBI code:
So I guess a more accurate description of what the DBI does: The DBI will croak no matter what the state of RaiseError if it detects an invalid argument list to connect(). I also found out through testing that if you misspell "Raiseerror", the DBI also croaks - it will croak for any syntax error that is detected (the spec doesn't say this, but the code does it).Carp::croak('Usage: $class->connect([$dsn [,$user [,$passwd [,\%attr]] +]])') if (ref $old_driver or ($attr and not ref $attr) or ref $pass);
I'm testing right now with SQLite which doesn't have users or passwords so there are scenarios with MySQL that I am unable to test.
At the end of the day, if I omit the "or die" clause to a connect (which also specifies the RaiseError attribute), then I would have to be 100% sure that the "or die" code can never be executed under any circumstance. I can't prove that and that is certainly not part of the public specification.
Now I know that the "hey Mom, Jimmy's mom let's him to X" (the other guys do it defense) is pretty weak, but I learned my "bad" habit about this from Programming the Perl DBI" by Alligator Descartes and Tim Bunce.
I think that I am on very solid ground with my current practice and recommendations.
Back to original question in the original post!!!
I still have not found any way at all for a prepare of the INSERT statement to succeed where one of the columns does not exist in the table.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: DBI not erroring out on Insert
by mje (Curate) on Sep 14, 2011 at 08:23 UTC | |
by Marshall (Canon) on Sep 14, 2011 at 12:42 UTC | |
by mje (Curate) on Sep 15, 2011 at 18:44 UTC |