SPOPS::Exception::DBI - SPOPS exception with extra DBI parameters


SPOPS documentation  | view source Contained in the SPOPS distribution.

Index


NAME

Top

SPOPS::Exception::DBI - SPOPS exception with extra DBI parameters

SYNOPSIS

Top

 my $rows = eval { SPOPS::SQLInterface->db_select( \%params ) };
 if ( $@ and $@->isa( 'SPOPS::Exception::DBI' ) ) {
     print "Tried to excecute SQL: ", $@->sql, "\n",
           "with values: ", ( ref $@->bound_value )
                              ? join( " :: ", @{ $@->bound_value } ) : 'n/a',
           "but died with the message: ", $@->message, "\n";
 }

DESCRIPTION

Top

Same as SPOPS::Exception but we add three new properties:

sql ($)

The SQL statement SPOPS tried to run. Note that this may be empty if the exception was thrown before the statement could be prepared. (For instance, if SPOPS cannot find a datasource.)

bound_value (\@)

The value(s) that would have been bound to the various placeholders. This may return undef if SPOPS did not reach the stage where it collected the bound values or if there were none. So you will want to test and ensure the return value is an arrayref before using it as such, otherwise you will get the dreaded error: "Can't use an undefined value as an ARRAY reference".

action ($)

Indicates the DBI action (generally 'do', 'prepare' or 'execute') that was being run when SPOPS encountered the error. This may be empty if we did not even reach the DBI stage yet.

METHODS

Top

No extra methods, but we override 'to_string' so any SQL executed will be part of the error.

Additionally, you can use a shortcut if you are throwing errors:

 use SPOPS::Exception::DBI qw( spops_dbi_error );

 ...
 spops_dbi_error "I found a DBI error: $@ ",
                 { sql => $sql, action => 'prepare' };

BUGS

Top

None known.

TO DO

Top

Nothing known.

SEE ALSO

Top

SPOPS::Exception

DBI

COPYRIGHT

Top

AUTHORS

Top

Chris Winters <chris@cwinters.com>


SPOPS documentation  | view source Contained in the SPOPS distribution.