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