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

Reverse engineering of Dynamics CRM TDS endpoint and Synapse Serverless SQL Pool #29122

Merged
merged 8 commits into from
Nov 20, 2022
Merged
Changes from 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ FROM [sys].[views] AS [v]
WHERE "
+ viewFilter;

command.CommandText = commandText + viewCommandText;
command.CommandText = SupportsViews() ? commandText + viewCommandText : commandText;

using (var reader = command.ExecuteReader())
{
Expand Down Expand Up @@ -646,7 +646,12 @@ FROM [sys].[views] AS [v]

// This is done separately due to MARS property may be turned off
GetColumns(connection, tables, filter, viewFilter, typeAliases, databaseCollation);
GetIndexes(connection, tables, filter);

if (SupportsIndexes())
{
GetIndexes(connection, tables, filter);
}

GetForeignKeys(connection, tables, filter);
GetTriggers(connection, tables, filter);

Expand Down Expand Up @@ -685,14 +690,19 @@ private void GetColumns(
[c].[collation_name],
[c].[is_sparse]
FROM
(
(";
if (SupportsViewsAndIndexes())
{
commandText += @"
SELECT[v].[name], [v].[object_id], [v].[schema_id]
FROM [sys].[views] v WHERE ";

commandText += viewFilter;
commandText += viewFilter;

commandText += @"
UNION ALL";
}
commandText += @"
UNION ALL
SELECT [t].[name], [t].[object_id], [t].[schema_id]
FROM [sys].[tables] t WHERE ";

Expand Down Expand Up @@ -1156,14 +1166,17 @@ private void GetForeignKeys(DbConnection connection, IReadOnlyList<DatabaseTable
SCHEMA_NAME([t].[schema_id]) AS [table_schema],
[t].[name] AS [table_name],
[f].[name],
OBJECT_SCHEMA_NAME([f].[referenced_object_id]) AS [principal_table_schema],
OBJECT_NAME([f].[referenced_object_id]) AS [principal_table_name],
[f].[delete_referential_action_desc],
col_name([fc].[parent_object_id], [fc].[parent_column_id]) AS [column_name],
col_name([fc].[referenced_object_id], [fc].[referenced_column_id]) AS [referenced_column_name]
FROM [sys].[foreign_keys] AS [f]
JOIN [sys].[tables] AS [t] ON [f].[parent_object_id] = [t].[object_id]
JOIN [sys].[foreign_key_columns] AS [fc] ON [f].[object_id] = [fc].[constraint_object_id]
SCHEMA_NAME(tab2.[schema_id]) AS [principal_table_schema],
[tab2].name AS [principal_table_name],
[f].[delete_referential_action_desc],
[col1].[name] AS [column_name],
[col2].[name] AS [referenced_column_name]
FROM [sys].[foreign_keys] AS [f]
ErikEJ marked this conversation as resolved.
Show resolved Hide resolved
JOIN [sys].[foreign_key_columns] AS fc ON [fc].[constraint_object_id] = [f].[object_id]
JOIN [sys].[tables] AS [t] ON [t].[object_id] = [fc].[parent_object_id]
JOIN [sys].[columns] AS [col1] ON [col1].[column_id] = [fc].[parent_column_id] AND [col1].[object_id] = [t].[object_id]
JOIN [sys].[tables] AS [tab2] ON [tab2].[object_id] = [fc].[referenced_object_id]
JOIN [sys].[columns] AS [col2] ON [col2].[column_id] = [fc].[referenced_column_id] AND [col2].[object_id] = [tab2].[object_id]
WHERE "
+ tableFilter
+ @"
Expand Down Expand Up @@ -1335,13 +1348,19 @@ FROM [sys].[triggers] AS [tr]
}

private bool SupportsTemporalTable()
=> _compatibilityLevel >= 130 && _engineEdition != 6;
=> _compatibilityLevel >= 130 && (_engineEdition is not 6 and not 11 and not 1000);

private bool SupportsMemoryOptimizedTable()
=> _compatibilityLevel >= 120 && _engineEdition != 6;
=> _compatibilityLevel >= 120 && (_engineEdition is not 6 and not 11 and not 1000);

private bool SupportsSequences()
=> _compatibilityLevel >= 110 && _engineEdition != 6;
=> _compatibilityLevel >= 110 && (_engineEdition is not 6 and not 11 and not 1000);

private bool SupportsIndexes()
=> _engineEdition != 1000;

private bool SupportsViews()
=> _engineEdition != 1000;

private static string DisplayName(string? schema, string name)
=> (!string.IsNullOrEmpty(schema) ? schema + "." : "") + name;
Expand Down