fix inserts with active cursors
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / Common.pm
1 package DBIx::Class::Storage::DBI::Sybase::Common;
2
3 use strict;
4 use warnings;
5
6 use base qw/DBIx::Class::Storage::DBI/;
7 use mro 'c3';
8
9 =head1 NAME
10
11 DBIx::Class::Storage::DBI::Sybase::Common - Common functionality for drivers using
12 DBD::Sybase
13
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
23 =cut
24
25 sub _ping {
26   my $self = shift;
27
28   my $dbh = $self->_dbh or return 0;
29
30   local $dbh->{RaiseError} = 1;
31   eval {
32     $dbh->do('select 1');
33   };
34
35   return $@ ? 0 : 1;
36 }
37
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
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 {
62   my $self = shift;
63
64   return $self->_dbh->{syb_oc_version} =~ /freetds/i;
65 }
66
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
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