33a4e7abb65a225e6e837e0017922739bf1421fb
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / ODBC / DB2_400_SQL.pm
1 package DBIx::Class::Storage::DBI::ODBC::DB2_400_SQL;
2 use strict;
3 use warnings;
4
5 use base qw/DBIx::Class::Storage::DBI::ODBC/;
6 use mro 'c3';
7
8 sub _dbh_last_insert_id {
9     my ($self, $dbh, $source, $col) = @_;
10
11     # get the schema/table separator:
12     #    '.' when SQL naming is active
13     #    '/' when system naming is active
14     my $sep = $dbh->get_info(41);
15     my $sth = $dbh->prepare_cached(
16         "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM${sep}SYSDUMMY1", {}, 3);
17     $sth->execute();
18
19     my @res = $sth->fetchrow_array();
20
21     return @res ? $res[0] : undef;
22 }
23
24 sub _sql_maker_opts {
25     my ($self) = @_;
26     
27     $self->dbh_do(sub {
28         my ($self, $dbh) = @_;
29
30         return {
31             limit_dialect => 'FetchFirst',
32             name_sep => $dbh->get_info(41)
33         };
34     });
35 }
36
37 1;
38
39 =head1 NAME
40
41 DBIx::Class::Storage::DBI::ODBC::DB2_400_SQL - Support specific to DB2/400
42 over ODBC
43
44 =head1 SYNOPSIS
45
46   # In your table classes
47   __PACKAGE__->load_components(qw/PK::Auto Core/);
48   __PACKAGE__->set_primary_key('id');
49
50
51 =head1 DESCRIPTION
52
53 This class implements support specific to DB2/400 over ODBC, including
54 auto-increment primary keys, SQL::Abstract::Limit dialect, and name separator
55 for connections using either SQL naming or System naming.
56
57
58 =head1 AUTHORS
59
60 Marc Mims C<< <marc@questright.com> >>
61
62 Based on DBIx::Class::Storage::DBI::DB2 by Jess Robinson.
63
64 =head1 LICENSE
65
66 You may distribute this code under the same terms as Perl itself.
67
68 =cut