From: Rafael Kitover Date: Fri, 24 Jul 2009 07:58:24 +0000 (+0000) Subject: add support for IDENTITY_INSERT X-Git-Tag: v0.08112~14^2~91 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=289877b0f45dc590dce3f9943543bfde98a7613f;p=dbsrgits%2FDBIx-Class.git add support for IDENTITY_INSERT --- diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index 68ce2c1..e67f1ca 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -9,6 +9,7 @@ use base qw/ /; use mro 'c3'; use Carp::Clan qw/^DBIx::Class/; +use List::Util (); =head1 NAME @@ -175,11 +176,26 @@ sub _is_lob_type { # 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; diff --git a/t/746sybase.t b/t/746sybase.t index 34eb475..7c9e56b 100644 --- a/t/746sybase.t +++ b/t/746sybase.t @@ -181,6 +181,7 @@ SQL } # blob insert with explicit PK + # also a good opportunity to test IDENTITY_INSERT { local $SIG{__WARN__} = sub {}; eval { $dbh->do('DROP TABLE bindtype_test') }; @@ -188,7 +189,7 @@ SQL $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