File Coverage

blib/lib/DBIx/Class/Storage/DBI/IdentityInsert.pm
Criterion Covered Total %
statement 15 22 68.1
branch 0 2 0.0
condition n/a
subroutine 5 6 83.3
pod n/a
total 20 30 66.6


line stmt bran cond sub pod time code
1             package DBIx::Class::Storage::DBI::IdentityInsert;
2              
3 5     5   27 use strict;
  5         8  
  5         126  
4 5     5   20 use warnings;
  5         4  
  5         118  
5 5     5   18 use base 'DBIx::Class::Storage::DBI';
  5         8  
  5         340  
6 5     5   23 use mro 'c3';
  5         7  
  5         24  
7              
8 5     5   99 use namespace::clean;
  5         9  
  5         31  
9              
10             =head1 NAME
11              
12             DBIx::Class::Storage::DBI::IdentityInsert - Storage Component for Sybase ASE and
13             MSSQL for Identity Inserts / Updates
14              
15             =head1 DESCRIPTION
16              
17             This is a storage component for Sybase ASE
18             (L) and Microsoft SQL Server
19             (L) to support identity inserts, that is
20             inserts of explicit values into C columns.
21              
22             This is done by wrapping C operations in a pair of table identity
23             toggles 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
32             # $dbh->do the $sql and the wrapping set()s individually. Hence the
33             # sql mangling. The newlines are important.
34             sub _prep_for_execute {
35 0     0     my $self = shift;
36              
37 0 0         return $self->next::method(@_) unless $self->_autoinc_supplied_for_op;
38              
39 0           my ($op, $ident) = @_;
40              
41 0           my $table = $self->sql_maker->_quote($ident->name);
42 0           $op = uc $op;
43              
44 0           my ($sql, $bind) = $self->next::method(@_);
45              
46 0           return (<
47             SET IDENTITY_$op $table ON
48             $sql
49             SET IDENTITY_$op $table OFF
50             EOS
51              
52             }
53              
54             =head1 FURTHER QUESTIONS?
55              
56             Check the list of L.
57              
58             =head1 COPYRIGHT AND LICENSE
59              
60             This module is free software L
61             by the L. You can
62             redistribute it and/or modify it under the same terms as the
63             L.
64              
65             =cut
66              
67             1;