class documentation

class MySQLDialect(default.DefaultDialect):

Known subclasses: sqlalchemy.dialects.mysql.mariadbconnector.MySQLDialect_mariadbconnector, sqlalchemy.dialects.mysql.mysqlconnector.MySQLDialect_mysqlconnector, sqlalchemy.dialects.mysql.mysqldb.MySQLDialect_mysqldb, sqlalchemy.dialects.mysql.oursql.MySQLDialect_oursql, sqlalchemy.dialects.mysql.pyodbc.MySQLDialect_pyodbc

View In Hierarchy

Details of the MySQL dialect. Not used directly in application code.
Class Method ​_is​_mariadb​_from​_url Undocumented
Method __init__ Undocumented
Method ​_compat​_fetchall Proxy result rows to smooth over MySQL-Python driver inconsistencies.
Method ​_compat​_fetchone Proxy a result row to smooth over MySQL-Python driver inconsistencies.
Method ​_compat​_first Proxy a result row to smooth over MySQL-Python driver inconsistencies.
Method ​_correct​_for​_mysql​_bugs​_88718​_96365 Undocumented
Method ​_describe​_table Run DESCRIBE for a Table and return processed rows.
Method ​_detect​_ansiquotes Detect and adjust for the ANSI_QUOTES sql mode.
Method ​_detect​_casing Sniff out identifier case sensitivity.
Method ​_detect​_charset Undocumented
Method ​_detect​_collations Pull the active COLLATIONS list from the server.
Method ​_detect​_sql​_mode Undocumented
Method ​_extract​_error​_code Undocumented
Method ​_get​_default​_schema​_name Return the string name of the currently selected schema from the given connection.
Method ​_get​_server​_version​_info Retrieve the server version info from the given connection.
Method ​_parse​_server​_version Undocumented
Method ​_parsed​_state​_or​_create Undocumented
Method ​_sequences​_not​_supported Undocumented
Method ​_set​_isolation​_level Undocumented
Method ​_set​_mariadb Undocumented
Method ​_setup​_parser Undocumented
Method ​_show​_create​_table Run SHOW CREATE TABLE for a Table.
Method ​_warn​_for​_known​_db​_issues Undocumented
Method do​_begin​_twophase Begin a two phase transaction on the given connection.
Method do​_commit​_twophase Commit a two phase transaction on the given connection.
Method do​_prepare​_twophase Prepare a two phase transaction on the given connection.
Method do​_recover​_twophase Recover list of uncommitted prepared two phase transaction identifiers on the given connection.
Method do​_rollback​_twophase Rollback a two phase transaction on the given connection.
Method get​_check​_constraints Return information about check constraints in table_name.
Method get​_columns Return information about columns in table_name.
Method get​_foreign​_keys Return information about foreign_keys in table_name.
Method get​_indexes Return information about indexes in table_name.
Method get​_isolation​_level Given a DBAPI connection, return its isolation level.
Method get​_pk​_constraint Return information about the primary key constraint on table_name`.
Method get​_schema​_names Undocumented
Method get​_sequence​_names Return a list of all sequence names available in the database.
Method get​_table​_comment Return the "comment" for the table identified by table_name.
Method get​_table​_names Return a Unicode SHOW TABLES from a given schema.
Method get​_table​_options Undocumented
Method get​_unique​_constraints Return information about unique constraints in table_name.
Method get​_view​_definition Return view definition.
Method get​_view​_names Return a list of all view names available in the database.
Method has​_sequence Check the existence of a particular sequence in the database.
Method has​_table For internal dialect use, check the existence of a particular table in the database.
Method initialize Called during strategized creation of the dialect with a connection.
Method is​_disconnect Return True if the given DB-API error indicates an invalid connection
Method on​_connect return a callable which sets up a newly created DBAPI connection.
Method set​_isolation​_level Given a DBAPI connection, set its isolation level.
Class Variable ​_isolation​_lookup Undocumented
Class Variable construct​_arguments Optional set of argument specifiers for various SQLAlchemy constructs, typically schema items.
Class Variable cte​_follows​_insert Undocumented
Class Variable default​_paramstyle Undocumented
Class Variable inline​_comments Undocumented
Class Variable max​_constraint​_name​_length Undocumented
Class Variable max​_identifier​_length Undocumented
Class Variable max​_index​_name​_length Undocumented
Class Variable name Undocumented
Class Variable sequences​_optional Undocumented
Class Variable supports​_alter Undocumented
Class Variable supports​_comments Undocumented
Class Variable supports​_default​_metavalue dialect supports INSERT... VALUES (DEFAULT) syntax
Class Variable supports​_default​_values dialect supports INSERT... DEFAULT VALUES syntax
Class Variable supports​_multivalues​_insert Undocumented
Class Variable supports​_native​_boolean Undocumented
Class Variable supports​_native​_enum Undocumented
Class Variable supports​_sane​_multi​_rowcount Undocumented
Class Variable supports​_sane​_rowcount Undocumented
Class Variable supports​_statement​_cache indicates if this dialect supports caching.
Instance Variable ​_backslash​_escapes Undocumented
Instance Variable ​_casing Undocumented
Instance Variable ​_connection​_charset Undocumented
Instance Variable ​_json​_deserializer Undocumented
Instance Variable ​_json​_serializer Undocumented
Instance Variable ​_mariadb​_normalized​_version​_info Undocumented
Instance Variable ​_needs​_correct​_for​_88718​_96365 Undocumented
Instance Variable ​_server​_ansiquotes Undocumented
Instance Variable ​_sql​_mode Undocumented
Instance Variable identifier​_preparer Undocumented
Instance Variable is​_mariadb Undocumented
Instance Variable isolation​_level Undocumented
Instance Variable preparer Undocumented
Instance Variable server​_version​_info Undocumented
Instance Variable supports​_for​_update​_of Undocumented
Instance Variable supports​_sequences Undocumented
Property ​_is​_mariadb Undocumented
Property ​_is​_mariadb​_102 Undocumented
Property ​_is​_mysql Undocumented
Property ​_support​_float​_cast Undocumented
Property ​_tabledef​_parser return the MySQLTableDefinitionParser, generate if needed.

Inherited from DefaultDialect:

Class Method get​_pool​_class Undocumented
Class Method load​_provisioning set up the provision.py module for this dialect.
Method connect Establish a connection using this dialect's DBAPI.
Method create​_connect​_args Build DB-API compatible connection arguments.
Method create​_xid Create a random two-phase transaction ID.
Method denormalize​_name convert the given name to a case insensitive identifier for the backend if it is an all-lowercase name.
Method do​_begin Provide an implementation of connection.begin(), given a DB-API connection.
Method do​_close Provide an implementation of connection.close(), given a DBAPI connection.
Method do​_commit Provide an implementation of connection.commit(), given a DB-API connection.
Method do​_execute Provide an implementation of cursor.execute(statement, parameters).
Method do​_execute​_no​_params Provide an implementation of cursor.execute(statement).
Method do​_executemany Provide an implementation of cursor.executemany(statement, parameters).
Method do​_release​_savepoint Release the named savepoint on a connection.
Method do​_rollback Provide an implementation of connection.rollback(), given a DB-API connection.
Method do​_rollback​_to​_savepoint Rollback a connection to the named savepoint.
Method do​_savepoint Create a savepoint with the given name.
Method get​_default​_isolation​_level Given a DBAPI connection, return its isolation level, or a default isolation level if one cannot be retrieved.
Method get​_driver​_connection Returns the connection object as returned by the external driver package.
Method has​_index Check the existence of a particular index name in the database.
Method normalize​_name convert the given name to lowercase if it is detected as case insensitive.
Method reset​_isolation​_level Given a DBAPI connection, revert its isolation to the default.
Method type​_descriptor Provide a database-specific .TypeEngine object, given the generic object which comes from the types module.
Class Variable 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.
Class Variable supports​_empty​_insert dialect supports INSERT () VALUES ()
Instance Variable returns​_unicode​_strings Undocumented
Instance Variable type​_compiler Undocumented
Method ​_check​_max​_identifier​_length Perform a connection / server version specific check to determine the max_identifier_length.
Method ​_check​_unicode​_description Undocumented
Method ​_check​_unicode​_returns Undocumented
Method ​_ensure​_has​_table​_connection Undocumented
Method ​_reset​_characteristics Undocumented
Method ​_set​_connection​_characteristics Undocumented
Method do​_ping Undocumented
Method get​_dialect​_pool​_class Undocumented
Method set​_connection​_execution​_options Undocumented
Method set​_engine​_execution​_options Undocumented
Method validate​_identifier Undocumented
Class Variable colspecs Undocumented
Class Variable connection​_characteristics Undocumented
Class Variable default​_sequence​_base Undocumented
Class Variable engine​_config​_types Undocumented
Class Variable full​_returning Undocumented
Class Variable insert​_executemany​_returning Undocumented
Class Variable is​_async Undocumented
Class Variable non​_native​_boolean​_check​_constraint Undocumented
Class Variable postfetch​_lastrowid Undocumented
Class Variable preexecute​_autoincrement​_sequences Undocumented
Class Variable reflection​_options Undocumented
Class Variable requires​_name​_normalize Undocumented
Class Variable server​_side​_cursors Undocumented
Class Variable supports​_identity​_columns Undocumented
Class Variable supports​_is​_distinct​_from Undocumented
Class Variable supports​_native​_decimal Undocumented
Class Variable supports​_schemas Undocumented
Class Variable supports​_server​_side​_cursors Undocumented
Class Variable supports​_simple​_order​_by​_label Undocumented
Class Variable supports​_unicode​_binds Undocumented
Class Variable supports​_unicode​_statements Undocumented
Class Variable supports​_views Undocumented
Class Variable tuple​_in​_values Undocumented
Class Variable use​_setinputsizes Undocumented
Instance Variable ​_decoder Undocumented
Instance Variable ​_description​_decoder Undocumented
Instance Variable ​_encoder Undocumented
Instance Variable ​_ischema Undocumented
Instance Variable ​_user​_defined​_max​_identifier​_length Undocumented
Instance Variable case​_sensitive Undocumented
Instance Variable compiler​_linting Undocumented
Instance Variable convert​_unicode Undocumented
Instance Variable dbapi Undocumented
Instance Variable default​_isolation​_level Undocumented
Instance Variable default​_schema​_name Undocumented
Instance Variable description​_encoding Undocumented
Instance Variable encoding Undocumented
Instance Variable implicit​_returning Undocumented
Instance Variable label​_length Undocumented
Instance Variable paramstyle Undocumented
Instance Variable positional Undocumented
Property ​_dialect​_specific​_select​_one Undocumented
Property ​_supports​_statement​_cache Undocumented
Property ​_type​_memos Undocumented
Property dialect​_description Undocumented
Property supports​_sane​_rowcount​_returning True if this dialect supports sane rowcount even if RETURNING is in use.

Inherited from Dialect (via DefaultDialect):

Class Method engine​_created A convenience hook called before returning the final _engine.Engine.
Class Method get​_dialect​_cls Given a URL, return the .Dialect that will be used.
Method do​_set​_input​_sizes invoke the cursor.setinputsizes() method with appropriate arguments
Method get​_temp​_table​_names Return a list of temporary table names on the given connection, if supported by the underlying backend.
Method get​_temp​_view​_names Return a list of temporary view names on the given connection, if supported by the underlying backend.
Method on​_connect​_url return a callable which sets up a newly created DBAPI connection.
Class Variable ​_has​_events Undocumented
@classmethod
def _is_mariadb_from_url(cls, url):

Undocumented

def _compat_fetchall(self, rp, charset=None):
Proxy result rows to smooth over MySQL-Python driver inconsistencies.
def _compat_fetchone(self, rp, charset=None):
Proxy a result row to smooth over MySQL-Python driver inconsistencies.
def _compat_first(self, rp, charset=None):
Proxy a result row to smooth over MySQL-Python driver inconsistencies.
def _correct_for_mysql_bugs_88718_96365(self, fkeys, connection):

Undocumented

def _describe_table(self, connection, table, charset=None, full_name=None):
Run DESCRIBE for a Table and return processed rows.
def _detect_ansiquotes(self, connection):
Detect and adjust for the ANSI_QUOTES sql mode.
def _detect_casing(self, connection):

Sniff out identifier case sensitivity.

Cached per-connection. This value can not change without a server restart.

def _detect_collations(self, connection):

Pull the active COLLATIONS list from the server.

Cached per-connection.

def _detect_sql_mode(self, connection):

Undocumented

def _get_default_schema_name(self, connection):

Return the string name of the currently selected schema from the given connection.

This is used by the default implementation to populate the "default_schema_name" attribute and is called exactly once upon first connect.

def _get_server_version_info(self, connection):

Retrieve the server version info from the given connection.

This is used by the default implementation to populate the "server_version_info" attribute and is called exactly once upon first connect.

def _parse_server_version(self, val):

Undocumented

def _parsed_state_or_create(self, connection, table_name, schema=None, **kw):

Undocumented

def _sequences_not_supported(self):

Undocumented

def _set_mariadb(self, is_mariadb, server_version_info):

Undocumented

@reflection.cache
def _setup_parser(self, connection, table_name, schema=None, **kw):

Undocumented

def _show_create_table(self, connection, table, charset=None, full_name=None):
Run SHOW CREATE TABLE for a Table.
def _warn_for_known_db_issues(self):

Undocumented

def do_begin_twophase(self, connection, xid):
Begin a two phase transaction on the given connection.
Parameters
connectiona _engine.Connection.
xidxid
def do_commit_twophase(self, connection, xid, is_prepared=True, recover=False):
Commit a two phase transaction on the given connection.
Parameters
connectiona _engine.Connection.
xidxid
is​_preparedwhether or not .TwoPhaseTransaction.prepare was called.
recoverif the recover flag was passed.
def do_prepare_twophase(self, connection, xid):
Prepare a two phase transaction on the given connection.
Parameters
connectiona _engine.Connection.
xidxid
def do_recover_twophase(self, connection):
Recover list of uncommitted prepared two phase transaction identifiers on the given connection.
Parameters
connectiona _engine.Connection.
def do_rollback_twophase(self, connection, xid, is_prepared=True, recover=False):
Rollback a two phase transaction on the given connection.
Parameters
connectiona _engine.Connection.
xidxid
is​_preparedwhether or not .TwoPhaseTransaction.prepare was called.
recoverif the recover flag was passed.
@reflection.cache
def get_check_constraints(self, 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 name
  • sqltext - the check constraint's SQL expression
  • **kw - other options passed to the dialect's get_check_constraints() method.
New in version 1.1.0.
@reflection.cache
def get_columns(self, connection, table_name, schema=None, **kw):

Return information about columns in table_name.

Given a _engine.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 name
type
[sqlalchemy.types#TypeEngine]
nullable
boolean
default
the column's default value
autoincrement
boolean
sequence
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.

@reflection.cache
def get_foreign_keys(self, connection, table_name, schema=None, **kw):

Return information about foreign_keys in table_name.

Given a _engine.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 name
constrained_columns
a list of column names that make up the foreign key
referred_schema
the name of the referred schema
referred_table
the name of the referred table
referred_columns
a list of column names in the referred table that correspond to constrained_columns
@reflection.cache
def get_indexes(self, connection, table_name, schema=None, **kw):

Return information about indexes in table_name.

Given a _engine.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 name
column_names
list of column names in order
unique
boolean
def get_isolation_level(self, connection):

Given a DBAPI connection, return its isolation level.

When working with a _engine.Connection object, the corresponding DBAPI connection may be procured using the _engine.Connection.connection accessor.

Note that this is a dialect-level method which is used as part of the implementation of the _engine.Connection and _engine.Engine isolation level facilities; these APIs should be preferred for most typical use cases.

See Also

_engine.Connection.get_isolation_level - view current level

_engine.Connection.default_isolation_level - view default level

:paramref:`.Connection.execution_options.isolation_level` - set per _engine.Connection isolation level

:paramref:`_sa.create_engine.isolation_level` - set per _engine.Engine isolation level

@reflection.cache
def get_pk_constraint(self, connection, table_name, schema=None, **kw):

Return information about the primary key constraint on table_name`.

Given a _engine.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 key
name
optional name of the primary key constraint.
@reflection.cache
def get_schema_names(self, connection, **kw):
@reflection.cache
def get_sequence_names(self, connection, schema=None, **kw):

Return a list of all sequence names available in the database.

New in version 1.4.
Parameters
connectionUndocumented
schemaschema name to query, if not the default schema.
**kwUndocumented
@reflection.cache
def get_table_comment(self, 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.
@reflection.cache
def get_table_names(self, connection, schema=None, **kw):
Return a Unicode SHOW TABLES from a given schema.
@reflection.cache
def get_table_options(self, connection, table_name, schema=None, **kw):
@reflection.cache
def get_unique_constraints(self, 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 name
column_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.
@reflection.cache
def get_view_definition(self, connection, view_name, schema=None, **kw):

Return view definition.

Given a _engine.Connection, a string view_name, and an optional string schema, return the view definition.

@reflection.cache
def get_view_names(self, connection, schema=None, **kw):
Return a list of all view names available in the database.
Parameters
connectionUndocumented
schemaschema name to query, if not the default schema.
**kwUndocumented
def has_sequence(self, connection, sequence_name, schema=None):

Check the existence of a particular sequence in the database.

Given a _engine.Connection object and a string sequence_name, return True if the given sequence exists in the database, False otherwise.

def has_table(self, connection, table_name, schema=None):

For internal dialect use, check the existence of a particular table in the database.

Given a _engine.Connection object, a string table_name and optional schema name, return True if the given table exists in the database, False otherwise.

This method serves as the underlying implementation of the public facing .Inspector.has_table method, and is also used internally to implement the "checkfirst" behavior for methods like _schema.Table.create and _schema.MetaData.create_all.

Note

This method is used internally by SQLAlchemy, and is published so that third-party dialects may provide an implementation. It is not the public API for checking for table presence. Please use the .Inspector.has_table method. Alternatively, for legacy cross-compatibility, the _engine.Engine.has_table method may be used.

def initialize(self, 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().

Note

as of SQLAlchemy 1.4, this method is called before any _engine.Dialect.on_connect hooks are called.

def on_connect(self):

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 _events.PoolEvents.connect event hook, then unwrapping the DBAPI connection and passing it into the callable.

Changed in version 1.4: the on_connect hook is no longer called twice for the first connection of a dialect. The on_connect hook is still called before the _engine.Dialect.initialize method however.
Changed in version 1.4.3: the on_connect hook is invoked from a new method on_connect_url that passes the URL that was used to create the connect args. Dialects can implement on_connect_url instead of on_connect if they need the URL object that was used for the connection in order to get additional context.

If None is returned, no event listener is generated.

See Also

.Dialect.connect - allows the DBAPI connect() sequence itself to be controlled.

.Dialect.on_connect_url - supersedes .Dialect.on_connect to also receive the _engine.URL object in context.

Returns
a callable that accepts a single DBAPI connection as an argument, or None.
def set_isolation_level(self, connection, 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 _engine.Connection and _engine.Engine isolation level facilities; these APIs should be preferred for most typical use cases.

See Also

_engine.Connection.get_isolation_level - view current level

_engine.Connection.default_isolation_level - view default level

:paramref:`.Connection.execution_options.isolation_level` - set per _engine.Connection isolation level

:paramref:`_sa.create_engine.isolation_level` - set per _engine.Engine isolation level

construct_arguments =

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

cte_follows_insert: bool =
inline_comments: bool =
max_constraint_name_length: int =
max_identifier_length: int =
max_index_name_length: int =
name: str =
sequences_optional: bool =
supports_alter: bool =
supports_comments: bool =
supports_default_metavalue: bool =
dialect supports INSERT... VALUES (DEFAULT) syntax
supports_default_values: bool =
dialect supports INSERT... DEFAULT VALUES syntax
supports_multivalues_insert: bool =
supports_native_boolean: bool =
supports_native_enum: bool =
supports_statement_cache: bool =

indicates if this dialect supports caching.

All dialects that are compatible with statement caching should set this flag to True directly on each dialect class and subclass that supports it. SQLAlchemy tests that this flag is locally present on each dialect subclass before it will use statement caching. This is to provide safety for legacy or new dialects that are not yet fully tested to be compliant with SQL statement caching.

New in version 1.4.5.
_backslash_escapes =

Undocumented

_casing =

Undocumented

_connection_charset =

Undocumented

_json_deserializer =

Undocumented

_json_serializer =

Undocumented

_mariadb_normalized_version_info =

Undocumented

_needs_correct_for_88718_96365 =

Undocumented

_server_ansiquotes =

Undocumented

_sql_mode: str =

Undocumented

identifier_preparer =
is_mariadb =

Undocumented

isolation_level =
preparer =

Undocumented

server_version_info =
supports_for_update_of =
supports_sequences =
@property
_is_mariadb =

Undocumented

@property
_is_mariadb_102 =

Undocumented

@property
_is_mysql =

Undocumented

@property
_support_float_cast =

Undocumented

@util.memoized_property
_tabledef_parser =

return the MySQLTableDefinitionParser, generate if needed.

The deferred creation ensures that the dialect has retrieved server version information first.