Commit | Line | Data |
88a8d0fa |
1 | package DBIx::Class::Storage::DBI::InterBase; |
2 | |
3 | # mostly stolen from DBIx::Class::Storage::DBI::MSSQL |
4 | |
5 | use strict; |
6 | use warnings; |
7 | |
8 | use base qw/DBIx::Class::Storage::DBI::AmbiguousGlob DBIx::Class::Storage::DBI/; |
9 | use mro 'c3'; |
10 | |
11 | use List::Util(); |
12 | |
13 | __PACKAGE__->mk_group_accessors(simple => qw/ |
14 | _identity _identity_method |
15 | /); |
16 | |
17 | __PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks::InterBase'); |
18 | |
19 | sub insert_bulk { |
20 | my $self = shift; |
21 | my ($source, $cols, $data) = @_; |
22 | |
23 | my $is_identity_insert = (List::Util::first |
24 | { $source->column_info ($_)->{is_auto_increment} } |
25 | (@{$cols}) |
26 | ) |
27 | ? 1 |
28 | : 0; |
29 | |
30 | $self->next::method(@_); |
31 | } |
32 | |
33 | |
34 | sub _prep_for_execute { |
35 | my $self = shift; |
36 | my ($op, $extra_bind, $ident, $args) = @_; |
37 | |
38 | my ($sql, $bind) = $self->next::method (@_); |
39 | |
40 | if ($op eq 'insert') { |
41 | $sql .= 'RETURNING "Id"'; |
42 | |
43 | } |
44 | |
45 | return ($sql, $bind); |
46 | } |
47 | |
48 | sub _execute { |
49 | my $self = shift; |
50 | my ($op) = @_; |
51 | |
52 | my ($rv, $sth, @bind) = $self->dbh_do($self->can('_dbh_execute'), @_); |
53 | |
54 | if ($op eq 'insert') { |
55 | |
56 | # this should bring back the result of SELECT SCOPE_IDENTITY() we tacked |
57 | # on in _prep_for_execute above |
58 | local $@; |
59 | my ($identity) = eval { $sth->fetchrow_array }; |
60 | |
61 | $self->_identity($identity); |
62 | $sth->finish; |
63 | } |
64 | |
65 | return wantarray ? ($rv, $sth, @bind) : $rv; |
66 | } |
67 | |
68 | sub last_insert_id { shift->_identity } |
69 | |
70 | 1; |
71 | |