1 package DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server;
5 use base qw/DBIx::Class::Storage::DBI::MSSQL/;
8 use Carp::Clan qw/^DBIx::Class/;
12 __PACKAGE__->mk_group_accessors(simple => qw/
13 _using_dynamic_cursors
18 DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server - Support specific
19 to Microsoft SQL Server over ODBC
23 This class implements support specific to Microsoft SQL Server over ODBC. It is
24 loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it detects a
27 Most of the functionality is provided from the superclass
28 L<DBIx::Class::Storage::DBI::MSSQL>.
30 =head1 MULTIPLE ACTIVE STATEMENTS
32 The following options are alternative ways to enable concurrent executing
33 statement support. Each has its own advantages and drawbacks.
35 =head2 connect_call_use_dynamic_cursors
39 on_connect_call => 'use_dynamic_cursors'
41 in your L<DBIx::Class::Storage::DBI/connect_info> as one way to enable multiple
42 concurrent statements.
44 Will add C<< odbc_cursortype => 2 >> to your DBI connection attributes. See
45 L<DBD::ODBC/odbc_cursortype> for more information.
47 Alternatively, you can add it yourself and dynamic cursor will be automatically
50 This will not work with CODE ref connect_info's and will do nothing if you set
51 C<odbc_cursortype> yourself.
53 B<WARNING:> this will break C<SCOPE_IDENTITY()>, and C<SELECT @@IDENTITY> will
54 be used instead, which on SQL Server 2005 and later will return erroneous
55 results on tables which have an on insert trigger that inserts into another
56 table with an C<IDENTITY> column.
60 sub connect_call_use_dynamic_cursors {
63 if (ref($self->_dbi_connect_info->[0]) eq 'CODE') {
64 croak 'cannot set DBI attributes on a CODE ref connect_info';
67 my $dbi_attrs = $self->_dbi_connect_info->[-1];
69 unless (ref($dbi_attrs) && Scalar::Util::reftype($dbi_attrs) eq 'HASH') {
71 push @{ $self->_dbi_connect_info }, $dbi_attrs;
74 if (not exists $dbi_attrs->{odbc_cursortype}) {
75 # turn on support for multiple concurrent statements, unless overridden
76 $dbi_attrs->{odbc_cursortype} = 2;
77 my $connected = defined $self->_dbh;
79 $self->ensure_connected if $connected;
80 $self->_set_dynamic_cursors;
84 sub _set_dynamic_cursors {
86 $self->_using_dynamic_cursors(1);
87 $self->_identity_method('@@identity');
91 no warnings 'uninitialized';
94 if (ref($self->_dbi_connect_info->[0]) ne 'CODE' &&
95 eval { $self->_dbi_connect_info->[-1]{odbc_cursortype} } == 2) {
96 $self->_set_dynamic_cursors;
100 $self->_using_dynamic_cursors(0);
103 =head2 connect_call_use_server_cursors
107 on_connect_call => 'use_server_cursors'
109 May allow multiple active select statements. See
110 L<DBD::ODBC/odbc_SQL_ROWSET_SIZE> for more information.
112 Takes an optional parameter for the value to set the attribute to, default is
115 B<WARNING>: this does not work on all versions of SQL Server, and may lock up
120 sub connect_call_use_server_cursors {
122 my $sql_rowset_size = shift || 2;
124 $self->_dbh->{odbc_SQL_ROWSET_SIZE} = $sql_rowset_size;
127 =head2 connect_call_use_mars
131 on_connect_call => 'use_mars'
133 Use to enable a feature of SQL Server 2005 and later, "Multiple Active Result
134 Sets". See L<DBD::ODBC::FAQ/Does DBD::ODBC support Multiple Active Statements?>
135 for more information.
137 B<WARNING>: This has implications for the way transactions are handled.
141 sub connect_call_use_mars {
144 my $dsn = $self->_dbi_connect_info->[0];
146 if (ref($dsn) eq 'CODE') {
147 croak 'cannot change the DBI DSN on a CODE ref connect_info';
150 if ($dsn !~ /MARS_Connection=/) {
151 $self->_dbi_connect_info->[0] = "$dsn;MARS_Connection=Yes";
152 my $connected = defined $self->_dbh;
154 $self->ensure_connected if $connected;
162 See L<DBIx::Class/CONTRIBUTORS>.
166 You may distribute this code under the same terms as Perl itself.