From: Peter Rabbitson Date: Sun, 23 Aug 2009 08:01:10 +0000 (+0000) Subject: Generalize and hide placeholder support check X-Git-Tag: v0.08112~14^2~55 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=70ced5192842574caed415d1a51c48447d5186e6;p=dbsrgits%2FDBIx-Class.git Generalize and hide placeholder support check --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index d9e938c..0d8a855 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1900,9 +1900,6 @@ sub _order_select_columns { return @{$_[2]}; } - - - sub source_bind_attributes { my ($self, $source) = @_; @@ -2076,6 +2073,38 @@ Returns the database driver name. sub sqlt_type { shift->_get_dbh->{Driver}->{Name} } + +# Check if placeholders are supported at all +sub _placeholders_supported { + my $self = shift; + my $dbh = $self->_get_dbh; + + # some drivers provide a $dbh attribute (e.g. Sybase and $dbh->{syb_dynamic_supported}) + # but it is inaccurate more often than not + eval { + local $dbh->{PrintError} = 0; + local $dbh->{RaiseError} = 1; + $dbh->do('select ?', {}, 1); + }; + return $@ ? 0 : 1; +} + +# Check if placeholders bound to non-string types throw exceptions +# +sub _typeless_placeholders_supported { + my $self = shift; + my $dbh = $self->_get_dbh; + + eval { + local $dbh->{PrintError} = 0; + local $dbh->{RaiseError} = 1; + # this specifically tests a bind that is NOT a string + $dbh->do('select 1 where 1 = ?', {}, 1); + }; + return $@ ? 0 : 1; +} + + =head2 bind_attribute_by_data_type Given a datatype from column info, returns a database specific bind diff --git a/lib/DBIx/Class/Storage/DBI/Sybase.pm b/lib/DBIx/Class/Storage/DBI/Sybase.pm index 7e68b38..e7d1e41 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase.pm @@ -83,8 +83,8 @@ See perldoc DBIx::Class::Storage::DBI::Sybase for more details. To turn off this warning set the DBIC_SYBASE_FREETDS_NOWARN environment variable. EOF - if (not $self->placeholders_with_type_conversion_supported) { - if ($self->placeholders_supported) { + if (not $self->_typeless_placeholders_supported) { + if ($self->_placeholders_supported) { $self->auto_cast(1); } else { $self->ensure_class_loaded($no_bind_vars); diff --git a/lib/DBIx/Class/Storage/DBI/Sybase/Base.pm b/lib/DBIx/Class/Storage/DBI/Sybase/Base.pm index 08b5ca4..293b3e1 100644 --- a/lib/DBIx/Class/Storage/DBI/Sybase/Base.pm +++ b/lib/DBIx/Class/Storage/DBI/Sybase/Base.pm @@ -35,47 +35,6 @@ sub _ping { return $@ ? 0 : 1; } -=head2 placeholders_supported - -Whether or not string placeholders work. Does not check for implicit conversion -errors, see L. - -=cut - -sub placeholders_supported { - my $self = shift; - my $dbh = $self->_get_dbh; - - return eval { -# There's also $dbh->{syb_dynamic_supported} but it can be inaccurate for this -# purpose. - local $dbh->{PrintError} = 0; - local $dbh->{RaiseError} = 1; - $dbh->selectrow_array('select ?', {}, 1); - }; -} - -=head2 placeholders_with_type_conversion_supported - -Checks if placeholders bound to non-string types throw implicit type conversion -errors or not. - -See L. - -=cut - -sub placeholders_with_type_conversion_supported { - my $self = shift; - my $dbh = $self->_dbh; - - return eval { - local $dbh->{PrintError} = 0; - local $dbh->{RaiseError} = 1; -# this specifically tests a bind that is NOT a string - $dbh->selectrow_array('select 1 where 1 = ?', {}, 1); - }; -} - sub _set_max_connect { my $self = shift; my $val = shift || 256;