The code should fail at the prepare statement (see my test code below). If you have a valid $dbh handle, the prepare simply won't work if in your case column "column2" does not exist, in my case column "abc".
I would include an "or die" clause on the connect() like I did below because you are not guaranteed to have the 'RaiseError' in effect unless the connect succeeds. Think about it, if you omitted say the user name field, the connect() is going to fail and things won't work so well interpreting the attribute hash as a password string! In other words, don't rely on 'RaiseError' working until you are sure that the statement that set that attribute itself worked! Your code may be going wrong right at the connect!
I did some tests with and without "use strict" and "use warnings". This made no difference in the error that I got in this simple test. However there are run time aspects to those and the DBI does work with standard $SIG(__WARN__} and $SIG{__DIE__} signal handlers, so I would leave this extra warning stuff on unless there is an unusual performance requirement and even then don't turn it off until after testing is complete.
At the end of the day, a single connect statement and a single prepare statement is enough to demonstrate what happens when an SQL INSERT into a non-existent column (in an existing table, in my case the "logs" table) is attempted.#!/usr/bin/perl -w use strict; #result the same without strict or warnings use DBI; my $dbfile = "./SomeDB.sqlite"; my %attr = ( RaiseError => 1); #auto die with error printout my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","",\%attr) or die "Couldn't connect to database: " . DBI->errstr; my $s2 = $dbh->prepare("INSERT INTO logs ('abc') VALUES ('xyzzy')"); $s2->execute(); __END__ DBD::SQLite::db prepare failed: table logs has no column named abc process exits with error code 2 in my environment...
In reply to Re: DBI not erroring out on Insert
by Marshall
in thread DBI not erroring out on Insert
by rethaew
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |