1 package DBIx::Class::Storage::DBI::Informix;
5 use base qw/DBIx::Class::Storage::DBI/;
9 use Context::Preserve 'preserve_context';
12 __PACKAGE__->sql_limit_dialect ('SkipFirst');
14 __PACKAGE__->mk_group_accessors('simple' => '__last_insert_id');
18 DBIx::Class::Storage::DBI::Informix - Base Storage Class for Informix Support
22 This class implements storage-specific support for the Informix RDBMS
31 my ($rv, $sth, @rest) = $self->next::method(@_);
32 if ($op eq 'insert') {
33 $self->__last_insert_id($sth->{ix_sqlerrd}[1]);
35 return (wantarray ? ($rv, $sth, @rest) : $rv);
39 shift->__last_insert_id;
43 my ($self, $name) = @_;
45 $self->_get_dbh->do("SAVEPOINT $name");
48 # can't release savepoints
49 sub _svp_release { 1 }
52 my ($self, $name) = @_;
54 $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
57 sub with_deferred_fk_checks {
58 my ($self, $sub) = @_;
60 my $txn_scope_guard = $self->txn_scope_guard;
62 $self->_do_query('SET CONSTRAINTS ALL DEFERRED');
64 my $sg = Scope::Guard->new(sub {
65 $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE');
68 return preserve_context { $sub->() } after => sub { $txn_scope_guard->commit };
71 =head2 connect_call_datetime_setup
75 on_connect_call => 'datetime_setup'
77 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the C<DATE> and
80 Sets the following environment variables:
83 GL_DATETIME="%Y-%m-%d %H:%M:%S%F5"
85 The C<DBDATE> and C<DBCENTURY> environment variables are cleared.
87 B<NOTE:> setting the C<GL_DATE> environment variable seems to have no effect
88 after the process has started, so the default format is used. The C<GL_DATETIME>
89 setting does take effect however.
91 The C<DATETIME> data type supports up to 5 digits after the decimal point for
92 second precision, depending on how you have declared your column. The full
93 possible precision is used.
95 The column declaration for a C<DATETIME> with maximum precision is:
97 column_name DATETIME YEAR TO FRACTION(5)
99 The C<DATE> data type stores the date portion only, and it B<MUST> be declared
104 in your Result class.
106 You will need the L<DateTime::Format::Strptime> module for inflation to work.
110 sub connect_call_datetime_setup {
113 delete @ENV{qw/DBDATE DBCENTURY/};
115 $ENV{GL_DATE} = "%m/%d/%Y";
116 $ENV{GL_DATETIME} = "%Y-%m-%d %H:%M:%S%F5";
119 sub datetime_parser_type {
120 'DBIx::Class::Storage::DBI::Informix::DateTime::Format'
123 package # hide from PAUSE
124 DBIx::Class::Storage::DBI::Informix::DateTime::Format;
126 my $timestamp_format = '%Y-%m-%d %H:%M:%S.%5N'; # %F %T
127 my $date_format = '%m/%d/%Y';
129 my ($timestamp_parser, $date_parser);
133 require DateTime::Format::Strptime;
134 $timestamp_parser ||= DateTime::Format::Strptime->new(
135 pattern => $timestamp_format,
138 return $timestamp_parser->parse_datetime(shift);
141 sub format_datetime {
143 require DateTime::Format::Strptime;
144 $timestamp_parser ||= DateTime::Format::Strptime->new(
145 pattern => $timestamp_format,
148 return $timestamp_parser->format_datetime(shift);
153 require DateTime::Format::Strptime;
154 $date_parser ||= DateTime::Format::Strptime->new(
155 pattern => $date_format,
158 return $date_parser->parse_datetime(shift);
163 require DateTime::Format::Strptime;
164 $date_parser ||= DateTime::Format::Strptime->new(
165 pattern => $date_format,
168 return $date_parser->format_datetime(shift);
175 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
179 You may distribute this code under the same terms as Perl itself.