SQLA::Limit is no more \o/
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Informix.pm
CommitLineData
193590c2 1package DBIx::Class::Storage::DBI::Informix;
2use strict;
3use warnings;
4
5use base qw/DBIx::Class::Storage::DBI/;
193590c2 6use mro 'c3';
7
d3774d9b 8use Scope::Guard ();
6298a324 9use Context::Preserve 'preserve_context';
10use namespace::clean;
d3774d9b 11
6a247f33 12__PACKAGE__->sql_limit_dialect ('SkipFirst');
13
193590c2 14__PACKAGE__->mk_group_accessors('simple' => '__last_insert_id');
15
b0a4cf8e 16=head1 NAME
17
18DBIx::Class::Storage::DBI::Informix - Base Storage Class for Informix Support
19
20=head1 DESCRIPTION
21
22This class implements storage-specific support for the Informix RDBMS
23
24=head1 METHODS
25
26=cut
27
193590c2 28sub _execute {
29 my $self = shift;
30 my ($op) = @_;
31 my ($rv, $sth, @rest) = $self->next::method(@_);
32 if ($op eq 'insert') {
33 $self->__last_insert_id($sth->{ix_sqlerrd}[1]);
34 }
35 return (wantarray ? ($rv, $sth, @rest) : $rv);
36}
37
38sub last_insert_id {
39 shift->__last_insert_id;
40}
41
9fb04139 42sub _svp_begin {
43 my ($self, $name) = @_;
44
45 $self->_get_dbh->do("SAVEPOINT $name");
46}
47
48# can't release savepoints
49sub _svp_release { 1 }
50
51sub _svp_rollback {
52 my ($self, $name) = @_;
53
54 $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
55}
56
d3774d9b 57sub with_deferred_fk_checks {
58 my ($self, $sub) = @_;
59
60 my $txn_scope_guard = $self->txn_scope_guard;
61
62 $self->_do_query('SET CONSTRAINTS ALL DEFERRED');
63
64 my $sg = Scope::Guard->new(sub {
65 $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE');
66 });
67
6298a324 68 return preserve_context { $sub->() } after => sub { $txn_scope_guard->commit };
d3774d9b 69}
70
b0a4cf8e 71=head2 connect_call_datetime_setup
9fb04139 72
b0a4cf8e 73Used as:
193590c2 74
b0a4cf8e 75 on_connect_call => 'datetime_setup'
193590c2 76
b0a4cf8e 77In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the C<DATE> and
78C<DATETIME> formats.
193590c2 79
b0a4cf8e 80Sets the following environment variables:
193590c2 81
b0a4cf8e 82 GL_DATE="%m/%d/%Y"
83 GL_DATETIME="%Y-%m-%d %H:%M:%S%F5"
193590c2 84
b0a4cf8e 85The C<DBDATE> and C<DBCENTURY> environment variables are cleared.
86
87B<NOTE:> setting the C<GL_DATE> environment variable seems to have no effect
88after the process has started, so the default format is used. The C<GL_DATETIME>
89setting does take effect however.
90
91The C<DATETIME> data type supports up to 5 digits after the decimal point for
92second precision, depending on how you have declared your column. The full
93possible precision is used.
94
95The column declaration for a C<DATETIME> with maximum precision is:
96
97 column_name DATETIME YEAR TO FRACTION(5)
193590c2 98
b0a4cf8e 99The C<DATE> data type stores the date portion only, and it B<MUST> be declared
100with:
101
102 data_type => 'date'
103
104in your Result class.
105
106You will need the L<DateTime::Format::Strptime> module for inflation to work.
107
108=cut
109
110sub connect_call_datetime_setup {
111 my $self = shift;
112
113 delete @ENV{qw/DBDATE DBCENTURY/};
114
115 $ENV{GL_DATE} = "%m/%d/%Y";
116 $ENV{GL_DATETIME} = "%Y-%m-%d %H:%M:%S%F5";
117}
118
119sub datetime_parser_type {
120 'DBIx::Class::Storage::DBI::Informix::DateTime::Format'
121}
122
123package # hide from PAUSE
124 DBIx::Class::Storage::DBI::Informix::DateTime::Format;
125
126my $timestamp_format = '%Y-%m-%d %H:%M:%S.%5N'; # %F %T
127my $date_format = '%m/%d/%Y';
128
129my ($timestamp_parser, $date_parser);
130
131sub parse_datetime {
132 shift;
133 require DateTime::Format::Strptime;
134 $timestamp_parser ||= DateTime::Format::Strptime->new(
135 pattern => $timestamp_format,
136 on_error => 'croak',
137 );
138 return $timestamp_parser->parse_datetime(shift);
139}
140
141sub format_datetime {
142 shift;
143 require DateTime::Format::Strptime;
144 $timestamp_parser ||= DateTime::Format::Strptime->new(
145 pattern => $timestamp_format,
146 on_error => 'croak',
147 );
148 return $timestamp_parser->format_datetime(shift);
149}
150
151sub parse_date {
152 shift;
153 require DateTime::Format::Strptime;
154 $date_parser ||= DateTime::Format::Strptime->new(
155 pattern => $date_format,
156 on_error => 'croak',
157 );
158 return $date_parser->parse_datetime(shift);
159}
160
161sub format_date {
162 shift;
163 require DateTime::Format::Strptime;
164 $date_parser ||= DateTime::Format::Strptime->new(
165 pattern => $date_format,
166 on_error => 'croak',
167 );
168 return $date_parser->format_datetime(shift);
169}
170
1711;
193590c2 172
b0a4cf8e 173=head1 AUTHOR
193590c2 174
b0a4cf8e 175See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
193590c2 176
177=head1 LICENSE
178
179You may distribute this code under the same terms as Perl itself.
180
181=cut