Skip to content

Commit

Permalink
Allow accessing catalog views using TDS Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Feb 27, 2024
1 parent 9ee1297 commit 067c485
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions MarkMpn.Sql4Cds.Engine/Visitors/TDSEndpointCompatibilityVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,27 @@ public TDSEndpointCompatibilityVisitor(IDbConnection con, IAttributeMetadataCach
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
_supportedTables.Add(reader.GetString(0));
_supportedTables.Add("dbo." + reader.GetString(0));
}
}

_supportedTables.Add("sys.all_columns");
_supportedTables.Add("sys.all_objects");
_supportedTables.Add("sys.check_constraints");
_supportedTables.Add("sys.columns");
_supportedTables.Add("sys.computed_columns");
_supportedTables.Add("sys.default_constraints");
_supportedTables.Add("sys.foreign_key_columns");
_supportedTables.Add("sys.foreign_keys");
_supportedTables.Add("sys.index_columns");
_supportedTables.Add("sys.objects");
_supportedTables.Add("sys.sequences");
_supportedTables.Add("sys.sql_modules");
_supportedTables.Add("sys.stats");
_supportedTables.Add("sys.synonyms");
_supportedTables.Add("sys.table_types");
_supportedTables.Add("sys.tables");
_supportedTables.Add("sys.triggers");
}

IsCompatible = true;
Expand All @@ -89,16 +107,15 @@ public override void Visit(TSqlFragment node)
public override void Visit(NamedTableReference node)
{
if (node.SchemaObject.ServerIdentifier != null ||
node.SchemaObject.DatabaseIdentifier != null ||
(!String.IsNullOrEmpty(node.SchemaObject.SchemaIdentifier?.Value) && !node.SchemaObject.SchemaIdentifier.Value.Equals("dbo", StringComparison.OrdinalIgnoreCase)))
node.SchemaObject.DatabaseIdentifier != null)
{
// Can't do cross-instance queries
// No access to metadata schema
IsCompatible = false;
return;
}

if (_supportedTables != null && !_supportedTables.Contains(node.SchemaObject.BaseIdentifier.Value) &&
if (_supportedTables != null && !_supportedTables.Contains((node.SchemaObject.SchemaIdentifier?.Value ?? "dbo") + "." + node.SchemaObject.BaseIdentifier.Value) &&
(node.SchemaObject.Identifiers.Count != 1 || !_ctes.ContainsKey(node.SchemaObject.BaseIdentifier.Value)))
{
// Table does not exist in TDS endpoint and is not defined as a CTE
Expand Down

0 comments on commit 067c485

Please sign in to comment.