factor out subclass-specific _execute_array callback
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase.pm
index dcba119..b6352e0 100644 (file)
@@ -277,7 +277,8 @@ sub _prep_for_execute {
     );
   }
 
-  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);
@@ -449,6 +450,8 @@ sub update {
 # it is originally put by _remove_blob_cols .)
   my %blobs_to_empty = map { ($_ => delete $fields->{$_}) } keys %$blob_cols;
 
+# We can't only update NULL blobs, because blobs cannot be in the WHERE clause.
+
   $self->next::method($source, \%blobs_to_empty, $where, @rest);
 
 # Now update the blobs before the other columns in case the update of other
@@ -510,15 +513,12 @@ EOF
       && (not $is_identity_insert)
       && ($self->_identity_method||'') ne '@@IDENTITY';
 
-    ($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);
-      }
-    };
+    ($self, my $guard) = $self->{transaction_depth} == 0 ? 
+      ($self->_writer_storage, $self->_writer_storage->txn_scope_guard)
+      :
+      ($self, undef);
+
+    local $self->{insert_bulk} = 1;
 
     $self->next::method(@_);
 
@@ -547,6 +547,7 @@ EOF
     }
 
     $guard->commit if $guard;
+
     return;
   }
 
@@ -631,7 +632,9 @@ EOF
     };
 
     $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);
@@ -661,6 +664,15 @@ EOF
   }
 }
 
+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 {
@@ -681,7 +693,7 @@ sub _remove_blob_cols {
     }
   }
 
-  return keys %blob_cols ? \%blob_cols : undef;
+  return %blob_cols ? \%blob_cols : undef;
 }
 
 # same for insert_bulk
@@ -852,7 +864,7 @@ C<SMALLDATETIME> columns only have minute precision.
 
   sub connect_call_datetime_setup {
     my $self = shift;
-    my $dbh = $self->_dbh;
+    my $dbh = $self->_get_dbh;
 
     if ($dbh->can('syb_date_fmt')) {
       # amazingly, this works with FreeTDS
@@ -1088,6 +1100,33 @@ loading your app, if it doesn't match the character set of your database.
 When inserting IMAGE columns using this method, you'll need to use
 L</connect_call_blob_setup> as well.
 
+=head1 TODO
+
+=over
+
+=item *
+
+Transitions to AutoCommit=0 (starting a transaction) mode by exhausting
+any active cursors, using eager cursors.
+
+=item *
+
+Real limits and limited counts using stored procedures deployed on startup.
+
+=item *
+
+Adaptive Server Anywhere (ASA) support, with possible SQLA::Limit support.
+
+=item *
+
+Blob update with a LIKE query on a blob, without invalidating the WHERE condition.
+
+=item *
+
+bulk_insert using prepare_cached (see comments.)
+
+=back
+
 =head1 AUTHOR
 
 See L<DBIx::Class/CONTRIBUTORS>.