From: Peter Rabbitson Date: Fri, 22 Jan 2010 10:59:25 +0000 (+0000) Subject: Initial informix support X-Git-Tag: v0.08116~23^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=193590c261bf21b2ec81667295b78703f5d7bc82;p=dbsrgits%2FDBIx-Class.git Initial informix support --- diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index 52a7af6..4c783c1 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -84,6 +84,24 @@ sub _rno_default_order { return undef; } +# Informix specific limit, almost like LIMIT/OFFSET +sub _SkipFirst { + my ($self, $sql, $order, $rows, $offset) = @_; + + $sql =~ s/^ \s* SELECT \s+ //ix + or croak "Unrecognizable SELECT: $sql"; + + return sprintf ('SELECT %s%s%s%s', + $offset + ? sprintf ('SKIP %d ', $offset) + : '' + , + sprintf ('FIRST %d ', $rows), + $sql, + $self->_order_by ($order), + ); +} + # Crappy Top based Limit/Offset support. Legacy from MSSQL. sub _Top { my ( $self, $sql, $order, $rows, $offset ) = @_; diff --git a/lib/DBIx/Class/Storage/DBI/Informix.pm b/lib/DBIx/Class/Storage/DBI/Informix.pm new file mode 100644 index 0000000..c08cb9a --- /dev/null +++ b/lib/DBIx/Class/Storage/DBI/Informix.pm @@ -0,0 +1,57 @@ +package DBIx::Class::Storage::DBI::Informix; +use strict; +use warnings; + +use base qw/DBIx::Class::Storage::DBI/; + +use mro 'c3'; + +__PACKAGE__->mk_group_accessors('simple' => '__last_insert_id'); + +sub _execute { + my $self = shift; + my ($op) = @_; + my ($rv, $sth, @rest) = $self->next::method(@_); + if ($op eq 'insert') { + $self->__last_insert_id($sth->{ix_sqlerrd}[1]); + } + return (wantarray ? ($rv, $sth, @rest) : $rv); +} + +sub last_insert_id { + shift->__last_insert_id; +} + +sub _sql_maker_opts { + my ( $self, $opts ) = @_; + + if ( $opts ) { + $self->{_sql_maker_opts} = { %$opts }; + } + + return { limit_dialect => 'SkipFirst', %{$self->{_sql_maker_opts}||{}} }; +} + +1; + +__END__ + +=head1 NAME + +DBIx::Class::Storage::DBI::Informix - Base Storage Class for INFORMIX Support + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +This class implements storage-specific support for Informix + +=head1 AUTHORS + +See L + +=head1 LICENSE + +You may distribute this code under the same terms as Perl itself. + +=cut