From: Rafael Kitover Date: Sat, 23 May 2009 19:46:11 +0000 (+0000) Subject: Sybase bindvar and IC::DT support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0814e8043fb4dbad52bab9d77f5c9891feaa77d9;p=dbsrgits%2FDBIx-Class-Historic.git Sybase bindvar and IC::DT support --- diff --git a/Makefile.PL b/Makefile.PL index 8b730ca..7d8175f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -87,6 +87,7 @@ my %force_requires_if_author = ( 'Hash::Merge', => 0.11, # t/96_is_deteministic_value.t + # t/746sybase.t 'DateTime::Format::Strptime' => 0, ); diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index 1a63bc8..28b4059 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -3,28 +3,51 @@ package DBIx::Class::Storage::DBI::Sybase; use strict; use warnings; -use base qw/DBIx::Class::Storage::DBI::NoBindVars/; +use base qw/DBIx::Class::Storage::DBI/; sub _rebless { - my $self = shift; - - my $dbtype = eval { @{$self->dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2] }; - unless ( $@ ) { - $dbtype =~ s/\W/_/gi; - my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}"; - if ($self->load_optional_class($subclass) && !$self->isa($subclass)) { - bless $self, $subclass; - $self->_rebless; - } + my $self = shift; + + if (ref($self) eq 'DBIx::Class::Storage::DBI::Sybase') { + my $dbtype = eval { + @{$self->dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2] + } || ''; + + my $exception = $@; + $dbtype =~ s/\W/_/gi; + my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}"; + + if (!$exception && $dbtype && $self->load_optional_class($subclass)) { + bless $self, $subclass; + $self->_rebless; + } else { # probably real Sybase + if (not $self->dbh->{syb_dynamic_supported}) { + bless $self, 'DBIx::Class::Storage:DBI::Sybase::NoBindVars'; + $self->_rebless; + } + + $self->dbh->syb_date_fmt('ISO_strict'); + $self->dbh->do('set dateformat mdy'); } + } } sub _dbh_last_insert_id { - my $self = shift; - my $sth = $self->_dbh->prepare_cached('select @@identity'); - ($self->_dbh->selectrow_array($sth))[0]; + my ($self, $dbh, $source, $col) = @_; + + if (not $self->dbh->{syb_dynamic_supported}) { + # @@identity works only if not using placeholders + # Should this query be cached? + return ($dbh->selectrow_array('select @@identity'))[0]; + } + + # sorry, there's no other way! + my $sth = $dbh->prepare_cached("select max($col) from ".$source->from); + return ($dbh->selectrow_array($sth))[0]; } +sub datetime_parser_type { "DBIx::Class::Storage::DBI::Sybase::DateTime" } + 1; =head1 NAME @@ -39,21 +62,41 @@ L. =head1 CAVEATS -This storage driver uses L as a base. -This means that bind variables will be interpolated (properly quoted of course) +If your version of Sybase does not support placeholders, then this storage +driver uses L as a base, + +In which case, bind variables will be interpolated (properly quoted of course) into the SQL query itself, without using bind placeholders. More importantly this means that caching of prepared statements is explicitly disabled, as the interpolation renders it useless. +If your version of Sybase B support placeholders (check +C<<$dbh->{syb_dynamic_supported}>> then unfortunately there's no way to get the +C without doing a C