X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FDB2.pm;h=aea773f6bc778f8444b591bf95b91ebc82cd3668;hb=1abccf54e92eefc27a8afb1db3878462b348157c;hp=4b5051b016e3ec2560ee007db5cec11255f62738;hpb=d4f16b21abb7a541e0c44bfe3ec68309a8d722fa;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBI/DB2.pm b/lib/DBIx/Class/Storage/DBI/DB2.pm index 4b5051b..aea773f 100644 --- a/lib/DBIx/Class/Storage/DBI/DB2.pm +++ b/lib/DBIx/Class/Storage/DBI/DB2.pm @@ -4,44 +4,82 @@ use strict; use warnings; use base qw/DBIx::Class::Storage::DBI/; +use mro 'c3'; +use Try::Tiny; +use namespace::clean; -# __PACKAGE__->load_components(qw/PK::Auto/); +__PACKAGE__->datetime_parser_type('DateTime::Format::DB2'); +__PACKAGE__->sql_quote_char ('"'); -sub _dbh_last_insert_id { - my ($self, $dbh, $source, $col) = @_; +# lazy-default kind of thing +sub sql_name_sep { + my $self = shift; - my $sth = $dbh->prepare_cached('VALUES(IDENTITY_VAL_LOCAL())', {}, 3); - $sth->execute(); + my $v = $self->next::method(@_); - my @res = $sth->fetchrow_array(); + if (! defined $v and ! @_) { + $v = $self->next::method($self->_dbh_get_info(41) || '.'); + } - return @res ? $res[0] : undef; + return $v; } -sub datetime_parser_type { "DateTime::Format::DB2"; } +sub sql_limit_dialect { + my $self = shift; -1; + my $v = $self->next::method(@_); -=head1 NAME + if (! defined $v and ! @_) { + $v = $self->next::method( + ($self->_server_info->{normalized_dbms_version}||0) >= 5.004 + ? 'RowNumberOver' + : 'FetchFirst' + ); + } + + return $v; +} + +sub _dbh_last_insert_id { + my ($self, $dbh, $source, $col) = @_; -DBIx::Class::Storage::DBI::DB2 - Automatic primary key class for DB2 + my $name_sep = $self->sql_name_sep; -=head1 SYNOPSIS + my $sth = $dbh->prepare_cached( + # An older equivalent of 'VALUES(IDENTITY_VAL_LOCAL())', for compat + # with ancient DB2 versions. Should work on modern DB2's as well: + # 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 + "SELECT IDENTITY_VAL_LOCAL() FROM sysibm${name_sep}sysdummy1", + {}, + 3 + ); + $sth->execute(); + + my @res = $sth->fetchrow_array(); + + return @res ? $res[0] : undef; +} + +1; + +=head1 NAME - # In your table classes - __PACKAGE__->load_components(qw/PK::Auto Core/); - __PACKAGE__->set_primary_key('id'); +DBIx::Class::Storage::DBI::DB2 - IBM DB2 support for DBIx::Class =head1 DESCRIPTION -This class implements autoincrements for DB2. +This class implements autoincrements for DB2, sets the limit dialect to +RowNumberOver over FetchFirst depending on the availability of support for +RowNumberOver, queries the server name_sep from L and sets the L +parser to L. -=head1 AUTHORS +=head1 AUTHOR -Jess Robinson +See L and L. =head1 LICENSE You may distribute this code under the same terms as Perl itself. =cut +# vim:sts=2 sw=2: