add placeholder support detection for mssql through dbd::sybase
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / Microsoft_SQL_Server.pm
1 package DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server;
2
3 use strict;
4 use warnings;
5
6 use base qw/
7   DBIx::Class::Storage::DBI::Sybase::Base
8   DBIx::Class::Storage::DBI::MSSQL
9 /;
10 use mro 'c3';
11
12 sub _rebless {
13   my $self = shift;
14   my $dbh  = $self->_dbh;
15
16   my ($placeholders_supported) = eval {
17 # There's also $dbh->{syb_dynamic_supported} but it can be inaccurate for this
18 # purpose.
19     local $dbh->{PrintError} = 0;
20     $dbh->selectrow_array('select ?', {}, 1);
21   };
22
23   if (not $placeholders_supported) {
24     bless $self,
25       'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars';
26     $self->_rebless;
27   }
28
29 # LongReadLen doesn't work with MSSQL through DBD::Sybase, and the default is
30 # huge on some versions of SQL server and can cause memory problems, so we
31 # fix it up here.
32   my $text_size = eval { $self->_dbi_connect_info->[-1]->{LongReadLen} } ||
33     32768; # the DBD::Sybase default
34
35   $dbh->do("set textsize $text_size");
36 }
37
38 1;
39
40 =head1 NAME
41
42 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server - Support for Microsoft
43 SQL Server via DBD::Sybase
44
45 =head1 SYNOPSIS
46
47 This subclass supports MSSQL server connections via L<DBD::Sybase>.
48
49 =head1 DESCRIPTION
50
51 This driver tries to determine whether your version of L<DBD::Sybase> and
52 supporting libraries (usually FreeTDS) support using placeholders, if not the
53 storage will be reblessed to
54 L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars>.
55
56 The MSSQL specific functionality is provided by
57 L<DBIx::Class::Storage::DBI::MSSQL>.
58
59 =head1 AUTHOR
60
61 See L<DBIx::Class/CONTRIBUTORS>.
62
63 =head1 LICENSE
64
65 You may distribute this code under the same terms as Perl itself.
66
67 =cut