update Sybase docs
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Sybase.pm
1 package DBIx::Class::Storage::DBI::Sybase;
2
3 use strict;
4 use warnings;
5
6 use base qw/DBIx::Class::Storage::DBI/;
7
8 use Carp::Clan qw/^DBIx::Class/;
9
10 sub _rebless {
11   my $self = shift;
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;
25     } elsif (not $self->dbh->{syb_dynamic_supported}) {
26       bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars';
27       $self->_rebless;
28     }
29   }
30 }
31
32 {
33   my $old_dbd_warned = 0;
34
35   sub _populate_dbh {
36     my $self = shift;
37     $self->next::method(@_);
38     my $dbh = $self->_dbh;
39
40     if ($dbh->can('syb_date_fmt')) {
41       $dbh->syb_date_fmt('ISO_strict');
42     } elsif (not $old_dbd_warned) {
43       carp "Your DBD::Sybase is too old to support ".
44       "DBIx::Class::InflateColumn::DateTime, please upgrade!";
45       $old_dbd_warned = 1;
46     }
47
48     $dbh->do('set dateformat mdy');
49
50     1;
51   }
52 }
53
54 sub _dbh_last_insert_id {
55   my ($self, $dbh, $source, $col) = @_;
56
57   # sorry, there's no other way!
58   my $sth = $dbh->prepare_cached("select max($col) from ".$source->from);
59   return ($dbh->selectrow_array($sth))[0];
60 }
61
62 sub datetime_parser_type { "DBIx::Class::Storage::DBI::Sybase::DateTime" }
63
64 1;
65
66 =head1 NAME
67
68 DBIx::Class::Storage::DBI::Sybase - Storage::DBI subclass for Sybase
69
70 =head1 SYNOPSIS
71
72 This subclass supports L<DBD::Sybase> for real Sybase databases.  If you are
73 using an MSSQL database via L<DBD::Sybase>, your storage will be reblessed to
74 L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server>.
75
76 =head1 DESCRIPTION
77
78 If your version of Sybase does not support placeholders, then your storage
79 will be reblessed to L<DBIx::Class::Storage::DBI::Sybase::NoBindVars>. You can
80 also enable that driver explicitly, see the documentation for more details.
81
82 With this driver there is unfortunately no way to get the C<last_insert_id>
83 without doing a C<select max(col)>.
84
85 But your queries will be cached.
86
87 =head1 DATES
88
89 On connection C<syb_date_fmt> is set to C<ISO_strict>, e.g.:
90 C<2004-08-21T14:36:48.080Z> and C<dateformat> is set to C<mdy>, e.g.:
91 C<08/13/1979 18:08:55.080>.
92
93 You will need the L<DateTime::Format::Strptime> module if you are going to use
94 L<DBIx::Class::InflateColumn::DateTime>.
95
96 =head1 AUTHORS
97
98 See L<DBIx::Class/CONTRIBUTORS>.
99
100 =head1 LICENSE
101
102 You may distribute this code under the same terms as Perl itself.
103
104 =cut
105 # vim:sts=2 sw=2: