Generalize and hide placeholder support check
[dbsrgits/DBIx-Class.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
a3a526cc 38sub _set_max_connect {
39 my $self = shift;
40 my $val = shift || 256;
41
42 my $dsn = $self->_dbi_connect_info->[0];
43
44 return if ref($dsn) eq 'CODE';
45
46 if ($dsn !~ /maxConnect=/) {
47 $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val";
48 my $connected = defined $self->_dbh;
49 $self->disconnect;
50 $self->ensure_connected if $connected;
51 }
52}
53
e97a6ee2 54=head2 using_freetds
55
56Whether or not L<DBD::Sybase> was compiled against FreeTDS. If false, it means
57the Sybase OpenClient libraries were used.
58
59=cut
60
61sub using_freetds {
a3a526cc 62 my $self = shift;
63
64 return $self->_dbh->{syb_oc_version} =~ /freetds/i;
65}
66
e97a6ee2 67=head2 set_textsize
68
69When using FreeTDS and/or MSSQL, C<< $dbh->{LongReadLen} >> is not available,
70use this function instead. It does:
71
72 $dbh->do("SET TEXTSIZE $bytes");
73
74Takes the number of bytes, or uses the C<LongReadLen> value from your
75L<DBIx::Class/connect_info> if omitted.
76
77=cut
78
79sub set_textsize {
80 my $self = shift;
81 my $text_size = shift ||
82 eval { $self->_dbi_connect_info->[-1]->{LongReadLen} };
83
84 return unless defined $text_size;
85
86 $self->_dbh->do("SET TEXTSIZE $text_size");
87}
88
eabab5d0 891;
90
91=head1 AUTHORS
92
93See L<DBIx::Class/CONTRIBUTORS>.
94
95=head1 LICENSE
96
97You may distribute this code under the same terms as Perl itself.
98
99=cut