summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects/mysql/base.py
diff options
context:
space:
mode:
authorFederico Caselli <cfederico87@gmail.com>2020-08-22 00:30:44 +0200
committerMike Bayer <mike_mp@zzzcomputing.com>2020-08-22 12:46:12 -0400
commit9ab4da7018eae8fc86430c24a38f8ffb0a5951ab (patch)
treed6f9e401cbc24a3beb11a9fec56dd17f89cfe6fe /lib/sqlalchemy/dialects/mysql/base.py
parent317f2e1be2b06cdc12bc84510eb743d9752763dd (diff)
downloadsqlalchemy-9ab4da7018eae8fc86430c24a38f8ffb0a5951ab.tar.gz
Updates for MariaDB sequences
MariaDB should not run a Sequence if it has optional=True. Additionally, rework the rules in crud.py to accommodate the new combination MariaDB brings us, which is a dialect that supports both cursor.lastrowid, explicit sequences, *and* no support for returning. Co-authored-by: Mike Bayer <mike_mp@zzzcomputing.com> Fixes: #5528 Change-Id: I9a8ea69a34983affa95dfd22186e2908fdf0d58c
Diffstat (limited to 'lib/sqlalchemy/dialects/mysql/base.py')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index 1d032b600..46529636d 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -1782,15 +1782,10 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
if not column.nullable:
colspec.append("NOT NULL")
- # see: http://docs.sqlalchemy.org/en/latest/dialects/
- # mysql.html#mysql_timestamp_null
+ # see: http://docs.sqlalchemy.org/en/latest/dialects/mysql.html#mysql_timestamp_null # noqa
elif column.nullable and is_timestamp:
colspec.append("NULL")
- default = self.get_column_default_string(column)
- if default is not None:
- colspec.append("DEFAULT " + default)
-
comment = column.comment
if comment is not None:
literal = self.sql_compiler.render_literal_value(
@@ -1802,9 +1797,17 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
column.table is not None
and column is column.table._autoincrement_column
and column.server_default is None
+ and not (
+ self.dialect.supports_sequences
+ and isinstance(column.default, sa_schema.Sequence)
+ and not column.default.optional
+ )
):
colspec.append("AUTO_INCREMENT")
-
+ else:
+ default = self.get_column_default_string(column)
+ if default is not None:
+ colspec.append("DEFAULT " + default)
return " ".join(colspec)
def post_create_table(self, table):