File Coverage

blib/lib/DBIx/Class/Storage/DBI/Sybase.pm
Criterion Covered Total %
statement 23 62 37.1
branch 1 20 5.0
condition 2 9 22.2
subroutine 8 16 50.0
pod n/a
total 34 107 31.7


line stmt bran cond sub pod time code
1             package DBIx::Class::Storage::DBI::Sybase;
2              
3 4     4   939 use strict;
  4         8  
  4         111  
4 4     4   22 use warnings;
  4         9  
  4         116  
5 4     4   23 use DBIx::Class::_Util qw( dbic_internal_try dbic_internal_catch );
  4         10  
  4         207  
6 4     4   24 use namespace::clean;
  4         11  
  4         26  
7              
8 4     4   919 use base qw/DBIx::Class::Storage::DBI/;
  4         10  
  4         1449  
9              
10             =head1 NAME
11              
12             DBIx::Class::Storage::DBI::Sybase - Base class for drivers using
13             L
14              
15             =head1 DESCRIPTION
16              
17             This is the base class/dispatcher for Storage's designed to work with
18             L
19              
20             =head1 METHODS
21              
22             =cut
23              
24 0     0   0 sub _rebless { shift->_determine_connector_driver('Sybase') }
25              
26             sub _get_rdbms_name {
27 0     0   0 my $self = shift;
28              
29             dbic_internal_try {
30 0     0   0 my $name = $self->_get_dbh->selectrow_arrayref('sp_server_info @attribute_id=1')->[2];
31              
32 0 0       0 if ($name) {
33 0         0 $name =~ s/\W/_/gi;
34              
35             # saner class name
36 0 0       0 $name = 'ASE' if $name eq 'SQL_Server';
37             }
38              
39 0         0 $name; # RV
40             }
41             dbic_internal_catch {
42 0     0   0 $self->throw_exception("Unable to establish connection to determine database type: $_")
43 0         0 };
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 1     1   11 my $self = shift;
50 1 50 33     20 if (! $self->isa('DBIx::Class::Storage::DBI::Sybase::FreeTDS') and $self->_using_freetds) {
51 0         0 require DBIx::Class::Storage::DBI::Sybase::FreeTDS;
52              
53 0         0 my @isa = @{mro::get_linear_isa(ref $self)};
  0         0  
54 0         0 my $class = shift @isa; # this is our current ref
55              
56 0         0 my $trait_class = $class . '::FreeTDS';
57 0         0 mro::set_mro ($trait_class, 'c3');
58 4     4   32 no strict 'refs';
  4         6  
  4         1418  
59 0         0 @{"${trait_class}::ISA"} = ($class, 'DBIx::Class::Storage::DBI::Sybase::FreeTDS', @isa);
  0         0  
60              
61 0         0 bless ($self, $trait_class);
62              
63 0         0 Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO;
64              
65 0         0 $self->_init(@_);
66             }
67              
68 1         5 $self->next::method(@_);
69             }
70              
71             sub _ping {
72 0     0   0 my $self = shift;
73              
74 0 0       0 my $dbh = $self->_dbh or return 0;
75              
76 0         0 local $dbh->{RaiseError} = 1;
77 0         0 local $dbh->{PrintError} = 0;
78              
79 0     0   0 ( dbic_internal_try { $dbh->do('select 1'); 1 } )
  0         0  
80 0 0       0 ? 1
81             : 0
82             ;
83             }
84              
85             sub _set_max_connect {
86 0     0   0 my $self = shift;
87 0   0     0 my $val = shift || 256;
88              
89 0         0 my $dsn = $self->_dbi_connect_info->[0];
90              
91 0 0       0 return if ref($dsn) eq 'CODE';
92              
93 0 0       0 if ($dsn !~ /maxConnect=/) {
94 0         0 $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val";
95 0         0 my $connected = defined $self->_dbh;
96 0         0 $self->disconnect;
97 0 0       0 $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 2     2   4 my $self = shift;
105 2   50     9 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 0     0     my $inf = shift->_get_dbh->{syb_oc_version};
112 0 0 0       return undef unless ($inf||'') =~ /freetds/i;
113 0 0         return $inf =~ /v([0-9\.]+)/ ? $1 : 0;
114             }
115              
116             =head1 FURTHER QUESTIONS?
117              
118             Check the list of L.
119              
120             =head1 COPYRIGHT AND LICENSE
121              
122             This module is free software L
123             by the L. You can
124             redistribute it and/or modify it under the same terms as the
125             L.
126              
127             =cut
128              
129             1;
130