1 package DBIx::Class::Storage::DBI::Sybase;
7 use base qw/DBIx::Class::Storage::DBI/;
9 use Carp::Clan qw/^DBIx::Class/;
14 if (ref($self) eq 'DBIx::Class::Storage::DBI::Sybase') {
16 @{$self->dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2]
21 my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}";
23 if (!$exception && $dbtype && $self->load_optional_class($subclass)) {
24 bless $self, $subclass;
28 if (not $self->dbh->{syb_dynamic_supported}) {
29 bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars';
32 $self->connect_call_datetime_setup;
33 $self->connect_call_blob_setup;
40 $self->next::method(@_);
41 $self->connect_call_datetime_setup;
42 $self->connect_call_blob_setup;
46 =head2 connect_call_blob_setup
50 on_connect_call => 'blob_setup'
52 Does C<< $dbh->{syb_binary_images} = 1; >> to return C<IMAGE> data as raw binary
53 instead of as a hex string.
57 sub connect_call_blob_setup {
59 my $dbh = $self->_dbh;
60 $dbh->{syb_binary_images} = 1;
64 my $old_dbd_warned = 0;
66 =head2 connect_call_datetime_setup
70 on_connect_call => 'datetime_setup'
72 In L<DBIx::Class::Storage::DBI/connect_info> to set:
74 $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z
75 $dbh->do('set dateformat mdy'); # input fmt: 08/13/1979 18:08:55.080
77 On connection for use with L<DBIx::Class::InflateColumn::DateTime>, using
78 L<DateTime::Format::Sybase>, which you will need to install.
80 This works for both C<DATETIME> and C<SMALLDATETIME> columns, although
81 C<SMALLDATETIME> columns only have minute precision.
85 sub connect_call_datetime_setup {
87 my $dbh = $self->_dbh;
89 if ($dbh->can('syb_date_fmt')) {
90 $dbh->syb_date_fmt('ISO_strict');
91 } elsif (not $old_dbd_warned) {
92 carp "Your DBD::Sybase is too old to support ".
93 "DBIx::Class::InflateColumn::DateTime, please upgrade!";
97 $dbh->do('set dateformat mdy');
103 sub _dbh_last_insert_id {
104 my ($self, $dbh, $source, $col) = @_;
106 # sorry, there's no other way!
107 my $sth = $dbh->prepare_cached("select max($col) from ".$source->from);
108 return ($dbh->selectrow_array($sth))[0];
113 my ($source, $attrs) = @_;
115 if (not exists $attrs->{rows}) {
116 return $self->next::method(@_);
119 my $offset = $attrs->{offset} || 0;
120 my $total = $attrs->{rows} + $offset;
122 my $new_attrs = $self->_copy_attributes_for_count($source, $attrs);
124 my $first_pk = ($source->primary_columns)[0];
126 $new_attrs->{select} = $first_pk ? "me.$first_pk" : 1;
128 my $tmp_rs = $source->resultset_class->new($source, $new_attrs);
130 $self->dbh->{syb_rowcount} = $total;
133 $count++ while $tmp_rs->cursor->next;
135 $self->dbh->{syb_rowcount} = 0;
137 return $count - $offset;
140 sub datetime_parser_type { "DateTime::Format::Sybase" }
146 DBIx::Class::Storage::DBI::Sybase - Storage::DBI subclass for Sybase
150 This subclass supports L<DBD::Sybase> for real Sybase databases. If you are
151 using an MSSQL database via L<DBD::Sybase>, your storage will be reblessed to
152 L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server>.
156 If your version of Sybase does not support placeholders, then your storage
157 will be reblessed to L<DBIx::Class::Storage::DBI::Sybase::NoBindVars>. You can
158 also enable that driver explicitly, see the documentation for more details.
160 With this driver there is unfortunately no way to get the C<last_insert_id>
161 without doing a C<select max(col)>.
163 But your queries will be cached.
167 See L</connect_call_datetime_setup> to setup date formats
168 for L<DBIx::Class::InflateColumn::DateTime>.
172 See L</connect_call_blob_setup> for a L<DBIx::Class::Storage::DBI/connect_info>
173 setting you need to work with C<IMAGE> columns.
177 See L<DBIx::Class/CONTRIBUTORS>.
181 You may distribute this code under the same terms as Perl itself.