summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authorJ. Nick Koston <nick@koston.org>2023-03-25 22:00:25 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2023-03-27 14:43:57 -0400
commit348d76072c108e996baf59900fc45468f48c4cce (patch)
tree15c7af506778c99915032a904f723d20a5c4e6ee /lib/sqlalchemy/dialects
parentc7ce7ff0225fe0ddaf63f0706429b885410de365 (diff)
downloadsqlalchemy-348d76072c108e996baf59900fc45468f48c4cce.tar.gz
Fix creating zero length char with MySQL dialect
Fixed issue where string datatypes such as :class:`.CHAR`, :class:`.VARCHAR`, :class:`.TEXT`, as well as binary :class:`.BLOB`, could not be produced with an explicit length of zero, which has special meaning for MySQL. Pull request courtesy J. Nick Koston. Fixes: #9544 Closes: #9543 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9543 Pull-request-sha: dc17fc3e93f0ba90881c4efb06016ddf83c7af8b Change-Id: I96925d45f16887f5dfd68a5d4f9284b3abc46d25
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index ebef48a77..387b0141c 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -2252,7 +2252,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
return "YEAR(%s)" % type_.display_width
def visit_TEXT(self, type_, **kw):
- if type_.length:
+ if type_.length is not None:
return self._extend_string(type_, {}, "TEXT(%d)" % type_.length)
else:
return self._extend_string(type_, {}, "TEXT")
@@ -2267,7 +2267,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
return self._extend_string(type_, {}, "LONGTEXT")
def visit_VARCHAR(self, type_, **kw):
- if type_.length:
+ if type_.length is not None:
return self._extend_string(type_, {}, "VARCHAR(%d)" % type_.length)
else:
raise exc.CompileError(
@@ -2275,7 +2275,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
)
def visit_CHAR(self, type_, **kw):
- if type_.length:
+ if type_.length is not None:
return self._extend_string(
type_, {}, "CHAR(%(length)s)" % {"length": type_.length}
)
@@ -2285,7 +2285,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
def visit_NVARCHAR(self, type_, **kw):
# We'll actually generate the equiv. "NATIONAL VARCHAR" instead
# of "NVARCHAR".
- if type_.length:
+ if type_.length is not None:
return self._extend_string(
type_,
{"national": True},
@@ -2299,7 +2299,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
def visit_NCHAR(self, type_, **kw):
# We'll actually generate the equiv.
# "NATIONAL CHAR" instead of "NCHAR".
- if type_.length:
+ if type_.length is not None:
return self._extend_string(
type_,
{"national": True},
@@ -2327,7 +2327,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
return self._visit_enumerated_values("ENUM", type_, type_.enums)
def visit_BLOB(self, type_, **kw):
- if type_.length:
+ if type_.length is not None:
return "BLOB(%d)" % type_.length
else:
return "BLOB"