diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-11-10 17:08:06 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-11-11 13:30:25 -0500 |
commit | 5fba7db9be7a03076d50051fb84dade31d55262e (patch) | |
tree | 08b4da15962dbac0eae834f69005be2de9a221fe /lib/sqlalchemy | |
parent | 91e7d46fe1dc037a4817667813abb0a0bf164a1a (diff) | |
download | sqlalchemy-5fba7db9be7a03076d50051fb84dade31d55262e.tar.gz |
Quote URL tokens with semicolons for pyodbc, adodbapi
Fixed bug in pyodbc dialect (as well as in the mostly non-working
adodbapi dialect) whereby a semicolon present in the password
or username fields could be interpreted as a separator for another
token; the values are now quoted when semicolons are present.
Change-Id: I5f99fd8db53ebf8e805e7d9d60bc09b8f1af603f
Fixes: #3762
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/connectors/pyodbc.py | 11 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/adodbapi.py | 9 |
2 files changed, 19 insertions, 1 deletions
diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index 1811229d7..6478de582 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -55,6 +55,7 @@ class PyODBCConnector(Connector): opts.update(url.query) keys = opts + query = url.query connect_args = {} @@ -65,6 +66,15 @@ class PyODBCConnector(Connector): if 'odbc_connect' in keys: connectors = [util.unquote_plus(keys.pop('odbc_connect'))] else: + def check_quote(token): + if ";" in str(token): + token = "'%s'" % token + return token + + keys = dict( + (k, check_quote(v)) for k, v in keys.items() + ) + dsn_connection = 'dsn' in keys or \ ('host' in keys and 'database' not in keys) if dsn_connection: @@ -107,6 +117,7 @@ class PyODBCConnector(Connector): keys.pop("odbc_autotranslate")) connectors.extend(['%s=%s' % (k, v) for k, v in keys.items()]) + return [[";".join(connectors)], connect_args] def is_disconnect(self, e, connection, cursor): diff --git a/lib/sqlalchemy/dialects/mssql/adodbapi.py b/lib/sqlalchemy/dialects/mssql/adodbapi.py index 60fa25d34..a85ce5a57 100644 --- a/lib/sqlalchemy/dialects/mssql/adodbapi.py +++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py @@ -56,7 +56,14 @@ class MSDialect_adodbapi(MSDialect): ) def create_connect_args(self, url): - keys = url.query + def check_quote(token): + if ";" in str(token): + token = "'%s'" % token + return token + + keys = dict( + (k, check_quote(v)) for k, v in url.query.items() + ) connectors = ["Provider=SQLOLEDB"] if 'port' in keys: |