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>.
29 sub _prep_for_execute {
31 my ($op, $extra_bind, $ident, $args) = @_;
33 if ($op eq 'insert') {
34 my @pk = $ident->primary_columns;
38 my @auto_inc_cols = grep {
39 my $inserting = $args->[0]{$_};
41 ($ident->column_info($_)->{is_auto_increment}
44 (not defined $inserting)
46 (ref $inserting eq 'SCALAR' && $$inserting =~ /^null\z/i)
51 $args->[1]{returning} = \@auto_inc_cols;
53 $self->_auto_incs([]);
54 $self->_auto_incs->[0] = \@auto_inc_cols;
58 return $self->next::method(@_);
65 my ($rv, $sth, @bind) = $self->dbh_do($self->can('_dbh_execute'), @_);
67 if ($op eq 'insert' && $self->_auto_incs) {
69 my (@auto_incs) = eval {
70 local $SIG{__WARN__} = sub {};
73 $self->_auto_incs->[1] = \@auto_incs;
77 return wantarray ? ($rv, $sth, @bind) : $rv;
81 my ($self, $source, @cols) = @_;
85 @auto_incs{ @{ $self->_auto_incs->[0] } } =
86 @{ $self->_auto_incs->[1] };
88 push @result, $auto_incs{$_} for @cols;
93 # this sub stolen from DB2
96 my ( $self, $opts ) = @_;
99 $self->{_sql_maker_opts} = { %$opts };
102 return { limit_dialect => 'FirstSkip', %{$self->{_sql_maker_opts}||{}} };
105 sub datetime_parser_type { __PACKAGE__ }
107 my ($datetime_parser, $datetime_formatter);
111 require DateTime::Format::Strptime;
112 $datetime_parser ||= DateTime::Format::Strptime->new(
113 pattern => '%a %d %b %Y %r',
114 # there should be a %Z (TZ) on the end, but it's ambiguous and not parsed
117 $datetime_parser->parse_datetime(shift);
120 sub format_datetime {
122 require DateTime::Format::Strptime;
123 $datetime_formatter ||= DateTime::Format::Strptime->new(
124 pattern => '%F %H:%M:%S.%4N',
127 $datetime_formatter->format_datetime(shift);
138 C<last_insert_id> support only works for Firebird versions 2 or greater. To
139 work with earlier versions, we'll need to figure out how to retrieve the bodies
140 of C<BEFORE INSERT> triggers and parse them for the C<GENERATOR> name.
144 C<TIMESTAMP> values are written with precision of 4 numbers after the decimal
145 point for seconds, but read with only second precision.
147 If you know of a session variable we can set to control how timestamps look as
148 strings, please let us know (via RT.)
150 Otherwise we'll need to rewrite the produced SQL for timestamps, at some point.
156 See L<DBIx::Class/AUTHOR> and L<DBIx::Class/CONTRIBUTORS>.
160 You may distribute this code under the same terms as Perl itself.