Skip to content
drmuey edited this page Feb 5, 2016 · 31 revisions

MSSQL Fork TODOs:

  • Typical engine tests for mssql.pm
  • POD for new()’s _driver attr (or do we?) we do, since its public dbd_driver() now
  • Determine DSN/URI logic (e.g. look at discussion in PR #6 and grep for ?how does $uri->dbi_dsn know what $self->driver to use?)
    • Done (will check off parent item once its is merged) Created mssql_multi_driver_dsn branch on my fork
    • Done Forked URI::db for pull request and created branch mssql_multi_driver_support.
  • Determine if the this being necessary seems like a bug, no? comment is a thing or not.
  • Address # TODO: is this correct for all 3 $self->dbd_driver()?
  • Should provider() and integrated_security() return a sane default (or die or ??) if its not configured (i.e. if $self->sqitch->config->get() returns nothing)

RFC: Sketch of something that relates to the last 2 TODO items above

diff --git a/lib/App/Sqitch/Engine/mssql.pm b/lib/App/Sqitch/Engine/mssql.pm
index dfb5fcd..082045a 100644
--- a/lib/App/Sqitch/Engine/mssql.pm
+++ b/lib/App/Sqitch/Engine/mssql.pm
@@ -27,7 +27,7 @@ has integrated_security => (
     default => sub {
         my $self   = shift;
         my $engine = $self->key;
-        return $self->sqitch->config->get( key => "engine.$engine.integrated_security" );
+        return $self->sqitch->config->get( key => "engine.$engine.integrated_security" ) || 'SSPI';    # See registry_uri()
     }
 );
 
@@ -56,13 +56,27 @@ has registry_uri => (
         my $pwd    = $uri->password;
 
         # TODO: is this correct for all 3 $self->dbd_driver()? if so: update this comment to reflect that. If not: update the code to do th
+        $uri->query_param( 'Provider', $self->provider ) if $self->provider;
+        $uri->query_param( 'Initial Catalog', $db );
+        $uri->query_param( 'Server',          $host[1] );
+
         if ( defined $pwd ) {
-            $uri->query( "Provider=" . $self->provider . ";Initial Catalog=" . $db . ";Server=" . $host[1] . ";" );
+            $uri->query_param( "Persist Security Info", "False" );
         }
-        if ( not defined $pwd ) {
-
-            $uri->query( "Provider=" . $self->provider . ";Integrated Security=" . $self->integrated_security . ";Initial Catalog=" . $db .
+        else {
+            # https://msdn.microsoft.com/library/ms254500(v=vs.100).aspx#Anchor_1
+            my $seckey = 'Integrated Security';
+            my $secval = $self->integrated_security;
+            if ( $self->provider =~ m/odbc/i ) {
+                $seckey = 'Trusted_Connection';
+                $secval = 'yes' if $self->integrated_security eq 'SSPI';
+            }
+            elsif ( $self->provider =~ m/oracleclient/i ) {
+                $secval = 'yes' if $self->integrated_security eq 'SSPI';
+            }
+            $uri->query_param( $seckey, $secval );
         }
+
         return $uri;
     },
 );

Relevant URLs

Clone this wiki locally