]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- mssql+pymssql dialect now honors the "port" portion
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Oct 2010 16:00:58 +0000 (12:00 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 24 Oct 2010 16:00:58 +0000 (12:00 -0400)
of the URL instead of discarding it.  [ticket:1952]
- testing.only_on() accepts db specs optionally as a list

CHANGES
lib/sqlalchemy/dialects/mssql/pymssql.py
lib/sqlalchemy/test/testing.py
test/dialect/test_mssql.py

diff --git a/CHANGES b/CHANGES
index 9eab740d690f2511ae2120377089410639257443..2acf1b76f6e21b3a36df412aeafcc211c0df671b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -267,6 +267,9 @@ CHANGES
      Note that reflection of indexes requires SQL 
      Server 2005 or greater.  [ticket:1770]
      
+   - mssql+pymssql dialect now honors the "port" portion
+     of the URL instead of discarding it.  [ticket:1952]
+     
 - informix
    - *Major* cleanup / modernization of the Informix 
      dialect for 0.6, courtesy Florian Apolloner. 
index b6728c6b0430e5a20902305e45aa81c71c2cc1ad..c5f4719426b6e7007f1ddc0a16f7459c7f659f78 100644 (file)
@@ -85,7 +85,9 @@ class MSDialect_pymssql(MSDialect):
     def create_connect_args(self, url):
         opts = url.translate_connect_args(username='user')
         opts.update(url.query)
-        opts.pop('port', None)
+        port = opts.pop('port', None)
+        if port and 'host' in opts:
+            opts['host'] = "%s:%s" % (opts['host'], port)
         return [[], opts]
 
     def is_disconnect(self, e):
@@ -99,4 +101,4 @@ class MSDialect_pymssql(MSDialect):
         else:
             return False
 
-dialect = MSDialect_pymssql
\ No newline at end of file
+dialect = MSDialect_pymssql
index 471044742f97ed54134fec4553556a0487e1f070..12cbe5e029c6e87693ec47c97bfd6cb1fa540b3f 100644 (file)
@@ -208,9 +208,9 @@ def _block_unconditionally(db, reason):
         return function_named(maybe, fn_name)
     return decorate
 
-def only_on(db, reason):
+def only_on(dbs, reason):
     carp = _should_carp_about_exclusion(reason)
-    spec = db_spec(db)
+    spec = db_spec(*util.to_list(dbs))
     def decorate(fn):
         fn_name = fn.__name__
         def maybe(*args, **kw):
index f9912317c6144121736982bd9d8359d011a7b35c..e766a8301ab23604aef61b744c32c9601a2908dc 100644 (file)
@@ -9,7 +9,7 @@ from sqlalchemy import types, exc, schema
 from sqlalchemy.orm import *
 from sqlalchemy.sql import table, column
 from sqlalchemy.databases import mssql
-from sqlalchemy.dialects.mssql import pyodbc, mxodbc
+from sqlalchemy.dialects.mssql import pyodbc, mxodbc, pymssql
 from sqlalchemy.engine import url
 from sqlalchemy.test import *
 from sqlalchemy.test.testing import eq_, emits_warning_on, \
@@ -866,12 +866,10 @@ class MatchTest(TestBase, AssertsCompiledSQL):
 
 
 class ParseConnectTest(TestBase, AssertsCompiledSQL):
-    __only_on__ = 'mssql'
-
     @classmethod
     def setup_class(cls):
         global dialect
-        dialect = pyodbc.MSDialect_pyodbc()
+        dialect = pyodbc.dialect()
 
     def test_pyodbc_connect_dsn_trusted(self):
         u = url.make_url('mssql://mydsn')
@@ -957,7 +955,27 @@ class ParseConnectTest(TestBase, AssertsCompiledSQL):
         connection = dialect.create_connect_args(u)
         eq_([['DRIVER={SQL Server};Server=hostspec;Database=database;UI'
             'D=username;PWD=password'], {}], connection)
+    
+    def test_pymssql_port_setting(self):
+        dialect = pymssql.dialect()
 
+        u = \
+            url.make_url('mssql+pymssql://scott:tiger@somehost/test')
+        connection = dialect.create_connect_args(u)
+        eq_(
+            [[], {'host': 'somehost', 'password': 'tiger', 
+                    'user': 'scott', 'database': 'test'}], connection
+        )
+
+        u = \
+            url.make_url('mssql+pymssql://scott:tiger@somehost:5000/test')
+        connection = dialect.create_connect_args(u)
+        eq_(
+            [[], {'host': 'somehost:5000', 'password': 'tiger', 
+                    'user': 'scott', 'database': 'test'}], connection
+        )
+    
+    @testing.only_on(['mssql+pyodbc', 'mssql+pymssql'], "FreeTDS specific test")
     def test_bad_freetds_warning(self):
         engine = engines.testing_engine()