Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions src/SqlObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ internal class SqlObject
/// </summary>
public readonly string FullName;
/// <summary>
/// The full name of the object in the format 'SCHEMA.NAME' (or just 'NAME' if there is no specified schema), quoted and escaped with single quotes
/// The full name of the object in the format '[SCHEMA].[NAME]' (or just '[NAME]' if there is no specified schema), quoted and escaped with single quotes
/// </summary>
/// <remarks>The schema and name are also bracket quoted to avoid issues when there are .'s in the object names</remarks>
public readonly string QuotedFullName;

/// <summary>
Expand Down Expand Up @@ -73,8 +74,8 @@ public SqlObject(string fullName)
this.Name = visitor.objectName;
this.QuotedName = this.Name.AsSingleQuotedString();
this.FullName = this.Schema == SCHEMA_NAME_FUNCTION ? this.Name : $"{this.Schema}.{this.Name}";
this.QuotedFullName = this.FullName.AsSingleQuotedString();
this.BracketQuotedFullName = this.Schema == SCHEMA_NAME_FUNCTION ? this.Name.AsBracketQuotedString() : $"{this.Schema.AsBracketQuotedString()}.{this.Name.AsBracketQuotedString()}";
this.QuotedFullName = this.BracketQuotedFullName.AsSingleQuotedString();
}

/// <summary>
Expand Down
14 changes: 7 additions & 7 deletions test/Unit/SqlOutputBindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public async Task TestAddAsync()
}

[Theory]
[InlineData("dbo.Products", "dbo", "'dbo'", "Products", "'Products'", "dbo.Products", "'dbo.Products'", "[dbo].[Products]")] // Simple full name
[InlineData("Products", "SCHEMA_NAME()", "SCHEMA_NAME()", "Products", "'Products'", "Products", "'Products'", "[Products]")] // Simple no schema
[InlineData("[dbo].[Products]", "dbo", "'dbo'", "Products", "'Products'", "dbo.Products", "'dbo.Products'", "[dbo].[Products]")] // Simple full name bracket quoted
[InlineData("[dbo].Products", "dbo", "'dbo'", "Products", "'Products'", "dbo.Products", "'dbo.Products'", "[dbo].[Products]")] // Simple full name only schema bracket quoted
[InlineData("dbo.[Products]", "dbo", "'dbo'", "Products", "'Products'", "dbo.Products", "'dbo.Products'", "[dbo].[Products]")] // Simple full name only name bracket quoted
[InlineData("[My'Schema].[Prod'ucts]", "My'Schema", "'My''Schema'", "Prod'ucts", "'Prod''ucts'", "My'Schema.Prod'ucts", "'My''Schema.Prod''ucts'", "[My'Schema].[Prod'ucts]")] // Full name with single quotes in schema and name
[InlineData("[My]]Schema].[My]]Object]", "My]Schema", "'My]Schema'", "My]Object", "'My]Object'", "My]Schema.My]Object", "'My]Schema.My]Object'", "[My]]Schema].[My]]Object]")] // Full name with brackets in schema and name
[InlineData("dbo.Products", "dbo", "'dbo'", "Products", "'Products'", "dbo.Products", "'[dbo].[Products]'", "[dbo].[Products]")] // Simple full name
[InlineData("Products", "SCHEMA_NAME()", "SCHEMA_NAME()", "Products", "'Products'", "Products", "'[Products]'", "[Products]")] // Simple no schema
[InlineData("[dbo].[Products]", "dbo", "'dbo'", "Products", "'Products'", "dbo.Products", "'[dbo].[Products]'", "[dbo].[Products]")] // Simple full name bracket quoted
[InlineData("[dbo].Products", "dbo", "'dbo'", "Products", "'Products'", "dbo.Products", "'[dbo].[Products]'", "[dbo].[Products]")] // Simple full name only schema bracket quoted
[InlineData("dbo.[Products]", "dbo", "'dbo'", "Products", "'Products'", "dbo.Products", "'[dbo].[Products]'", "[dbo].[Products]")] // Simple full name only name bracket quoted
[InlineData("[My'Schema].[Prod'ucts]", "My'Schema", "'My''Schema'", "Prod'ucts", "'Prod''ucts'", "My'Schema.Prod'ucts", "'[My''Schema].[Prod''ucts]'", "[My'Schema].[Prod'ucts]")] // Full name with single quotes in schema and name
[InlineData("[My]]Schema].[My]]Object]", "My]Schema", "'My]Schema'", "My]Object", "'My]Object'", "My]Schema.My]Object", "'[My]]Schema].[My]]Object]'", "[My]]Schema].[My]]Object]")] // Full name with brackets in schema and name
public void TestSqlObject(string fullName,
string expectedSchema,
string expectedQuotedSchema,
Expand Down