diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2021-03-25 00:25:46 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-03-25 00:25:46 +0000 |
| commit | 9d3e43333db23959bc2d83a1d5ba0364aa81b21a (patch) | |
| tree | e2f9beaf22e134d21e208e4d6a9ba7fb94e90ebd /lib/sqlalchemy/engine | |
| parent | 767e8828f629973c2d7ba1030b07aea0eacd6ac2 (diff) | |
| parent | 4476dca00786adef5da3bcf74699e0b217f8ffa6 (diff) | |
| download | sqlalchemy-9d3e43333db23959bc2d83a1d5ba0364aa81b21a.tar.gz | |
Merge "Repair pysqlcipher and use sqlcipher3"
Diffstat (limited to 'lib/sqlalchemy/engine')
| -rw-r--r-- | lib/sqlalchemy/engine/create.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/engine/interfaces.py | 71 |
2 files changed, 72 insertions, 1 deletions
diff --git a/lib/sqlalchemy/engine/create.py b/lib/sqlalchemy/engine/create.py index 789030f2b..682d0dd5d 100644 --- a/lib/sqlalchemy/engine/create.py +++ b/lib/sqlalchemy/engine/create.py @@ -646,7 +646,7 @@ def create_engine(url, **kwargs): engine = engineclass(pool, dialect, u, **engine_args) if _initialize: - do_on_connect = dialect.on_connect() + do_on_connect = dialect.on_connect_url(url) if do_on_connect: def on_connect(dbapi_connection, connection_record): diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 010abcc24..24e0e5b0d 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -746,6 +746,67 @@ class Dialect(object): """ + def on_connect_url(self, url): + """return a callable which sets up a newly created DBAPI connection. + + This method is a new hook that supersedes the + :meth:`_engine.Dialect.on_connect` method when implemented by a + dialect. When not implemented by a dialect, it invokes the + :meth:`_engine.Dialect.on_connect` method directly to maintain + compatibility with existing dialects. There is no deprecation + for :meth:`_engine.Dialect.on_connect` expected. + + The callable should accept a single argument "conn" which is the + DBAPI connection itself. The inner callable has no + return value. + + E.g.:: + + class MyDialect(default.DefaultDialect): + # ... + + def on_connect_url(self, url): + def do_on_connect(connection): + connection.execute("SET SPECIAL FLAGS etc") + + return do_on_connect + + This is used to set dialect-wide per-connection options such as + isolation modes, Unicode modes, etc. + + This method differs from :meth:`_engine.Dialect.on_connect` in that + it is passed the :class:`_engine.URL` object that's relevant to the + connect args. Normally the only way to get this is from the + :meth:`_engine.Dialect.on_connect` hook is to look on the + :class:`_engine.Engine` itself, however this URL object may have been + replaced by plugins. + + .. note:: + + The default implementation of + :meth:`_engine.Dialect.on_connect_url` is to invoke the + :meth:`_engine.Dialect.on_connect` method. Therefore if a dialect + implements this method, the :meth:`_engine.Dialect.on_connect` + method **will not be called** unless the overriding dialect calls + it directly from here. + + .. versionadded:: 1.4.3 added :meth:`_engine.Dialect.on_connect_url` + which normally calls into :meth:`_engine.Dialect.on_connect`. + + :param url: a :class:`_engine.URL` object representing the + :class:`_engine.URL` that was passed to the + :meth:`_engine.Dialect.create_connect_args` method. + + :return: a callable that accepts a single DBAPI connection as an + argument, or None. + + .. seealso:: + + :meth:`_engine.Dialect.on_connect` + + """ + return self.on_connect() + def on_connect(self): """return a callable which sets up a newly created DBAPI connection. @@ -776,6 +837,12 @@ class Dialect(object): for the first connection of a dialect. The on_connect hook is still called before the :meth:`_engine.Dialect.initialize` method however. + .. versionchanged:: 1.4.3 the on_connect hook is invoked from a new + method on_connect_url that passes the URL that was used to create + the connect args. Dialects can implement on_connect_url instead + of on_connect if they need the URL object that was used for the + connection in order to get additional context. + If None is returned, no event listener is generated. :return: a callable that accepts a single DBAPI connection as an @@ -786,6 +853,10 @@ class Dialect(object): :meth:`.Dialect.connect` - allows the DBAPI ``connect()`` sequence itself to be controlled. + :meth:`.Dialect.on_connect_url` - supersedes + :meth:`.Dialect.on_connect` to also receive the + :class:`_engine.URL` object in context. + """ return None |
