From: Zhong Zheng Date: Fri, 16 Feb 2024 17:20:59 +0000 (-0500) Subject: Fix mysql dialect text docstring, length is interpreted as byte size X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c58fe53b6fd069cbb82955ddaf9eb5405076146;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix mysql dialect text docstring, length is interpreted as byte size ### Description The `Text` and its variant types in MySQL are bytes size limited, not character length, so fixing the doctoring where the upper limit uses the `characters` as the unit instead of `bytes` https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html Screenshot 2024-02-15 at 17 27 59 ### Checklist This pull request is: - [x] A documentation / typographical / small typing error fix - Good to go, no issue or tests are needed - [ ] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #11018 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11018 Pull-request-sha: 13fa52917efea9a229c7abf19a3be40e24a79cb9 Change-Id: Iea903a6dc4b52ee4b7b5d2d64256c69abbd1f8aa --- diff --git a/lib/sqlalchemy/dialects/mysql/types.py b/lib/sqlalchemy/dialects/mysql/types.py index f563ead357..734f6ae372 100644 --- a/lib/sqlalchemy/dialects/mysql/types.py +++ b/lib/sqlalchemy/dialects/mysql/types.py @@ -499,7 +499,7 @@ class YEAR(sqltypes.TypeEngine): class TEXT(_StringType, sqltypes.TEXT): - """MySQL TEXT type, for text up to 2^16 characters.""" + """MySQL TEXT type, for character storage encoded up to 2^16 bytes.""" __visit_name__ = "TEXT" @@ -508,7 +508,7 @@ class TEXT(_StringType, sqltypes.TEXT): :param length: Optional, if provided the server may optimize storage by substituting the smallest TEXT type sufficient to store - ``length`` characters. + ``length`` bytes of characters. :param charset: Optional, a column-level character set for this string value. Takes precedence to 'ascii' or 'unicode' short-hand. @@ -535,7 +535,7 @@ class TEXT(_StringType, sqltypes.TEXT): class TINYTEXT(_StringType): - """MySQL TINYTEXT type, for text up to 2^8 characters.""" + """MySQL TINYTEXT type, for character storage encoded up to 2^8 bytes.""" __visit_name__ = "TINYTEXT" @@ -567,7 +567,8 @@ class TINYTEXT(_StringType): class MEDIUMTEXT(_StringType): - """MySQL MEDIUMTEXT type, for text up to 2^24 characters.""" + """MySQL MEDIUMTEXT type, for character storage encoded up + to 2^24 bytes.""" __visit_name__ = "MEDIUMTEXT" @@ -599,7 +600,7 @@ class MEDIUMTEXT(_StringType): class LONGTEXT(_StringType): - """MySQL LONGTEXT type, for text up to 2^32 characters.""" + """MySQL LONGTEXT type, for character storage encoded up to 2^32 bytes.""" __visit_name__ = "LONGTEXT" @@ -683,7 +684,7 @@ class CHAR(_StringType, sqltypes.CHAR): super().__init__(length=length, **kwargs) @classmethod - def _adapt_string_for_cast(self, type_): + def _adapt_string_for_cast(cls, type_): # copy the given string type into a CHAR # for the purposes of rendering a CAST expression type_ = sqltypes.to_instance(type_)