NAME

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

SYNOPSIS

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

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

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

None known.

TO DO

Nothing known.

SEE ALSO

SPOPS::Exception

DBI

COPYRIGHT

Copyright (c) 2001-2004 intes.net, inc.. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS

Chris Winters <chris@cwinters.com>