__PACKAGE__->mk_group_accessors('simple' =>
qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts _conn_pid
- _conn_tid transaction_depth _dbh_autocommit _driver_determined savepoints/
+ _conn_tid transaction_depth _dbh_autocommit _driver_determined savepoints
+ __server_info/
);
# the values for these accessors are picked out (and deleted) from
# default cursor class, overridable in connect_info attributes
__PACKAGE__->cursor_class('DBIx::Class::Storage::DBI::Cursor');
-__PACKAGE__->mk_group_accessors('inherited' => qw/sql_maker_class/);
+__PACKAGE__->mk_group_accessors('inherited' => qw/
+ sql_maker_class
+ can_insert_returning
+/);
__PACKAGE__->sql_maker_class('DBIx::Class::SQLAHacks');
$self->{transaction_depth} = $self->_dbh_autocommit ? 0 : 1;
$self->_run_connection_actions unless $self->{_in_determine_driver};
+
+ $self->_populate_server_info;
}
sub _run_connection_actions {
$self->_do_connection_actions(connect_call_ => $_) for @actions;
}
+sub _populate_server_info {
+ my $self = shift;
+ my %info;
+
+ my $dbms_ver = eval { local $@; $self->_get_dbh->get_info(18) };
+
+ $info{dbms_ver} = $dbms_ver if defined $dbms_ver;
+
+ $self->__server_info(\%info);
+
+ return \%info;
+}
+
+sub _server_info {
+ my $self = shift;
+
+ $self->_get_dbh;
+
+ return $self->__server_info(@_);
+}
+
sub _determine_driver {
my ($self) = @_;
sub insert {
my $self = shift;
- my ($source, $to_insert) = @_;
+ my ($source, $to_insert, $opts) = @_;
my $updated_cols = $self->_prefetch_insert_auto_nextvals (@_);
my $bind_attributes = $self->source_bind_attributes($source);
- $self->_execute('insert' => [], $source, $bind_attributes, $to_insert);
+ my ($rv, $sth) = $self->_execute('insert' => [], $source, $bind_attributes, $to_insert, $opts);
+
+ if ($opts->{returning}) {
+ my @ret_cols = @{$opts->{returning}};
+
+ my @ret_vals = eval {
+ local $SIG{__WARN__} = sub {};
+ my @r = $sth->fetchrow_array;
+ $sth->finish;
+ @r;
+ };
+
+ my %ret;
+ @ret{@ret_cols} = @ret_vals if (@ret_vals);
+
+ $updated_cols = {
+ %$updated_cols,
+ %ret,
+ };
+ }
return $updated_cols;
}