Fix datetimes in ODBC/Firebird (merge identical code left after a870aa85e)
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / InterBase.pm
CommitLineData
88a8d0fa 1package DBIx::Class::Storage::DBI::InterBase;
2
88a8d0fa 3use strict;
4use warnings;
e46df41a 5use base qw/DBIx::Class::Storage::DBI::Firebird::Common/;
88a8d0fa 6use mro 'c3';
ed7ab0f4 7use Try::Tiny;
fd323bf1 8use namespace::clean;
88a8d0fa 9
90489c23 10=head1 NAME
11
e46df41a 12DBIx::Class::Storage::DBI::InterBase - Driver for the Firebird RDBMS via
13L<DBD::InterBase>
90489c23 14
15=head1 DESCRIPTION
16
e46df41a 17This driver is a subclass of L<DBIx::Class::Storage::DBI::Firebird::Common> for
18use with L<DBD::InterBase>, see that driver for general details.
90489c23 19
dd2109ee 20You need to use either the
21L<disable_sth_caching|DBIx::Class::Storage::DBI/disable_sth_caching> option or
22L</connect_call_use_softcommit> (see L</CAVEATS>) for your code to function
47ec67c3 23correctly with this driver. Otherwise you will likely get bizarre error messages
d1fc96c7 24such as C<no statement executing>. The alternative is to use the
25L<ODBC|DBIx::Class::Storage::DBI::ODBC::Firebird> driver, which is more suitable
26for long running processes such as under L<Catalyst>.
90489c23 27
c5827074 28To turn on L<DBIx::Class::InflateColumn::DateTime> support, see
29L</connect_call_datetime_setup>.
32323fc2 30
90489c23 31=cut
32
32323fc2 33sub _ping {
34 my $self = shift;
35
36 my $dbh = $self->_dbh or return 0;
37
38 local $dbh->{RaiseError} = 1;
ecdf1ac8 39 local $dbh->{PrintError} = 0;
32323fc2 40
52b420dd 41 return try {
32323fc2 42 $dbh->do('select 1 from rdb$database');
52b420dd 43 1;
ed7ab0f4 44 } catch {
52b420dd 45 0;
32323fc2 46 };
32323fc2 47}
48
9633951d 49# We want dialect 3 for new features and quoting to work, DBD::InterBase uses
50# dialect 1 (interbase compat) by default.
51sub _init {
52 my $self = shift;
53 $self->_set_sql_dialect(3);
54}
55
56sub _set_sql_dialect {
57 my $self = shift;
58 my $val = shift || 3;
59
60 my $dsn = $self->_dbi_connect_info->[0];
61
62 return if ref($dsn) eq 'CODE';
63
64 if ($dsn !~ /ib_dialect=/) {
65 $self->_dbi_connect_info->[0] = "$dsn;ib_dialect=$val";
66 my $connected = defined $self->_dbh;
67 $self->disconnect;
68 $self->ensure_connected if $connected;
69 }
70}
71
dd2109ee 72=head2 connect_call_use_softcommit
73
74Used as:
75
76 on_connect_call => 'use_softcommit'
77
78In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the
79L<DBD::InterBase> C<ib_softcommit> option.
80
81You need either this option or C<< disable_sth_caching => 1 >> for
47ec67c3 82L<DBIx::Class> code to function correctly (otherwise you may get C<no statement
d1fc96c7 83executing> errors.) Or use the L<ODBC|DBIx::Class::Storage::DBI::ODBC::Firebird>
84driver.
dd2109ee 85
86The downside of using this option is that your process will B<NOT> see UPDATEs,
87INSERTs and DELETEs from other processes for already open statements.
88
89=cut
90
91sub connect_call_use_softcommit {
a499b173 92 my $self = shift;
93
94 $self->_dbh->{ib_softcommit} = 1;
a499b173 95}
96
32323fc2 97=head2 connect_call_datetime_setup
9cd0b325 98
32323fc2 99Used as:
9cd0b325 100
32323fc2 101 on_connect_call => 'datetime_setup'
102
f0f8ac86 103In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the date and
104timestamp formats using:
32323fc2 105
106 $dbh->{ib_time_all} = 'ISO';
107
108See L<DBD::InterBase> for more details.
109
110The C<TIMESTAMP> data type supports up to 4 digits after the decimal point for
111second precision. The full precision is used.
112
c5827074 113The C<DATE> data type stores the date portion only, and it B<MUST> be declared
114with:
115
116 data_type => 'date'
117
118in your Result class.
119
120Timestamp columns can be declared with either C<datetime> or C<timestamp>.
121
32323fc2 122You will need the L<DateTime::Format::Strptime> module for inflation to work.
123
a870aa85 124For L<DBIx::Class::Storage::DBI::ODBC::Firebird>, this is a noop.
32323fc2 125
126=cut
127
128sub connect_call_datetime_setup {
129 my $self = shift;
130
131 $self->_get_dbh->{ib_time_all} = 'ISO';
9cd0b325 132}
133
145b2a3d 1341;
90489c23 135
136=head1 CAVEATS
137
138=over 4
139
140=item *
141
dd2109ee 142with L</connect_call_use_softcommit>, you will not be able to see changes made
143to data in other processes. If this is an issue, use
47ec67c3 144L<disable_sth_caching|DBIx::Class::Storage::DBI/disable_sth_caching> as a
145workaround for the C<no statement executing> errors, this of course adversely
146affects performance.
dd2109ee 147
d1fc96c7 148Alternately, use the L<ODBC|DBIx::Class::Storage::DBI::ODBC::Firebird> driver.
149
90489c23 150=back
151
152=head1 AUTHOR
153
154See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
155
156=head1 LICENSE
157
158You may distribute this code under the same terms as Perl itself.
159
160=cut
e02b39b4 161# vim:sts=2 sw=2: