X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FSybase.pm;h=abf15bfbcfd2b243b20c0a7adc7f27ae5050e5a3;hb=fd323bf1046faa7de5a8c985268d80ec5b703361;hp=28b4059836bbf9bea57c7fc7d9569a34c1b1e0a5;hpb=c5ce7cd6bbb375009987f267fd8af28292b38930;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index 28b4059..abf15bf 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -2,101 +2,136 @@ package DBIx::Class::Storage::DBI::Sybase; use strict; use warnings; +use Try::Tiny; +use namespace::clean; use base qw/DBIx::Class::Storage::DBI/; +=head1 NAME + +DBIx::Class::Storage::DBI::Sybase - Base class for drivers using +L + +=head1 DESCRIPTION + +This is the base class/dispatcher for Storage's designed to work with +L + +=head1 METHODS + +=cut + sub _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 $dbtype; + try { + $dbtype = @{$self->_get_dbh->selectrow_arrayref(qq{sp_server_info \@attribute_id=1})}[2] + } catch { + $self->throw_exception("Unable to estable connection to determine database type: $_") + }; - my $exception = $@; + if ($dbtype) { $dbtype =~ s/\W/_/gi; - my $subclass = "DBIx::Class::Storage::DBI::Sybase::${dbtype}"; - if (!$exception && $dbtype && $self->load_optional_class($subclass)) { + # saner class name + $dbtype = 'ASE' if $dbtype eq 'SQL_Server'; + + my $subclass = __PACKAGE__ . "::$dbtype"; + if ($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, $dbh, $source, $col) = @_; +sub _ping { + my $self = shift; + + my $dbh = $self->_dbh or return 0; - 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]; + local $dbh->{RaiseError} = 1; + local $dbh->{PrintError} = 0; + + if ($dbh->{syb_no_child_con}) { +# if extra connections are not allowed, then ->ping is reliable + return try { $dbh->ping } catch { 0; }; } - # sorry, there's no other way! - my $sth = $dbh->prepare_cached("select max($col) from ".$source->from); - return ($dbh->selectrow_array($sth))[0]; + return try { +# XXX if the main connection goes stale, does opening another for this statement +# really determine anything? + $dbh->do('select 1'); + 1; + } catch { + 0; + }; } -sub datetime_parser_type { "DBIx::Class::Storage::DBI::Sybase::DateTime" } +sub _set_max_connect { + my $self = shift; + my $val = shift || 256; -1; + my $dsn = $self->_dbi_connect_info->[0]; -=head1 NAME + return if ref($dsn) eq 'CODE'; -DBIx::Class::Storage::DBI::Sybase - Storage::DBI subclass for Sybase + if ($dsn !~ /maxConnect=/) { + $self->_dbi_connect_info->[0] = "$dsn;maxConnect=$val"; + my $connected = defined $self->_dbh; + $self->disconnect; + $self->ensure_connected if $connected; + } +} -=head1 SYNOPSIS +=head2 using_freetds -This subclass supports L for real Sybase databases. If -you are using an MSSQL database via L, see -L. +Whether or not L was compiled against FreeTDS. If false, it means +the Sybase OpenClient libraries were used. -=head1 CAVEATS +=cut -If your version of Sybase does not support placeholders, then this storage -driver uses L as a base, +sub using_freetds { + my $self = shift; -In which case, bind variables will be interpolated (properly quoted of course) -into the SQL query itself, without using bind placeholders. + return $self->_get_dbh->{syb_oc_version} =~ /freetds/i; +} -More importantly this means that caching of prepared statements is explicitly -disabled, as the interpolation renders it useless. +=head2 set_textsize -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