From: Arthur Axel "fREW" Schmidt Date: Fri, 12 Jun 2009 15:26:53 +0000 (+0000) Subject: Insert Identity works! X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=05f7f61a710d17c9443b9ac823f63d867ebf0830;p=dbsrgits%2FDBIx-Class-Historic.git Insert Identity works! --- diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm index 4383e4d..832b1ed 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm @@ -12,23 +12,28 @@ sub insert_bulk { COLUMNS: foreach my $col (@{$cols}) { if ($source->column_info($col)->{is_auto_increment}) { + warn $col; $identity_insert = 1; last COLUMNS; } } my $table = $source->from; - $source->storage->dbh_do(sub { - my ($storage, $dbh, @cols) = @_; - $dbh->do("SET IDENTITY_INSERT $table ON;"); - }); + if ($identity_insert) { + $source->storage->dbh_do(sub { + my ($storage, $dbh, @cols) = @_; + $dbh->do("SET IDENTITY_INSERT $table ON;"); + }); + } next::method(@_); - $source->storage->dbh_do(sub { - my ($storage, $dbh, @cols) = @_; - $dbh->do("SET IDENTITY_INSERT $table OFF;"); - }); + if ($identity_insert) { + $source->storage->dbh_do(sub { + my ($storage, $dbh, @cols) = @_; + $dbh->do("SET IDENTITY_INSERT $table OFF;"); + }); + } }