From: Michael Trier Date: Mon, 10 Nov 2008 04:37:08 +0000 (+0000) Subject: Handle the mssql port properly. If we're using the SQL Server driver then use the... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8878ef62a7215dbad8bcc0dd345d981023fd938;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Handle the mssql port properly. If we're using the SQL Server driver then use the correct host,port syntax, otherwise use the Port= parameter in the connection string. Fixes #1192. Also backports support to handle custom connection string arguments. --- diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 9894a46f3b..6a72e6a272 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -778,18 +778,24 @@ class MSSQLDialect_pyodbc(MSSQLDialect): if 'max_identifier_length' in keys: self.max_identifier_length = int(keys.pop('max_identifier_length')) if 'dsn' in keys: - connectors = ['dsn=%s' % keys['dsn']] + connectors = ['dsn=%s' % keys.pop('dsn')] else: + port = '' + if 'port' in keys and ( + keys.get('driver', 'SQL Server') == 'SQL Server'): + port = ',%d' % int(keys.pop('port')) + connectors = ["DRIVER={%s}" % keys.pop('driver', 'SQL Server'), - 'Server=%s' % keys['host'], - 'Database=%s' % keys['database'] ] - if 'port' in keys: - connectors.append('Port=%d' % int(keys['port'])) - - user = keys.get("user") + 'Server=%s%s' % (keys.pop('host', ''), port), + 'Database=%s' % keys.pop('database', '') ] + + if 'port' in keys and not port: + connectors.append('Port=%d' % int(keys.pop('port'))) + + user = keys.pop("user", None) if user: connectors.append("UID=%s" % user) - connectors.append("PWD=%s" % keys.get("password", "")) + connectors.append("PWD=%s" % keys.pop('password', '')) else: connectors.append("TrustedConnection=Yes") @@ -797,7 +803,7 @@ class MSSQLDialect_pyodbc(MSSQLDialect): # textual data from your database encoding to your client encoding # This should obviously be set to 'No' if you query a cp1253 encoded # database from a latin1 client... - if 'odbc_autotranslate' in keys: + if 'odbc_autotranslate' in keys: connectors.append("AutoTranslate=%s" % keys.pop("odbc_autotranslate")) # Allow specification of partial ODBC connect string @@ -806,7 +812,7 @@ class MSSQLDialect_pyodbc(MSSQLDialect): if odbc_options[0]=="'" and odbc_options[-1]=="'": odbc_options=odbc_options[1:-1] connectors.append(odbc_options) - + connectors.extend(['%s=%s' % (k,v) for k,v in keys.iteritems()]) return [[";".join (connectors)], {}] def is_disconnect(self, e):