diff options
author | Daniel Hall <daniel.hall@moesol.com> | 2022-07-30 15:12:20 -0400 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2022-08-10 21:11:59 +0200 |
commit | ddbd9dafffdedf6fb464947394c81c8b02153e14 (patch) | |
tree | 20a0e23fb1058d0b21a462772e91cf217dbd80ea /lib/sqlalchemy/dialects/mssql/information_schema.py | |
parent | c4b7f1f7c9745a72f22886e6ca487f3c631a20f5 (diff) | |
download | sqlalchemy-ddbd9dafffdedf6fb464947394c81c8b02153e14.tar.gz |
Support comments on MSSQL
Added support table and column comments on MSSQL when
creating a table. Added support for reflecting table comments.
Thanks to Daniel Hall for the help in this pull request.
Fixes: #7844
Closes: #8225
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8225
Pull-request-sha: 540f4eb6395f9feed4b4240e3d22f539021948e9
Change-Id: I69f48c6dda4e00ec3d82fdeff13f3df9d735b7b0
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/information_schema.py')
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/information_schema.py | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/information_schema.py b/lib/sqlalchemy/dialects/mssql/information_schema.py index b7e560bf1..33ab1f992 100644 --- a/lib/sqlalchemy/dialects/mssql/information_schema.py +++ b/lib/sqlalchemy/dialects/mssql/information_schema.py @@ -6,7 +6,6 @@ # the MIT License: https://www.opensource.org/licenses/mit-license.php # mypy: ignore-errors - from ... import cast from ... import Column from ... import MetaData @@ -16,6 +15,7 @@ from ...sql import expression from ...types import Boolean from ...types import Integer from ...types import Numeric +from ...types import NVARCHAR from ...types import String from ...types import TypeDecorator from ...types import Unicode @@ -198,7 +198,7 @@ sequences = Table( ) -class IdentitySqlVariant(TypeDecorator): +class NumericSqlVariant(TypeDecorator): r"""This type casts sql_variant columns in the identity_columns view to numeric. This is required because: @@ -220,9 +220,34 @@ identity_columns = Table( Column("object_id", Integer), Column("name", CoerceUnicode), Column("is_identity", Boolean), - Column("seed_value", IdentitySqlVariant), - Column("increment_value", IdentitySqlVariant), - Column("last_value", IdentitySqlVariant), + Column("seed_value", NumericSqlVariant), + Column("increment_value", NumericSqlVariant), + Column("last_value", NumericSqlVariant), Column("is_not_for_replication", Boolean), schema="sys", ) + + +class NVarcharSqlVariant(TypeDecorator): + """This type casts sql_variant columns in the extended_properties view + to nvarchar. This is required because pyodbc does not support sql_variant + """ + + impl = Unicode + cache_ok = True + + def column_expression(self, colexpr): + return cast(colexpr, NVARCHAR) + + +extended_properties = Table( + "extended_properties", + ischema, + Column("class", Integer), # TINYINT + Column("class_desc", CoerceUnicode), + Column("major_id", Integer), + Column("minor_id", Integer), + Column("name", CoerceUnicode), + Column("value", NVarcharSqlVariant), + schema="sys", +) |