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