From: Arthur Axel "fREW" Schmidt Date: Fri, 12 Jun 2009 15:13:32 +0000 (+0000) Subject: Now I just need to check if the actual values are set... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=134a3bb99c31b216ef74f50264458db6c09ba61f;p=dbsrgits%2FDBIx-Class-Historic.git Now I just need to check if the actual values are set... --- 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 ff79f54..4383e4d 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm @@ -6,7 +6,30 @@ use base qw/DBIx::Class::Storage::DBI::MSSQL/; sub insert_bulk { my ($self, $source, $cols, $data) = @_; + + my $identity_insert = 0; + + COLUMNS: + foreach my $col (@{$cols}) { + if ($source->column_info($col)->{is_auto_increment}) { + $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;"); + }); + next::method(@_); + + $source->storage->dbh_do(sub { + my ($storage, $dbh, @cols) = @_; + $dbh->do("SET IDENTITY_INSERT $table OFF;"); + }); + } sub _prep_for_execute { diff --git a/t/746mssql.t b/t/746mssql.t index b1871f1..32464a6 100644 --- a/t/746mssql.t +++ b/t/746mssql.t @@ -93,13 +93,11 @@ CREATE TABLE Owners ( [name] VARCHAR(100), ) -SET IDENTITY_INSERT Owners ON - SQL }); $schema->populate ('Owners', [ - [qw/id [name] /], + [qw/id name /], [qw/1 wiggle/], [qw/2 woggle/], [qw/3 boggle/], @@ -144,15 +142,15 @@ $schema->populate ('BooksInLibrary', [ }, { prefetch => 'books', distinct => 1, - order_by => 'name', - page => 2, - rows => 5, + #order_by => 'name', + #page => 2, + #rows => 5, }); my $owners2 = $schema->resultset ('Owners')->search ({ id => { -in => $owners->get_column ('me.id')->as_query }}); for ($owners, $owners2) { - is ($_->all, 2, 'Prefetched grouped search returns correct number of rows'); - is ($_->count, 2, 'Prefetched grouped search returns correct count'); + is ($_->all, 8, 'Prefetched grouped search returns correct number of rows'); + is ($_->count, 8, 'Prefetched grouped search returns correct count'); } # try a ->belongs_to direction (no select collapse) @@ -161,9 +159,9 @@ $schema->populate ('BooksInLibrary', [ }, { prefetch => 'owner', distinct => 1, - order_by => 'name', - page => 2, - rows => 5, + #order_by => 'name', + #page => 2, + #rows => 5, }); my $books2 = $schema->resultset ('BooksInLibrary')->search ({ id => { -in => $books->get_column ('me.id')->as_query }}); @@ -172,13 +170,6 @@ $schema->populate ('BooksInLibrary', [ is ($_->count, 1, 'Prefetched grouped search returns correct count'); } - #my $result = $schema->resultset('BooksInLibrary')->search(undef, { - #page => 1, - #rows => 25, - #order_by => ['name', 'title'], - #prefetch => 'owner' - #})->first; - } # clean up our mess