[Bast-commits] r7112 - in DBIx-Class/0.08/branches/sybase:
lib/DBIx/Class/Storage/DBI t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Fri Jul 24 07:58:24 GMT 2009
Author: caelum
Date: 2009-07-24 07:58:24 +0000 (Fri, 24 Jul 2009)
New Revision: 7112
Modified:
DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
DBIx-Class/0.08/branches/sybase/t/746sybase.t
Log:
add support for IDENTITY_INSERT
Modified: DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm
===================================================================
--- DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-07-24 07:22:33 UTC (rev 7111)
+++ DBIx-Class/0.08/branches/sybase/lib/DBIx/Class/Storage/DBI/Sybase.pm 2009-07-24 07:58:24 UTC (rev 7112)
@@ -9,6 +9,7 @@
/;
use mro 'c3';
use Carp::Clan qw/^DBIx::Class/;
+use List::Util ();
=head1 NAME
@@ -175,11 +176,26 @@
# 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;
Modified: DBIx-Class/0.08/branches/sybase/t/746sybase.t
===================================================================
--- DBIx-Class/0.08/branches/sybase/t/746sybase.t 2009-07-24 07:22:33 UTC (rev 7111)
+++ DBIx-Class/0.08/branches/sybase/t/746sybase.t 2009-07-24 07:58:24 UTC (rev 7112)
@@ -181,6 +181,7 @@
}
# 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 @@
$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
More information about the Bast-commits
mailing list