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