diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2021-11-25 18:22:59 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2021-11-25 18:22:59 +0000 |
commit | 8ddb3ef165d0c2d6d7167bb861bb349e68b5e8df (patch) | |
tree | 1f61463f9888eedbd156b35858af266135f7d6e7 /lib/sqlalchemy/engine/interfaces.py | |
parent | 3619f084bfb5208ae45686a0993d620b2711adf2 (diff) | |
parent | 939de240d31a5441ad7380738d410a976d4ecc3a (diff) | |
download | sqlalchemy-8ddb3ef165d0c2d6d7167bb861bb349e68b5e8df.tar.gz |
Merge "propose emulated setinputsizes embedded in the compiler" into main
Diffstat (limited to 'lib/sqlalchemy/engine/interfaces.py')
-rw-r--r-- | lib/sqlalchemy/engine/interfaces.py | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py index 6772a27bd..251d01c5e 100644 --- a/lib/sqlalchemy/engine/interfaces.py +++ b/lib/sqlalchemy/engine/interfaces.py @@ -7,10 +7,60 @@ """Define core interfaces used by the engine system.""" +from enum import Enum + from ..sql.compiler import Compiled # noqa from ..sql.compiler import TypeCompiler # noqa +class BindTyping(Enum): + """Define different methods of passing typing information for + bound parameters in a statement to the database driver. + + .. versionadded:: 2.0 + + """ + + NONE = 1 + """No steps are taken to pass typing information to the database driver. + + This is the default behavior for databases such as SQLite, MySQL / MariaDB, + SQL Server. + + """ + + SETINPUTSIZES = 2 + """Use the pep-249 setinputsizes method. + + This is only implemented for DBAPIs that support this method and for which + the SQLAlchemy dialect has the appropriate infrastructure for that + dialect set up. Current dialects include cx_Oracle as well as + optional support for SQL Server using pyodbc. + + When using setinputsizes, dialects also have a means of only using the + method for certain datatypes using include/exclude lists. + + When SETINPUTSIZES is used, the :meth:`.Dialect.do_set_input_sizes` method + is called for each statement executed which has bound parameters. + + """ + + RENDER_CASTS = 3 + """Render casts or other directives in the SQL string. + + This method is used for all PostgreSQL dialects, including asyncpg, + pg8000, psycopg, psycopg2. Dialects which implement this can choose + which kinds of datatypes are explicitly cast in SQL statements and which + aren't. + + When RENDER_CASTS is used, the compiler will invoke the + :meth:`.SQLCompiler.render_bind_cast` method for each + :class:`.BindParameter` object whose dialect-level type sets the + :attr:`.TypeEngine.render_bind_cast` attribute. + + """ + + class Dialect: """Define the behavior of a specific database and DB-API combination. @@ -156,6 +206,16 @@ class Dialect: """ + bind_typing = BindTyping.NONE + """define a means of passing typing information to the database and/or + driver for bound parameters. + + See :class:`.BindTyping` for values. + + ..versionadded:: 2.0 + + """ + def create_connect_args(self, url): """Build DB-API compatible connection arguments. @@ -587,7 +647,9 @@ class Dialect: def do_set_input_sizes(self, cursor, list_of_tuples, context): """invoke the cursor.setinputsizes() method with appropriate arguments - This hook is called if the dialect.use_inputsizes flag is set to True. + This hook is called if the :attr:`.Dialect.bind_typing` attribute is + set to the + :attr:`.BindTyping.SETINPUTSIZES` value. Parameter data is passed in a list of tuples (paramname, dbtype, sqltype), where ``paramname`` is the key of the parameter in the statement, ``dbtype`` is the DBAPI datatype and ``sqltype`` is the @@ -595,6 +657,12 @@ class Dialect: .. versionadded:: 1.4 + .. versionchanged:: 2.0 - setinputsizes mode is now enabled by + setting :attr:`.Dialect.bind_typing` to + :attr:`.BindTyping.SETINPUTSIZES`. Dialects which accept + a ``use_setinputsizes`` parameter should set this value + appropriately. + """ raise NotImplementedError() |