Merge branch 'people/riba/retire_sqla_limit'
[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 warn 'Major advances took place in the DBIC codebase since this driver'
9   .' (::Storage::DBI::ODBC::DB2_400_SQL) was written. However since the'
10   .' RDBMS in question is so rare it is not possible for us to test any'
11   .' of the "new hottness". If you are using DB2 on AS-400 please get'
12   .' in contact with the developer team:'
13   .' http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class.pm#GETTING_HELP/SUPPORT'
14   ."\n"
15 ;
16
17 # FIXME
18 # Most likely all of this code is redundant and unnecessary. We should
19 # be able to simply use base qw/DBIx::Class::Storage::DBI::DB2/;
20 # Unfortunately nobody has an RDBMS engine to test with, so keeping
21 # things as-is for the time being
22
23 sub _dbh_last_insert_id {
24     my ($self, $dbh, $source, $col) = @_;
25
26     # get the schema/table separator:
27     #    '.' when SQL naming is active
28     #    '/' when system naming is active
29     my $sep = $dbh->get_info(41);
30     my $sth = $dbh->prepare_cached(
31         "SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM${sep}SYSDUMMY1", {}, 3);
32     $sth->execute();
33
34     my @res = $sth->fetchrow_array();
35
36     return @res ? $res[0] : undef;
37 }
38
39 sub _sql_maker_opts {
40     my ($self) = @_;
41
42     $self->dbh_do(sub {
43         my ($self, $dbh) = @_;
44
45         return {
46             limit_dialect => 'FetchFirst',
47             name_sep => $dbh->get_info(41)
48         };
49     });
50 }
51
52 1;
53
54 =head1 NAME
55
56 DBIx::Class::Storage::DBI::ODBC::DB2_400_SQL - Support specific to DB2/400
57 over ODBC
58
59 =head1 SYNOPSIS
60
61   # In your result (table) classes
62   use base 'DBIx::Class::Core';
63   __PACKAGE__->set_primary_key('id');
64
65
66 =head1 DESCRIPTION
67
68 This class implements support specific to DB2/400 over ODBC, including
69 auto-increment primary keys, SQL::Abstract::Limit dialect, and name separator
70 for connections using either SQL naming or System naming.
71
72
73 =head1 AUTHORS
74
75 Marc Mims C<< <marc@questright.com> >>
76
77 Based on DBIx::Class::Storage::DBI::DB2 by Jess Robinson.
78
79 =head1 LICENSE
80
81 You may distribute this code under the same terms as Perl itself.
82
83 =cut