1 package DBIx::Class::Storage::DBI::InterBase;
3 # partly stolen from DBIx::Class::Storage::DBI::MSSQL
7 use base qw/DBIx::Class::Storage::DBI/;
11 __PACKAGE__->mk_group_accessors(simple => qw/
17 DBIx::Class::Storage::DBI::InterBase - Driver for the Firebird RDBMS
21 This class implements autoincrements for Firebird using C<RETURNING>, sets the
22 limit dialect to C<FIRST X SKIP X> and provides preliminary
23 L<DBIx::Class::InflateColumn::DateTime> support.
25 For ODBC support, see L<DBIx::Class::Storage::DBI::ODBC::Firebird>.
27 To turn on L<DBIx::Class::InflateColumn::DateTime> support, add:
29 on_connect_call => 'datetime_setup'
31 to your L<DBIx::Class::Storage::DBI/connect_info>.
35 sub _prep_for_execute {
37 my ($op, $extra_bind, $ident, $args) = @_;
39 if ($op eq 'insert') {
40 my @pk = $ident->primary_columns;
44 my @auto_inc_cols = grep {
45 my $inserting = $args->[0]{$_};
47 ($ident->column_info($_)->{is_auto_increment}
50 (not defined $inserting)
52 (ref $inserting eq 'SCALAR' && $$inserting =~ /^null\z/i)
57 $args->[1]{returning} = \@auto_inc_cols;
59 $self->_auto_incs([]);
60 $self->_auto_incs->[0] = \@auto_inc_cols;
64 return $self->next::method(@_);
71 my ($rv, $sth, @bind) = $self->dbh_do($self->can('_dbh_execute'), @_);
73 if ($op eq 'insert' && $self->_auto_incs) {
75 my (@auto_incs) = eval {
76 local $SIG{__WARN__} = sub {};
79 $self->_auto_incs->[1] = \@auto_incs;
83 return wantarray ? ($rv, $sth, @bind) : $rv;
87 my ($self, $source, @cols) = @_;
91 @auto_incs{ @{ $self->_auto_incs->[0] } } =
92 @{ $self->_auto_incs->[1] };
94 push @result, $auto_incs{$_} for @cols;
99 # this sub stolen from DB2
101 sub _sql_maker_opts {
102 my ( $self, $opts ) = @_;
105 $self->{_sql_maker_opts} = { %$opts };
108 return { limit_dialect => 'FirstSkip', %{$self->{_sql_maker_opts}||{}} };
112 my ($self, $name) = @_;
114 $self->_get_dbh->do("SAVEPOINT $name");
118 my ($self, $name) = @_;
120 $self->_get_dbh->do("RELEASE SAVEPOINT $name");
124 my ($self, $name) = @_;
126 $self->_get_dbh->do("ROLLBACK TO SAVEPOINT $name")
132 my $dbh = $self->_dbh or return 0;
134 local $dbh->{RaiseError} = 1;
137 $dbh->do('select 1 from rdb$database');
143 =head2 connect_call_datetime_setup
147 on_connect_call => 'datetime_setup'
149 In L<DBIx::Class::Storage::DBI/connect_info> to set the date and timestamp
152 $dbh->{ib_time_all} = 'ISO';
154 See L<DBD::InterBase> for more details.
156 The C<TIMESTAMP> data type supports up to 4 digits after the decimal point for
157 second precision. The full precision is used.
159 You will need the L<DateTime::Format::Strptime> module for inflation to work.
161 For L<DBIx::Class::Storage::DBI::ODBC::Firebird>, this is a noop and sub-second
162 precision is not currently available.
166 sub connect_call_datetime_setup {
169 $self->_get_dbh->{ib_time_all} = 'ISO';
175 sub build_datetime_parser {
177 my $type = "DateTime::Format::Strptime";
179 $self->throw_exception("Couldn't load ${type}: $@") if $@;
181 pattern => '%Y-%m-%d %H:%M:%S.%4N', # %F %T
194 C<last_insert_id> support only works for Firebird versions 2 or greater. To
195 work with earlier versions, we'll need to figure out how to retrieve the bodies
196 of C<BEFORE INSERT> triggers and parse them for the C<GENERATOR> name.
202 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
206 You may distribute this code under the same terms as Perl itself.