Remove non-functional part of ::Storage::DBI::Sybase::_ping
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase.pm
1 package DBIx::Class::Storage::DBI::Sybase;
2
3 use strict;
4 use warnings;
5 use DBIx::Class::_Util 'dbic_internal_try';
6 use Try::Tiny;
7 use namespace::clean;
8
9 use base qw/DBIx::Class::Storage::DBI/;
10
11 =head1 NAME
12
13 DBIx::Class::Storage::DBI::Sybase - Base class for drivers using
14 L<DBD::Sybase>
15
16 =head1 DESCRIPTION
17
18 This is the base class/dispatcher for Storage's designed to work with
19 L<DBD::Sybase>
20
21 =head1 METHODS
22
23 =cut
24
25 sub _rebless { shift->_determine_connector_driver('Sybase') }
26
27 sub _get_rdbms_name {
28   my $self = shift;
29
30   dbic_internal_try {
31     my $name = $self->_get_dbh->selectrow_arrayref('sp_server_info @attribute_id=1')->[2];
32
33     if ($name) {
34       $name =~ s/\W/_/gi;
35
36       # saner class name
37       $name = 'ASE' if $name eq 'SQL_Server';
38     }
39
40     $name;  # RV
41   } catch {
42     $self->throw_exception("Unable to establish connection to determine database type: $_")
43   };
44 }
45
46 sub _init {
47   # once the driver is determined see if we need to insert the DBD::Sybase w/ FreeTDS fixups
48   # this is a dirty version of "instance role application", \o/ DO WANT Moo \o/
49   my $self = shift;
50   if (! $self->isa('DBIx::Class::Storage::DBI::Sybase::FreeTDS') and $self->_using_freetds) {
51     require DBIx::Class::Storage::DBI::Sybase::FreeTDS;
52
53     my @isa = @{mro::get_linear_isa(ref $self)};
54     my $class = shift @isa; # this is our current ref
55
56     my $trait_class = $class . '::FreeTDS';
57     mro::set_mro ($trait_class, 'c3');
58     no strict 'refs';
59     @{"${trait_class}::ISA"} = ($class, 'DBIx::Class::Storage::DBI::Sybase::FreeTDS', @isa);
60
61     bless ($self, $trait_class);
62
63     Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO;
64
65     $self->_init(@_);
66   }
67
68   $self->next::method(@_);
69 }
70
71 sub _ping {
72   my $self = shift;
73
74   my $dbh = $self->_dbh or return 0;
75
76   local $dbh->{RaiseError} = 1;
77   local $dbh->{PrintError} = 0;
78
79   ( dbic_internal_try { $dbh->do('select 1'); 1 } )
80     ? 1
81     : 0
82   ;
83 }
84
85 sub _set_max_connect {
86   my $self = shift;
87   my $val  = shift || 256;
88
89   my $dsn = $self->_dbi_connect_info->[0];
90
91   return if ref($dsn) eq 'CODE';
92
93   if ($dsn !~ /maxConnect=/) {
94     $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val";
95     my $connected = defined $self->_dbh;
96     $self->disconnect;
97     $self->ensure_connected if $connected;
98   }
99 }
100
101 # Whether or not DBD::Sybase was compiled against FreeTDS. If false, it means
102 # the Sybase OpenClient libraries were used.
103 sub _using_freetds {
104   my $self = shift;
105   return ($self->_get_dbh->{syb_oc_version}||'') =~ /freetds/i;
106 }
107
108 # Either returns the FreeTDS version against which DBD::Sybase was compiled,
109 # 0 if can't be determined, or undef otherwise
110 sub _using_freetds_version {
111   my $inf = shift->_get_dbh->{syb_oc_version};
112   return undef unless ($inf||'') =~ /freetds/i;
113   return $inf =~ /v([0-9\.]+)/ ? $1 : 0;
114 }
115
116 =head1 FURTHER QUESTIONS?
117
118 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
119
120 =head1 COPYRIGHT AND LICENSE
121
122 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
123 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
124 redistribute it and/or modify it under the same terms as the
125 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
126
127 =cut
128
129 1;
130