X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FInformix.pm;h=e8c123d4cb62d39af0b678ec142a6d3f6689580a;hb=ab7c6418e3ea4fde7d58df897b5609fa41829161;hp=575bc4b6dd32b8e27cec2cbe660046a726a78df2;hpb=9fb04139a7323dbcf9f2c6f81476e2f10bde95d4;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Informix.pm b/lib/DBIx/Class/Storage/DBI/Informix.pm index 575bc4b..e8c123d 100644 --- a/lib/DBIx/Class/Storage/DBI/Informix.pm +++ b/lib/DBIx/Class/Storage/DBI/Informix.pm @@ -3,18 +3,40 @@ use strict; use warnings; use base qw/DBIx::Class::Storage::DBI/; - use mro 'c3'; +use Scope::Guard (); +use Context::Preserve 'preserve_context'; +use namespace::clean; + +__PACKAGE__->sql_limit_dialect ('SkipFirst'); +__PACKAGE__->sql_quote_char ('"'); +__PACKAGE__->datetime_parser_type ( + 'DBIx::Class::Storage::DBI::Informix::DateTime::Format' +); + + __PACKAGE__->mk_group_accessors('simple' => '__last_insert_id'); +=head1 NAME + +DBIx::Class::Storage::DBI::Informix - Base Storage Class for Informix Support + +=head1 DESCRIPTION + +This class implements storage-specific support for the Informix RDBMS + +=head1 METHODS + +=cut + 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]); - } + + $self->__last_insert_id($sth->{ix_sqlerrd}[1]) + if $self->_perform_autoinc_retrieval; + return (wantarray ? ($rv, $sth, @rest) : $rv); } @@ -22,52 +44,143 @@ sub last_insert_id { shift->__last_insert_id; } -sub _sql_maker_opts { - my ( $self, $opts ) = @_; - - if ( $opts ) { - $self->{_sql_maker_opts} = { %$opts }; - } +sub _exec_svp_begin { + my ($self, $name) = @_; - return { limit_dialect => 'SkipFirst', %{$self->{_sql_maker_opts}||{}} }; + $self->_dbh->do("SAVEPOINT $name"); } -sub _svp_begin { +# can't release savepoints +sub _exec_svp_release { 1 } + +sub _exec_svp_rollback { my ($self, $name) = @_; - $self->_get_dbh->do("SAVEPOINT $name"); + $self->_dbh->do("ROLLBACK TO SAVEPOINT $name") } -# can't release savepoints -sub _svp_release { 1 } +sub with_deferred_fk_checks { + my ($self, $sub) = @_; -sub _svp_rollback { - my ($self, $name) = @_; + my $txn_scope_guard = $self->txn_scope_guard; - $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name") + $self->_do_query('SET CONSTRAINTS ALL DEFERRED'); + + my $sg = Scope::Guard->new(sub { + $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE'); + }); + + return preserve_context { $sub->() } after => sub { $txn_scope_guard->commit }; } +=head2 connect_call_datetime_setup -1; +Used as: -__END__ + on_connect_call => 'datetime_setup' -=head1 NAME +In L to set the C and +C formats. -DBIx::Class::Storage::DBI::Informix - Base Storage Class for INFORMIX Support +Sets the following environment variables: -=head1 SYNOPSIS + GL_DATE="%m/%d/%Y" + GL_DATETIME="%Y-%m-%d %H:%M:%S%F5" -=head1 DESCRIPTION +The C and C environment variables are cleared. + +B setting the C environment variable seems to have no effect +after the process has started, so the default format is used. The C +setting does take effect however. -This class implements storage-specific support for Informix +The C data type supports up to 5 digits after the decimal point for +second precision, depending on how you have declared your column. The full +possible precision is used. -=head1 AUTHORS +The column declaration for a C with maximum precision is: -See L + column_name DATETIME YEAR TO FRACTION(5) -=head1 LICENSE +The C data type stores the date portion only, and it B be declared +with: -You may distribute this code under the same terms as Perl itself. + data_type => 'date' + +in your Result class. + +You will need the L module for inflation to work. =cut + +sub connect_call_datetime_setup { + my $self = shift; + + delete @ENV{qw/DBDATE DBCENTURY/}; + + $ENV{GL_DATE} = "%m/%d/%Y"; + $ENV{GL_DATETIME} = "%Y-%m-%d %H:%M:%S%F5"; +} + +package # hide from PAUSE + DBIx::Class::Storage::DBI::Informix::DateTime::Format; + +my $timestamp_format = '%Y-%m-%d %H:%M:%S.%5N'; # %F %T +my $date_format = '%m/%d/%Y'; + +my ($timestamp_parser, $date_parser); + +sub parse_datetime { + shift; + require DateTime::Format::Strptime; + $timestamp_parser ||= DateTime::Format::Strptime->new( + pattern => $timestamp_format, + on_error => 'croak', + ); + return $timestamp_parser->parse_datetime(shift); +} + +sub format_datetime { + shift; + require DateTime::Format::Strptime; + $timestamp_parser ||= DateTime::Format::Strptime->new( + pattern => $timestamp_format, + on_error => 'croak', + ); + return $timestamp_parser->format_datetime(shift); +} + +sub parse_date { + shift; + require DateTime::Format::Strptime; + $date_parser ||= DateTime::Format::Strptime->new( + pattern => $date_format, + on_error => 'croak', + ); + return $date_parser->parse_datetime(shift); +} + +sub format_date { + shift; + require DateTime::Format::Strptime; + $date_parser ||= DateTime::Format::Strptime->new( + pattern => $date_format, + on_error => 'croak', + ); + return $date_parser->format_datetime(shift); +} + +=head1 FURTHER QUESTIONS? + +Check the list of L. + +=head1 COPYRIGHT AND LICENSE + +This module is free software L +by the L. You can +redistribute it and/or modify it under the same terms as the +L. + +=cut + +1; +