fix _insert_dbh code to only connect when needed, doc update
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase.pm
index 43bb7bb..68c2e20 100644 (file)
@@ -12,7 +12,7 @@ use Carp::Clan qw/^DBIx::Class/;
 use List::Util ();
 
 __PACKAGE__->mk_group_accessors('simple' =>
-    qw/_identity _blob_log_on_update unsafe_insert/
+    qw/_identity _blob_log_on_update unsafe_insert _insert_dbh/
 );
 
 =head1 NAME
@@ -258,7 +258,7 @@ sub _native_data_type {
   my ($self, $type) = @_;
 
   $type = lc $type;
-  $type =~ s/ identity//;
+  $type =~ s/\s* identity//x;
 
   return uc($TYPE_MAPPING{$type} || $type);
 }
@@ -312,9 +312,13 @@ sub insert {
     if (
       $need_last_insert_id && !$self->unsafe_insert && !$self->{transaction_depth}
     ) {
+      $self->_insert_dbh($self->_connect(@{ $self->_dbi_connect_info }))
+        unless $self->_insert_dbh;
+      local $self->{_dbh} = $self->_insert_dbh;
       my $guard = $self->txn_scope_guard;
       my $upd_cols = $self->next::method (@_);
       $guard->commit;
+      $self->_insert_dbh($self->_dbh);
       $upd_cols;
     }
     else {
@@ -618,19 +622,12 @@ C<next> or C<first> but has not been exhausted or
 L<reset|DBIx::Class::ResultSet/reset>.
 
 Transactions done for inserts in C<AutoCommit> mode when placeholders are in use
-are also affected, so this won't work:
-
-  while (my $row = $rs1->next) {
-    $rs2->create({ foo => $row->foo });
-  }
+are not affected, as they use an extra database handle to do the insert.
 
 Some workarounds:
 
 =over 4
 
-=item * set C<< $schema->storage->unsafe_insert(1) >> temporarily (see
-L</connect_call_unsafe_insert>)
-
 =item * use L<DBIx::Class::Storage::DBI::Replicated>
 
 =item * L<connect|DBIx::Class::Schema/connect> another L<Schema|DBIx::Class::Schema>