Merge 'trunk' into 'sybase'
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / Storage / DBI / Sybase / Base.pm
CommitLineData
e97a6ee2 1package DBIx::Class::Storage::DBI::Sybase::Base;
eabab5d0 2
3use strict;
4use warnings;
5
2ad62d97 6use base qw/DBIx::Class::Storage::DBI/;
7use mro 'c3';
8
eabab5d0 9=head1 NAME
10
11DBIx::Class::Storage::DBI::Sybase::Base - Common functionality for drivers using
2932b9a6 12DBD::Sybase
eabab5d0 13
e97a6ee2 14=head1 DESCRIPTION
15
16This is the base class for L<DBIx::Class::Storage::DBI::Sybase> and
17L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server>. It provides some
18utility methods related to L<DBD::Sybase> and the supported functions of the
19database you are connecting to.
20
21=head1 METHODS
22
eabab5d0 23=cut
24
6dc4be0f 25sub _ping {
eabab5d0 26 my $self = shift;
27
d7ffa0ce 28 my $dbh = $self->_dbh or return 0;
d7ffa0ce 29
526dc858 30 local $dbh->{RaiseError} = 1;
eabab5d0 31 eval {
283fb613 32 $dbh->do('select 1');
eabab5d0 33 };
34
35 return $@ ? 0 : 1;
36}
37
e97a6ee2 38=head2 placeholders_supported
39
40Whether or not string placeholders work. Does not check for implicit conversion
41errors, see L</placeholders_with_type_conversion_supported>.
42
43=cut
44
45sub placeholders_supported {
f6de7111 46 my $self = shift;
86e68d2d 47 my $dbh = $self->last_dbh;
f6de7111 48
49 return eval {
50# There's also $dbh->{syb_dynamic_supported} but it can be inaccurate for this
51# purpose.
52 local $dbh->{PrintError} = 0;
e97a6ee2 53 local $dbh->{RaiseError} = 1;
a3a526cc 54 $dbh->selectrow_array('select ?', {}, 1);
55 };
56}
57
e97a6ee2 58=head2 placeholders_with_type_conversion_supported
59
60=cut
61
62sub placeholders_with_type_conversion_supported {
a3a526cc 63 my $self = shift;
64 my $dbh = $self->_dbh;
65
66 return eval {
67 local $dbh->{PrintError} = 0;
e97a6ee2 68 local $dbh->{RaiseError} = 1;
f6de7111 69# this specifically tests a bind that is NOT a string
70 $dbh->selectrow_array('select 1 where 1 = ?', {}, 1);
71 };
72}
73
a3a526cc 74sub _set_max_connect {
75 my $self = shift;
76 my $val = shift || 256;
77
78 my $dsn = $self->_dbi_connect_info->[0];
79
80 return if ref($dsn) eq 'CODE';
81
82 if ($dsn !~ /maxConnect=/) {
83 $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val";
84 my $connected = defined $self->_dbh;
85 $self->disconnect;
86 $self->ensure_connected if $connected;
87 }
88}
89
e97a6ee2 90=head2 using_freetds
91
92Whether or not L<DBD::Sybase> was compiled against FreeTDS. If false, it means
93the Sybase OpenClient libraries were used.
94
95=cut
96
97sub using_freetds {
a3a526cc 98 my $self = shift;
99
100 return $self->_dbh->{syb_oc_version} =~ /freetds/i;
101}
102
e97a6ee2 103=head2 set_textsize
104
105When using FreeTDS and/or MSSQL, C<< $dbh->{LongReadLen} >> is not available,
106use this function instead. It does:
107
108 $dbh->do("SET TEXTSIZE $bytes");
109
110Takes the number of bytes, or uses the C<LongReadLen> value from your
111L<DBIx::Class/connect_info> if omitted.
112
113=cut
114
115sub set_textsize {
116 my $self = shift;
117 my $text_size = shift ||
118 eval { $self->_dbi_connect_info->[-1]->{LongReadLen} };
119
120 return unless defined $text_size;
121
122 $self->_dbh->do("SET TEXTSIZE $text_size");
123}
124
eabab5d0 1251;
126
127=head1 AUTHORS
128
129See L<DBIx::Class/CONTRIBUTORS>.
130
131=head1 LICENSE
132
133You may distribute this code under the same terms as Perl itself.
134
135=cut