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 {
[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/],
}, {
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)
}, {
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 }});
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