1 package DBIx::Class::Storage::DBI::IdentityInsert;
5 use base 'DBIx::Class::Storage::DBI';
10 DBIx::Class::Storage::DBI::IdentityInsert - Storage Component for Sybase ASE and
11 MSSQL for Identity Inserts / Updates
15 This is a storage component for Sybase ASE
16 (L<DBIx::Class::Storage::DBI::Sybase::ASE>) and Microsoft SQL Server
17 (L<DBIx::Class::Storage::DBI::MSSQL>) to support identity inserts, that is
18 inserts of explicit values into C<IDENTITY> columns.
20 This is done by wrapping C<INSERT> operations in a pair of table identity
23 SET IDENTITY_INSERT $table ON
25 SET IDENTITY_INSERT $table OFF
29 # SET IDENTITY_X only works as part of a statement scope. We can not
30 # $dbh->do the $sql and the wrapping set()s individually. Hence the
31 # sql mangling. The newlines are important.
32 sub _prep_for_execute {
35 return $self->next::method(@_) unless $self->_autoinc_supplied_for_op;
37 my ($op, $ident) = @_;
39 my $table = $self->sql_maker->_quote($ident->name);
42 DBIx::Class::Exception->throw(
43 "Unexpected _autoinc_supplied_for_op flag in callstack - please file a bug including the stacktrace ( @{[ DBIx::Class::_ENV_::HELP_URL() ]} ):\n\n STACKTRACE STARTS",
45 ) if $op ne 'INSERT' and $op ne 'UPDATE';
47 my ($sql, $bind) = $self->next::method(@_);
49 return (<<EOS, $bind);
50 SET IDENTITY_$op $table ON
52 SET IDENTITY_$op $table OFF
57 =head1 FURTHER QUESTIONS?
59 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
61 =head1 COPYRIGHT AND LICENSE
63 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
64 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
65 redistribute it and/or modify it under the same terms as the
66 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.