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