| 1 | package DBIO::Sybase::Storage; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Base class for drivers using L<DBD::Sybase> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use DBIO::Util 'old_mro'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use base qw/DBIO::Storage::DBI/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | __PACKAGE__->register_driver('Sybase' => __PACKAGE__); | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub dbio_deploy_class { 'DBIO::Sybase::Deploy' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dbio_deploy_class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub _rebless { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rebless: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | my $dbtype; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $dbtype = @{$self->_get_dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2] | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | $self->throw_exception("Unable to establish connection to determine database type: $_") | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($dbtype) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $dbtype =~ s/\W/_/gi; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # saner class name | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $dbtype = 'ASE' if $dbtype eq 'SQL_Server'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # Microsoft SQL Server lives in a different distribution/namespace | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # (DBIO::MSSQL), not under DBIO::Sybase::Storage::*. load_optional_class | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # below loads it on demand and fails gracefully if dbio-mssql is absent. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $subclass = $dbtype eq 'Microsoft_SQL_Server' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | ? 'DBIO::MSSQL::Storage::Sybase' | ||||||||||||||||||||||||||||||||||||||||||
| 38 | : __PACKAGE__ . "::$dbtype"; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($self->load_optional_class($subclass)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | bless $self, $subclass; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->_rebless; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 3 | ▶ | sub _init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | # once the driver is determined see if we need to insert the DBD::Sybase w/ FreeTDS fixups | ||||||||||||||||||||||||||||||||||||||||||
| 49 | # this is a dirty version of "instance role application", \o/ DO WANT Moo \o/ | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 51 | # Only synthesize a "<ref>::FreeTDS" trait once we have reblessed into a | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # concrete server subclass. On the bare base the synthetic trait name would | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # collide with the real DBIO::Sybase::Storage::FreeTDS module and its @ISA | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # rewrite would make that class inherit from itself (recursive inheritance). | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $self ne __PACKAGE__ and not $self->isa("DBIO::Sybase::Storage::FreeTDS") and $self->_using_freetds
ref $self ne __PACKAGE__ and not $self->isa("DBIO::Sybase::Storage::FreeTDS")
MC/DC66%2/3
ref $self ne __PACKAGE__ and not $self->isa("DBIO::Sybase::Storage::FreeTDS") and $self->_using_freetds
ref $self ne __PACKAGE__
not $self->isa("DBIO::Sybase::Storage::FreeTDS")
$self->_using_freetds
Truth table75%3/4
A and not(B) and C
A= ref $self ne __PACKAGE__B= not $self->isa("DBIO::Sybase::Storage::FreeTDS")C= $self->_using_freetds
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | ref($self) ne __PACKAGE__ | ||||||||||||||||||||||||||||||||||||||||||
| 57 | and | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ! $self->isa('DBIO::Sybase::Storage::FreeTDS') | ||||||||||||||||||||||||||||||||||||||||||
| 59 | and | ||||||||||||||||||||||||||||||||||||||||||
| 60 | $self->_using_freetds | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | require DBIO::Sybase::Storage::FreeTDS; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my @isa = @{mro::get_linear_isa(ref $self)}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | my $class = shift @isa; # this is our current ref | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | my $trait_class = $class . '::FreeTDS'; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | mro::set_mro ($trait_class, 'c3'); | |||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | @{"${trait_class}::ISA"} = ($class, 'DBIO::Sybase::Storage::FreeTDS', @isa); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | bless ($self, $trait_class); | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | Class::C3->reinitialize() if old_mro(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | $self->_init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub _ping { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ping: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $dbh = $self->_dbh or return 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | local $dbh->{RaiseError} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | local $dbh->{PrintError} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | ( try { $dbh->do('select 1'); 1 } ) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | ? 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | : 0 | ||||||||||||||||||||||||||||||||||||||||||
| 93 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub _set_max_connect { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_max_connect: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $val = shift // 256; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() // 256
MC/DC0%0/1
shift() // 256
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $dsn = $self->_dbi_connect_info->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return if ref($dsn) eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ($dsn !~ /maxConnect=/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val"; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $connected = defined $self->_dbh; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $self->ensure_connected if $connected; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # Whether or not DBD::Sybase was compiled against FreeTDS. If false, it means | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # the Sybase OpenClient libraries were used. | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub _using_freetds { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_using_freetds: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | return ($self->_get_dbh->{syb_oc_version}||'') =~ /freetds/i; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_get_dbh->{'syb_oc_version'} || ''
MC/DC0%0/1
$self->_get_dbh->{'syb_oc_version'} || ''
$self->_get_dbh->{'syb_oc_version'}
Truth table0%0/2
A
A= $self->_get_dbh->{'syb_oc_version'}
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | # Either returns the FreeTDS version against which DBD::Sybase was compiled, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # 0 if can't be determined, or undef otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub _using_freetds_version { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_using_freetds_version: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $inf = shift->_get_dbh->{syb_oc_version}; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | return $inf =~ /v([0-9\.]+)/ ? $1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | DBIO::Sybase::Storage - Base class for drivers using L<DBD::Sybase> | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | version 0.900001 | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | Base storage class and dispatcher for L<DBD::Sybase>-based connections. | ||||||||||||||||||||||||||||||||||||||||||
| 147 | On first use, this storage introspects the connected server type via | ||||||||||||||||||||||||||||||||||||||||||
| 148 | C<sp_server_info> and reblesses itself into the appropriate subclass: | ||||||||||||||||||||||||||||||||||||||||||
| 149 | L<DBIO::Sybase::Storage::ASE> for Sybase ASE, or falls back to subclasses | ||||||||||||||||||||||||||||||||||||||||||
| 150 | registered for other server types (such as L<DBIO::MSSQL::Storage::Sybase> | ||||||||||||||||||||||||||||||||||||||||||
| 151 | for Microsoft SQL Server). | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | If L<DBD::Sybase> was compiled against FreeTDS, the FreeTDS fixups from | ||||||||||||||||||||||||||||||||||||||||||
| 154 | L<DBIO::Sybase::Storage::FreeTDS> are mixed in automatically. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | =item * L<DBIO::Sybase> - Sybase schema component | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | =item * L<DBIO::Sybase::Storage::ASE> - Sybase ASE storage | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =item * L<DBIO::Sybase::Storage::FreeTDS> - FreeTDS connection layer | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =item * L<DBIO::MSSQL::Storage::Sybase> - MSSQL via L<DBD::Sybase> | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =item * L<DBIO::Storage::DBI> - Base DBI storage class | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | DBIO & DBIx::Class Authors | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | Copyright (C) 2026 DBIO Authors | ||||||||||||||||||||||||||||||||||||||||||
| 179 | Portions Copyright (C) 2005-2025 DBIx::Class Authors | ||||||||||||||||||||||||||||||||||||||||||
| 180 | Based on DBIx::Class, heavily modified. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 183 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||||||||||||||||