From: Rafael Kitover Date: Wed, 24 Mar 2010 20:25:24 +0000 (+0000) Subject: collect _server_info on connection X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1f5aae08362fffa1fcf0991909293d9c418e1c40;p=dbsrgits%2FDBIx-Class-Historic.git collect _server_info on connection --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 00c8eb8..736bcc9 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -18,7 +18,8 @@ use Sub::Name (); __PACKAGE__->mk_group_accessors('simple' => qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts _conn_pid - _conn_tid transaction_depth _dbh_autocommit _driver_determined savepoints/ + _conn_tid transaction_depth _dbh_autocommit _driver_determined savepoints + _server_info/ ); # the values for these accessors are picked out (and deleted) from @@ -919,6 +920,8 @@ sub _populate_dbh { $self->{transaction_depth} = $self->_dbh_autocommit ? 0 : 1; $self->_run_connection_actions unless $self->{_in_determine_driver}; + + $self->_get_server_info; } sub _run_connection_actions { @@ -931,6 +934,17 @@ sub _run_connection_actions { $self->_do_connection_actions(connect_call_ => $_) for @actions; } +sub _get_server_info { + my $self = shift; + my %info; + + $info{dbms_ver} = $self->_get_dbh->get_info(18); + + $self->_server_info(\%info); + + return \%info; +} + sub _determine_driver { my ($self) = @_; diff --git a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm index 210a650..cd0fa57 100644 --- a/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm +++ b/lib/DBIx/Class/Storage/DBI/ODBC/Microsoft_SQL_Server.pm @@ -178,7 +178,7 @@ sub connect_call_use_MARS { sub _get_mssql_version { my $self = shift; - my ($version) = $self->_get_dbh->get_info(18) =~ /^(\d+)/; + my ($version) = $self->_server_info->{dbms_ver} =~ /^(\d+)/; return $version; } diff --git a/lib/DBIx/Class/Storage/DBI/Pg.pm b/lib/DBIx/Class/Storage/DBI/Pg.pm index 05d4f47..6d9d2e7 100644 --- a/lib/DBIx/Class/Storage/DBI/Pg.pm +++ b/lib/DBIx/Class/Storage/DBI/Pg.pm @@ -19,9 +19,7 @@ warn __PACKAGE__.": DBD::Pg 2.9.2 or greater is strongly recommended\n" sub can_insert_returning { my $self = shift; - my $pg_ver = $self->_get_dbh->get_info(18); - - my ($major, $minor) = $pg_ver =~ /^(\d+)\.(\d+)/; + my ($major, $minor) = $self->_server_info->{dbms_ver} =~ /^(\d+)\.(\d+)/; return 1 if ($major > 8) || ($major == 8 && $minor >= 2); diff --git a/t/72pg.t b/t/72pg.t index f3ad48e..4065b26 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -25,9 +25,13 @@ DBICTest::Schema->load_classes( map {s/.+:://;$_} @test_classes ) if @test_class my $schema; +require DBIx::Class::Storage::DBI::Pg; + +my $can_insert_returning = + DBIx::Class::Storage::DBI::Pg->can('can_insert_returning'); + for my $use_insert_returning (0..1) { no warnings qw/redefine once/; - require DBIx::Class::Storage::DBI::Pg; local *DBIx::Class::Storage::DBI::Pg::can_insert_returning = sub { $use_insert_returning }; @@ -63,6 +67,14 @@ for my $use_insert_returning (0..1) { ### connect, create postgres-specific test schema $schema = DBICTest::Schema->connect($dsn, $user, $pass); + $schema->storage->ensure_connected; + + if ($use_insert_returning && (not $can_insert_returning->($schema->storage))) + { + diag "Your version of PostgreSQL does not support INSERT ... RETURNING."; + diag "*** SKIPPING FURTHER TESTS"; + last; + } drop_test_schema($schema); create_test_schema($schema);