| 1 | package DBIx::Class::Storage::DBI::Sybase; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use base qw/DBIx::Class::Storage::DBI/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | DBIx::Class::Storage::DBI::Sybase - Base class for drivers using | ||||||||||||||||||||||||||||
| 13 | L<DBD::Sybase> | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | This is the base class/dispatcher for Storage's designed to work with | ||||||||||||||||||||||||||||
| 18 | L<DBD::Sybase> | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 METHODS | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | sub _rebless { | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_rebless: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my $dbtype; | |||||||||||||||||||||||||||
| 28 | try { | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | $dbtype = @{$self->_get_dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2] | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 30 | } catch { | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $self->throw_exception("Unable to establish connection to determine database type: $_") | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 0 | }; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($dbtype) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | $dbtype =~ s/\W/_/gi; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # saner class name | ||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $dbtype = 'ASE' if $dbtype eq 'SQL_Server'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $subclass = __PACKAGE__ . "::$dbtype"; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ($self->load_optional_class($subclass)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | bless $self, $subclass; | |||||||||||||||||||||||||||
| 43 | 0 | $self->_rebless; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub _init { | ||||||||||||||||||||||||||||
| 49 | # once the driver is determined see if we need to insert the DBD::Sybase w/ FreeTDS fixups | ||||||||||||||||||||||||||||
| 50 | # this is a dirty version of "instance role application", \o/ DO WANT Moo \o/ | ||||||||||||||||||||||||||||
| 51 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=3 SCAR=16.7
| |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | if (! $self->isa('DBIx::Class::Storage::DBI::Sybase::FreeTDS') and $self->_using_freetds) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->isa("DBIx::Class::Storage::DBI::Sybase::FreeTDS") and $self->_using_freetds
MC/DC0%0/2
not $self->isa("DBIx::Class::Storage::DBI::Sybase::FreeTDS") and $self->_using_freetds
not $self->isa("DBIx::Class::Storage::DBI::Sybase::FreeTDS")
$self->_using_freetds
Truth table33%1/3
not(A) and B
A= not $self->isa("DBIx::Class::Storage::DBI::Sybase::FreeTDS")B= $self->_using_freetds
| |||||||||||||||||||||||||||||
| 53 | 0 | require DBIx::Class::Storage::DBI::Sybase::FreeTDS; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my @isa = @{mro::get_linear_isa(ref $self)}; | |||||||||||||||||||||||||||
| 56 | 0 | my $class = shift @isa; # this is our current ref | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $trait_class = $class . '::FreeTDS'; | |||||||||||||||||||||||||||
| 59 | 0 | mro::set_mro ($trait_class, 'c3'); | |||||||||||||||||||||||||||
| 60 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 0 | @{"${trait_class}::ISA"} = ($class, 'DBIx::Class::Storage::DBI::Sybase::FreeTDS', @isa); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | bless ($self, $trait_class); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | Class::C3->reinitialize() if DBIx::Class::_ENV_::OLD_MRO; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | $self->_init(@_); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | $self->next::method(@_); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | sub _ping { | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_ping: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | my $dbh = $self->_dbh or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | local $dbh->{RaiseError} = 1; | |||||||||||||||||||||||||||
| 79 | 0 | local $dbh->{PrintError} = 0; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # FIXME if the main connection goes stale, does opening another for this statement | ||||||||||||||||||||||||||||
| 82 | # really determine anything? | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($dbh->{syb_no_child_con}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | return try { | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $self->_connect->do('select 1'); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 87 | 0 | 1; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | catch { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | 0; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 91 | 0 | }; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | return try { | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | $dbh->do('select 1'); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 96 | 0 | 1; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | catch { | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | 0; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 100 | 0 | }; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | sub _set_max_connect { | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_set_max_connect: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my $val = shift || 256; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 256
MC/DC0%0/1
shift() || 256
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | my $dsn = $self->_dbi_connect_info->[0]; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | return if ref($dsn) eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($dsn !~ /maxConnect=/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val"; | |||||||||||||||||||||||||||
| 113 | 0 | my $connected = defined $self->_dbh; | |||||||||||||||||||||||||||
| 114 | 0 | $self->disconnect; | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | $self->ensure_connected if $connected; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # Whether or not DBD::Sybase was compiled against FreeTDS. If false, it means | ||||||||||||||||||||||||||||
| 120 | # the Sybase OpenClient libraries were used. | ||||||||||||||||||||||||||||
| 121 | sub _using_freetds { | ||||||||||||||||||||||||||||
| 122 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_using_freetds: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 123 | 2 | ▶ | return ($self->_get_dbh->{syb_oc_version}||'') =~ /freetds/i; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->_get_dbh->{'syb_oc_version'} || ''
MC/DC0%0/1
$self->_get_dbh->{'syb_oc_version'} || ''
$self->_get_dbh->{'syb_oc_version'}
Truth table50%1/2
A
A= $self->_get_dbh->{'syb_oc_version'}
| |||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # Either returns the FreeTDS version against which DBD::Sybase was compiled, | ||||||||||||||||||||||||||||
| 127 | # 0 if can't be determined, or undef otherwise | ||||||||||||||||||||||||||||
| 128 | sub _using_freetds_version { | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my $inf = shift->_get_dbh->{syb_oc_version}; | ||||||||||||||||||||||||||
|
Subroutine
_using_freetds_version: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return undef unless ($inf||'') =~ /freetds/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$inf || ''
MC/DC0%0/1
$inf || ''
$inf
Truth table0%0/2
A
A= $inf
| |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return $inf =~ /v([0-9\.]+)/ ? $1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 3 | 1; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | See L<DBIx::Class/CONTRIBUTORS>. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | You may distribute this code under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||