Factor SQL-standard deferred FK checks into a component
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Informix.pm
CommitLineData
193590c2 1package DBIx::Class::Storage::DBI::Informix;
2use strict;
3use warnings;
4
9334469c 5use base qw/DBIx::Class::Storage::DBI::SetConstraintsDeferred/;
193590c2 6use mro 'c3';
7
6298a324 8use 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
21DBIx::Class::Storage::DBI::Informix - Base Storage Class for Informix Support
22
23=head1 DESCRIPTION
24
25This class implements storage-specific support for the Informix RDBMS
26
27=head1 METHODS
28
29=cut
30
193590c2 31sub _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
41sub last_insert_id {
42 shift->__last_insert_id;
43}
44
90d7422f 45sub _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 52sub _exec_svp_release { 1 }
9fb04139 53
90d7422f 54sub _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 62Used as:
193590c2 63
b0a4cf8e 64 on_connect_call => 'datetime_setup'
193590c2 65
b0a4cf8e 66In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the C<DATE> and
67C<DATETIME> formats.
193590c2 68
b0a4cf8e 69Sets 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 74The C<DBDATE> and C<DBCENTURY> environment variables are cleared.
75
76B<NOTE:> setting the C<GL_DATE> environment variable seems to have no effect
77after the process has started, so the default format is used. The C<GL_DATETIME>
78setting does take effect however.
79
80The C<DATETIME> data type supports up to 5 digits after the decimal point for
81second precision, depending on how you have declared your column. The full
82possible precision is used.
83
84The column declaration for a C<DATETIME> with maximum precision is:
85
86 column_name DATETIME YEAR TO FRACTION(5)
193590c2 87
b0a4cf8e 88The C<DATE> data type stores the date portion only, and it B<MUST> be declared
89with:
90
91 data_type => 'date'
92
93in your Result class.
94
95You will need the L<DateTime::Format::Strptime> module for inflation to work.
96
97=cut
98
99sub 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 108package # hide from PAUSE
109 DBIx::Class::Storage::DBI::Informix::DateTime::Format;
110
111my $timestamp_format = '%Y-%m-%d %H:%M:%S.%5N'; # %F %T
112my $date_format = '%m/%d/%Y';
113
114my ($timestamp_parser, $date_parser);
115
116sub 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
126sub 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
136sub 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
146sub 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 158Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
193590c2 159
a2bd3796 160=head1 COPYRIGHT AND LICENSE
193590c2 161
a2bd3796 162This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
163by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
164redistribute it and/or modify it under the same terms as the
165L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
193590c2 166
167=cut
a2bd3796 168
1691;
170