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