in reply to SQL INSERTs don't work

You do not test, whether the connection to the database fails or not.

Test it:
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile","","", { RaiseError + => 1 }) or die $DBI::errstr;


Replies are listed 'Best First'.
Re^2: SQL INSERTs don't work
by thor (Priest) on Nov 08, 2004 at 13:48 UTC
    Pretty sure that RaiseError also applies to the connect. That is to say that if you specify RaiseError and the connect fails, the script will die. Someone can (and will) correct me if I'm wrong...

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      RaiseError does not apply to the connect. You should always check the return value of the connect() call, period.

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

        Do you have docs to back it up? Here's a snippet from Programming the Perl DBI that seems germane:
        #!/usr/bin/perl -w # # ch04/error/ex2: Small example using automatic error handling with # RaiseError, i.e., the program will abort upon detection # of any errors. use DBI; # Load the DBI module my ($dbh, $sth, @row); ### Perform the connection using the Oracle driver $dbh = DBI->connect( "dbi:Oracle:archaeo", "username", "password" , { PrintError => 0, ### Don't report errors via warn( ) RaiseError => 1 ### Do report errors via die( ) } ); ### Prepare a SQL statement for execution $sth = $dbh->prepare( "SELECT * FROM megaliths" ); ### Execute the statement in the database $sth->execute( ); ### Retrieve the returned rows of data while ( @row = $sth->fetchrow_array( ) ) { print "Row: @row\n"; } ### Disconnect from the database $dbh->disconnect( ); exit;
        Seems odd that they'd leave the error checking off of the connect when they do it in the section called "manual error checking". I'd honestly like to know if my programming style is wrong. I read once that RaiseError applied to the connect and have been leaving the 'or die "Couldn't connect..."' off ever since.

        thor

        Feel the white light, the light within
        Be your own disciple, fan the sparks of will
        For all of us waiting, your kingdom will come