Commit | Line | Data |
3885cff6 |
1 | package DBIx::Class::Storage::DBI::Sybase; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a0348159 |
6 | use Class::C3; |
c5ce7cd6 |
7 | use base qw/DBIx::Class::Storage::DBI/; |
3885cff6 |
8 | |
6b1f5ef7 |
9 | use Carp::Clan qw/^DBIx::Class/; |
10 | |
47d9646a |
11 | sub _rebless { |
b50a5275 |
12 | my $self = shift; |
c5ce7cd6 |
13 | |
14 | if (ref($self) eq 'DBIx::Class::Storage::DBI::Sybase') { |
15 | my $dbtype = eval { |
16 | @{$self->dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2] |
17 | } || ''; |
18 | |
19 | my $exception = $@; |
20 | $dbtype =~ s/\W/_/gi; |
21 | my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}"; |
22 | |
23 | if (!$exception && $dbtype && $self->load_optional_class($subclass)) { |
24 | bless $self, $subclass; |
25 | $self->_rebless; |
683f73ec |
26 | } else { |
27 | # real Sybase |
28 | if (not $self->dbh->{syb_dynamic_supported}) { |
29 | bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars'; |
30 | $self->_rebless; |
31 | } |
32 | $self->_init_date_fmt; |
47d9646a |
33 | } |
c5ce7cd6 |
34 | } |
b50a5275 |
35 | } |
36 | |
683f73ec |
37 | sub _populate_dbh { |
38 | my $self = shift; |
39 | $self->next::method(@_); |
40 | $self->_init_date_fmt; |
41 | 1; |
42 | } |
43 | |
6b1f5ef7 |
44 | { |
45 | my $old_dbd_warned = 0; |
46 | |
683f73ec |
47 | sub _init_date_fmt { |
6b1f5ef7 |
48 | my $self = shift; |
6b1f5ef7 |
49 | my $dbh = $self->_dbh; |
50 | |
51 | if ($dbh->can('syb_date_fmt')) { |
52 | $dbh->syb_date_fmt('ISO_strict'); |
53 | } elsif (not $old_dbd_warned) { |
54 | carp "Your DBD::Sybase is too old to support ". |
55 | "DBIx::Class::InflateColumn::DateTime, please upgrade!"; |
56 | $old_dbd_warned = 1; |
57 | } |
58 | |
59 | $dbh->do('set dateformat mdy'); |
c5ce7cd6 |
60 | |
6b1f5ef7 |
61 | 1; |
c5ce7cd6 |
62 | } |
6b1f5ef7 |
63 | } |
64 | |
65 | sub _dbh_last_insert_id { |
66 | my ($self, $dbh, $source, $col) = @_; |
c5ce7cd6 |
67 | |
68 | # sorry, there's no other way! |
69 | my $sth = $dbh->prepare_cached("select max($col) from ".$source->from); |
70 | return ($dbh->selectrow_array($sth))[0]; |
a964a928 |
71 | } |
72 | |
b7505130 |
73 | sub count { |
aa56ff9a |
74 | my $self = shift; |
75 | my ($source, $attrs) = @_; |
b7505130 |
76 | |
6537ddaa |
77 | if (not exists $attrs->{rows}) { |
78 | return $self->next::method(@_); |
79 | } |
b7505130 |
80 | |
6537ddaa |
81 | my $offset = $attrs->{offset} || 0; |
82 | my $total = $attrs->{rows} + $offset; |
b7505130 |
83 | |
6537ddaa |
84 | my $new_attrs = $self->_trim_attributes_for_count($source, $attrs); |
85 | $new_attrs->{select} = '1'; |
86 | $new_attrs->{as} = ['dummy']; |
a0348159 |
87 | |
6537ddaa |
88 | my $tmp_rs = $source->resultset_class->new($source, $new_attrs); |
b7505130 |
89 | |
6537ddaa |
90 | $self->dbh->{syb_rowcount} = $total; |
b7505130 |
91 | |
6537ddaa |
92 | my $count = 0; |
93 | $count++ while $tmp_rs->cursor->next; |
b7505130 |
94 | |
6537ddaa |
95 | $self->dbh->{syb_rowcount} = 0; |
b7505130 |
96 | |
6537ddaa |
97 | return $count - $offset; |
b7505130 |
98 | } |
99 | |
c5ce7cd6 |
100 | sub datetime_parser_type { "DBIx::Class::Storage::DBI::Sybase::DateTime" } |
101 | |
3885cff6 |
102 | 1; |
103 | |
104 | =head1 NAME |
105 | |
106 | DBIx::Class::Storage::DBI::Sybase - Storage::DBI subclass for Sybase |
107 | |
108 | =head1 SYNOPSIS |
109 | |
7e8cecc1 |
110 | This subclass supports L<DBD::Sybase> for real Sybase databases. If you are |
111 | using an MSSQL database via L<DBD::Sybase>, your storage will be reblessed to |
112 | L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server>. |
3885cff6 |
113 | |
7e8cecc1 |
114 | =head1 DESCRIPTION |
d4483998 |
115 | |
7e8cecc1 |
116 | If your version of Sybase does not support placeholders, then your storage |
117 | will be reblessed to L<DBIx::Class::Storage::DBI::Sybase::NoBindVars>. You can |
118 | also enable that driver explicitly, see the documentation for more details. |
c5ce7cd6 |
119 | |
7e8cecc1 |
120 | With this driver there is unfortunately no way to get the C<last_insert_id> |
121 | without doing a C<select max(col)>. |
c5ce7cd6 |
122 | |
123 | But your queries will be cached. |
124 | |
125 | =head1 DATES |
126 | |
127 | On connection C<syb_date_fmt> is set to C<ISO_strict>, e.g.: |
128 | C<2004-08-21T14:36:48.080Z> and C<dateformat> is set to C<mdy>, e.g.: |
7e8cecc1 |
129 | C<08/13/1979 18:08:55.080>. |
c5ce7cd6 |
130 | |
b7505130 |
131 | This works for both C<DATETIME> and C<SMALLDATETIME> columns, although |
132 | C<SMALLDATETIME> columns only have minute precision. |
133 | |
c5ce7cd6 |
134 | You will need the L<DateTime::Format::Strptime> module if you are going to use |
135 | L<DBIx::Class::InflateColumn::DateTime>. |
136 | |
3885cff6 |
137 | =head1 AUTHORS |
138 | |
7e8cecc1 |
139 | See L<DBIx::Class/CONTRIBUTORS>. |
c5ce7cd6 |
140 | |
3885cff6 |
141 | =head1 LICENSE |
142 | |
143 | You may distribute this code under the same terms as Perl itself. |
144 | |
145 | =cut |
c5ce7cd6 |
146 | # vim:sts=2 sw=2: |