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