document placeholders_with_type_conversion_supported and add a redispatch to reblesse...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase / Base.pm
CommitLineData
e97a6ee2 1package DBIx::Class::Storage::DBI::Sybase::Base;
eabab5d0 2
3use strict;
4use warnings;
5
2ad62d97 6use base qw/DBIx::Class::Storage::DBI/;
7use mro 'c3';
8
eabab5d0 9=head1 NAME
10
11DBIx::Class::Storage::DBI::Sybase::Base - Common functionality for drivers using
2932b9a6 12DBD::Sybase
eabab5d0 13
e97a6ee2 14=head1 DESCRIPTION
15
16This is the base class for L<DBIx::Class::Storage::DBI::Sybase> and
17L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server>. It provides some
18utility methods related to L<DBD::Sybase> and the supported functions of the
19database you are connecting to.
20
21=head1 METHODS
22
eabab5d0 23=cut
24
6dc4be0f 25sub _ping {
eabab5d0 26 my $self = shift;
27
d7ffa0ce 28 my $dbh = $self->_dbh or return 0;
d7ffa0ce 29
526dc858 30 local $dbh->{RaiseError} = 1;
eabab5d0 31 eval {
283fb613 32 $dbh->do('select 1');
eabab5d0 33 };
34
35 return $@ ? 0 : 1;
36}
37
e97a6ee2 38=head2 placeholders_supported
39
40Whether or not string placeholders work. Does not check for implicit conversion
41errors, see L</placeholders_with_type_conversion_supported>.
42
43=cut
44
45sub placeholders_supported {
f6de7111 46 my $self = shift;
86e68d2d 47 my $dbh = $self->last_dbh;
f6de7111 48
49 return eval {
50# There's also $dbh->{syb_dynamic_supported} but it can be inaccurate for this
51# purpose.
52 local $dbh->{PrintError} = 0;
e97a6ee2 53 local $dbh->{RaiseError} = 1;
a3a526cc 54 $dbh->selectrow_array('select ?', {}, 1);
55 };
56}
57
e97a6ee2 58=head2 placeholders_with_type_conversion_supported
59
bc144884 60Checks if placeholders bound to non-string types throw implicit type conversion
61errors or not.
62
63See L<DBIx::Class::Storage::DBI::Sybase/connect_call_set_auto_cast>.
64
e97a6ee2 65=cut
66
67sub placeholders_with_type_conversion_supported {
a3a526cc 68 my $self = shift;
69 my $dbh = $self->_dbh;
70
71 return eval {
72 local $dbh->{PrintError} = 0;
e97a6ee2 73 local $dbh->{RaiseError} = 1;
f6de7111 74# this specifically tests a bind that is NOT a string
75 $dbh->selectrow_array('select 1 where 1 = ?', {}, 1);
76 };
77}
78
a3a526cc 79sub _set_max_connect {
80 my $self = shift;
81 my $val = shift || 256;
82
83 my $dsn = $self->_dbi_connect_info->[0];
84
85 return if ref($dsn) eq 'CODE';
86
87 if ($dsn !~ /maxConnect=/) {
88 $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val";
89 my $connected = defined $self->_dbh;
90 $self->disconnect;
91 $self->ensure_connected if $connected;
92 }
93}
94
e97a6ee2 95=head2 using_freetds
96
97Whether or not L<DBD::Sybase> was compiled against FreeTDS. If false, it means
98the Sybase OpenClient libraries were used.
99
100=cut
101
102sub using_freetds {
a3a526cc 103 my $self = shift;
104
105 return $self->_dbh->{syb_oc_version} =~ /freetds/i;
106}
107
e97a6ee2 108=head2 set_textsize
109
110When using FreeTDS and/or MSSQL, C<< $dbh->{LongReadLen} >> is not available,
111use this function instead. It does:
112
113 $dbh->do("SET TEXTSIZE $bytes");
114
115Takes the number of bytes, or uses the C<LongReadLen> value from your
116L<DBIx::Class/connect_info> if omitted.
117
118=cut
119
120sub set_textsize {
121 my $self = shift;
122 my $text_size = shift ||
123 eval { $self->_dbi_connect_info->[-1]->{LongReadLen} };
124
125 return unless defined $text_size;
126
127 $self->_dbh->do("SET TEXTSIZE $text_size");
128}
129
eabab5d0 1301;
131
132=head1 AUTHORS
133
134See L<DBIx::Class/CONTRIBUTORS>.
135
136=head1 LICENSE
137
138You may distribute this code under the same terms as Perl itself.
139
140=cut