Core Internals¶
Some key internal constructs are listed here.
Object Name | Description |
---|---|
Represent a compiled SQL or DDL expression. |
|
Default implementation of Dialect |
|
Define the behavior of a specific database and DB-API combination. |
|
A messenger object for a Dialect that corresponds to a single execution. |
|
Handle quoting and case-folding of identifiers based on options. |
|
Default implementation of |
|
A |
- class sqlalchemy.engine.interfaces.Compiled(dialect, statement, bind=None, schema_translate_map=None, compile_kwargs={})¶
Represent a compiled SQL or DDL expression.
Members
__init__(), compile(), construct_params(), execute(), execution_options, params, scalar(), sql_compiler
The
__str__
method of theCompiled
object should produce the actual text of the statement.Compiled
objects are specific to their underlying database dialect, and also may or may not be specific to the columns referenced within a particular set of bind parameters. In no case should theCompiled
object be dependent on the actual values of those bind parameters, even though it may reference those values as defaults.-
method
sqlalchemy.engine.interfaces.Compiled.
__init__(dialect, statement, bind=None, schema_translate_map=None, compile_kwargs={})¶ Construct a new
Compiled
object.- Parameters:
dialect –
Dialect
to compile against.statement –
ClauseElement
to be compiled.bind – Optional Engine or Connection to compile this statement against.
schema_translate_map –
dictionary of schema names to be translated when forming the resultant SQL
New in version 1.1.
See also
compile_kwargs – additional kwargs that will be passed to the initial call to
Compiled.process()
.
-
method
sqlalchemy.engine.interfaces.Compiled.
compile()¶ Produce the internal string representation of this element.
Deprecated since version 0.7: The
Compiled.compile()
method is deprecated and will be removed in a future release. TheCompiled
object now runs its compilation within the constructor, and this method does nothing.
-
method
sqlalchemy.engine.interfaces.Compiled.
construct_params(params=None)¶ Return the bind params for this compiled object.
- Parameters:
params – a dict of string/object pairs whose values will override bind values compiled in to the statement.
-
method
sqlalchemy.engine.interfaces.Compiled.
execute(*multiparams, **params)¶ Execute this compiled object.
-
attribute
sqlalchemy.engine.interfaces.Compiled.
execution_options = {}¶ Execution options propagated from the statement. In some cases, sub-elements of the statement can modify these.
-
attribute
sqlalchemy.engine.interfaces.Compiled.
params¶ Return the bind params for this compiled object.
-
method
sqlalchemy.engine.interfaces.Compiled.
scalar(*multiparams, **params)¶ Execute this compiled object and return the result’s scalar value.
-
attribute
sqlalchemy.engine.interfaces.Compiled.
sql_compiler¶ Return a Compiled that is capable of processing SQL expressions.
If this compiler is one, it would likely just return ‘self’.
-
method
- class sqlalchemy.sql.compiler.DDLCompiler(dialect, statement, bind=None, schema_translate_map=None, compile_kwargs={})¶
Members
__init__(), compile(), construct_params(), define_constraint_remote_table(), execute(), execution_options, params, scalar(), sql_compiler
Class signature
class
sqlalchemy.sql.compiler.DDLCompiler
(sqlalchemy.sql.compiler.Compiled
)-
method
sqlalchemy.sql.compiler.DDLCompiler.
__init__(dialect, statement, bind=None, schema_translate_map=None, compile_kwargs={})¶ inherited from the
sqlalchemy.sql.compiler.Compiled.__init__
method ofCompiled
Construct a new
Compiled
object.- Parameters:
dialect –
Dialect
to compile against.statement –
ClauseElement
to be compiled.bind – Optional Engine or Connection to compile this statement against.
schema_translate_map –
dictionary of schema names to be translated when forming the resultant SQL
New in version 1.1.
See also
compile_kwargs – additional kwargs that will be passed to the initial call to
Compiled.process()
.
-
method
sqlalchemy.sql.compiler.DDLCompiler.
compile()¶ inherited from the
Compiled.compile()
method ofCompiled
Produce the internal string representation of this element.
Deprecated since version 0.7: The
Compiled.compile()
method is deprecated and will be removed in a future release. TheCompiled
object now runs its compilation within the constructor, and this method does nothing.
-
method
sqlalchemy.sql.compiler.DDLCompiler.
construct_params(params=None)¶ Return the bind params for this compiled object.
- Parameters:
params – a dict of string/object pairs whose values will override bind values compiled in to the statement.
-
method
sqlalchemy.sql.compiler.DDLCompiler.
define_constraint_remote_table(constraint, table, preparer)¶ Format the remote table clause of a CREATE CONSTRAINT clause.
-
method
sqlalchemy.sql.compiler.DDLCompiler.
execute(*multiparams, **params)¶ inherited from the
Compiled.execute()
method ofCompiled
Execute this compiled object.
-
attribute
sqlalchemy.sql.compiler.DDLCompiler.
execution_options = {}¶ inherited from the
Compiled.execution_options
attribute ofCompiled
Execution options propagated from the statement. In some cases, sub-elements of the statement can modify these.
-
attribute
sqlalchemy.sql.compiler.DDLCompiler.
params¶ inherited from the
Compiled.params
attribute ofCompiled
Return the bind params for this compiled object.
-
method
sqlalchemy.sql.compiler.DDLCompiler.
scalar(*multiparams, **params)¶ inherited from the
Compiled.scalar()
method ofCompiled
Execute this compiled object and return the result’s scalar value.
-
attribute
sqlalchemy.sql.compiler.DDLCompiler.
sql_compiler¶
-
method
- class sqlalchemy.engine.default.DefaultDialect(convert_unicode=False, encoding='utf-8', paramstyle=None, dbapi=None, implicit_returning=None, supports_right_nested_joins=None, case_sensitive=True, supports_native_boolean=None, empty_in_strategy='static', max_identifier_length=None, label_length=None, **kwargs)¶
Default implementation of Dialect
Members
connect(), construct_arguments, create_connect_args(), create_xid(), dbapi_exception_translation_map, ddl_compiler, denormalize_name(), do_begin(), do_begin_twophase(), do_close(), do_commit(), do_commit_twophase(), do_execute(), do_execute_no_params(), do_executemany(), do_prepare_twophase(), do_recover_twophase(), do_release_savepoint(), do_rollback(), do_rollback_to_savepoint(), do_rollback_twophase(), do_savepoint(), engine_created(), execute_sequence_format, execution_ctx_cls, get_check_constraints(), get_columns(), get_default_isolation_level(), get_dialect_cls(), get_foreign_keys(), get_indexes(), get_isolation_level(), get_pk_constraint(), get_primary_keys(), get_table_comment(), get_table_names(), get_temp_table_names(), get_temp_view_names(), get_unique_constraints(), get_view_definition(), get_view_names(), has_sequence(), has_table(), initialize(), is_disconnect(), load_provisioning(), normalize_name(), on_connect(), preparer, reflecttable(), reset_isolation_level(), set_isolation_level(), statement_compiler, supports_sane_rowcount_returning, type_compiler, type_descriptor()
Class signature
class
sqlalchemy.engine.default.DefaultDialect
(sqlalchemy.engine.interfaces.Dialect
)-
method
sqlalchemy.engine.default.DefaultDialect.
connect(*cargs, **cparams)¶ Establish a connection using this dialect’s DBAPI.
The default implementation of this method is:
def connect(self, *cargs, **cparams): return self.dbapi.connect(*cargs, **cparams)
The
*cargs, **cparams
parameters are generated directly from this dialect’sDialect.create_connect_args()
method.This method may be used for dialects that need to perform programmatic per-connection steps when a new connection is procured from the DBAPI.
- Parameters:
*cargs – positional parameters returned from the
Dialect.create_connect_args()
method**cparams – keyword parameters returned from the
Dialect.create_connect_args()
method.
- Returns:
a DBAPI connection, typically from the PEP 249 module level
.connect()
function.
-
attribute
sqlalchemy.engine.default.DefaultDialect.
construct_arguments = None¶ Optional set of argument specifiers for various SQLAlchemy constructs, typically schema items.
To implement, establish as a series of tuples, as in:
construct_arguments = [ (schema.Index, { "using": False, "where": None, "ops": None }) ]
If the above construct is established on the PostgreSQL dialect, the
Index
construct will now accept the keyword argumentspostgresql_using
,postgresql_where
, nadpostgresql_ops
. Any other argument specified to the constructor ofIndex
which is prefixed withpostgresql_
will raiseArgumentError
.A dialect which does not include a
construct_arguments
member will not participate in the argument validation system. For such a dialect, any argument name is accepted by all participating constructs, within the namespace of arguments prefixed with that dialect name. The rationale here is so that third-party dialects that haven’t yet implemented this feature continue to function in the old way.New in version 0.9.2.
See also
DialectKWArgs
- implementing base class which consumesDefaultDialect.construct_arguments
-
method
sqlalchemy.engine.default.DefaultDialect.
create_connect_args(url)¶ Build DB-API compatible connection arguments.
Given a
URL
object, returns a tuple consisting of a(*args, **kwargs)
suitable to send directly to the dbapi’s connect function. The arguments are sent to theDialect.connect()
method which then runs the DBAPI-levelconnect()
function.The method typically makes use of the
URL.translate_connect_args()
method in order to generate a dictionary of options.The default implementation is:
def create_connect_args(self, url): opts = url.translate_connect_args() opts.update(url.query) return [[], opts]
- Parameters:
url – a
URL
object- Returns:
a tuple of
(*args, **kwargs)
which will be passed to theDialect.connect()
method.
See also
-
method
sqlalchemy.engine.default.DefaultDialect.
create_xid()¶ Create a random two-phase transaction ID.
This id will be passed to do_begin_twophase(), do_rollback_twophase(), do_commit_twophase(). Its format is unspecified.
-
attribute
sqlalchemy.engine.default.DefaultDialect.
dbapi_exception_translation_map = {}¶ mapping used in the extremely unusual case that a DBAPI’s published exceptions don’t actually have the __name__ that they are linked towards.
New in version 1.0.5.
-
attribute
sqlalchemy.engine.default.DefaultDialect.
ddl_compiler¶ alias of
DDLCompiler
-
method
sqlalchemy.engine.default.DefaultDialect.
denormalize_name(name)¶ convert the given name to a case insensitive identifier for the backend if it is an all-lowercase name.
This method is only used if the dialect defines requires_name_normalize=True.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_begin(dbapi_connection)¶ Provide an implementation of
connection.begin()
, given a DB-API connection.The DBAPI has no dedicated “begin” method and it is expected that transactions are implicit. This hook is provided for those DBAPIs that might need additional help in this area.
Note that
Dialect.do_begin()
is not called unless aTransaction
object is in use. TheDialect.do_autocommit()
hook is provided for DBAPIs that need some extra commands emitted after a commit in order to enter the next transaction, when the SQLAlchemyConnection
is used in its default “autocommit” mode.- Parameters:
dbapi_connection – a DBAPI connection, typically proxied within a
ConnectionFairy
.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_begin_twophase(connection, xid)¶ inherited from the
Dialect.do_begin_twophase()
method ofDialect
Begin a two phase transaction on the given connection.
- Parameters:
connection – a
Connection
.xid – xid
-
method
sqlalchemy.engine.default.DefaultDialect.
do_close(dbapi_connection)¶ Provide an implementation of
connection.close()
, given a DBAPI connection.This hook is called by the
Pool
when a connection has been detached from the pool, or is being returned beyond the normal capacity of the pool.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_commit(dbapi_connection)¶ Provide an implementation of
connection.commit()
, given a DB-API connection.- Parameters:
dbapi_connection – a DBAPI connection, typically proxied within a
ConnectionFairy
.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_commit_twophase(connection, xid, is_prepared=True, recover=False)¶ inherited from the
Dialect.do_commit_twophase()
method ofDialect
Commit a two phase transaction on the given connection.
- Parameters:
connection – a
Connection
.xid – xid
is_prepared – whether or not
TwoPhaseTransaction.prepare()
was called.recover – if the recover flag was passed.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_execute(cursor, statement, parameters, context=None)¶ Provide an implementation of
cursor.execute(statement, parameters)
.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_execute_no_params(cursor, statement, context=None)¶ Provide an implementation of
cursor.execute(statement)
.The parameter collection should not be sent.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_executemany(cursor, statement, parameters, context=None)¶ Provide an implementation of
cursor.executemany(statement, parameters)
.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_prepare_twophase(connection, xid)¶ inherited from the
Dialect.do_prepare_twophase()
method ofDialect
Prepare a two phase transaction on the given connection.
- Parameters:
connection – a
Connection
.xid – xid
-
method
sqlalchemy.engine.default.DefaultDialect.
do_recover_twophase(connection)¶ inherited from the
Dialect.do_recover_twophase()
method ofDialect
Recover list of uncommitted prepared two phase transaction identifiers on the given connection.
- Parameters:
connection – a
Connection
.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_release_savepoint(connection, name)¶ Release the named savepoint on a connection.
- Parameters:
connection – a
Connection
.name – savepoint name.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_rollback(dbapi_connection)¶ Provide an implementation of
connection.rollback()
, given a DB-API connection.- Parameters:
dbapi_connection – a DBAPI connection, typically proxied within a
ConnectionFairy
.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_rollback_to_savepoint(connection, name)¶ Rollback a connection to the named savepoint.
- Parameters:
connection – a
Connection
.name – savepoint name.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_rollback_twophase(connection, xid, is_prepared=True, recover=False)¶ inherited from the
Dialect.do_rollback_twophase()
method ofDialect
Rollback a two phase transaction on the given connection.
- Parameters:
connection – a
Connection
.xid – xid
is_prepared – whether or not
TwoPhaseTransaction.prepare()
was called.recover – if the recover flag was passed.
-
method
sqlalchemy.engine.default.DefaultDialect.
do_savepoint(connection, name)¶ Create a savepoint with the given name.
- Parameters:
connection – a
Connection
.name – savepoint name.
-
classmethod
sqlalchemy.engine.default.DefaultDialect.
engine_created(engine)¶ inherited from the
Dialect.engine_created()
method ofDialect
A convenience hook called before returning the final
Engine
.If the dialect returned a different class from the
get_dialect_cls()
method, then the hook is called on both classes, first on the dialect class returned by theget_dialect_cls()
method and then on the class on which the method was called.The hook should be used by dialects and/or wrappers to apply special events to the engine or its components. In particular, it allows a dialect-wrapping class to apply dialect-level events.
New in version 1.0.3.
-
attribute
sqlalchemy.engine.default.DefaultDialect.
execute_sequence_format¶ alias of
tuple
-
attribute
sqlalchemy.engine.default.DefaultDialect.
execution_ctx_cls¶ alias of
DefaultExecutionContext
-
method
sqlalchemy.engine.default.DefaultDialect.
get_check_constraints(connection, table_name, schema=None, **kw)¶ inherited from the
Dialect.get_check_constraints()
method ofDialect
Return information about check constraints in table_name.
Given a string table_name and an optional string schema, return check constraint information as a list of dicts with these keys:
name
- the check constraint’s namesqltext
- the check constraint’s SQL expression**kw
- other options passed to the dialect’s get_check_constraints() method.
New in version 1.1.0.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_columns(connection, table_name, schema=None, **kw)¶ inherited from the
Dialect.get_columns()
method ofDialect
Return information about columns in table_name.
Given a
Connection
, a string table_name, and an optional string schema, return column information as a list of dictionaries with these keys:name
- the column’s nametype
- [sqlalchemy.types#TypeEngine]nullable
- booleandefault
- the column’s default valueautoincrement
- booleansequence
- a dictionary of the form {‘name’ : str, ‘start’ :int, ‘increment’: int, ‘minvalue’: int, ‘maxvalue’: int, ‘nominvalue’: bool, ‘nomaxvalue’: bool, ‘cycle’: bool, ‘cache’: int, ‘order’: bool}
Additional column attributes may be present.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_default_isolation_level(dbapi_conn)¶ Given a DBAPI connection, return its isolation level, or a default isolation level if one cannot be retrieved.
May be overridden by subclasses in order to provide a “fallback” isolation level for databases that cannot reliably retrieve the actual isolation level.
By default, calls the
Interfaces.get_isolation_level()
method, propagating any exceptions raised.New in version 1.3.22.
-
classmethod
sqlalchemy.engine.default.DefaultDialect.
get_dialect_cls(url)¶ inherited from the
Dialect.get_dialect_cls()
method ofDialect
Given a URL, return the
Dialect
that will be used.This is a hook that allows an external plugin to provide functionality around an existing dialect, by allowing the plugin to be loaded from the url based on an entrypoint, and then the plugin returns the actual dialect to be used.
By default this just returns the cls.
New in version 1.0.3.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_foreign_keys(connection, table_name, schema=None, **kw)¶ inherited from the
Dialect.get_foreign_keys()
method ofDialect
Return information about foreign_keys in table_name.
Given a
Connection
, a string table_name, and an optional string schema, return foreign key information as a list of dicts with these keys:name
- the constraint’s nameconstrained_columns
- a list of column names that make up the foreign keyreferred_schema
- the name of the referred schemareferred_table
- the name of the referred tablereferred_columns
- a list of column names in the referred table that correspond to constrained_columns
-
method
sqlalchemy.engine.default.DefaultDialect.
get_indexes(connection, table_name, schema=None, **kw)¶ inherited from the
Dialect.get_indexes()
method ofDialect
Return information about indexes in table_name.
Given a
Connection
, a string table_name and an optional string schema, return index information as a list of dictionaries with these keys:name
- the index’s namecolumn_names
- list of column names in orderunique
- boolean
-
method
sqlalchemy.engine.default.DefaultDialect.
get_isolation_level(dbapi_conn)¶ inherited from the
Dialect.get_isolation_level()
method ofDialect
Given a DBAPI connection, return its isolation level.
When working with a
Connection
object, the corresponding DBAPI connection may be procured using theConnection.connection
accessor.Note that this is a dialect-level method which is used as part of the implementation of the
Connection
andEngine
isolation level facilities; these APIs should be preferred for most typical use cases.See also
Connection.get_isolation_level()
- view current levelConnection.default_isolation_level
- view default levelConnection.execution_options.isolation_level
- set perConnection
isolation levelcreate_engine.isolation_level
- set perEngine
isolation level
-
method
sqlalchemy.engine.default.DefaultDialect.
get_pk_constraint(conn, table_name, schema=None, **kw)¶ Compatibility method, adapts the result of get_primary_keys() for those dialects which don’t implement get_pk_constraint().
-
method
sqlalchemy.engine.default.DefaultDialect.
get_primary_keys(connection, table_name, schema=None, **kw)¶ inherited from the
Dialect.get_primary_keys()
method ofDialect
Return information about primary keys in table_name.
Deprecated since version 0.8: The
Dialect.get_primary_keys()
method is deprecated and will be removed in a future release. Please refer to theDialect.get_pk_constraint()
method.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_table_comment(connection, table_name, schema=None, **kw)¶ inherited from the
Dialect.get_table_comment()
method ofDialect
Return the “comment” for the table identified by table_name.
Given a string table_name and an optional string schema, return table comment information as a dictionary with this key:
- text
text of the comment
Raises
NotImplementedError
for dialects that don’t support comments.New in version 1.2.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_table_names(connection, schema=None, **kw)¶ inherited from the
Dialect.get_table_names()
method ofDialect
Return a list of table names for schema.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_temp_table_names(connection, schema=None, **kw)¶ inherited from the
Dialect.get_temp_table_names()
method ofDialect
Return a list of temporary table names on the given connection, if supported by the underlying backend.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_temp_view_names(connection, schema=None, **kw)¶ inherited from the
Dialect.get_temp_view_names()
method ofDialect
Return a list of temporary view names on the given connection, if supported by the underlying backend.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_unique_constraints(connection, table_name, schema=None, **kw)¶ inherited from the
Dialect.get_unique_constraints()
method ofDialect
Return information about unique constraints in table_name.
Given a string table_name and an optional string schema, return unique constraint information as a list of dicts with these keys:
name
- the unique constraint’s namecolumn_names
- list of column names in order**kw
- other options passed to the dialect’s get_unique_constraints() method.
New in version 0.9.0.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_view_definition(connection, view_name, schema=None, **kw)¶ inherited from the
Dialect.get_view_definition()
method ofDialect
Return view definition.
Given a
Connection
, a string view_name, and an optional string schema, return the view definition.
-
method
sqlalchemy.engine.default.DefaultDialect.
get_view_names(connection, schema=None, **kw)¶ inherited from the
Dialect.get_view_names()
method ofDialect
Return a list of all view names available in the database.
- Parameters:
schema – Optional, retrieve names from a non-default schema.
-
method
sqlalchemy.engine.default.DefaultDialect.
has_sequence(connection, sequence_name, schema=None)¶ inherited from the
Dialect.has_sequence()
method ofDialect
Check the existence of a particular sequence in the database.
Given a
Connection
object and a string sequence_name, return True if the given sequence exists in the database, False otherwise.
-
method
sqlalchemy.engine.default.DefaultDialect.
has_table(connection, table_name, schema=None)¶ inherited from the
Dialect.has_table()
method ofDialect
Check the existence of a particular table in the database.
Given a
Connection
object and a string table_name, return True if the given table (possibly within the specified schema) exists in the database, False otherwise.
-
method
sqlalchemy.engine.default.DefaultDialect.
initialize(connection)¶ Called during strategized creation of the dialect with a connection.
Allows dialects to configure options based on server version info or other properties.
The connection passed here is a SQLAlchemy Connection object, with full capabilities.
The initialize() method of the base dialect should be called via super().
-
method
sqlalchemy.engine.default.DefaultDialect.
is_disconnect(e, connection, cursor)¶ Return True if the given DB-API error indicates an invalid connection.
-
classmethod
sqlalchemy.engine.default.DefaultDialect.
load_provisioning()¶ Set up the provision.py module for this dialect.
For dialects that include a provision.py module that sets up provisioning followers, this method should initiate that process.
A typical implementation would be:
@classmethod def load_provisioning(cls): __import__("mydialect.provision")
The default method assumes a module named
provision.py
inside the owning package of the current dialect, based on the__module__
attribute:@classmethod def load_provisioning(cls): package = ".".join(cls.__module__.split(".")[0:-1]) try: __import__(package + ".provision") except ImportError: pass
New in version 1.3.14.
-
method
sqlalchemy.engine.default.DefaultDialect.
normalize_name(name)¶ convert the given name to lowercase if it is detected as case insensitive.
This method is only used if the dialect defines requires_name_normalize=True.
-
method
sqlalchemy.engine.default.DefaultDialect.
on_connect()¶ Return a callable which sets up a newly created DBAPI connection.
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(self): 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.
The “do_on_connect” callable is invoked by using the
PoolEvents.first_connect()
andPoolEvents.connect()
event hooks, then unwrapping the DBAPI connection and passing it into the callable. The reason it is invoked for both events is so that any dialect-level initialization that occurs upon first connection, which also makes use of thePoolEvents.first_connect()
method, will proceed after this hook has been called. This currently means the hook is in fact called twice for the very first connection in which a dialect creates; and once per connection afterwards.If None is returned, no event listener is generated.
- Returns:
a callable that accepts a single DBAPI connection as an argument, or None.
See also
Dialect.connect()
- allows the DBAPIconnect()
sequence itself to be controlled.
-
attribute
sqlalchemy.engine.default.DefaultDialect.
preparer¶ alias of
IdentifierPreparer
-
method
sqlalchemy.engine.default.DefaultDialect.
reflecttable(connection, table, include_columns, exclude_columns, resolve_fks, **opts)¶ Load table description from the database.
Given a
Connection
and aTable
object, reflect its columns and properties from the database.The implementation of this method is provided by
DefaultDialect.reflecttable()
, which makes use ofInspector
to retrieve column information.Dialects should not seek to implement this method, and should instead implement individual schema inspection operations such as
Dialect.get_columns()
,Dialect.get_pk_constraint()
, etc.
-
method
sqlalchemy.engine.default.DefaultDialect.
reset_isolation_level(dbapi_conn)¶ Given a DBAPI connection, revert its isolation to the default.
Note that this is a dialect-level method which is used as part of the implementation of the
Connection
andEngine
isolation level facilities; these APIs should be preferred for most typical use cases.See also
Connection.get_isolation_level()
- view current levelConnection.default_isolation_level
- view default levelConnection.execution_options.isolation_level
- set perConnection
isolation levelcreate_engine.isolation_level
- set perEngine
isolation level
-
method
sqlalchemy.engine.default.DefaultDialect.
set_isolation_level(dbapi_conn, level)¶ inherited from the
Dialect.set_isolation_level()
method ofDialect
Given a DBAPI connection, set its isolation level.
Note that this is a dialect-level method which is used as part of the implementation of the
Connection
andEngine
isolation level facilities; these APIs should be preferred for most typical use cases.See also
Connection.get_isolation_level()
- view current levelConnection.default_isolation_level
- view default levelConnection.execution_options.isolation_level
- set perConnection
isolation levelcreate_engine.isolation_level
- set perEngine
isolation level
-
attribute
sqlalchemy.engine.default.DefaultDialect.
statement_compiler¶ alias of
SQLCompiler
-
attribute
sqlalchemy.engine.default.DefaultDialect.
supports_sane_rowcount_returning¶ True if this dialect supports sane rowcount even if RETURNING is in use.
For dialects that don’t support RETURNING, this is synonymous with
supports_sane_rowcount
.
-
attribute
sqlalchemy.engine.default.DefaultDialect.
type_compiler¶ alias of
GenericTypeCompiler
-
method
sqlalchemy.engine.default.DefaultDialect.
type_descriptor(typeobj)¶ Provide a database-specific
TypeEngine
object, given the generic object which comes from the types module.This method looks for a dictionary called
colspecs
as a class or instance-level variable, and passes on toadapt_type()
.
-
method
- class sqlalchemy.engine.interfaces.Dialect¶
Define the behavior of a specific database and DB-API combination.
Any aspect of metadata definition, SQL query generation, execution, result-set handling, or anything else which varies between databases is defined under the general category of the Dialect. The Dialect acts as a factory for other database-specific object implementations including ExecutionContext, Compiled, DefaultGenerator, and TypeEngine.
Note
Third party dialects should not subclass
Dialect
directly. Instead, subclassDefaultDialect
or descendant class.All dialects include the following attributes. There are many other attributes that may be supported as well:
Members
connect(), create_connect_args(), create_xid(), denormalize_name(), do_begin(), do_begin_twophase(), do_close(), do_commit(), do_commit_twophase(), do_execute(), do_execute_no_params(), do_executemany(), do_prepare_twophase(), do_recover_twophase(), do_release_savepoint(), do_rollback(), do_rollback_to_savepoint(), do_rollback_twophase(), do_savepoint(), engine_created(), get_check_constraints(), get_columns(), get_default_isolation_level(), get_dialect_cls(), get_foreign_keys(), get_indexes(), get_isolation_level(), get_pk_constraint(), get_primary_keys(), get_table_comment(), get_table_names(), get_temp_table_names(), get_temp_view_names(), get_unique_constraints(), get_view_definition(), get_view_names(), has_sequence(), has_table(), initialize(), is_disconnect(), load_provisioning(), normalize_name(), on_connect(), reflecttable(), reset_isolation_level(), set_isolation_level(), type_descriptor()
name
identifying name for the dialect from a DBAPI-neutral point of view (i.e. ‘sqlite’)
driver
identifying name for the dialect’s DBAPI
positional
True if the paramstyle for this Dialect is positional.
paramstyle
the paramstyle to be used (some DB-APIs support multiple paramstyles).
encoding
type of encoding to use for unicode, usually defaults to ‘utf-8’.
statement_compiler
a
Compiled
class used to compile SQL statementsddl_compiler
a
Compiled
class used to compile DDL statementsserver_version_info
a tuple containing a version number for the DB backend in use. This value is only available for supporting dialects, and is typically populated during the initial connection to the database.
default_schema_name
the name of the default schema. This value is only available for supporting dialects, and is typically populated during the initial connection to the database.
execution_ctx_cls
a
ExecutionContext
class used to handle statement executionexecute_sequence_format
either the ‘tuple’ or ‘list’ type, depending on what cursor.execute() accepts for the second argument (they vary).
preparer
a
IdentifierPreparer
class used to quote identifiers.supports_alter
True
if the database supportsALTER TABLE
- used only for generating foreign key constraints in certain circumstancesmax_identifier_length
The maximum length of identifier names.
supports_sane_rowcount
Indicate whether the dialect properly implements rowcount for
UPDATE
andDELETE
statements.supports_sane_multi_rowcount
Indicate whether the dialect properly implements rowcount for
UPDATE
andDELETE
statements when executed via executemany.preexecute_autoincrement_sequences
True if ‘implicit’ primary key functions must be executed separately in order to get their value. This is currently oriented towards PostgreSQL.
implicit_returning
use RETURNING or equivalent during INSERT execution in order to load newly generated primary keys and other column defaults in one execution, which are then available via inserted_primary_key. If an insert statement has returning() specified explicitly, the “implicit” functionality is not used and inserted_primary_key will not be available.
colspecs
A dictionary of TypeEngine classes from sqlalchemy.types mapped to subclasses that are specific to the dialect class. This dictionary is class-level only and is not accessed from the dialect instance itself.
supports_default_values
Indicates if the construct
INSERT INTO tablename DEFAULT VALUES
is supportedsupports_sequences
Indicates if the dialect supports CREATE SEQUENCE or similar.
sequences_optional
If True, indicates if the “optional” flag on the Sequence() construct should signal to not generate a CREATE SEQUENCE. Applies only to dialects that support sequences. Currently used only to allow PostgreSQL SERIAL to be used on a column that specifies Sequence() for usage on other backends.
supports_native_enum
Indicates if the dialect supports a native ENUM construct. This will prevent types.Enum from generating a CHECK constraint when that type is used.
supports_native_boolean
Indicates if the dialect supports a native boolean construct. This will prevent types.Boolean from generating a CHECK constraint when that type is used.
dbapi_exception_translation_map
A dictionary of names that will contain as values the names of pep-249 exceptions (“IntegrityError”, “OperationalError”, etc) keyed to alternate class names, to support the case where a DBAPI has exception classes that aren’t named as they are referred to (e.g. IntegrityError = MyException). In the vast majority of cases this dictionary is empty.
New in version 1.0.5.
-
method
sqlalchemy.engine.interfaces.Dialect.
connect(*cargs, **cparams)¶ Establish a connection using this dialect’s DBAPI.
The default implementation of this method is:
def connect(self, *cargs, **cparams): return self.dbapi.connect(*cargs, **cparams)
The
*cargs, **cparams
parameters are generated directly from this dialect’sDialect.create_connect_args()
method.This method may be used for dialects that need to perform programmatic per-connection steps when a new connection is procured from the DBAPI.
- Parameters:
*cargs – positional parameters returned from the
Dialect.create_connect_args()
method**cparams – keyword parameters returned from the
Dialect.create_connect_args()
method.
- Returns:
a DBAPI connection, typically from the PEP 249 module level
.connect()
function.
-
method
sqlalchemy.engine.interfaces.Dialect.
create_connect_args(url)¶ Build DB-API compatible connection arguments.
Given a
URL
object, returns a tuple consisting of a(*args, **kwargs)
suitable to send directly to the dbapi’s connect function. The arguments are sent to theDialect.connect()
method which then runs the DBAPI-levelconnect()
function.The method typically makes use of the
URL.translate_connect_args()
method in order to generate a dictionary of options.The default implementation is:
def create_connect_args(self, url): opts = url.translate_connect_args() opts.update(url.query) return [[], opts]
- Parameters:
url – a
URL
object- Returns:
a tuple of
(*args, **kwargs)
which will be passed to theDialect.connect()
method.
See also
-
method
sqlalchemy.engine.interfaces.Dialect.
create_xid()¶ Create a two-phase transaction ID.
This id will be passed to do_begin_twophase(), do_rollback_twophase(), do_commit_twophase(). Its format is unspecified.
-
method
sqlalchemy.engine.interfaces.Dialect.
denormalize_name(name)¶ convert the given name to a case insensitive identifier for the backend if it is an all-lowercase name.
This method is only used if the dialect defines requires_name_normalize=True.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_begin(dbapi_connection)¶ Provide an implementation of
connection.begin()
, given a DB-API connection.The DBAPI has no dedicated “begin” method and it is expected that transactions are implicit. This hook is provided for those DBAPIs that might need additional help in this area.
Note that
Dialect.do_begin()
is not called unless aTransaction
object is in use. TheDialect.do_autocommit()
hook is provided for DBAPIs that need some extra commands emitted after a commit in order to enter the next transaction, when the SQLAlchemyConnection
is used in its default “autocommit” mode.- Parameters:
dbapi_connection – a DBAPI connection, typically proxied within a
ConnectionFairy
.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_begin_twophase(connection, xid)¶ Begin a two phase transaction on the given connection.
- Parameters:
connection – a
Connection
.xid – xid
-
method
sqlalchemy.engine.interfaces.Dialect.
do_close(dbapi_connection)¶ Provide an implementation of
connection.close()
, given a DBAPI connection.This hook is called by the
Pool
when a connection has been detached from the pool, or is being returned beyond the normal capacity of the pool.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_commit(dbapi_connection)¶ Provide an implementation of
connection.commit()
, given a DB-API connection.- Parameters:
dbapi_connection – a DBAPI connection, typically proxied within a
ConnectionFairy
.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_commit_twophase(connection, xid, is_prepared=True, recover=False)¶ Commit a two phase transaction on the given connection.
- Parameters:
connection – a
Connection
.xid – xid
is_prepared – whether or not
TwoPhaseTransaction.prepare()
was called.recover – if the recover flag was passed.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_execute(cursor, statement, parameters, context=None)¶ Provide an implementation of
cursor.execute(statement, parameters)
.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_execute_no_params(cursor, statement, parameters, context=None)¶ Provide an implementation of
cursor.execute(statement)
.The parameter collection should not be sent.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_executemany(cursor, statement, parameters, context=None)¶ Provide an implementation of
cursor.executemany(statement, parameters)
.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_prepare_twophase(connection, xid)¶ Prepare a two phase transaction on the given connection.
- Parameters:
connection – a
Connection
.xid – xid
-
method
sqlalchemy.engine.interfaces.Dialect.
do_recover_twophase(connection)¶ Recover list of uncommitted prepared two phase transaction identifiers on the given connection.
- Parameters:
connection – a
Connection
.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_release_savepoint(connection, name)¶ Release the named savepoint on a connection.
- Parameters:
connection – a
Connection
.name – savepoint name.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_rollback(dbapi_connection)¶ Provide an implementation of
connection.rollback()
, given a DB-API connection.- Parameters:
dbapi_connection – a DBAPI connection, typically proxied within a
ConnectionFairy
.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_rollback_to_savepoint(connection, name)¶ Rollback a connection to the named savepoint.
- Parameters:
connection – a
Connection
.name – savepoint name.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_rollback_twophase(connection, xid, is_prepared=True, recover=False)¶ Rollback a two phase transaction on the given connection.
- Parameters:
connection – a
Connection
.xid – xid
is_prepared – whether or not
TwoPhaseTransaction.prepare()
was called.recover – if the recover flag was passed.
-
method
sqlalchemy.engine.interfaces.Dialect.
do_savepoint(connection, name)¶ Create a savepoint with the given name.
- Parameters:
connection – a
Connection
.name – savepoint name.
-
classmethod
sqlalchemy.engine.interfaces.Dialect.
engine_created(engine)¶ A convenience hook called before returning the final
Engine
.If the dialect returned a different class from the
get_dialect_cls()
method, then the hook is called on both classes, first on the dialect class returned by theget_dialect_cls()
method and then on the class on which the method was called.The hook should be used by dialects and/or wrappers to apply special events to the engine or its components. In particular, it allows a dialect-wrapping class to apply dialect-level events.
New in version 1.0.3.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_check_constraints(connection, table_name, schema=None, **kw)¶ Return information about check constraints in table_name.
Given a string table_name and an optional string schema, return check constraint information as a list of dicts with these keys:
name
- the check constraint’s namesqltext
- the check constraint’s SQL expression**kw
- other options passed to the dialect’s get_check_constraints() method.
New in version 1.1.0.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_columns(connection, table_name, schema=None, **kw)¶ Return information about columns in table_name.
Given a
Connection
, a string table_name, and an optional string schema, return column information as a list of dictionaries with these keys:name
- the column’s nametype
- [sqlalchemy.types#TypeEngine]nullable
- booleandefault
- the column’s default valueautoincrement
- booleansequence
- a dictionary of the form {‘name’ : str, ‘start’ :int, ‘increment’: int, ‘minvalue’: int, ‘maxvalue’: int, ‘nominvalue’: bool, ‘nomaxvalue’: bool, ‘cycle’: bool, ‘cache’: int, ‘order’: bool}
Additional column attributes may be present.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_default_isolation_level(dbapi_conn)¶ Given a DBAPI connection, return its isolation level, or a default isolation level if one cannot be retrieved.
This method may only raise NotImplementedError and must not raise any other exception, as it is used implicitly upon first connect.
The method must return a value for a dialect that supports isolation level settings, as this level is what will be reverted towards when a per-connection isolation level change is made.
The method defaults to using the
Dialect.get_isolation_level()
method unless overridden by a dialect.New in version 1.3.22.
-
classmethod
sqlalchemy.engine.interfaces.Dialect.
get_dialect_cls(url)¶ Given a URL, return the
Dialect
that will be used.This is a hook that allows an external plugin to provide functionality around an existing dialect, by allowing the plugin to be loaded from the url based on an entrypoint, and then the plugin returns the actual dialect to be used.
By default this just returns the cls.
New in version 1.0.3.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_foreign_keys(connection, table_name, schema=None, **kw)¶ Return information about foreign_keys in table_name.
Given a
Connection
, a string table_name, and an optional string schema, return foreign key information as a list of dicts with these keys:name
- the constraint’s nameconstrained_columns
- a list of column names that make up the foreign keyreferred_schema
- the name of the referred schemareferred_table
- the name of the referred tablereferred_columns
- a list of column names in the referred table that correspond to constrained_columns
-
method
sqlalchemy.engine.interfaces.Dialect.
get_indexes(connection, table_name, schema=None, **kw)¶ Return information about indexes in table_name.
Given a
Connection
, a string table_name and an optional string schema, return index information as a list of dictionaries with these keys:name
- the index’s namecolumn_names
- list of column names in orderunique
- boolean
-
method
sqlalchemy.engine.interfaces.Dialect.
get_isolation_level(dbapi_conn)¶ Given a DBAPI connection, return its isolation level.
When working with a
Connection
object, the corresponding DBAPI connection may be procured using theConnection.connection
accessor.Note that this is a dialect-level method which is used as part of the implementation of the
Connection
andEngine
isolation level facilities; these APIs should be preferred for most typical use cases.See also
Connection.get_isolation_level()
- view current levelConnection.default_isolation_level
- view default levelConnection.execution_options.isolation_level
- set perConnection
isolation levelcreate_engine.isolation_level
- set perEngine
isolation level
-
method
sqlalchemy.engine.interfaces.Dialect.
get_pk_constraint(connection, table_name, schema=None, **kw)¶ Return information about the primary key constraint on table_name`.
Given a
Connection
, a string table_name, and an optional string schema, return primary key information as a dictionary with these keys:constrained_columns
- a list of column names that make up the primary keyname
- optional name of the primary key constraint.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_primary_keys(connection, table_name, schema=None, **kw)¶ Return information about primary keys in table_name.
Deprecated since version 0.8: The
Dialect.get_primary_keys()
method is deprecated and will be removed in a future release. Please refer to theDialect.get_pk_constraint()
method.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_table_comment(connection, table_name, schema=None, **kw)¶ Return the “comment” for the table identified by table_name.
Given a string table_name and an optional string schema, return table comment information as a dictionary with this key:
- text
text of the comment
Raises
NotImplementedError
for dialects that don’t support comments.New in version 1.2.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_table_names(connection, schema=None, **kw)¶ Return a list of table names for schema.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_temp_table_names(connection, schema=None, **kw)¶ Return a list of temporary table names on the given connection, if supported by the underlying backend.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_temp_view_names(connection, schema=None, **kw)¶ Return a list of temporary view names on the given connection, if supported by the underlying backend.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_unique_constraints(connection, table_name, schema=None, **kw)¶ Return information about unique constraints in table_name.
Given a string table_name and an optional string schema, return unique constraint information as a list of dicts with these keys:
name
- the unique constraint’s namecolumn_names
- list of column names in order**kw
- other options passed to the dialect’s get_unique_constraints() method.
New in version 0.9.0.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_view_definition(connection, view_name, schema=None, **kw)¶ Return view definition.
Given a
Connection
, a string view_name, and an optional string schema, return the view definition.
-
method
sqlalchemy.engine.interfaces.Dialect.
get_view_names(connection, schema=None, **kw)¶ Return a list of all view names available in the database.
- Parameters:
schema – Optional, retrieve names from a non-default schema.
-
method
sqlalchemy.engine.interfaces.Dialect.
has_sequence(connection, sequence_name, schema=None)¶ Check the existence of a particular sequence in the database.
Given a
Connection
object and a string sequence_name, return True if the given sequence exists in the database, False otherwise.
-
method
sqlalchemy.engine.interfaces.Dialect.
has_table(connection, table_name, schema=None)¶ Check the existence of a particular table in the database.
Given a
Connection
object and a string table_name, return True if the given table (possibly within the specified schema) exists in the database, False otherwise.
-
method
sqlalchemy.engine.interfaces.Dialect.
initialize(connection)¶ Called during strategized creation of the dialect with a connection.
Allows dialects to configure options based on server version info or other properties.
The connection passed here is a SQLAlchemy Connection object, with full capabilities.
The initialize() method of the base dialect should be called via super().
-
method
sqlalchemy.engine.interfaces.Dialect.
is_disconnect(e, connection, cursor)¶ Return True if the given DB-API error indicates an invalid connection.
-
classmethod
sqlalchemy.engine.interfaces.Dialect.
load_provisioning()¶ Set up the provision.py module for this dialect.
For dialects that include a provision.py module that sets up provisioning followers, this method should initiate that process.
A typical implementation would be:
@classmethod def load_provisioning(cls): __import__("mydialect.provision")
The default method assumes a module named
provision.py
inside the owning package of the current dialect, based on the__module__
attribute:@classmethod def load_provisioning(cls): package = ".".join(cls.__module__.split(".")[0:-1]) try: __import__(package + ".provision") except ImportError: pass
New in version 1.3.14.
-
method
sqlalchemy.engine.interfaces.Dialect.
normalize_name(name)¶ convert the given name to lowercase if it is detected as case insensitive.
This method is only used if the dialect defines requires_name_normalize=True.
-
method
sqlalchemy.engine.interfaces.Dialect.
on_connect()¶ Return a callable which sets up a newly created DBAPI connection.
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(self): 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.
The “do_on_connect” callable is invoked by using the
PoolEvents.first_connect()
andPoolEvents.connect()
event hooks, then unwrapping the DBAPI connection and passing it into the callable. The reason it is invoked for both events is so that any dialect-level initialization that occurs upon first connection, which also makes use of thePoolEvents.first_connect()
method, will proceed after this hook has been called. This currently means the hook is in fact called twice for the very first connection in which a dialect creates; and once per connection afterwards.If None is returned, no event listener is generated.
- Returns:
a callable that accepts a single DBAPI connection as an argument, or None.
See also
Dialect.connect()
- allows the DBAPIconnect()
sequence itself to be controlled.
-
method
sqlalchemy.engine.interfaces.Dialect.
reflecttable(connection, table, include_columns, exclude_columns, resolve_fks)¶ Load table description from the database.
Given a
Connection
and aTable
object, reflect its columns and properties from the database.The implementation of this method is provided by
DefaultDialect.reflecttable()
, which makes use ofInspector
to retrieve column information.Dialects should not seek to implement this method, and should instead implement individual schema inspection operations such as
Dialect.get_columns()
,Dialect.get_pk_constraint()
, etc.
-
method
sqlalchemy.engine.interfaces.Dialect.
reset_isolation_level(dbapi_conn)¶ Given a DBAPI connection, revert its isolation to the default.
Note that this is a dialect-level method which is used as part of the implementation of the
Connection
andEngine
isolation level facilities; these APIs should be preferred for most typical use cases.See also
Connection.get_isolation_level()
- view current levelConnection.default_isolation_level
- view default levelConnection.execution_options.isolation_level
- set perConnection
isolation levelcreate_engine.isolation_level
- set perEngine
isolation level
-
method
sqlalchemy.engine.interfaces.Dialect.
set_isolation_level(dbapi_conn, level)¶ Given a DBAPI connection, set its isolation level.
Note that this is a dialect-level method which is used as part of the implementation of the
Connection
andEngine
isolation level facilities; these APIs should be preferred for most typical use cases.See also
Connection.get_isolation_level()
- view current levelConnection.default_isolation_level
- view default levelConnection.execution_options.isolation_level
- set perConnection
isolation levelcreate_engine.isolation_level
- set perEngine
isolation level
-
classmethod
sqlalchemy.engine.interfaces.Dialect.
type_descriptor(typeobj)¶ Transform a generic type to a dialect-specific type.
Dialect classes will usually use the
adapt_type()
function in the types module to accomplish this.The returned result is cached per dialect class so can contain no dialect-instance state.
- class sqlalchemy.engine.default.DefaultExecutionContext¶
Members
create_cursor(), current_parameters, get_current_parameters(), get_lastrowid(), get_result_processor(), handle_dbapi_exception(), lastrow_has_defaults(), post_exec(), pre_exec(), set_input_sizes(), should_autocommit_text()
Class signature
class
sqlalchemy.engine.default.DefaultExecutionContext
(sqlalchemy.engine.interfaces.ExecutionContext
)-
method
sqlalchemy.engine.default.DefaultExecutionContext.
create_cursor()¶ Return a new cursor generated from this ExecutionContext’s connection.
Some dialects may wish to change the behavior of connection.cursor(), such as postgresql which may return a PG “server side” cursor.
-
attribute
sqlalchemy.engine.default.DefaultExecutionContext.
current_parameters = None¶ A dictionary of parameters applied to the current row.
This attribute is only available in the context of a user-defined default generation function, e.g. as described at Context-Sensitive Default Functions. It consists of a dictionary which includes entries for each column/value pair that is to be part of the INSERT or UPDATE statement. The keys of the dictionary will be the key value of each
Column
, which is usually synonymous with the name.Note that the
DefaultExecutionContext.current_parameters
attribute does not accommodate for the “multi-values” feature of theInsert.values()
method. TheDefaultExecutionContext.get_current_parameters()
method should be preferred.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
get_current_parameters(isolate_multiinsert_groups=True)¶ Return a dictionary of parameters applied to the current row.
This method can only be used in the context of a user-defined default generation function, e.g. as described at Context-Sensitive Default Functions. When invoked, a dictionary is returned which includes entries for each column/value pair that is part of the INSERT or UPDATE statement. The keys of the dictionary will be the key value of each
Column
, which is usually synonymous with the name.- Parameters:
isolate_multiinsert_groups=True – indicates that multi-valued INSERT constructs created using
Insert.values()
should be handled by returning only the subset of parameters that are local to the current column default invocation. WhenFalse
, the raw parameters of the statement are returned including the naming convention used in the case of multi-valued INSERT.
New in version 1.2: added
DefaultExecutionContext.get_current_parameters()
which provides more functionality over the existingDefaultExecutionContext.current_parameters
attribute.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
get_lastrowid()¶ return self.cursor.lastrowid, or equivalent, after an INSERT.
This may involve calling special cursor functions, issuing a new SELECT on the cursor (or a new one), or returning a stored value that was calculated within post_exec().
This function will only be called for dialects which support “implicit” primary key generation, keep preexecute_autoincrement_sequences set to False, and when no explicit id value was bound to the statement.
The function is called once, directly after post_exec() and before the transaction is committed or ResultProxy is generated. If the post_exec() method assigns a value to self._lastrowid, the value is used in place of calling get_lastrowid().
Note that this method is not equivalent to the
lastrowid
method onResultProxy
, which is a direct proxy to the DBAPIlastrowid
accessor in all cases.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
get_result_processor(type_, colname, coltype)¶ Return a ‘result processor’ for a given type as present in cursor.description.
This has a default implementation that dialects can override for context-sensitive result type handling.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
handle_dbapi_exception(e)¶ Receive a DBAPI exception which occurred upon execute, result fetch, etc.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
lastrow_has_defaults()¶ Return True if the last INSERT or UPDATE row contained inlined or database-side defaults.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
post_exec()¶ Called after the execution of a compiled statement.
If a compiled statement was passed to this ExecutionContext, the last_insert_ids, last_inserted_params, etc. datamembers should be available after this method completes.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
pre_exec()¶ Called before an execution of a compiled statement.
If a compiled statement was passed to this ExecutionContext, the statement and parameters datamembers must be initialized after this statement is complete.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
set_input_sizes(translate=None, include_types=None, exclude_types=None)¶ Given a cursor and ClauseParameters, call the appropriate style of
setinputsizes()
on the cursor, using DB-API types from the bind parameter’sTypeEngine
objects.This method only called by those dialects which require it, currently cx_oracle.
-
method
sqlalchemy.engine.default.DefaultExecutionContext.
should_autocommit_text(statement)¶ Parse the given textual statement and return True if it refers to a “committable” statement
-
method
- class sqlalchemy.engine.interfaces.ExecutionContext¶
A messenger object for a Dialect that corresponds to a single execution.
ExecutionContext should have these data members:
Members
create_cursor(), exception, get_rowcount(), handle_dbapi_exception(), is_disconnect, lastrow_has_defaults(), post_exec(), pre_exec(), result(), should_autocommit_text()
- connection
Connection object which can be freely used by default value generators to execute SQL. This Connection should reference the same underlying connection/transactional resources of root_connection.
- root_connection
Connection object which is the source of this ExecutionContext. This Connection may have close_with_result=True set, in which case it can only be used once.
- dialect
dialect which created this ExecutionContext.
- cursor
DB-API cursor procured from the connection,
- compiled
if passed to constructor, sqlalchemy.engine.base.Compiled object being executed,
- statement
string version of the statement to be executed. Is either passed to the constructor, or must be created from the sql.Compiled object by the time pre_exec() has completed.
- parameters
bind parameters passed to the execute() method. For compiled statements, this is a dictionary or list of dictionaries. For textual statements, it should be in a format suitable for the dialect’s paramstyle (i.e. dict or list of dicts for non positional, list or list of lists/tuples for positional).
- isinsert
True if the statement is an INSERT.
- isupdate
True if the statement is an UPDATE.
- should_autocommit
True if the statement is a “committable” statement.
- prefetch_cols
a list of Column objects for which a client-side default was fired off. Applies to inserts and updates.
- postfetch_cols
a list of Column objects for which a server-side default or inline SQL expression value was fired off. Applies to inserts and updates.
-
method
sqlalchemy.engine.interfaces.ExecutionContext.
create_cursor()¶ Return a new cursor generated from this ExecutionContext’s connection.
Some dialects may wish to change the behavior of connection.cursor(), such as postgresql which may return a PG “server side” cursor.
-
attribute
sqlalchemy.engine.interfaces.ExecutionContext.
exception = None¶ A DBAPI-level exception that was caught when this ExecutionContext attempted to execute a statement.
This attribute is meaningful only within the
ConnectionEvents.dbapi_error()
event.New in version 0.9.7.
-
method
sqlalchemy.engine.interfaces.ExecutionContext.
get_rowcount()¶ Return the DBAPI
cursor.rowcount
value, or in some cases an interpreted value.See
ResultProxy.rowcount
for details on this.
-
method
sqlalchemy.engine.interfaces.ExecutionContext.
handle_dbapi_exception(e)¶ Receive a DBAPI exception which occurred upon execute, result fetch, etc.
-
attribute
sqlalchemy.engine.interfaces.ExecutionContext.
is_disconnect = None¶ Boolean flag set to True or False when a DBAPI-level exception is caught when this ExecutionContext attempted to execute a statement.
This attribute is meaningful only within the
ConnectionEvents.dbapi_error()
event.New in version 0.9.7.
-
method
sqlalchemy.engine.interfaces.ExecutionContext.
lastrow_has_defaults()¶ Return True if the last INSERT or UPDATE row contained inlined or database-side defaults.
-
method
sqlalchemy.engine.interfaces.ExecutionContext.
post_exec()¶ Called after the execution of a compiled statement.
If a compiled statement was passed to this ExecutionContext, the last_insert_ids, last_inserted_params, etc. datamembers should be available after this method completes.
-
method
sqlalchemy.engine.interfaces.ExecutionContext.
pre_exec()¶ Called before an execution of a compiled statement.
If a compiled statement was passed to this ExecutionContext, the statement and parameters datamembers must be initialized after this statement is complete.
-
method
sqlalchemy.engine.interfaces.ExecutionContext.
result()¶ Return a result object corresponding to this ExecutionContext.
Returns a ResultProxy.
-
method
sqlalchemy.engine.interfaces.ExecutionContext.
should_autocommit_text(statement)¶ Parse the given textual statement and return True if it refers to a “committable” statement
- class sqlalchemy.sql.compiler.GenericTypeCompiler(dialect)¶
Class signature
class
sqlalchemy.sql.compiler.GenericTypeCompiler
(sqlalchemy.sql.compiler.TypeCompiler
)
- class sqlalchemy.log.Identified¶
- class sqlalchemy.sql.compiler.IdentifierPreparer(dialect, initial_quote='"', final_quote=None, escape_quote='"', quote_case_sensitive_collations=True, omit_schema=False)¶
Members
__init__(), format_column(), format_schema(), format_table(), format_table_seq(), quote(), quote_identifier(), quote_schema(), unformat_identifiers(), validate_sql_phrase()
Handle quoting and case-folding of identifiers based on options.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
__init__(dialect, initial_quote='"', final_quote=None, escape_quote='"', quote_case_sensitive_collations=True, omit_schema=False)¶ Construct a new
IdentifierPreparer
object.- initial_quote
Character that begins a delimited identifier.
- final_quote
Character that ends a delimited identifier. Defaults to initial_quote.
- omit_schema
Prevent prepending schema name. Useful for databases that do not support schemae.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
format_column(column, use_table=False, name=None, table_name=None, use_schema=False)¶ Prepare a quoted column name.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
format_schema(name)¶ Prepare a quoted schema name.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
format_table(table, use_schema=True, name=None)¶ Prepare a quoted table and schema name.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
format_table_seq(table, use_schema=True)¶ Format table name and schema as a tuple.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
quote(ident, force=None)¶ Conditionally quote an identfier.
The identifier is quoted if it is a reserved word, contains quote-necessary characters, or is an instance of
quoted_name
which includesquote
set toTrue
.Subclasses can override this to provide database-dependent quoting behavior for identifier names.
- Parameters:
ident – string identifier
force –
unused
Deprecated since version 0.9: The
IdentifierPreparer.quote.force
parameter is deprecated and will be removed in a future release. This flag has no effect on the behavior of theIdentifierPreparer.quote()
method; please refer toquoted_name
.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
quote_identifier(value)¶ Quote an identifier.
Subclasses should override this to provide database-dependent quoting behavior.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
quote_schema(schema, force=None)¶ Conditionally quote a schema name.
The name is quoted if it is a reserved word, contains quote-necessary characters, or is an instance of
quoted_name
which includesquote
set toTrue
.Subclasses can override this to provide database-dependent quoting behavior for schema names.
- Parameters:
schema – string schema name
force –
unused
Deprecated since version 0.9: The
IdentifierPreparer.quote_schema.force
parameter is deprecated and will be removed in a future release. This flag has no effect on the behavior of theIdentifierPreparer.quote()
method; please refer toquoted_name
.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
unformat_identifiers(identifiers)¶ Unpack ‘schema.table.column’-like strings into components.
-
method
sqlalchemy.sql.compiler.IdentifierPreparer.
validate_sql_phrase(element, reg)¶ keyword sequence filter.
a filter for elements that are intended to represent keyword sequences, such as “INITIALLY”, “INITIALLY DEFERRED”, etc. no special characters should be present.
New in version 1.3.
-
method
- class sqlalchemy.sql.compiler.SQLCompiler(dialect, statement, column_keys=None, inline=False, **kwargs)¶
Default implementation of
Compiled
.Compiles
ClauseElement
objects into SQL strings.Members
__init__(), ansi_bind_rules, construct_params(), contains_expanding_parameters, current_executable, default_from(), delete_extra_from_clause(), get_select_precolumns(), group_by_clause(), insert_single_values_expr, isdelete, order_by_clause(), params, render_literal_value(), render_table_with_column_in_update_from, returning, returning_precedes_values, sql_compiler, update_from_clause(), update_limit_clause(), update_tables_clause()
Class signature
class
sqlalchemy.sql.compiler.SQLCompiler
(sqlalchemy.sql.compiler.Compiled
)-
method
sqlalchemy.sql.compiler.SQLCompiler.
__init__(dialect, statement, column_keys=None, inline=False, **kwargs)¶ Construct a new
SQLCompiler
object.- Parameters:
dialect –
Dialect
to be usedstatement –
ClauseElement
to be compiledcolumn_keys – a list of column names to be compiled into an INSERT or UPDATE statement.
inline – whether to generate INSERT statements as “inline”, e.g. not formatted to return any generated defaults
kwargs – additional keyword arguments to be consumed by the superclass.
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
ansi_bind_rules = False¶ SQL 92 doesn’t allow bind parameters to be used in the columns clause of a SELECT, nor does it allow ambiguous expressions like “? = ?”. A compiler subclass can set this flag to False if the target driver/DB enforces this
-
method
sqlalchemy.sql.compiler.SQLCompiler.
construct_params(params=None, _group_number=None, _check=True)¶ return a dictionary of bind parameter keys and values
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
contains_expanding_parameters = False¶ True if we’ve encountered bindparam(…, expanding=True).
These need to be converted before execution time against the string statement.
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
current_executable¶ Return the current ‘executable’ that is being compiled.
This is currently the
Select
,Insert
,Update
,Delete
,CompoundSelect
object that is being compiled. Specifically it’s assigned to theself.stack
list of elements.When a statement like the above is being compiled, it normally is also assigned to the
.statement
attribute of theCompiler
object. However, all SQL constructs are ultimately nestable, and this attribute should never be consulted by avisit_
method, as it is not guaranteed to be assigned nor guaranteed to correspond to the current statement being compiled.New in version 1.3.21: For compatibility with previous versions, use the following recipe:
statement = getattr(self, "current_executable", False) if statement is False: statement = self.stack[-1]["selectable"]
For versions 1.4 and above, ensure only .current_executable is used; the format of “self.stack” may change.
-
method
sqlalchemy.sql.compiler.SQLCompiler.
default_from()¶ Called when a SELECT statement has no froms, and no FROM clause is to be appended.
Gives Oracle a chance to tack on a
FROM DUAL
to the string output.
-
method
sqlalchemy.sql.compiler.SQLCompiler.
delete_extra_from_clause(update_stmt, from_table, extra_froms, from_hints, **kw)¶ Provide a hook to override the generation of an DELETE..FROM clause.
This can be used to implement DELETE..USING for example.
MySQL and MSSQL override this.
-
method
sqlalchemy.sql.compiler.SQLCompiler.
get_select_precolumns(select, **kw)¶ Called when building a
SELECT
statement, position is just before column list.
-
method
sqlalchemy.sql.compiler.SQLCompiler.
group_by_clause(select, **kw)¶ allow dialects to customize how GROUP BY is rendered.
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
insert_single_values_expr = None¶ When an INSERT is compiled with a single set of parameters inside a VALUES expression, the string is assigned here, where it can be used for insert batching schemes to rewrite the VALUES expression.
New in version 1.3.8.
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
isdelete = False¶ class-level defaults which can be set at the instance level to define if this Compiled instance represents INSERT/UPDATE/DELETE
-
method
sqlalchemy.sql.compiler.SQLCompiler.
order_by_clause(select, **kw)¶ allow dialects to customize how ORDER BY is rendered.
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
params¶ Return the bind param dictionary embedded into this compiled object, for those values that are present.
-
method
sqlalchemy.sql.compiler.SQLCompiler.
render_literal_value(value, type_)¶ Render the value of a bind parameter as a quoted literal.
This is used for statement sections that do not accept bind parameters on the target driver/database.
This should be implemented by subclasses using the quoting services of the DBAPI.
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
render_table_with_column_in_update_from = False¶ set to True classwide to indicate the SET clause in a multi-table UPDATE statement should qualify columns with the table name (i.e. MySQL only)
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
returning = None¶ holds the “returning” collection of columns if the statement is CRUD and defines returning columns either implicitly or explicitly
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
returning_precedes_values = False¶ set to True classwide to generate RETURNING clauses before the VALUES or WHERE clause (i.e. MSSQL)
-
attribute
sqlalchemy.sql.compiler.SQLCompiler.
sql_compiler¶
-
method
sqlalchemy.sql.compiler.SQLCompiler.
update_from_clause(update_stmt, from_table, extra_froms, from_hints, **kw)¶ Provide a hook to override the generation of an UPDATE..FROM clause.
MySQL and MSSQL override this.
-
method
sqlalchemy.sql.compiler.SQLCompiler.
update_limit_clause(update_stmt)¶ Provide a hook for MySQL to add LIMIT to the UPDATE
-
method
sqlalchemy.sql.compiler.SQLCompiler.
update_tables_clause(update_stmt, from_table, extra_froms, **kw)¶ Provide a hook to override the initial table clause in an UPDATE statement.
MySQL overrides this.
-
method
- class sqlalchemy.sql.compiler.StrSQLCompiler(dialect, statement, column_keys=None, inline=False, **kwargs)¶
A
SQLCompiler
subclass which allows a small selection of non-standard SQL features to render into a string value.The
StrSQLCompiler
is invoked whenever a Core expression element is directly stringified without calling upon theClauseElement.compile()
method. It can render a limited set of non-standard SQL constructs to assist in basic stringification, however for more substantial custom or dialect-specific SQL constructs, it will be necessary to make use ofClauseElement.compile()
directly.Class signature
class
sqlalchemy.sql.compiler.StrSQLCompiler
(sqlalchemy.sql.compiler.SQLCompiler
)-
method
sqlalchemy.sql.compiler.StrSQLCompiler.
delete_extra_from_clause(update_stmt, from_table, extra_froms, from_hints, **kw)¶ Provide a hook to override the generation of an DELETE..FROM clause.
This can be used to implement DELETE..USING for example.
MySQL and MSSQL override this.
-
method
sqlalchemy.sql.compiler.StrSQLCompiler.
update_from_clause(update_stmt, from_table, extra_froms, from_hints, **kw)¶ Provide a hook to override the generation of an UPDATE..FROM clause.
MySQL and MSSQL override this.
-
method