Remove dead code from DBI::Replicated
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / IdentityInsert.pm
CommitLineData
fabbd5cc 1package DBIx::Class::Storage::DBI::IdentityInsert;
2
3use strict;
4use warnings;
5use base 'DBIx::Class::Storage::DBI';
6use mro 'c3';
7
8use namespace::clean;
9
10=head1 NAME
11
12DBIx::Class::Storage::DBI::IdentityInsert - Storage Component for Sybase ASE and
13MSSQL for Identity Inserts / Updates
14
15=head1 DESCRIPTION
16
17This is a storage component for Sybase ASE
18(L<DBIx::Class::Storage::DBI::Sybase::ASE>) and Microsoft SQL Server
19(L<DBIx::Class::Storage::DBI::MSSQL>) to support identity inserts, that is
20inserts of explicit values into C<IDENTITY> columns.
21
22This is done by wrapping C<INSERT> operations in a pair of table identity
23toggles like:
24
25 SET IDENTITY_INSERT $table ON
26 $sql
27 SET IDENTITY_INSERT $table OFF
28
29=cut
30
31# SET IDENTITY_X only works as part of a statement scope. We can not
4a0eed52 32# $dbh->do the $sql and the wrapping set()s individually. Hence the
fabbd5cc 33# sql mangling. The newlines are important.
34sub _prep_for_execute {
35 my $self = shift;
36
37 return $self->next::method(@_) unless $self->_autoinc_supplied_for_op;
38
39 my ($op, $ident) = @_;
40
41 my $table = $self->sql_maker->_quote($ident->name);
42 $op = uc $op;
43
4a5fd481 44 DBIx::Class::Exception->throw(
45 "Unexpected _autoinc_supplied_for_op flag in callstack - please file a bug including the stacktrace ( @{[ DBIx::Class::_ENV_::HELP_URL() ]} ):\n\n STACKTRACE STARTS",
46 'stacktrace'
47 ) if $op ne 'INSERT' and $op ne 'UPDATE';
48
fabbd5cc 49 my ($sql, $bind) = $self->next::method(@_);
50
51 return (<<EOS, $bind);
52SET IDENTITY_$op $table ON
53$sql
54SET IDENTITY_$op $table OFF
55EOS
56
57}
58
a2bd3796 59=head1 FURTHER QUESTIONS?
fabbd5cc 60
a2bd3796 61Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
fabbd5cc 62
a2bd3796 63=head1 COPYRIGHT AND LICENSE
fabbd5cc 64
a2bd3796 65This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
66by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
67redistribute it and/or modify it under the same terms as the
68L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
fabbd5cc 69
70=cut
71
721;