Some key internal constructs are listed here.
sqlalchemy.engine.interfaces.
Compiled
(dialect, statement, bind=None, schema_translate_map=None, compile_kwargs={})¶Represent a compiled SQL or DDL expression.
The __str__
method of the Compiled
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 the
Compiled
object be dependent on the actual values of those
bind parameters, even though it may reference those values as
defaults.
__init__
(dialect, statement, bind=None, schema_translate_map=None, compile_kwargs={})¶Construct a new Compiled
object.
Parameters: |
|
---|
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. The Compiled
object now runs its compilation within the constructor, and this method does nothing.
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. |
---|
execute
(*multiparams, **params)¶Execute this compiled object.
execution_options
= {}¶Execution options propagated from the statement. In some cases, sub-elements of the statement can modify these.
params
¶Return the bind params for this compiled object.
scalar
(*multiparams, **params)¶Execute this compiled object and return the result’s scalar value.
sql_compiler
¶Return a Compiled that is capable of processing SQL expressions.
If this compiler is one, it would likely just return ‘self’.
sqlalchemy.sql.compiler.
DDLCompiler
(dialect, statement, bind=None, schema_translate_map=None, compile_kwargs={})¶Bases: sqlalchemy.sql.compiler.Compiled
__eq__
¶__eq__
attribute of object
Return self==value.
__init__
(dialect, statement, bind=None, schema_translate_map=None, compile_kwargs={})¶__init__()
method of Compiled
Construct a new Compiled
object.
Parameters: |
|
---|
__le__
¶__le__
attribute of object
Return self<=value.
__lt__
¶__lt__
attribute of object
Return self<value.
__ne__
¶__ne__
attribute of object
Return self!=value.
compile
()¶compile()
method of Compiled
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. The Compiled
object now runs its compilation within the constructor, and this method does nothing.
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. |
---|
define_constraint_remote_table
(constraint, table, preparer)¶Format the remote table clause of a CREATE CONSTRAINT clause.
execute
(*multiparams, **params)¶execute()
method of Compiled
Execute this compiled object.
params
¶params
attribute of Compiled
Return the bind params for this compiled object.
scalar
(*multiparams, **params)¶scalar()
method of Compiled
Execute this compiled object and return the result’s scalar value.
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)¶Bases: sqlalchemy.engine.interfaces.Dialect
Default implementation of Dialect
__eq__
¶__eq__
attribute of object
Return self==value.
__le__
¶__le__
attribute of object
Return self<=value.
__lt__
¶__lt__
attribute of object
Return self<value.
__ne__
¶__ne__
attribute of object
Return self!=value.
connect
(*cargs, **cparams)¶return a callable which sets up a newly created DBAPI connection.
The callable accepts a single argument “conn” which is the DBAPI connection itself. It has no return value.
This is used to set dialect-wide per-connection options such as isolation modes, unicode modes, etc.
If a callable is returned, it will be assembled into a pool listener that receives the direct DBAPI connection, with all wrappers removed.
If None is returned, no listener will be generated.
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 arguments
postgresql_using
, postgresql_where
, nad postgresql_ops
.
Any other argument specified to the constructor of Index
which is prefixed with postgresql_
will raise ArgumentError
.
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 consumes
DefaultDialect.construct_arguments
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.
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.
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.
ddl_compiler
¶alias of sqlalchemy.sql.compiler.DDLCompiler
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.
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 a
Transaction
object is in use. The
Dialect.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
SQLAlchemy Connection
is used in its default “autocommit”
mode.
Parameters: | dbapi_connection¶ – a DBAPI connection, typically
proxied within a ConnectionFairy . |
---|
do_begin_twophase
(connection, xid)¶do_begin_twophase()
method of Dialect
Begin a two phase transaction on the given connection.
Parameters: |
|
---|
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.
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 . |
---|
do_commit_twophase
(connection, xid, is_prepared=True, recover=False)¶do_commit_twophase()
method of Dialect
Commit a two phase transaction on the given connection.
Parameters: |
|
---|
do_execute
(cursor, statement, parameters, context=None)¶Provide an implementation of cursor.execute(statement,
parameters)
.
do_execute_no_params
(cursor, statement, context=None)¶Provide an implementation of cursor.execute(statement)
.
The parameter collection should not be sent.
do_executemany
(cursor, statement, parameters, context=None)¶Provide an implementation of cursor.executemany(statement,
parameters)
.
do_prepare_twophase
(connection, xid)¶do_prepare_twophase()
method of Dialect
Prepare a two phase transaction on the given connection.
Parameters: |
|
---|
do_recover_twophase
(connection)¶do_recover_twophase()
method of Dialect
Recover list of uncommitted prepared two phase transaction identifiers on the given connection.
Parameters: | connection¶ – a Connection . |
---|
do_release_savepoint
(connection, name)¶Release the named savepoint on a connection.
Parameters: |
|
---|
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 . |
---|
do_rollback_to_savepoint
(connection, name)¶Rollback a connection to the named savepoint.
Parameters: |
|
---|
do_rollback_twophase
(connection, xid, is_prepared=True, recover=False)¶do_rollback_twophase()
method of Dialect
Rollback a two phase transaction on the given connection.
Parameters: |
|
---|
do_savepoint
(connection, name)¶Create a savepoint with the given name.
Parameters: |
|
---|
engine_created
(engine)¶engine_created()
method of Dialect
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 the get_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.
execute_sequence_format
¶alias of builtins.tuple
execution_ctx_cls
¶alias of DefaultExecutionContext
get_check_constraints
(connection, table_name, schema=None, **kw)¶get_check_constraints()
method of Dialect
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:
New in version 1.1.0.
get_columns
(connection, table_name, schema=None, **kw)¶get_columns()
method of Dialect
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:
Additional column attributes may be present.
get_dialect_cls
(url)¶get_dialect_cls()
method of Dialect
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.
get_foreign_keys
(connection, table_name, schema=None, **kw)¶get_foreign_keys()
method of Dialect
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:
get_indexes
(connection, table_name, schema=None, **kw)¶get_indexes()
method of Dialect
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:
get_isolation_level
(dbapi_conn)¶get_isolation_level()
method of Dialect
Given a DBAPI connection, return its isolation level.
When working with a Connection
object, the corresponding
DBAPI connection may be procured using the
Connection.connection
accessor.
Note that this is a dialect-level method which is used as part
of the implementation of the Connection
and
Engine
isolation level facilities;
these APIs should be preferred for most typical use cases.
See also
Connection.get_isolation_level()
- view current level
Connection.default_isolation_level
- view default level
Connection.execution_options.isolation_level
-
set per Connection
isolation level
create_engine.isolation_level
-
set per Engine
isolation level
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().
get_primary_keys
(connection, table_name, schema=None, **kw)¶get_primary_keys()
method of Dialect
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 the Dialect.get_pk_constraint()
method.
get_table_comment
(connection, table_name, schema=None, **kw)¶get_table_comment()
method of Dialect
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:
Raises NotImplementedError
for dialects that don’t support
comments.
New in version 1.2.
get_table_names
(connection, schema=None, **kw)¶get_table_names()
method of Dialect
Return a list of table names for schema.
get_temp_table_names
(connection, schema=None, **kw)¶get_temp_table_names()
method of Dialect
Return a list of temporary table names on the given connection, if supported by the underlying backend.
get_temp_view_names
(connection, schema=None, **kw)¶get_temp_view_names()
method of Dialect
Return a list of temporary view names on the given connection, if supported by the underlying backend.
get_unique_constraints
(connection, table_name, schema=None, **kw)¶get_unique_constraints()
method of Dialect
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:
New in version 0.9.0.
get_view_definition
(connection, view_name, schema=None, **kw)¶get_view_definition()
method of Dialect
Return view definition.
Given a Connection
, a string
view_name, and an optional string schema, return the view
definition.
get_view_names
(connection, schema=None, **kw)¶get_view_names()
method of Dialect
Return a list of all view names available in the database.
has_sequence
(connection, sequence_name, schema=None)¶has_sequence()
method of Dialect
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.
has_table
(connection, table_name, schema=None)¶has_table()
method of Dialect
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.
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().
is_disconnect
(e, connection, cursor)¶Return True if the given DB-API error indicates an invalid connection
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.
on_connect
()¶return a callable which sets up a newly created DBAPI connection.
This is used to set dialect-wide per-connection options such as isolation modes, unicode modes, etc.
If a callable is returned, it will be assembled into a pool listener that receives the direct DBAPI connection, with all wrappers removed.
If None is returned, no listener will be generated.
preparer
¶reflecttable
(connection, table, include_columns, exclude_columns, resolve_fks, **opts)¶Load table description from the database.
Given a Connection
and a
Table
object, reflect its columns and
properties from the database.
The implementation of this method is provided by
DefaultDialect.reflecttable()
, which makes use of
Inspector
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.
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
and
Engine
isolation level facilities; these APIs should be preferred for
most typical use cases.
See also
Connection.get_isolation_level()
- view current level
Connection.default_isolation_level
- view default level
Connection.execution_options.isolation_level
-
set per Connection
isolation level
create_engine.isolation_level
-
set per Engine
isolation level
set_isolation_level
(dbapi_conn, level)¶set_isolation_level()
method of Dialect
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
and
Engine
isolation level facilities; these APIs should be preferred for
most typical use cases.
See also
Connection.get_isolation_level()
- view current level
Connection.default_isolation_level
- view default level
Connection.execution_options.isolation_level
-
set per Connection
isolation level
create_engine.isolation_level
-
set per Engine
isolation level
statement_compiler
¶alias of sqlalchemy.sql.compiler.SQLCompiler
type_compiler
¶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 to types.adapt_type()
.
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.
All Dialects implement the following attributes:
str
types.Compiled
class used to compile SQL statementsCompiled
class used to compile DDL statementsExecutionContext
class used to handle statement executionIdentifierPreparer
class used to
quote identifiers.True
if the database supports ALTER TABLE
.UPDATE
and DELETE
statements.UPDATE
and DELETE
statements when executed via
executemany.INSERT INTO tablename DEFAULT
VALUES
is supportedA 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.
connect
()¶return a callable which sets up a newly created DBAPI connection.
The callable accepts a single argument “conn” which is the DBAPI connection itself. It has no return value.
This is used to set dialect-wide per-connection options such as isolation modes, unicode modes, etc.
If a callable is returned, it will be assembled into a pool listener that receives the direct DBAPI connection, with all wrappers removed.
If None is returned, no listener will be generated.
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.
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.
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.
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 a
Transaction
object is in use. The
Dialect.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
SQLAlchemy Connection
is used in its default “autocommit”
mode.
Parameters: | dbapi_connection¶ – a DBAPI connection, typically
proxied within a ConnectionFairy . |
---|
do_begin_twophase
(connection, xid)¶Begin a two phase transaction on the given connection.
Parameters: |
|
---|
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.
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 . |
---|
do_commit_twophase
(connection, xid, is_prepared=True, recover=False)¶Commit a two phase transaction on the given connection.
Parameters: |
|
---|
do_execute
(cursor, statement, parameters, context=None)¶Provide an implementation of cursor.execute(statement,
parameters)
.
do_execute_no_params
(cursor, statement, parameters, context=None)¶Provide an implementation of cursor.execute(statement)
.
The parameter collection should not be sent.
do_executemany
(cursor, statement, parameters, context=None)¶Provide an implementation of cursor.executemany(statement,
parameters)
.
do_prepare_twophase
(connection, xid)¶Prepare a two phase transaction on the given connection.
Parameters: |
|
---|
do_recover_twophase
(connection)¶Recover list of uncommitted prepared two phase transaction identifiers on the given connection.
Parameters: | connection¶ – a Connection . |
---|
do_release_savepoint
(connection, name)¶Release the named savepoint on a connection.
Parameters: |
|
---|
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 . |
---|
do_rollback_to_savepoint
(connection, name)¶Rollback a connection to the named savepoint.
Parameters: |
|
---|
do_rollback_twophase
(connection, xid, is_prepared=True, recover=False)¶Rollback a two phase transaction on the given connection.
Parameters: |
|
---|
do_savepoint
(connection, name)¶Create a savepoint with the given name.
Parameters: |
|
---|
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 the get_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.
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:
New in version 1.1.0.
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:
Additional column attributes may be present.
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.
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:
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:
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 the
Connection.connection
accessor.
Note that this is a dialect-level method which is used as part
of the implementation of the Connection
and
Engine
isolation level facilities;
these APIs should be preferred for most typical use cases.
See also
Connection.get_isolation_level()
- view current level
Connection.default_isolation_level
- view default level
Connection.execution_options.isolation_level
-
set per Connection
isolation level
create_engine.isolation_level
-
set per Engine
isolation level
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:
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 the Dialect.get_pk_constraint()
method.
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:
Raises NotImplementedError
for dialects that don’t support
comments.
New in version 1.2.
get_table_names
(connection, schema=None, **kw)¶Return a list of table names for schema.
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.
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.
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:
New in version 0.9.0.
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.
get_view_names
(connection, schema=None, **kw)¶Return a list of all view names available in the database.
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.
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.
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().
is_disconnect
(e, connection, cursor)¶Return True if the given DB-API error indicates an invalid connection
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.
reflecttable
(connection, table, include_columns, exclude_columns, resolve_fks)¶Load table description from the database.
Given a Connection
and a
Table
object, reflect its columns and
properties from the database.
The implementation of this method is provided by
DefaultDialect.reflecttable()
, which makes use of
Inspector
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.
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
and
Engine
isolation level facilities; these APIs should be preferred for
most typical use cases.
See also
Connection.get_isolation_level()
- view current level
Connection.default_isolation_level
- view default level
Connection.execution_options.isolation_level
-
set per Connection
isolation level
create_engine.isolation_level
-
set per Engine
isolation level
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
and
Engine
isolation level facilities; these APIs should be preferred for
most typical use cases.
See also
Connection.get_isolation_level()
- view current level
Connection.default_isolation_level
- view default level
Connection.execution_options.isolation_level
-
set per Connection
isolation level
create_engine.isolation_level
-
set per Engine
isolation level
type_descriptor
(typeobj)¶Transform a generic type to a dialect-specific type.
Dialect classes will usually use the
types.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.
sqlalchemy.engine.default.
DefaultExecutionContext
¶Bases: 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.
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 the
Insert.values()
method. The
DefaultExecutionContext.get_current_parameters()
method should be
preferred.
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. When False , 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 existing
DefaultExecutionContext.current_parameters
attribute.
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 on ResultProxy
, which is a
direct proxy to the DBAPI lastrowid
accessor
in all cases.
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.
handle_dbapi_exception
(e)¶Receive a DBAPI exception which occurred upon execute, result fetch, etc.
lastrow_has_defaults
()¶Return True if the last INSERT or UPDATE row contained inlined or database-side defaults.
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.
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.
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’s TypeEngine
objects.
This method only called by those dialects which require it, currently cx_oracle.
should_autocommit_text
(statement)¶Parse the given textual statement and return True if it refers to a “committable” statement
sqlalchemy.engine.interfaces.
ExecutionContext
¶A messenger object for a Dialect that corresponds to a single execution.
ExecutionContext should have these data members:
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.
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.
get_rowcount
()¶Return the DBAPI cursor.rowcount
value, or in some
cases an interpreted value.
See ResultProxy.rowcount
for details on this.
handle_dbapi_exception
(e)¶Receive a DBAPI exception which occurred upon execute, result fetch, etc.
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.
lastrow_has_defaults
()¶Return True if the last INSERT or UPDATE row contained inlined or database-side defaults.
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.
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.
result
()¶Return a result object corresponding to this ExecutionContext.
Returns a ResultProxy.
should_autocommit_text
(statement)¶Parse the given textual statement and return True if it refers to a “committable” statement
sqlalchemy.sql.compiler.
GenericTypeCompiler
(dialect)¶Bases: sqlalchemy.sql.compiler.TypeCompiler
__eq__
¶__eq__
attribute of object
Return self==value.
__le__
¶__le__
attribute of object
Return self<=value.
__lt__
¶__lt__
attribute of object
Return self<value.
__ne__
¶__ne__
attribute of object
Return self!=value.
sqlalchemy.log.
Identified
¶sqlalchemy.sql.compiler.
IdentifierPreparer
(dialect, initial_quote='"', final_quote=None, escape_quote='"', quote_case_sensitive_collations=True, omit_schema=False)¶Handle quoting and case-folding of identifiers based on options.
__init__
(dialect, initial_quote='"', final_quote=None, escape_quote='"', quote_case_sensitive_collations=True, omit_schema=False)¶Construct a new IdentifierPreparer
object.
format_column
(column, use_table=False, name=None, table_name=None, use_schema=False)¶Prepare a quoted column name.
format_schema
(name)¶Prepare a quoted schema name.
format_table
(table, use_schema=True, name=None)¶Prepare a quoted table and schema name.
format_table_seq
(table, use_schema=True)¶Format table name and schema as a tuple.
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 includes quote
set to True
.
Subclasses can override this to provide database-dependent quoting behavior for identifier names.
Parameters: |
|
---|
quote_identifier
(value)¶Quote an identifier.
Subclasses should override this to provide database-dependent quoting behavior.
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 includes
quote
set to True
.
Subclasses can override this to provide database-dependent quoting behavior for schema names.
Parameters: |
|
---|
unformat_identifiers
(identifiers)¶Unpack ‘schema.table.column’-like strings into components.
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.
sqlalchemy.sql.compiler.
SQLCompiler
(dialect, statement, column_keys=None, inline=False, **kwargs)¶Bases: sqlalchemy.sql.compiler.Compiled
Default implementation of Compiled
.
Compiles ClauseElement
objects into SQL strings.
__init__
(dialect, statement, column_keys=None, inline=False, **kwargs)¶Construct a new SQLCompiler
object.
Parameters: |
|
---|
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
construct_params
(params=None, _group_number=None, _check=True)¶return a dictionary of bind parameter keys and values
contains_expanding_parameters
= False¶True if we’ve encountered bindparam(…, expanding=True).
These need to be converted before execution time against the string statement.
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.
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.
get_select_precolumns
(select, **kw)¶Called when building a SELECT
statement, position is just
before column list.
group_by_clause
(select, **kw)¶allow dialects to customize how GROUP BY is rendered.
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.
isdelete
= False¶class-level defaults which can be set at the instance level to define if this Compiled instance represents INSERT/UPDATE/DELETE
order_by_clause
(select, **kw)¶allow dialects to customize how ORDER BY is rendered.
params
¶Return the bind param dictionary embedded into this compiled object, for those values that are present.
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.
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)
returning
= None¶holds the “returning” collection of columns if the statement is CRUD and defines returning columns either implicitly or explicitly
returning_precedes_values
= False¶set to True classwide to generate RETURNING clauses before the VALUES or WHERE clause (i.e. MSSQL)
sql_compiler
¶Return a Compiled that is capable of processing SQL expressions.
If this compiler is one, it would likely just return ‘self’.
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.
update_limit_clause
(update_stmt)¶Provide a hook for MySQL to add LIMIT to the UPDATE
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.
sqlalchemy.sql.compiler.
StrSQLCompiler
(dialect, statement, column_keys=None, inline=False, **kwargs)¶Bases: sqlalchemy.sql.compiler.SQLCompiler
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 the
ClauseElement.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 of ClauseElement.compile()
directly.
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.
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.