File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed
Filter options
src/Npgsql/Internal/Postgres Expand file tree Collapse file tree 3 files changed +34
-4
lines changed
Original file line number Diff line number Diff line change @@ -127,12 +127,14 @@ public static DataTypeName FromDisplayName(string displayName, string? schema =
127
127
// There is one exception and that's array syntax, which is always resolvable in both ways, while we want the canonical name.
128
128
var schemaEndIndex = displayNameSpan . IndexOf ( '.' ) ;
129
129
if ( schemaEndIndex is not - 1 &&
130
+ string . IsNullOrEmpty ( schema ) &&
130
131
! displayNameSpan . Slice ( schemaEndIndex ) . StartsWith ( "_" . AsSpan ( ) , StringComparison . Ordinal ) &&
131
132
! displayNameSpan . EndsWith ( "[]" . AsSpan ( ) , StringComparison . Ordinal ) )
132
133
return new ( displayName ) ;
133
134
134
135
// First we strip the schema to get the type name.
135
- if ( schemaEndIndex is not - 1 )
136
+ if ( schemaEndIndex is not - 1 &&
137
+ string . IsNullOrEmpty ( schema ) )
136
138
{
137
139
schema = displayNameSpan . Slice ( 0 , schemaEndIndex ) . ToString ( ) ;
138
140
displayNameSpan = displayNameSpan . Slice ( schemaEndIndex + 1 ) ;
Original file line number Diff line number Diff line change @@ -201,7 +201,10 @@ internal static async Task<T> AssertTypeReadCore<T>(
201
201
if ( dotIndex > - 1 && dataTypeName . Substring ( 0 , dotIndex ) is "pg_catalog" or "public" )
202
202
dataTypeName = dataTypeName . Substring ( dotIndex + 1 ) ;
203
203
204
- Assert . That ( dataTypeName , Is . EqualTo ( pgTypeName ) ,
204
+ // For composite type with dots, postgres works only with quoted name - scheme."My.type.name"
205
+ // but npgsql converts it to name without quotes
206
+ var pgTypeNameWithoutQuotes = dataTypeName . Replace ( "\" " , string . Empty ) ;
207
+ Assert . That ( dataTypeName , Is . EqualTo ( pgTypeNameWithoutQuotes ) ,
205
208
$ "Got wrong result from GetDataTypeName when reading '{ truncatedSqlLiteral } '") ;
206
209
207
210
if ( isDefault )
@@ -300,9 +303,12 @@ internal static async Task AssertTypeWriteCore<T>(
300
303
}
301
304
302
305
// With data type name
303
- p = new NpgsqlParameter { Value = valueFactory ( ) , DataTypeName = pgTypeNameWithoutFacets } ;
306
+ // For composite type with dots in name, Postgresql returns name with quotes - scheme."My.type.name"
307
+ // but for npgsql mapping we should use names without quotes - scheme.My.type.name
308
+ var pgTypeNameWithoutFacetsAndDots = pgTypeNameWithoutFacets . Replace ( "\" " , string . Empty ) ;
309
+ p = new NpgsqlParameter { Value = valueFactory ( ) , DataTypeName = pgTypeNameWithoutFacetsAndDots } ;
304
310
cmd . Parameters . Add ( p ) ;
305
- errorIdentifier [ ++ errorIdentifierIndex ] = $ "DataTypeName={ pgTypeNameWithoutFacets } ";
311
+ errorIdentifier [ ++ errorIdentifierIndex ] = $ "DataTypeName={ pgTypeNameWithoutFacetsAndDots } ";
306
312
CheckInference ( ) ;
307
313
308
314
// With DbType
Original file line number Diff line number Diff line change @@ -201,6 +201,28 @@ await AssertType(
201
201
isDefaultForWriting : true ) ;
202
202
}
203
203
204
+ [ Test , IssueLink ( "https://github.com/npgsql/npgsql/issues/5972" ) ]
205
+ public async Task With_schema_and_dots_in_type_name ( )
206
+ {
207
+ await using var adminConnection = await OpenConnectionAsync ( ) ;
208
+ var schema = await CreateTempSchema ( adminConnection ) ;
209
+ var typename = "Some.Composite.with.dots" ;
210
+
211
+ await adminConnection . ExecuteNonQueryAsync ( $ "CREATE TYPE { schema } .\" { typename } \" AS (x int, some_text text)") ;
212
+
213
+ var dataSourceBuilder = CreateDataSourceBuilder ( ) ;
214
+ dataSourceBuilder . MapComposite < SomeComposite > ( $ "{ schema } .{ typename } ") ;
215
+ await using var dataSource = dataSourceBuilder . Build ( ) ;
216
+ await using var connection = await dataSource . OpenConnectionAsync ( ) ;
217
+
218
+ await AssertType (
219
+ connection ,
220
+ new SomeComposite { SomeText = "foobar" , X = 10 } ,
221
+ "(10,foobar)" ,
222
+ $ "{ schema } .\" { typename } \" ",
223
+ npgsqlDbType : null ) ;
224
+ }
225
+
204
226
[ Test ]
205
227
public async Task Struct ( )
206
228
{
You can’t perform that action at this time.
0 commit comments