Clear up some legacy cruft and straighten inheritance
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / Common.pm
CommitLineData
2f92e90b 1package DBIx::Class::Storage::DBI::Sybase::Common;
eabab5d0 2
3use strict;
4use warnings;
5
2ad62d97 6use base qw/DBIx::Class::Storage::DBI/;
7use mro 'c3';
8
eabab5d0 9=head1 NAME
10
2f92e90b 11DBIx::Class::Storage::DBI::Sybase::Common - 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;
322b7a6b 31 local $dbh->{PrintError} = 0;
322b7a6b 32
33 if ($dbh->{syb_no_child_con}) {
34# ping is impossible with an active statement, we return false if so
35 my $ping = eval { $dbh->ping };
36 return $@ ? 0 : $ping;
37 }
38
eabab5d0 39 eval {
322b7a6b 40# XXX if the main connection goes stale, does opening another for this statement
41# really determine anything?
283fb613 42 $dbh->do('select 1');
eabab5d0 43 };
44
45 return $@ ? 0 : 1;
46}
47
a3a526cc 48sub _set_max_connect {
49 my $self = shift;
50 my $val = shift || 256;
51
52 my $dsn = $self->_dbi_connect_info->[0];
53
54 return if ref($dsn) eq 'CODE';
55
56 if ($dsn !~ /maxConnect=/) {
57 $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val";
58 my $connected = defined $self->_dbh;
59 $self->disconnect;
60 $self->ensure_connected if $connected;
61 }
62}
63
e97a6ee2 64=head2 using_freetds
65
66Whether or not L<DBD::Sybase> was compiled against FreeTDS. If false, it means
67the Sybase OpenClient libraries were used.
68
69=cut
70
71sub using_freetds {
a3a526cc 72 my $self = shift;
73
37b17a93 74 return $self->_get_dbh->{syb_oc_version} =~ /freetds/i;
a3a526cc 75}
76
e97a6ee2 77=head2 set_textsize
78
79When using FreeTDS and/or MSSQL, C<< $dbh->{LongReadLen} >> is not available,
80use this function instead. It does:
81
82 $dbh->do("SET TEXTSIZE $bytes");
83
84Takes the number of bytes, or uses the C<LongReadLen> value from your
322b7a6b 85L<DBIx::Class/connect_info> if omitted, lastly falls back to the C<32768> which
86is the L<DBD::Sybase> default.
e97a6ee2 87
88=cut
89
90sub set_textsize {
91 my $self = shift;
92 my $text_size = shift ||
322b7a6b 93 eval { $self->_dbi_connect_info->[-1]->{LongReadLen} } ||
94 32768; # the DBD::Sybase default
e97a6ee2 95
96 return unless defined $text_size;
97
98 $self->_dbh->do("SET TEXTSIZE $text_size");
99}
100
eabab5d0 1011;
102
103=head1 AUTHORS
104
105See L<DBIx::Class/CONTRIBUTORS>.
106
107=head1 LICENSE
108
109You may distribute this code under the same terms as Perl itself.
110
111=cut