From: Mike Bayer Date: Fri, 19 Aug 2022 13:49:25 +0000 (-0400) Subject: fix some inaccuracies in with_variant doc X-Git-Tag: rel_1_4_41~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0c5709b43376ebfa2179edf0f9e7af61354c360;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix some inaccuracies in with_variant doc * the table wont create on mysql/mariadb b.c. user_name had no length * "utf-8" is not recognized by mysql/mariadb, use "utf8" * mysql or mariadb name match is determined by the URL, not the actual DB that is detected (I know I made it work that way but I forgot) * for the 1.4 backport only, will remove the "mariadb" part as we dont support that API, #8408 Fixes: #8408 Change-Id: I5b0a58a3f94a3450631e2405bd07d0a77599ae26 (cherry picked from commit 7f99c4ab55a80ee428b3466e9fa476d6ea03bfaf) --- diff --git a/doc/build/core/type_basics.rst b/doc/build/core/type_basics.rst index eb6c879125..49fc715f06 100644 --- a/doc/build/core/type_basics.rst +++ b/doc/build/core/type_basics.rst @@ -139,7 +139,7 @@ makes use of the :meth:`_types.TypeEngine.with_variant` method in order to Such as, to use the :class:`_types.String` datatype, but when running on MySQL to make use of the :paramref:`_mysql.VARCHAR.charset` parameter of -:class:`_mysql.VARCHAR` when the table is created on MySQL or MariaDB, +:class:`_mysql.VARCHAR` when the table is created on MySQL, :meth:`_types.TypeEngine.with_variant` may be used as below:: from sqlalchemy import MetaData @@ -151,16 +151,17 @@ to make use of the :paramref:`_mysql.VARCHAR.charset` parameter of user = Table( "user", metadata_obj, - Column("user_name", String, primary_key=True), + Column("user_name", String(100), primary_key=True), Column( "bio", - String(255).with_variant(VARCHAR(255, charset="utf-8"), "mysql", "mariadb"), + String(255).with_variant(VARCHAR(255, charset="utf8"), "mysql"), ), ) In the above table definition, the ``"bio"`` column will have string-behaviors -on all backends. On most backends it will render in DDL as ``VARCHAR``. -However on MySQL and MariaDB, it will render as ``VARCHAR(255) CHARACTER SET utf-8``. +on all backends. On most backends it will render in DDL as ``VARCHAR``. However +on MySQL (indicated by database URLs that start with ``mysql``), it will +render as ``VARCHAR(255) CHARACTER SET utf8``. .. seealso::