File tree Expand file tree Collapse file tree 5 files changed +25
-13
lines changed
src/ProgressOnderwijsUtils
test/ProgressOnderwijsUtils.Tests Expand file tree Collapse file tree 5 files changed +25
-13
lines changed Original file line number Diff line number Diff line change 11<Project Sdk =" Microsoft.NET.Sdk" >
22 <Import Project =" ..\NugetPackagesCommon.props" />
33 <PropertyGroup Label =" Configuration" >
4- <Version >107.1 .0</Version >
5- <PackageReleaseNotes >DatabaseDescription.TryGetViewByName utility method added.</PackageReleaseNotes >
4+ <Version >108.0 .0</Version >
5+ <PackageReleaseNotes >Renamed DbQualifiedNameUtils to object names instead of table names; added QualifiedObjectName function .</PackageReleaseNotes >
66 <Title >ProgressOnderwijsUtils</Title >
77 <Description >Collection of utilities developed by ProgressOnderwijs</Description >
88 <PackageTags >ProgressOnderwijs</PackageTags >
Original file line number Diff line number Diff line change @@ -286,7 +286,7 @@ public string SchemaName
286286 => DbQualifiedNameUtils . SchemaFromQualifiedName ( QualifiedName ) ;
287287
288288 public string UnqualifiedName
289- => DbQualifiedNameUtils . UnqualifiedTableName ( QualifiedName ) ;
289+ => DbQualifiedNameUtils . UnqualifiedObjectName ( QualifiedName ) ;
290290
291291 public ParameterizedSql QualifiedNameSql
292292 => ParameterizedSql . RawSql_PotentialForSqlInjection ( QualifiedName ) ;
@@ -332,7 +332,7 @@ public string SchemaName
332332 => DbQualifiedNameUtils . SchemaFromQualifiedName ( QualifiedName ) ;
333333
334334 public string UnqualifiedName
335- => DbQualifiedNameUtils . UnqualifiedTableName ( QualifiedName ) ;
335+ => DbQualifiedNameUtils . UnqualifiedObjectName ( QualifiedName ) ;
336336
337337 public ParameterizedSql QualifiedNameSql
338338 => ParameterizedSql . RawSql_PotentialForSqlInjection ( QualifiedName ) ;
Original file line number Diff line number Diff line change @@ -2,14 +2,17 @@ namespace ProgressOnderwijsUtils.SchemaReflection;
22
33public static class DbQualifiedNameUtils
44{
5- public static string UnqualifiedTableName ( string table )
6- => table [ ( table . IndexOf ( '.' ) + 1 ) .. ] ;
5+ public static string QualifiedObjectName ( string schema , string unqualifiedName )
6+ => $ " { schema } . { unqualifiedName } " ;
77
8- public static ParameterizedSql UnqualifiedTableName ( ParameterizedSql table )
9- => ParameterizedSql . UnescapedSqlIdentifier ( UnqualifiedTableName ( table . CommandText ( ) ) ) ;
8+ public static string UnqualifiedObjectName ( string qualifiedName )
9+ => qualifiedName [ ( qualifiedName . IndexOf ( '.' ) + 1 ) .. ] ;
1010
11- public static bool IsNameInSchema ( string tabel , string schema )
12- => tabel . StartsWith ( $ "{ schema } .", StringComparison . OrdinalIgnoreCase ) ;
11+ public static ParameterizedSql UnqualifiedObjectName ( ParameterizedSql qualifiedName )
12+ => ParameterizedSql . UnescapedSqlIdentifier ( UnqualifiedObjectName ( qualifiedName . CommandText ( ) ) ) ;
13+
14+ public static bool IsNameInSchema ( string qualifiedName , string schema )
15+ => qualifiedName . StartsWith ( $ "{ schema } .", StringComparison . OrdinalIgnoreCase ) ;
1316
1417 public static string SchemaFromQualifiedName ( string qualifiedName )
1518 => qualifiedName [ ..qualifiedName . IndexOf ( '.' ) ] ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ public static DataTable ToEmptyDataTable(this DatabaseDescription.Table tableDes
77
88 public static DataTable ToEmptyDataTable ( this IEnumerable < IDbColumn > columns , string qualifiedTableName )
99 {
10- var table = new DataTable ( DbQualifiedNameUtils . UnqualifiedTableName ( qualifiedTableName ) , DbQualifiedNameUtils . SchemaFromQualifiedName ( qualifiedTableName ) ) ;
10+ var table = new DataTable ( DbQualifiedNameUtils . UnqualifiedObjectName ( qualifiedTableName ) , DbQualifiedNameUtils . SchemaFromQualifiedName ( qualifiedTableName ) ) ;
1111 table . Columns . AddRange ( columns . Select ( col => col . ToDataColumn ( ) ) . ToArray ( ) ) ;
1212 return table ;
1313 }
Original file line number Diff line number Diff line change @@ -4,11 +4,11 @@ public sealed class DbQualifiedNameUtilsTest
44{
55 [ Fact ]
66 public void SupportsUnqualifiedNames ( )
7- => PAssert . That ( ( ) => "bla" == DbQualifiedNameUtils . UnqualifiedTableName ( "bla" ) ) ;
7+ => PAssert . That ( ( ) => "bla" == DbQualifiedNameUtils . UnqualifiedObjectName ( "bla" ) ) ;
88
99 [ Fact ]
1010 public void SupportsStripsSchemaWhenPresent ( )
11- => PAssert . That ( ( ) => "dtproperties" == DbQualifiedNameUtils . UnqualifiedTableName ( "dbo.dtproperties" ) ) ;
11+ => PAssert . That ( ( ) => "dtproperties" == DbQualifiedNameUtils . UnqualifiedObjectName ( "dbo.dtproperties" ) ) ;
1212
1313 [ Fact ]
1414 public void SchemaFromQualifiedNameReturnsOnlySchema ( )
@@ -17,4 +17,13 @@ public void SchemaFromQualifiedNameReturnsOnlySchema()
1717 [ Fact ]
1818 public void SchemaFromQualifiedNameCrashesOnUnqualifiedName ( )
1919 => Assert . ThrowsAny < Exception > ( ( ) => DbQualifiedNameUtils . SchemaFromQualifiedName ( "bla" ) ) ;
20+
21+ [ Fact ]
22+ public void Qualified_to_unqualified ( )
23+ {
24+ var qualified = DbQualifiedNameUtils . QualifiedObjectName ( "dbo" , "dtproperties" ) ;
25+ var unqualified = DbQualifiedNameUtils . UnqualifiedObjectName ( qualified ) ;
26+
27+ PAssert . That ( ( ) => unqualified == "dtproperties" ) ;
28+ }
2029}
You can’t perform that action at this time.
0 commit comments