SPOPS/Key/DBI/Identity.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 40 CC 2 SCAR 12.0
CC
2
Cov
0%
post_fetch_id
6.0
pre_fetch_id
2.0
BEGIN
2.0
CRAP 3.3
1 package SPOPS::Key::DBI::Identity;
2  
3 # $Id: Identity.pm,v 3.4 2004/06/02 00:48:23 lachoy Exp $
4  
5 use strict;
6 use Log::Log4perl qw( get_logger );
7 use SPOPS;
8  
9 my $log = get_logger();
10  
11 $SPOPS::Key::DBI::Identity::VERSION = sprintf("%d.%02d", q$Revision: 3.4 $ =~ /(\d+)\.(\d+)/);
12  
13 # Ensure only POST_fetch_id used
14  
15 sub pre_fetch_id { return undef }
16  
17  
18 # Retrieve the IDENTITY value
19  
20 sub post_fetch_id {
21 my ( $self, $p ) = @_;
22 eval { $p->{statement}->finish };
23 my $sql = 'SELECT @@IDENTITY';
24 my ( $sth );
25 eval {
26 $sth = $p->{db}->prepare( $sql );
27 $sth->execute;
28 };
29 if ( $@ ) {
30 SPOPS::Exception::DBI->throw( "Cannot retrieve \@\@IDENTITY value: $@",
31 { sql => $sql, action => 'post_fetch_id' } );
32 }
33 my $row = $sth->fetchrow_arrayref;
34 $log->is_info &&
35 $log->info( "Found inserted ID ($row->[0])" );
36 return $row->[0];
37 }
38  
39 1;
40  
41 __END__