X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FODBC%2FMicrosoft_SQL_Server.pm;h=03053c6cb87b353eaf5236567ff013d9db075f38;hb=384b8bce2c9e4081cb131bba591627fda2672a5a;hp=e65654895cb1336f574b69cd96ab34d47ac71063;hpb=1d342d91aeb39ea8a6efd0b69e861ac643bc513f;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm index e656548..03053c6 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm @@ -2,95 +2,253 @@ package DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server; use strict; use warnings; -use base qw/DBIx::Class::Storage::DBI/; +use base qw/DBIx::Class::Storage::DBI::MSSQL/; +use mro 'c3'; +use Scalar::Util 'reftype'; +use Try::Tiny; +use Carp::Clan qw/^DBIx::Class/; +use namespace::clean; -sub _prep_for_execute { - my $self = shift; - my ($op, $extra_bind, $ident, $args) = @_; +__PACKAGE__->mk_group_accessors(simple => qw/ + _using_dynamic_cursors +/); - my ($sql, $bind) = $self->SUPER::_prep_for_execute(@_); - $sql .= ';SELECT SCOPE_IDENTITY()' if $op eq 'insert'; +=head1 NAME - return ($sql, $bind); -} +DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server - Support specific +to Microsoft SQL Server over ODBC -sub insert { - my ($self, $source, $to_insert) = @_; +=head1 DESCRIPTION - my $bind_attributes = $self->source_bind_attributes($source); - my (undef, $sth) = $self->_execute( 'insert' => [], $source, $bind_attributes, $to_insert); - $self->{_scope_identity} = $sth->fetchrow_array; +This class implements support specific to Microsoft SQL Server over ODBC. It is +loaded automatically by by DBIx::Class::Storage::DBI::ODBC when it detects a +MSSQL back-end. - return $to_insert; -} +Most of the functionality is provided from the superclass +L. + +=head1 MULTIPLE ACTIVE STATEMENTS + +The following options are alternative ways to enable concurrent executing +statement support. Each has its own advantages and drawbacks and works on +different platforms. Read each section carefully. + +In order of preference, they are: + +=over 8 + +=item * L -sub last_insert_id { shift->{_scope_identity} } +=item * L -sub sqlt_type { 'SQLServer' } +=item * L -sub _sql_maker_opts { - my ( $self, $opts ) = @_; +=back - if ( $opts ) { - $self->{_sql_maker_opts} = { %$opts }; +=head1 METHODS + +=head2 connect_call_use_mars + +Use as: + + on_connect_call => 'use_mars' + +Use to enable a feature of SQL Server 2005 and later, "Multiple Active Result +Sets". See L +for more information. + +This does not work on FreeTDS drivers at the time of this writing, and only +works with the Native Client, later versions of the Windows MS ODBC driver, and +the Easysoft driver. + +=cut + +sub connect_call_use_mars { + my $self = shift; + + my $dsn = $self->_dbi_connect_info->[0]; + + if (ref($dsn) eq 'CODE') { + $self->throw_exception('cannot change the DBI DSN on a CODE ref connect_info'); + } + + if ($dsn !~ /MARS_Connection=/) { + if ($self->using_freetds) { + $self->throw_exception('FreeTDS does not support MARS at the time of ' + .'writing.'); + } + + if (exists $self->_server_info->{normalized_dbms_version} && + $self->_server_info->{normalized_dbms_version} < 9) { + $self->throw_exception('SQL Server 2005 or later required to use MARS.'); + } + + if (my ($data_source) = $dsn =~ /^dbi:ODBC:([\w-]+)\z/i) { # prefix with DSN + warn "Bare DSN in ODBC connect string, rewriting to DSN=$data_source\n"; + $dsn = "dbi:ODBC:DSN=$data_source"; } - return { limit_dialect => 'Top', %{$self->{_sql_maker_opts}||{}} }; + $self->_dbi_connect_info->[0] = "$dsn;MARS_Connection=Yes"; + $self->disconnect; + $self->ensure_connected; + } +} + +sub connect_call_use_MARS { + carp "'connect_call_use_MARS' has been deprecated, use " + ."'connect_call_use_mars' instead."; + shift->connect_call_use_mars(@_) +} + +=head2 connect_call_use_dynamic_cursors + +Use as: + + on_connect_call => 'use_dynamic_cursors' + +in your L as one way to enable multiple +concurrent statements. + +Will add C<< odbc_cursortype => 2 >> to your DBI connection attributes. See +L for more information. + +Alternatively, you can add it yourself and dynamic cursor support will be +automatically enabled. + +If you're using FreeTDS, C must be set to at least C<8.0>. + +This will not work with CODE ref connect_info's. + +B this will break C, and C