@@ -27,6 +27,36 @@ public void AppendTableName(string? schema, string table, string expectedFullNam
2727 Assert . Equal ( expectedFullName , result . ToString ( ) ) ;
2828 }
2929
30+ [ Theory ]
31+ [ InlineData ( "schema" , "name" , "[schema].[name]" ) ]
32+ [ InlineData ( null , "name" , "[name]" ) ]
33+ [ InlineData ( "schema" , "it's" , "[schema].[it''s]" ) ]
34+ [ InlineData ( "it's" , "name" , "[it''s].[name]" ) ]
35+ [ InlineData ( "it's" , "it's" , "[it''s].[it''s]" ) ]
36+ [ InlineData ( null , "it's" , "[it''s]" ) ]
37+ [ InlineData ( "schema" , "[brackets]" , "[schema].[[brackets]]]" ) ]
38+ public void AppendTableNameInsideLiteral ( string ? schema , string table , string expectedFullName )
39+ {
40+ StringBuilder result = new ( ) ;
41+
42+ SqlServerCommandBuilder . AppendTableNameInsideLiteral ( result , schema , table ) ;
43+
44+ Assert . Equal ( expectedFullName , result . ToString ( ) ) ;
45+ }
46+
47+ [ Theory ]
48+ [ InlineData ( "name" , "[name]" ) ]
49+ [ InlineData ( "it's" , "[it''s]" ) ]
50+ [ InlineData ( "two''quotes" , "[two''''quotes]" ) ]
51+ public void AppendIdentifierInsideLiteral ( string identifier , string expected )
52+ {
53+ StringBuilder result = new ( ) ;
54+
55+ SqlServerCommandBuilder . AppendIdentifierInsideLiteral ( result , identifier ) ;
56+
57+ Assert . Equal ( expected , result . ToString ( ) ) ;
58+ }
59+
3060 [ Theory ]
3161 [ InlineData ( "name" , "@name_" ) ] // typical name
3262 [ InlineData ( "na me" , "@na_" ) ] // contains a whitespace, an illegal parameter name character
@@ -149,6 +179,34 @@ PRIMARY KEY ([id])
149179 Assert . Equal ( expectedCommand , command . CommandText , ignoreLineEndingDifferences : true ) ;
150180 }
151181
182+ [ Fact ]
183+ public void CreateTable_WithSingleQuoteInName ( )
184+ {
185+ var model = BuildModel (
186+ [
187+ new VectorStoreKeyProperty ( "id" , typeof ( long ) ) ,
188+ new VectorStoreDataProperty ( "name" , typeof ( string ) ) ,
189+ ] ) ;
190+
191+ using SqlConnection connection = CreateConnection ( ) ;
192+
193+ var commands = SqlServerCommandBuilder . CreateTable ( connection , "it's" , "ta'ble" , ifNotExists : true , model ) ;
194+
195+ var command = Assert . Single ( commands ) ;
196+ Assert . Equal (
197+ "IF OBJECT_ID(N'[it''s].[ta''ble]', N'U') IS NULL" + Environment . NewLine +
198+ """
199+ BEGIN
200+ CREATE TABLE [it's].[ta'ble] (
201+ [id] BIGINT IDENTITY,
202+ [name] NVARCHAR(MAX),
203+ PRIMARY KEY ([id])
204+ );
205+ END;
206+ """ ,
207+ command . CommandText , ignoreLineEndingDifferences : true ) ;
208+ }
209+
152210 [ Fact ]
153211 public void CreateTable_WithDiskAnnIndex ( )
154212 {
0 commit comments