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