File Coverage

blib/lib/DBIx/Class/Storage/DBI/DB2.pm
Criterion Covered Total %
statement 22 34 64.7
branch 0 8 0.0
condition 1 10 10.0
subroutine 7 9 77.7
pod 1 2 50.0
total 31 63 49.2


line stmt bran cond sub pod time code
1             package DBIx::Class::Storage::DBI::DB2;
2              
3 3     3   1745 use strict;
  3         7  
  3         78  
4 3     3   14 use warnings;
  3         5  
  3         83  
5              
6 3     3   15 use base qw/DBIx::Class::Storage::DBI/;
  3         6  
  3         303  
7 3     3   20 use mro 'c3';
  3         6  
  3         14  
8 3     3   76 use Try::Tiny;
  3         5  
  3         144  
9 3     3   17 use namespace::clean;
  3         7  
  3         20  
10              
11             __PACKAGE__->datetime_parser_type('DateTime::Format::DB2');
12             __PACKAGE__->sql_quote_char ('"');
13              
14             # lazy-default kind of thing
15             sub sql_name_sep {
16 1     1 0 882 my $self = shift;
17              
18 1         5 my $v = $self->next::method(@_);
19              
20 1 0 33     87 if (! defined $v and ! @_) {
21 0   0     0 $v = $self->next::method($self->_dbh_get_info('SQL_QUALIFIER_NAME_SEPARATOR') || '.');
22             }
23              
24 1         5 return $v;
25             }
26              
27             sub sql_limit_dialect {
28 0     0 1   my $self = shift;
29              
30 0           my $v = $self->next::method(@_);
31              
32 0 0 0       if (! defined $v and ! @_) {
33             $v = $self->next::method(
34 0 0 0       ($self->_server_info->{normalized_dbms_version}||0) >= 5.004
35             ? 'RowNumberOver'
36             : 'FetchFirst'
37             );
38             }
39              
40 0           return $v;
41             }
42              
43             sub _dbh_last_insert_id {
44 0     0     my ($self, $dbh, $source, $col) = @_;
45              
46 0           my $name_sep = $self->sql_name_sep;
47              
48 0           my $sth = $dbh->prepare_cached(
49             # An older equivalent of 'VALUES(IDENTITY_VAL_LOCAL())', for compat
50             # with ancient DB2 versions. Should work on modern DB2's as well:
51             # http://publib.boulder.ibm.com/infocenter/db2luw/v8/topic/com.ibm.db2.udb.doc/admin/r0002369.htm?resultof=%22%73%79%73%64%75%6d%6d%79%31%22%20
52             "SELECT IDENTITY_VAL_LOCAL() FROM sysibm${name_sep}sysdummy1",
53             {},
54             3
55             );
56 0           $sth->execute();
57              
58 0           my @res = $sth->fetchrow_array();
59              
60 0 0         return @res ? $res[0] : undef;
61             }
62              
63             =head1 NAME
64              
65             DBIx::Class::Storage::DBI::DB2 - IBM DB2 support for DBIx::Class
66              
67             =head1 DESCRIPTION
68              
69             This class implements autoincrements for DB2, sets the limit dialect to
70             RowNumberOver over FetchFirst depending on the availability of support for
71             RowNumberOver, queries the server name_sep from L<DBI> and sets the L<DateTime>
72             parser to L<DateTime::Format::DB2>.
73              
74             =head1 FURTHER QUESTIONS?
75              
76             Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
77              
78             =head1 COPYRIGHT AND LICENSE
79              
80             This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
81             by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
82             redistribute it and/or modify it under the same terms as the
83             L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
84              
85             =cut
86              
87             1;
88              
89             # vim:sts=2 sw=2: