fix Sybase DT stuff and storage bases
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / Storage / DBI / Sybase.pm
CommitLineData
3885cff6 1package DBIx::Class::Storage::DBI::Sybase;
2
3use strict;
4use warnings;
5
c5ce7cd6 6use base qw/DBIx::Class::Storage::DBI/;
3885cff6 7
6b1f5ef7 8use Carp::Clan qw/^DBIx::Class/;
9
47d9646a 10sub _rebless {
b50a5275 11 my $self = shift;
c5ce7cd6 12
13 if (ref($self) eq 'DBIx::Class::Storage::DBI::Sybase') {
14 my $dbtype = eval {
15 @{$self->dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2]
16 } || '';
17
18 my $exception = $@;
19 $dbtype =~ s/\W/_/gi;
20 my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}";
21
22 if (!$exception && $dbtype && $self->load_optional_class($subclass)) {
23 bless $self, $subclass;
24 $self->_rebless;
6b1f5ef7 25 } elsif (not $self->dbh->{syb_dynamic_supported}) {
26# probably real Sybase
27 bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars';
28 $self->_rebless;
47d9646a 29 }
c5ce7cd6 30 }
b50a5275 31}
32
6b1f5ef7 33{
34 my $old_dbd_warned = 0;
35
36 sub _populate_dbh {
37 my $self = shift;
38 $self->next::method(@_);
39 my $dbh = $self->_dbh;
40
41 if ($dbh->can('syb_date_fmt')) {
42 $dbh->syb_date_fmt('ISO_strict');
43 } elsif (not $old_dbd_warned) {
44 carp "Your DBD::Sybase is too old to support ".
45 "DBIx::Class::InflateColumn::DateTime, please upgrade!";
46 $old_dbd_warned = 1;
47 }
48
49 $dbh->do('set dateformat mdy');
c5ce7cd6 50
6b1f5ef7 51 1;
c5ce7cd6 52 }
6b1f5ef7 53}
54
55sub _dbh_last_insert_id {
56 my ($self, $dbh, $source, $col) = @_;
c5ce7cd6 57
58 # sorry, there's no other way!
59 my $sth = $dbh->prepare_cached("select max($col) from ".$source->from);
60 return ($dbh->selectrow_array($sth))[0];
a964a928 61}
62
c5ce7cd6 63sub datetime_parser_type { "DBIx::Class::Storage::DBI::Sybase::DateTime" }
64
3885cff6 651;
66
67=head1 NAME
68
69DBIx::Class::Storage::DBI::Sybase - Storage::DBI subclass for Sybase
70
71=head1 SYNOPSIS
72
81092e2d 73This subclass supports L<DBD::Sybase> for real Sybase databases. If
74you are using an MSSQL database via L<DBD::Sybase>, see
75L<DBIx::Class::Storage::DBI::Sybase::MSSQL>.
3885cff6 76
d4483998 77=head1 CAVEATS
78
c5ce7cd6 79If your version of Sybase does not support placeholders, then this storage
80driver uses L<DBIx::Class::Storage::DBI::NoBindVars> as a base,
81
82In which case, bind variables will be interpolated (properly quoted of course)
d4483998 83into the SQL query itself, without using bind placeholders.
84
85More importantly this means that caching of prepared statements is explicitly
86disabled, as the interpolation renders it useless.
87
c5ce7cd6 88If your version of Sybase B<DOES> support placeholders (check
89C<<$dbh->{syb_dynamic_supported}>> then unfortunately there's no way to get the
90C<last_insert_id> without doing a C<select max(col)>.
91
92But your queries will be cached.
93
94=head1 DATES
95
96On connection C<syb_date_fmt> is set to C<ISO_strict>, e.g.:
97C<2004-08-21T14:36:48.080Z> and C<dateformat> is set to C<mdy>, e.g.:
98C<08/13/1979>.
99
100You will need the L<DateTime::Format::Strptime> module if you are going to use
101L<DBIx::Class::InflateColumn::DateTime>.
102
3885cff6 103=head1 AUTHORS
104
105Brandon L Black <blblack@gmail.com>
106
47d9646a 107Justin Hunter <justin.d.hunter@gmail.com>
108
c5ce7cd6 109Rafael Kitover <rkitover@cpan.org>
110
3885cff6 111=head1 LICENSE
112
113You may distribute this code under the same terms as Perl itself.
114
115=cut
c5ce7cd6 116# vim:sts=2 sw=2: