From: Rafael Kitover Date: Tue, 19 Jul 2011 18:02:49 +0000 (-0400) Subject: Check DBD::Pg >= 2.17.2 with Pg >= 9.0 for BYTEA X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9aec3ec60e053fc70810822c75b1008acdccd8b0;p=dbsrgits%2FDBIx-Class-Historic.git Check DBD::Pg >= 2.17.2 with Pg >= 9.0 for BYTEA Checks for DBD::Pg < 2.17.2 when using PostgreSQL version 9.0 or greater when BYTEA column binds are encountered and prints a warning that a newer version of DBD::Pg is needed for these types of columns to work in bind_attribute_by_data_type in the Pg storage. Skips the t/72pg_bytea.t tests for this combination of versions, as well as for versions of DBD::Pg less than 2.9.2 regardless of Pg version. --- diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index f4dbda6..0dc7ea8 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -11,6 +11,7 @@ use mro 'c3'; use Scope::Guard (); use Context::Preserve 'preserve_context'; use DBIx::Class::Carp; +use Try::Tiny; use namespace::clean; __PACKAGE__->sql_limit_dialect ('LimitOffset'); @@ -170,8 +171,16 @@ sub bind_attribute_by_data_type { # Ask for a DBD::Pg with array support # pg uses (used?) version::qv() require DBD::Pg; - if ($DBD::Pg::VERSION < 2.009002) { - carp_once( __PACKAGE__.": DBD::Pg 2.9.2 or greater is strongly recommended\n" ); + + if ($self->_server_info->{normalized_dbms_version} >= 9.0) { + if (not try { DBD::Pg->VERSION('2.17.2') }) { + carp_once( __PACKAGE__.': BYTEA columns are known to not work on Pg >=' + . " 9.0 with DBD::Pg < 2.17.2\n" ); + } + } + elsif (not try { DBD::Pg->VERSION('2.9.2') }) { + carp_once( __PACKAGE__.': DBD::Pg 2.9.2 or greater is strongly recommended' + . "for BYTEA column support.\n" ); } # cache the result of _is_binary_lob_type diff --git a/t/72pg_bytea.t b/t/72pg_bytea.t index 0468976..234da7e 100644 --- a/t/72pg_bytea.t +++ b/t/72pg_bytea.t @@ -3,6 +3,7 @@ use warnings; use Test::More; use DBIx::Class::Optional::Dependencies (); +use Try::Tiny; use lib qw(t/lib); use DBICTest; @@ -16,6 +17,17 @@ plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test' my $schema = DBICTest::Schema->connection($dsn, $dbuser, $dbpass, { AutoCommit => 1 }); +if ($schema->storage->_server_info->{normalized_dbms_version} >= 9.0) { + if (not try { DBD::Pg->VERSION('2.17.2') }) { + plan skip_all => + 'DBD::Pg < 2.17.2 does not work with Pg >= 9.0 BYTEA columns'; + } +} +elsif (not try { DBD::Pg->VERSION('2.9.2') }) { + plan skip_all => + 'DBD::Pg < 2.9.2 does not work with BYTEA columns'; +} + my $dbh = $schema->storage->dbh; {