1 package DBIx::Class::Storage::DBI::Sybase;
7 use base qw/DBIx::Class::Storage::DBI/;
9 use Carp::Clan qw/^DBIx::Class/;
13 DBIx::Class::Storage::DBI::Sybase - Storage::DBI subclass for Sybase
17 This subclass supports L<DBD::Sybase> for real Sybase databases. If you are
18 using an MSSQL database via L<DBD::Sybase>, your storage will be reblessed to
19 L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server>.
23 If your version of Sybase does not support placeholders, then your storage
24 will be reblessed to L<DBIx::Class::Storage::DBI::Sybase::NoBindVars>. You can
25 also enable that driver explicitly, see the documentation for more details.
27 With this driver there is unfortunately no way to get the C<last_insert_id>
28 without doing a C<select max(col)>.
30 But your queries will be cached.
32 A recommended L<DBIx::Class::Storage::DBI/connect_info> setting:
34 on_connect_call => [qw/datetime_setup blob_setup/]
43 if (ref($self) eq 'DBIx::Class::Storage::DBI::Sybase') {
45 @{$self->dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2]
50 my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}";
52 if (!$exception && $dbtype && $self->load_optional_class($subclass)) {
53 bless $self, $subclass;
57 if (not $self->dbh->{syb_dynamic_supported}) {
58 bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars';
61 $self->connect_call_datetime_setup;
62 $self->connect_call_blob_setup;
69 $self->next::method(@_);
70 $self->connect_call_datetime_setup;
71 $self->connect_call_blob_setup;
75 =head2 connect_call_blob_setup
79 on_connect_call => 'blob_setup'
81 Does C<< $dbh->{syb_binary_images} = 1; >> to return C<IMAGE> data as raw binary
82 instead of as a hex string.
88 sub connect_call_blob_setup {
90 my $dbh = $self->_dbh;
91 $dbh->{syb_binary_images} = 1;
94 =head2 connect_call_datetime_setup
98 on_connect_call => 'datetime_setup'
100 In L<DBIx::Class::Storage::DBI/connect_info> to set:
102 $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z
103 $dbh->do('set dateformat mdy'); # input fmt: 08/13/1979 18:08:55.080
105 On connection for use with L<DBIx::Class::InflateColumn::DateTime>, using
106 L<DateTime::Format::Sybase>, which you will need to install.
108 This works for both C<DATETIME> and C<SMALLDATETIME> columns, although
109 C<SMALLDATETIME> columns only have minute precision.
114 my $old_dbd_warned = 0;
116 sub connect_call_datetime_setup {
118 my $dbh = $self->_dbh;
120 if ($dbh->can('syb_date_fmt')) {
121 $dbh->syb_date_fmt('ISO_strict');
122 } elsif (not $old_dbd_warned) {
123 carp "Your DBD::Sybase is too old to support ".
124 "DBIx::Class::InflateColumn::DateTime, please upgrade!";
128 $dbh->do('set dateformat mdy');
134 sub datetime_parser_type { "DateTime::Format::Sybase" }
136 sub _dbh_last_insert_id {
137 my ($self, $dbh, $source, $col) = @_;
139 # sorry, there's no other way!
140 my $sth = $dbh->prepare_cached("select max($col) from ".$source->from);
141 return ($dbh->selectrow_array($sth))[0];
144 # previous implementation of limited count for Sybase, does not include
147 #sub _copy_attributes_for_count {
148 # my ($self, $source, $attrs) = @_;
149 # my %attrs = %$attrs;
151 # # take off any column specs, any pagers, record_filter is cdbi, and no point of ordering a count
152 # delete @attrs{qw/select as rows offset page order_by record_filter/};
159 #Counts for limited queries are emulated by executing select queries and
160 #returning the number of successful executions minus the offset.
162 #This is necessary due to the limitations of Sybase.
168 # my ($source, $attrs) = @_;
170 # my $new_attrs = $self->_copy_attributes_for_count($source, $attrs);
172 # if (exists $attrs->{rows}) {
173 # my $offset = $attrs->{offset} || 0;
174 # my $total = $attrs->{rows} + $offset;
176 # my $first_pk = ($source->primary_columns)[0];
178 # $new_attrs->{select} = $first_pk ? "me.$first_pk" : 1;
180 # my $tmp_rs = $source->resultset_class->new($source, $new_attrs);
182 # $self->dbh->{syb_rowcount} = $total;
185 # $count++ while $tmp_rs->cursor->next;
187 # $self->dbh->{syb_rowcount} = 0;
189 # return $count - $offset;
191 # # overwrite the selector
192 # $new_attrs->{select} = { count => '*' };
194 # my $tmp_rs = $source->resultset_class->new($source, $new_attrs);
195 # my ($count) = $tmp_rs->cursor->next;
197 # # if the offset/rows attributes are still present, we did not use
198 # # a subquery, so we need to make the calculations in software
199 # $count -= $attrs->{offset} if $attrs->{offset};
200 # $count = $attrs->{rows} if $attrs->{rows} and $attrs->{rows} < $count;
201 # $count = 0 if ($count < 0);
211 See L</connect_call_datetime_setup> to setup date formats
212 for L<DBIx::Class::InflateColumn::DateTime>.
214 =head1 IMAGE AND TEXT COLUMNS
216 See L</connect_call_blob_setup> for a L<DBIx::Class::Storage::DBI/connect_info>
217 setting you need to work with C<IMAGE> columns.
219 Due to limitations in L<DBD::Sybase> and this driver, it is only possible to
220 select one C<TEXT> or C<IMAGE> column at a time.
224 See L<DBIx::Class/CONTRIBUTORS>.
228 You may distribute this code under the same terms as Perl itself.