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