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