override _run_connection_actions for internal connection setup in sybase stuff, much...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / Common.pm
CommitLineData
d867eeda 1package DBIx::Class::Storage::DBI::Sybase::Common;
2
3use strict;
4use warnings;
5
6use base qw/DBIx::Class::Storage::DBI/;
7use mro 'c3';
8
9=head1 NAME
10
11DBIx::Class::Storage::DBI::Sybase::Common - Common functionality for drivers using
12DBD::Sybase
13
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
23=cut
24
25sub _ping {
26 my $self = shift;
27
28 my $dbh = $self->_dbh or return 0;
29
30 local $dbh->{RaiseError} = 1;
31 local $dbh->{PrintError} = 0;
32
33 if ($dbh->{syb_no_child_con}) {
f244a815 34# if extra connections are not allowed, then ->ping is reliable
d867eeda 35 my $ping = eval { $dbh->ping };
36 return $@ ? 0 : $ping;
37 }
38
39 eval {
40# XXX if the main connection goes stale, does opening another for this statement
41# really determine anything?
42 $dbh->do('select 1');
43 };
44
45 return $@ ? 0 : 1;
46}
47
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
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 {
72 my $self = shift;
73
74 return $self->_get_dbh->{syb_oc_version} =~ /freetds/i;
75}
76
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
85L<DBIx::Class/connect_info> if omitted, lastly falls back to the C<32768> which
86is the L<DBD::Sybase> default.
87
88=cut
89
90sub set_textsize {
91 my $self = shift;
92 my $text_size = shift ||
93 eval { $self->_dbi_connect_info->[-1]->{LongReadLen} } ||
94 32768; # the DBD::Sybase default
95
96 return unless defined $text_size;
97
98 $self->_dbh->do("SET TEXTSIZE $text_size");
99}
100
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