/;
use mro 'c3';
use Carp::Clan qw/^DBIx::Class/;
+use List::Util ();
=head1 NAME
# override to handle TEXT/IMAGE
sub insert {
my ($self, $source, $to_insert) = splice @_, 0, 3;
+ my $dbh = $self->_dbh;
my $blob_cols = $self->_remove_blob_cols($source, $to_insert);
+# check if we need to set IDENTITY_INSERT
+ my $identity_insert = 0;
+ my %col_info = map { ($_, $source->column_info($_)) } keys %$to_insert;
+ my $table = $source->from;
+
+ if (List::Util::first { $_->{is_auto_increment} } (values %col_info)) {
+ $identity_insert = 1;
+ $dbh->do("SET IDENTITY_INSERT $table ON");
+ }
+
my $updated_cols = $self->next::method($source, $to_insert, @_);
+ if ($identity_insert) {
+ $dbh->do("SET IDENTITY_INSERT $table OFF");
+ }
+
$self->_insert_blobs($source, $blob_cols, $to_insert) if %$blob_cols;
return $updated_cols;
}
# blob insert with explicit PK
+ # also a good opportunity to test IDENTITY_INSERT
{
local $SIG{__WARN__} = sub {};
eval { $dbh->do('DROP TABLE bindtype_test') };
$dbh->do(qq[
CREATE TABLE bindtype_test
(
- id INT PRIMARY KEY,
+ id INT IDENTITY PRIMARY KEY,
bytea INT NULL,
blob IMAGE NULL,
clob TEXT NULL