Commit | Line | Data |
---|---|---|
f68f4d44 | 1 | package DBIx::Class::Storage::DBI::Sybase; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
ed7ab0f4 | 5 | use Try::Tiny; |
2ad62d97 | 6 | |
057db5ce | 7 | use base qw/DBIx::Class::Storage::DBI/; |
d867eeda | 8 | |
9 | =head1 NAME | |
10 | ||
95787afe | 11 | DBIx::Class::Storage::DBI::Sybase - Base class for drivers using |
12 | L<DBD::Sybase> | |
d867eeda | 13 | |
14 | =head1 DESCRIPTION | |
15 | ||
057db5ce | 16 | This is the base class/dispatcher for Storage's designed to work with |
17 | L<DBD::Sybase> | |
d867eeda | 18 | |
19 | =head1 METHODS | |
20 | ||
21 | =cut | |
f68f4d44 | 22 | |
47d9646a | 23 | sub _rebless { |
d867eeda | 24 | my $self = shift; |
d29565e0 | 25 | |
ed7ab0f4 | 26 | my $dbtype; |
27 | try { | |
28 | $dbtype = @{$self->_get_dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2] | |
29 | } catch { | |
30 | $self->throw_exception("Unable to estable connection to determine database type: $_") | |
057db5ce | 31 | }; |
d867eeda | 32 | |
057db5ce | 33 | if ($dbtype) { |
d867eeda | 34 | $dbtype =~ s/\W/_/gi; |
d867eeda | 35 | |
057db5ce | 36 | # saner class name |
37 | $dbtype = 'ASE' if $dbtype eq 'SQL_Server'; | |
38 | ||
39 | my $subclass = __PACKAGE__ . "::$dbtype"; | |
40 | if ($self->load_optional_class($subclass)) { | |
d867eeda | 41 | bless $self, $subclass; |
42 | $self->_rebless; | |
d867eeda | 43 | } |
44 | } | |
45 | } | |
46 | ||
057db5ce | 47 | sub _ping { |
d867eeda | 48 | my $self = shift; |
d867eeda | 49 | |
057db5ce | 50 | my $dbh = $self->_dbh or return 0; |
0a9a9955 | 51 | |
057db5ce | 52 | local $dbh->{RaiseError} = 1; |
53 | local $dbh->{PrintError} = 0; | |
0a9a9955 | 54 | |
057db5ce | 55 | if ($dbh->{syb_no_child_con}) { |
56 | # if extra connections are not allowed, then ->ping is reliable | |
52b420dd | 57 | return try { $dbh->ping } catch { 0; }; |
057db5ce | 58 | } |
d867eeda | 59 | |
52b420dd | 60 | return try { |
057db5ce | 61 | # XXX if the main connection goes stale, does opening another for this statement |
62 | # really determine anything? | |
63 | $dbh->do('select 1'); | |
52b420dd | 64 | 1; |
ed7ab0f4 | 65 | } catch { |
52b420dd | 66 | 0; |
d867eeda | 67 | }; |
0a9a9955 | 68 | } |
69 | ||
057db5ce | 70 | sub _set_max_connect { |
d867eeda | 71 | my $self = shift; |
057db5ce | 72 | my $val = shift || 256; |
d867eeda | 73 | |
057db5ce | 74 | my $dsn = $self->_dbi_connect_info->[0]; |
d867eeda | 75 | |
057db5ce | 76 | return if ref($dsn) eq 'CODE'; |
81a10d8d | 77 | |
057db5ce | 78 | if ($dsn !~ /maxConnect=/) { |
79 | $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val"; | |
80 | my $connected = defined $self->_dbh; | |
81 | $self->disconnect; | |
82 | $self->ensure_connected if $connected; | |
d867eeda | 83 | } |
84 | } | |
85 | ||
057db5ce | 86 | =head2 using_freetds |
d867eeda | 87 | |
057db5ce | 88 | Whether or not L<DBD::Sybase> was compiled against FreeTDS. If false, it means |
89 | the Sybase OpenClient libraries were used. | |
d867eeda | 90 | |
91 | =cut | |
92 | ||
057db5ce | 93 | sub using_freetds { |
d867eeda | 94 | my $self = shift; |
d867eeda | 95 | |
057db5ce | 96 | return $self->_get_dbh->{syb_oc_version} =~ /freetds/i; |
d867eeda | 97 | } |
98 | ||
057db5ce | 99 | =head2 set_textsize |
db66bc3f | 100 | |
057db5ce | 101 | When using FreeTDS and/or MSSQL, C<< $dbh->{LongReadLen} >> is not available, |
102 | use this function instead. It does: | |
0a9a9955 | 103 | |
057db5ce | 104 | $dbh->do("SET TEXTSIZE $bytes"); |
0a9a9955 | 105 | |
057db5ce | 106 | Takes the number of bytes, or uses the C<LongReadLen> value from your |
8384a713 | 107 | L<connect_info|DBIx::Class::Storage::DBI/connect_info> if omitted, lastly falls |
108 | back to the C<32768> which is the L<DBD::Sybase> default. | |
d867eeda | 109 | |
110 | =cut | |
111 | ||
057db5ce | 112 | sub set_textsize { |
d867eeda | 113 | my $self = shift; |
9780718f | 114 | my $text_size = |
115 | shift | |
116 | || | |
117 | try { $self->_dbi_connect_info->[-1]->{LongReadLen} } | |
118 | || | |
057db5ce | 119 | 32768; # the DBD::Sybase default |
d867eeda | 120 | |
057db5ce | 121 | return unless defined $text_size; |
d867eeda | 122 | |
057db5ce | 123 | $self->_dbh->do("SET TEXTSIZE $text_size"); |
a964a928 | 124 | } |
125 | ||
f68f4d44 | 126 | 1; |
127 | ||
057db5ce | 128 | =head1 AUTHORS |
f68f4d44 | 129 | |
d867eeda | 130 | See L<DBIx::Class/CONTRIBUTORS>. |
47d9646a | 131 | |
f68f4d44 | 132 | =head1 LICENSE |
133 | ||
134 | You may distribute this code under the same terms as Perl itself. | |
135 | ||
136 | =cut |