/;
use mro 'c3';
use Carp::Clan qw/^DBIx::Class/;
-use List::Util ();
-use Sub::Name ();
+use List::Util();
+use Sub::Name();
+use Data::Dumper::Concise();
__PACKAGE__->mk_group_accessors('simple' =>
qw/_identity _blob_log_on_update _writer_storage _is_extra_storage
my $dbtype = eval {
@{$self->_get_dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2]
} || '';
+ $self->throw_exception("Unable to estable connection to determine database type: $@")
+ if $@;
- my $exception = $@;
$dbtype =~ s/\W/_/gi;
my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}";
- if (!$exception && $dbtype && $self->load_optional_class($subclass)) {
+ if ($dbtype && $self->load_optional_class($subclass)) {
bless $self, $subclass;
$self->_rebless;
} else { # real Sybase
my $self = shift;
$self->_set_max_connect(256);
- # based on LongReadLen in connect_info
- $self->set_textsize if $self->using_freetds;
-
# create storage for insert/(update blob) transactions,
# unless this is that storage
return if $self->_is_extra_storage;
$self->next::method;
}
+# Set up session settings for Sybase databases for the connection.
+#
# Make sure we have CHAINED mode turned on if AutoCommit is off in non-FreeTDS
# DBD::Sybase (since we don't know how DBD::Sybase was compiled.) If however
# we're using FreeTDS, CHAINED mode turns on an implicit transaction which we
# only want when AutoCommit is off.
-sub _populate_dbh {
+#
+# Also SET TEXTSIZE for FreeTDS because LongReadLen doesn't work.
+sub _run_connection_actions {
my $self = shift;
- $self->next::method(@_);
-
if ($self->_is_bulk_storage) {
# this should be cleared on every reconnect
$self->_began_bulk_work(0);
if (not $self->using_freetds) {
$self->_dbh->{syb_chained_txn} = 1;
} else {
+ # based on LongReadLen in connect_info
+ $self->set_textsize;
+
if ($self->_dbh_autocommit) {
$self->_dbh->do('SET CHAINED OFF');
} else {
$self->_dbh->do('SET CHAINED ON');
}
}
+
+ $self->next::method(@_);
}
=head2 connect_call_blob_setup
);
}
- if ($op eq 'insert' && (not $bound_identity_col) && $identity_col) {
+ if ($op eq 'insert' && (not $bound_identity_col) && $identity_col &&
+ (not $self->{insert_bulk})) {
$sql =
"$sql\n" .
$self->_fetch_identity_sql($ident, $identity_col);
# we are already in a transaction, or there are no blobs
# and we don't need the PK - just (try to) do it
if ($self->{transaction_depth}
- || (!$blob_cols && !$dumb_last_insert_id)
+ || (!$blob_cols && !$dumb_last_insert_id)
) {
return $self->_insert (
$next, $source, $to_insert, $blob_cols, $identity_col
if (not $use_bulk_api) {
my $blob_cols = $self->_remove_blob_cols_array($source, $cols, $data);
- my $dumb_last_insert_id =
- $identity_col
- && (not $is_identity_insert)
- && ($self->_identity_method||'') ne '@@IDENTITY';
+# _execute_array uses a txn anyway, but it ends too early in case we need to
+# select max(col) to get the identity for inserting blobs.
+ ($self, my $guard) = $self->{transaction_depth} == 0 ?
+ ($self->_writer_storage, $self->_writer_storage->txn_scope_guard)
+ :
+ ($self, undef);
- ($self, my ($guard)) = do {
- if ($self->{transaction_depth} == 0 && $blob_cols &&
- $dumb_last_insert_id) {
- ($self->_writer_storage, $self->_writer_storage->txn_scope_guard);
- }
- else {
- ($self, undef);
- }
- };
+ local $self->{insert_bulk} = 1;
$self->next::method(@_);
}
$guard->commit if $guard;
+
return;
}
};
$self->_execute_array(
- $source, $sth, \@bind, \@source_columns, \@new_data, $guard
+ $source, $sth, \@bind, \@source_columns, \@new_data, sub {
+ $guard->commit
+ }
);
$bulk->_query_end($sql);
}
}
+sub _dbh_execute_array {
+ my ($self, $sth, $tuple_status, $cb) = @_;
+
+ my $rv = $self->next::method($sth, $tuple_status);
+ $cb->() if $cb;
+
+ return $rv;
+}
+
# Make sure blobs are not bound as placeholders, and return any non-empty ones
# as a hash.
sub _remove_blob_cols {
$self->throw_exception(
"Could not find row in table '$table' for blob update:\n"
- . $self->_pretty_print (\%where)
+ . Data::Dumper::Concise::Dumper (\%where)
);
}