Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update mssql extractor to utilize proper case for case sensitive MSSQL databases #2234

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions databuilder/databuilder/extractor/mssql_metadata_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,32 @@ class MSSQLMetadataExtractor(Extractor):
# SELECT statement from MS SQL to extract table and column metadata
SQL_STATEMENT = """
SELECT DISTINCT
{cluster_source} AS cluster,
{cluster_source} AS [cluster],
TBL.TABLE_SCHEMA AS [schema_name],
TBL.TABLE_NAME AS [name],
CAST(PROP.VALUE AS NVARCHAR(MAX)) AS [description],
CAST(PROP.value AS NVARCHAR(MAX)) AS [description],
COL.COLUMN_NAME AS [col_name],
COL.DATA_TYPE AS [col_type],
CAST(PROP_COL.VALUE AS NVARCHAR(MAX)) AS [col_description],
COL.ORDINAL_POSITION AS col_sort_order
CAST(PROP_COL.value AS NVARCHAR(MAX)) AS [col_description],
COL.ORDINAL_POSITION AS [col_sort_order]
FROM INFORMATION_SCHEMA.TABLES TBL
INNER JOIN INFORMATION_SCHEMA.COLUMNS COL
ON (COL.TABLE_NAME = TBL.TABLE_NAME
AND COL.TABLE_SCHEMA = TBL.TABLE_SCHEMA )
LEFT JOIN SYS.EXTENDED_PROPERTIES PROP
ON (PROP.MAJOR_ID = OBJECT_ID(TBL.TABLE_SCHEMA + '.' + TBL.TABLE_NAME)
AND PROP.MINOR_ID = 0
AND PROP.NAME = 'MS_Description')
LEFT JOIN SYS.EXTENDED_PROPERTIES PROP_COL
ON (PROP_COL.MAJOR_ID = OBJECT_ID(TBL.TABLE_SCHEMA + '.' + TBL.TABLE_NAME)
AND PROP_COL.MINOR_ID = COL.ORDINAL_POSITION
AND PROP_COL.NAME = 'MS_Description')
WHERE TBL.TABLE_TYPE = 'base table' {where_clause_suffix}
LEFT JOIN sys.extended_properties PROP
ON (PROP.major_id = OBJECT_ID(TBL.TABLE_SCHEMA + '.' + TBL.TABLE_NAME)
AND PROP.minor_id = 0
AND PROP.name = 'MS_Description')
LEFT JOIN sys.extended_properties PROP_COL
ON (PROP_COL.major_id = OBJECT_ID(TBL.TABLE_SCHEMA + '.' + TBL.TABLE_NAME)
AND PROP_COL.minor_id = COL.ORDINAL_POSITION
AND PROP_COL.name = 'MS_Description')
WHERE TBL.TABLE_TYPE = 'BASE TABLE' {where_clause_suffix}
ORDER BY
CLUSTER,
SCHEMA_NAME,
NAME,
COL_SORT_ORDER
cluster,
schema_name,
name,
col_sort_order
;
"""

Expand Down
Loading