Some key internal constructs are listed here.
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.
Construct a new Compiled object.
Parameters: |
---|
Produce the internal string representation of this element.
Deprecated since version 0.7: Compiled objects now compile within the constructor.
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 this compiled object.
Return the bind params for this compiled object.
Execute this compiled object and return the result’s scalar value.
Return a Compiled that is capable of processing SQL expressions.
If this compiler is one, it would likely just return ‘self’.
Bases: sqlalchemy.sql.compiler.Compiled
Construct a new Compiled object.
Parameters: |
---|
Produce the internal string representation of this element.
Deprecated since version 0.7: Compiled objects now compile within the constructor.
Format the remote table clause of a CREATE CONSTRAINT clause.
Execute this compiled object.
Return the bind params for this compiled object.
Execute this compiled object and return the result’s scalar value.
Bases: sqlalchemy.engine.interfaces.Dialect
Default implementation of Dialect
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 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.
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.
Begin a two phase transaction on the given connection.
Parameters: |
|
---|
Commit a two phase transaction on the given connection.
Parameters: |
|
---|
Prepare a two phase transaction on the given connection.
Parameters: |
|
---|
Recover list of uncommited prepared two phase transaction identifiers on the given connection.
Parameters: | connection¶ – a Connection. |
---|
Rollback a two phase transaction on the given connection.
Parameters: |
|
---|
alias of tuple
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.
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:
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:
Given a DBAPI connection, return its isolation level.
Compatibility method, adapts the result of get_primary_keys() for those dialects which don’t implement get_pk_constraint().
Return information about primary keys in table_name.
Deprecated. This method is only called by the default implementation of Dialect.get_pk_constraint(). Dialects should instead implement the Dialect.get_pk_constraint() method directly.
Return a list of table names for schema.
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.
Return view definition.
Given a Connection, a string view_name, and an optional string schema, return the view definition.
Return a list of all view names available in the database.
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.
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.
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.
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.
alias of IdentifierPreparer
Given a DBAPI connection, set its isolation level.
alias of SQLCompiler
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().
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:
A mapping of DB-API type objects present in this Dialect’s DB-API implementation mapped to TypeEngine implementations used by the dialect.
This is used to apply types to result sets based on the DB-API types present in cursor.description; it only takes effect for result sets against textual statements where no explicit typemap was present.
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.
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 a two-phase transaction ID.
This id will be passed to do_begin_twophase(), do_rollback_twophase(), do_commit_twophase(). Its format is unspecified.
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.
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. |
---|
Begin a two phase transaction on the given connection.
Parameters: |
|
---|
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.
New in version 0.8.
Provide an implementation of connection.commit(), given a DB-API connection.
Parameters: | dbapi_connection¶ – a DBAPI connection, typically proxied within a ConnectionFairy. |
---|
Commit a two phase transaction on the given connection.
Parameters: |
|
---|
Provide an implementation of cursor.execute(statement, parameters).
Provide an implementation of cursor.execute(statement).
The parameter collection should not be sent.
Provide an implementation of cursor.executemany(statement, parameters).
Prepare a two phase transaction on the given connection.
Parameters: |
|
---|
Recover list of uncommited prepared two phase transaction identifiers on the given connection.
Parameters: | connection¶ – a Connection. |
---|
Release the named savepoint on a connection.
Parameters: |
|
---|
Provide an implementation of connection.rollback(), given a DB-API connection.
Parameters: | dbapi_connection¶ – a DBAPI connection, typically proxied within a ConnectionFairy. |
---|
Rollback a connection to the named savepoint.
Parameters: |
|
---|
Rollback a two phase transaction on the given connection.
Parameters: |
|
---|
Create a savepoint with the given name.
Parameters: |
|
---|
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.
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:
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:
Given a DBAPI connection, return its isolation level.
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:
Return information about primary keys in table_name.
Deprecated. This method is only called by the default implementation of Dialect.get_pk_constraint(). Dialects should instead implement the Dialect.get_pk_constraint() method directly.
Return a list of table names for schema.
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.
Return view definition.
Given a Connection, a string view_name, and an optional string schema, return the view definition.
Return a list of all view names available in the database.
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.
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.
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().
Return True if the given DB-API error indicates an invalid connection
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.
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.
Given a DBAPI connection, revert its isolation to the default.
Given a DBAPI connection, set its isolation level.
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.
Bases: sqlalchemy.engine.interfaces.ExecutionContext
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.
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.
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.
A messenger object for a Dialect that corresponds to a single execution.
ExecutionContext should have these data members:
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.
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.
Return the DBAPI cursor.rowcount value, or in some cases an interpreted value.
See ResultProxy.rowcount for details on this.
Receive a DBAPI exception which occurred upon execute, result fetch, etc.
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.
Return True if the last INSERT or UPDATE row contained inlined or database-side defaults.
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.
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.
Return a result object corresponding to this ExecutionContext.
Returns a ResultProxy.
Parse the given textual statement and return True if it refers to a “committable” statement
Handle quoting and case-folding of identifiers based on options.
Construct a new IdentifierPreparer object.
Prepare a quoted column name.
Prepare a quoted schema name.
Prepare a quoted table and schema name.
Format table name and schema as a tuple.
Conditionally quote an identifier.
the ‘force’ flag should be considered deprecated.
Quote an identifier.
Subclasses should override this to provide database-dependent quoting behavior.
Conditionally quote a schema.
Subclasses can override this to provide database-dependent quoting behavior for schema names.
the ‘force’ flag should be considered deprecated.
Unpack ‘schema.table.column’-like strings into components.
Bases: sqlalchemy.sql.compiler.Compiled
Default implementation of Compiled.
Compiles ClauseElements into SQL strings. Uses a similar visit paradigm as visitors.ClauseVisitor but implements its own traversal.
Construct a new DefaultCompiler object.
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
return a dictionary of bind parameter keys and values
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.
provide escaping for the literal_column() construct.
Called when building a SELECT statement, position is just before column list.
class-level defaults which can be set at the instance level to define if this Compiled instance represents INSERT/UPDATE/DELETE
class-level defaults which can be set at the instance level to define if this Compiled instance represents INSERT/UPDATE/DELETE
class-level defaults which can be set at the instance level to define if this Compiled instance represents INSERT/UPDATE/DELETE
Return the bind param dictionary embedded into this compiled object, for those values that are present.
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.
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)
holds the “returning” collection of columns if the statement is CRUD and defines returning columns either implicitly or explicitly
set to True classwide to generate RETURNING clauses before the VALUES or WHERE clause (i.e. MSSQL)
Provide a hook to override the generation of an UPDATE..FROM clause.
MySQL and MSSQL override this.
Provide a hook for MySQL to add LIMIT to the UPDATE
Provide a hook to override the initial table clause in an UPDATE statement.
MySQL overrides this.