Commit | Line | Data |
843f8ecd |
1 | package DBIx::Class::Storage::DBI::DB2; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use base qw/DBIx::Class::Storage::DBI/; |
2ad62d97 |
7 | use mro 'c3'; |
96eacdb7 |
8 | use Try::Tiny; |
9 | use namespace::clean; |
843f8ecd |
10 | |
6f7a118e |
11 | __PACKAGE__->datetime_parser_type('DateTime::Format::DB2'); |
96eacdb7 |
12 | __PACKAGE__->sql_quote_char ('"'); |
6a247f33 |
13 | |
96eacdb7 |
14 | # lazy-default kind of thing |
15 | sub sql_name_sep { |
16 | my $self = shift; |
843f8ecd |
17 | |
96eacdb7 |
18 | my $v = $self->next::method(@_); |
843f8ecd |
19 | |
96eacdb7 |
20 | if (! defined $v and ! @_) { |
af1f4f84 |
21 | $v = $self->next::method($self->_dbh_get_info('SQL_QUALIFIER_NAME_SEPARATOR') || '.'); |
96eacdb7 |
22 | } |
843f8ecd |
23 | |
96eacdb7 |
24 | return $v; |
843f8ecd |
25 | } |
26 | |
96eacdb7 |
27 | sub sql_limit_dialect { |
28 | my $self = shift; |
45fa8288 |
29 | |
96eacdb7 |
30 | my $v = $self->next::method(@_); |
843f8ecd |
31 | |
96eacdb7 |
32 | if (! defined $v and ! @_) { |
33 | $v = $self->next::method( |
34 | ($self->_server_info->{normalized_dbms_version}||0) >= 5.004 |
35 | ? 'RowNumberOver' |
36 | : 'FetchFirst' |
37 | ); |
38 | } |
39 | |
40 | return $v; |
41 | } |
42 | |
43 | sub _dbh_last_insert_id { |
44 | my ($self, $dbh, $source, $col) = @_; |
45 | |
46 | my $name_sep = $self->sql_name_sep; |
47 | |
48 | 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 | $sth->execute(); |
57 | |
58 | my @res = $sth->fetchrow_array(); |
843f8ecd |
59 | |
96eacdb7 |
60 | return @res ? $res[0] : undef; |
61 | } |
62 | |
63 | 1; |
843f8ecd |
64 | |
96eacdb7 |
65 | =head1 NAME |
843f8ecd |
66 | |
96eacdb7 |
67 | DBIx::Class::Storage::DBI::DB2 - IBM DB2 support for DBIx::Class |
843f8ecd |
68 | |
69 | =head1 DESCRIPTION |
70 | |
96eacdb7 |
71 | This class implements autoincrements for DB2, sets the limit dialect to |
72 | RowNumberOver over FetchFirst depending on the availability of support for |
73 | RowNumberOver, queries the server name_sep from L<DBI> and sets the L<DateTime> |
74 | parser to L<DateTime::Format::DB2>. |
843f8ecd |
75 | |
96eacdb7 |
76 | =head1 AUTHOR |
843f8ecd |
77 | |
96eacdb7 |
78 | See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>. |
843f8ecd |
79 | |
80 | =head1 LICENSE |
81 | |
82 | You may distribute this code under the same terms as Perl itself. |
83 | |
84 | =cut |
96eacdb7 |
85 | # vim:sts=2 sw=2: |