diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-03 09:30:58 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-04 23:22:20 -0500 |
commit | b38fb59fe484d6e4e5992c9b2dc9b9f7724f016a (patch) | |
tree | 21bac11da9981fe45b20bdb06240b37fb47b5800 /lib/sqlalchemy/dialects/mssql/provision.py | |
parent | 7099dd20e90307237240f30d5db0816a08356a5b (diff) | |
download | sqlalchemy-b38fb59fe484d6e4e5992c9b2dc9b9f7724f016a.tar.gz |
audition pymssql once more; retire sane_rowcount_returning
pymssql seems to be maintained again and seems to be working
completely, so let's try re-enabling it.
Fixed issue in the new :class:`.Uuid` datatype which prevented it from
working with the pymssql driver. As pymssql seems to be maintained again,
restored testing support for pymssql.
Tweaked the pymssql dialect to take better advantage of
RETURNING for INSERT statements in order to retrieve last inserted primary
key values, in the same way as occurs for the mssql+pyodbc dialect right
now.
Identified that the ``sqlite`` and ``mssql+pyodbc`` dialects are now
compatible with the SQLAlchemy ORM's "versioned rows" feature, since
SQLAlchemy now computes rowcount for a RETURNING statement in this specific
case by counting the rows returned, rather than relying upon
``cursor.rowcount``. In particular, the ORM versioned rows use case
(documented at :ref:`mapper_version_counter`) should now be fully
supported with the SQL Server pyodbc dialect.
Change-Id: I38a0666587212327aecf8f98e86031ab25d1f14d
References: #5321
Fixes: #9414
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/provision.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/provision.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/provision.py b/lib/sqlalchemy/dialects/mssql/provision.py index a7ecf4aa3..336e10cd9 100644 --- a/lib/sqlalchemy/dialects/mssql/provision.py +++ b/lib/sqlalchemy/dialects/mssql/provision.py @@ -12,6 +12,7 @@ from ...schema import Table from ...testing.provision import create_db from ...testing.provision import drop_all_schema_objects_pre_tables from ...testing.provision import drop_db +from ...testing.provision import generate_driver_url from ...testing.provision import get_temp_table_name from ...testing.provision import log from ...testing.provision import normalize_sequence @@ -19,6 +20,27 @@ from ...testing.provision import run_reap_dbs from ...testing.provision import temp_table_keyword_args +@generate_driver_url.for_db("mssql") +def generate_driver_url(url, driver, query_str): + + backend = url.get_backend_name() + + new_url = url.set(drivername="%s+%s" % (backend, driver)) + + if driver != "pyodbc": + new_url = new_url.set(query="") + + if query_str: + new_url = new_url.update_query_string(query_str) + + try: + new_url.get_dialect() + except exc.NoSuchModuleError: + return None + else: + return new_url + + @create_db.for_db("mssql") def _mssql_create_db(cfg, eng, ident): with eng.connect().execution_options(isolation_level="AUTOCOMMIT") as conn: |