Commit | Line | Data |
2f92e90b |
1 | package DBIx::Class::Storage::DBI::Sybase::Common; |
eabab5d0 |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
2ad62d97 |
6 | use base qw/DBIx::Class::Storage::DBI/; |
7 | use mro 'c3'; |
8 | |
eabab5d0 |
9 | =head1 NAME |
10 | |
2f92e90b |
11 | DBIx::Class::Storage::DBI::Sybase::Common - Common functionality for drivers using |
2932b9a6 |
12 | DBD::Sybase |
eabab5d0 |
13 | |
e97a6ee2 |
14 | =head1 DESCRIPTION |
15 | |
16 | This is the base class for L<DBIx::Class::Storage::DBI::Sybase> and |
17 | L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server>. It provides some |
18 | utility methods related to L<DBD::Sybase> and the supported functions of the |
19 | database you are connecting to. |
20 | |
21 | =head1 METHODS |
22 | |
eabab5d0 |
23 | =cut |
24 | |
6dc4be0f |
25 | sub _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 |
38 | sub _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 | |
56 | Whether or not L<DBD::Sybase> was compiled against FreeTDS. If false, it means |
57 | the Sybase OpenClient libraries were used. |
58 | |
59 | =cut |
60 | |
61 | sub 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 | |
69 | When using FreeTDS and/or MSSQL, C<< $dbh->{LongReadLen} >> is not available, |
70 | use this function instead. It does: |
71 | |
72 | $dbh->do("SET TEXTSIZE $bytes"); |
73 | |
74 | Takes the number of bytes, or uses the C<LongReadLen> value from your |
75 | L<DBIx::Class/connect_info> if omitted. |
76 | |
77 | =cut |
78 | |
79 | sub 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 |
89 | 1; |
90 | |
91 | =head1 AUTHORS |
92 | |
93 | See L<DBIx::Class/CONTRIBUTORS>. |
94 | |
95 | =head1 LICENSE |
96 | |
97 | You may distribute this code under the same terms as Perl itself. |
98 | |
99 | =cut |