diff options
author | Federico Caselli <cfederico87@gmail.com> | 2020-03-14 14:02:44 +0100 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-03-21 17:03:45 -0400 |
commit | 9ec75882203b2c01aa1d362f939e21ebcd188e8d (patch) | |
tree | 343d9e368f12f839c2c737cc05d1f5e7bc615536 /lib/sqlalchemy/dialects/mssql/provision.py | |
parent | 376708f4a4958bf2559c14900c52aa6fc7fd05b3 (diff) | |
download | sqlalchemy-9ec75882203b2c01aa1d362f939e21ebcd188e8d.tar.gz |
Deprecate plain string in execute and introduce `exec_driver_sql`
Execution of literal sql string is deprecated in the
:meth:`.Connection.execute` and a warning is raised when used stating
that it will be coerced to :func:`.text` in a future release.
To execute a raw sql string the new connection method
:meth:`.Connection.exec_driver_sql` was added, that will retain the previous
behavior, passing the string to the DBAPI driver unchanged.
Usage of scalar or tuple positional parameters in :meth:`.Connection.execute`
is also deprecated.
Fixes: #4848
Fixes: #5178
Change-Id: I2830181054327996d594f7f0d59c157d477c3aa9
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/provision.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/provision.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/provision.py b/lib/sqlalchemy/dialects/mssql/provision.py index a10043db1..84b9e4194 100644 --- a/lib/sqlalchemy/dialects/mssql/provision.py +++ b/lib/sqlalchemy/dialects/mssql/provision.py @@ -15,16 +15,16 @@ def _mssql_update_db_opts(db_url, db_opts): @create_db.for_db("mssql") def _mssql_create_db(cfg, eng, ident): with eng.connect().execution_options(isolation_level="AUTOCOMMIT") as conn: - conn.execute("create database %s" % ident) - conn.execute( + conn.exec_driver_sql("create database %s" % ident) + conn.exec_driver_sql( "ALTER DATABASE %s SET ALLOW_SNAPSHOT_ISOLATION ON" % ident ) - conn.execute( + conn.exec_driver_sql( "ALTER DATABASE %s SET READ_COMMITTED_SNAPSHOT ON" % ident ) - conn.execute("use %s" % ident) - conn.execute("create schema test_schema") - conn.execute("create schema test_schema_2") + conn.exec_driver_sql("use %s" % ident) + conn.exec_driver_sql("create schema test_schema") + conn.exec_driver_sql("create schema test_schema_2") @drop_db.for_db("mssql") @@ -37,13 +37,13 @@ def _mssql_drop_ignore(conn, ident): try: # typically when this happens, we can't KILL the session anyway, # so let the cleanup process drop the DBs - # for row in conn.execute( + # for row in conn.exec_driver_sql( # "select session_id from sys.dm_exec_sessions " # "where database_id=db_id('%s')" % ident): # log.info("killing SQL server sesssion %s", row['session_id']) - # conn.execute("kill %s" % row['session_id']) + # conn.exec_driver_sql("kill %s" % row['session_id']) - conn.execute("drop database %s" % ident) + conn.exec_driver_sql("drop database %s" % ident) log.info("Reaped db: %s", ident) return True except exc.DatabaseError as err: @@ -59,7 +59,7 @@ def _reap_mssql_dbs(url, idents): log.info("identifiers in file: %s", ", ".join(idents)) - to_reap = conn.execute( + to_reap = conn.exec_driver_sql( "select d.name from sys.databases as d where name " "like 'TEST_%' and not exists (select session_id " "from sys.dm_exec_sessions " |