Merge 'trunk' into 'dbicadmin-non-versioned'
Peter Rabbitson [Mon, 31 May 2010 21:53:45 +0000 (21:53 +0000)]
r9501@Thesaurus (orig r9487):  rabbit | 2010-05-31 19:45:27 +0200
Fix RT57467, simplify test
r9503@Thesaurus (orig r9489):  rabbit | 2010-05-31 23:52:17 +0200
Fix Schema::Versioned borkage

Changes
lib/DBIx/Class/Schema/Versioned.pm
lib/DBIx/Class/Storage/DBI.pm
lib/DBIx/Class/Storage/DBI/Sybase/Microsoft_SQL_Server.pm
t/74mssql.t

diff --git a/Changes b/Changes
index 0ef7352..9dd6ebf 100644 (file)
--- a/Changes
+++ b/Changes
@@ -36,6 +36,10 @@ Revision history for DBIx::Class
           connection_info
         - Do not recreate the same related object twice during MultiCreate
           (solves the problem of orphaned IC::FS files)
+        - Fully qualify xp_msver selector when using DBD::Sybase with
+          MSSQL (RT#57467)
+        - Fix ::DBI::Storage to always be able to present a full set of
+          connect() attributes to e.g. Schema::Versioned
 
     * Misc
         - Add a warning to load_namespaces if a class in ResultSet/
index 036d452..bd4687e 100644 (file)
@@ -568,23 +568,23 @@ sub _on_connect
 {
   my ($self) = @_;
 
-  my $info = $self->storage->connect_info;
-  my $args = $info->[-1];
+  my $conn_info = $self->storage->connect_info;
+  $self->{vschema} = DBIx::Class::Version->connect(@$conn_info);
+  my $conn_attrs = $self->{vschema}->storage->_dbic_connect_attributes || {};
 
-  $self->{vschema} = DBIx::Class::Version->connect(@$info);
   my $vtable = $self->{vschema}->resultset('Table');
 
   # useful when connecting from scripts etc
-  return if ($args->{ignore_version} || ($ENV{DBIC_NO_VERSION_CHECK} && !exists $args->{ignore_version}));
+  return if ($conn_attrs->{ignore_version} || ($ENV{DBIC_NO_VERSION_CHECK} && !exists $conn_attrs->{ignore_version}));
 
   # check for legacy versions table and move to new if exists
-  my $vschema_compat = DBIx::Class::VersionCompat->connect(@$info);
+  my $vschema_compat = DBIx::Class::VersionCompat->connect(@$conn_info);
   unless ($self->_source_exists($vtable)) {
     my $vtable_compat = $vschema_compat->resultset('TableCompat');
     if ($self->_source_exists($vtable_compat)) {
       $self->{vschema}->deploy;
       map { $vtable->create({ installed => $_->Installed, version => $_->Version }) } $vtable_compat->all;
-      $self->storage->dbh->do("DROP TABLE " . $vtable_compat->result_source->from);
+      $self->storage->_get_dbh->do("DROP TABLE " . $vtable_compat->result_source->from);
     }
   }
 
index 1989821..3dbfd39 100644 (file)
@@ -19,11 +19,11 @@ use Try::Tiny;
 use File::Path ();
 use namespace::clean;
 
-__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
-     _server_info_hash/
-);
+__PACKAGE__->mk_group_accessors('simple' => qw/
+  _connect_info _dbi_connect_info _dbic_connect_attributes _driver_determined
+  _dbh _server_info_hash _conn_pid _conn_tid _sql_maker _sql_maker_opts
+  transaction_depth _dbh_autocommit  savepoints
+/);
 
 # the values for these accessors are picked out (and deleted) from
 # the attribute hashref passed to connect_info
@@ -582,6 +582,11 @@ sub connect_info {
   $self->_dbi_connect_info([@args,
     %attrs && !(ref $args[0] eq 'CODE') ? \%attrs : ()]);
 
+  # FIXME - dirty:
+  # save attributes them in a separate accessor so they are always
+  # introspectable, even in case of a CODE $dbhmaker
+  $self->_dbic_connect_attributes (\%attrs);
+
   return $self->_connect_info;
 }
 
index ff9223a..d0eb72b 100644 (file)
@@ -59,7 +59,7 @@ sub _dbh_rollback {
 sub _get_server_version {
   my $self = shift;
 
-  my $product_version = $self->_get_dbh->selectrow_hashref('xp_msver ProductVersion');
+  my $product_version = $self->_get_dbh->selectrow_hashref('master.dbo.xp_msver ProductVersion');
 
   if ((my $version = $product_version->{Character_Value}) =~ /^(\d+)\./) {
     return $version;
index cec6cb7..c51e9de 100644 (file)
@@ -186,20 +186,12 @@ SQL
 
     my $have_rno = $version >= 9 ? 1 : 0;
 
-    # Delete version information to force RNO check when rebuilding SQLA
-    # instance.
-    no strict 'refs';
-    no warnings 'redefine';
-    local *{(ref $storage).'::_get_server_version'} = sub { undef };
-
-    my $server_info = { %{ $storage->_server_info_hash } }; # clone
-
-    delete @$server_info{qw/dbms_version normalized_dbms_version/};
-
-    local $storage->{_server_info_hash} = $server_info;
     local $storage->{_sql_maker}        = undef;
     local $storage->{_sql_maker_opts}   = undef;
 
+    local $storage->{_server_info_hash} = { %{ $storage->_server_info_hash } }; # clone
+    delete @{$storage->{_server_info_hash}}{qw/dbms_version normalized_dbms_version/};
+
     $storage->sql_maker;
 
     my $rno_detected =