@@ -75,6 +75,12 @@ public async ValueTask<DataTable> GetSchemaAsync(IOBehavior ioBehavior, string c
7575 await FillUserPrivilegesAsync ( ioBehavior , dataTable , "UserPrivileges" , restrictionValues , cancellationToken ) . ConfigureAwait ( false ) ;
7676 else if ( string . Equals ( collectionName , "Views" , StringComparison . OrdinalIgnoreCase ) )
7777 await FillViewsAsync ( ioBehavior , dataTable , "Views" , restrictionValues , cancellationToken ) . ConfigureAwait ( false ) ;
78+ else if ( string . Equals ( collectionName , "Foreign Keys" , StringComparison . OrdinalIgnoreCase ) )
79+ await FillForeignKeysAsync ( ioBehavior , dataTable , "Foreign Keys" , restrictionValues , cancellationToken ) . ConfigureAwait ( false ) ;
80+ else if ( string . Equals ( collectionName , "Indexes" , StringComparison . OrdinalIgnoreCase ) )
81+ await FillIndexesAsync ( ioBehavior , dataTable , "Indexes" , restrictionValues , cancellationToken ) . ConfigureAwait ( false ) ;
82+ else if ( string . Equals ( collectionName , "IndexColumns" , StringComparison . OrdinalIgnoreCase ) )
83+ await FillIndexColumnsAsync ( ioBehavior , dataTable , "IndexColumns" , restrictionValues , cancellationToken ) . ConfigureAwait ( false ) ;
7884 else
7985 throw new ArgumentException ( $ "Invalid collection name: '{ collectionName } '.", nameof ( collectionName ) ) ;
8086
@@ -123,6 +129,9 @@ private Task FillMetaDataCollectionsAsync(IOBehavior ioBehavior, DataTable dataT
123129 dataTable . Rows . Add ( "Triggers" , 0 , 3 ) ;
124130 dataTable . Rows . Add ( "UserPrivileges" , 0 , 0 ) ;
125131 dataTable . Rows . Add ( "Views" , 0 , 3 ) ;
132+ dataTable . Rows . Add ( "Foreign Keys" , 4 , 0 ) ;
133+ dataTable . Rows . Add ( "Indexes" , 4 , 0 ) ;
134+ dataTable . Rows . Add ( "IndexColumns" , 5 , 0 ) ;
126135
127136 return Task . CompletedTask ;
128137 }
@@ -628,6 +637,19 @@ private Task FillRestrictionsAsync(IOBehavior ioBehavior, DataTable dataTable, s
628637 dataTable . Rows . Add ( "Tables" , "Schema" , "TABLE_SCHEMA" , 2 ) ;
629638 dataTable . Rows . Add ( "Tables" , "Table" , "TABLE_NAME" , 3 ) ;
630639 dataTable . Rows . Add ( "Tables" , "TableType" , "TABLE_TYPE" , 4 ) ;
640+ dataTable . Rows . Add ( "Foreign Keys" , "Catalog" , "TABLE_CATALOG" , 1 ) ;
641+ dataTable . Rows . Add ( "Foreign Keys" , "Schema" , "TABLE_SCHEMA" , 2 ) ;
642+ dataTable . Rows . Add ( "Foreign Keys" , "Table" , "TABLE_NAME" , 3 ) ;
643+ dataTable . Rows . Add ( "Foreign Keys" , "Column" , "COLUMN_NAME" , 4 ) ;
644+ dataTable . Rows . Add ( "Indexes" , "Catalog" , "TABLE_CATALOG" , 1 ) ;
645+ dataTable . Rows . Add ( "Indexes" , "Schema" , "TABLE_SCHEMA" , 2 ) ;
646+ dataTable . Rows . Add ( "Indexes" , "Table" , "TABLE_NAME" , 3 ) ;
647+ dataTable . Rows . Add ( "Indexes" , "Column" , "COLUMN_NAME" , 4 ) ;
648+ dataTable . Rows . Add ( "IndexColumns" , "Catalog" , "TABLE_CATALOG" , 1 ) ;
649+ dataTable . Rows . Add ( "IndexColumns" , "Schema" , "TABLE_SCHEMA" , 2 ) ;
650+ dataTable . Rows . Add ( "IndexColumns" , "Table" , "TABLE_NAME" , 3 ) ;
651+ dataTable . Rows . Add ( "IndexColumns" , "Constraint" , "CONSTRAINT_NAME" , 4 ) ;
652+ dataTable . Rows . Add ( "IndexColumns" , "Column" , "COLUMN_NAME" , 5 ) ;
631653
632654 return Task . CompletedTask ;
633655 }
@@ -832,4 +854,70 @@ private async Task FillViewsAsync(IOBehavior ioBehavior, DataTable dataTable, st
832854 await FillDataTableAsync ( ioBehavior , dataTable , "VIEWS" , null , cancellationToken ) . ConfigureAwait ( false ) ;
833855 }
834856
857+ private async Task FillForeignKeysAsync ( IOBehavior ioBehavior , DataTable dataTable , string tableName , string ? [ ] ? restrictionValues , CancellationToken cancellationToken )
858+ {
859+ if ( restrictionValues is { Length : > 4 } )
860+ throw new ArgumentException ( "More than 4 restrictionValues are not supported for schema 'Foreign Keys'." , nameof ( restrictionValues ) ) ;
861+
862+ dataTable . TableName = tableName ;
863+ dataTable . Columns . AddRange (
864+ [
865+ new ( "CONSTRAINT_CATALOG" , typeof ( string ) ) ,
866+ new ( "CONSTRAINT_SCHEMA" , typeof ( string ) ) ,
867+ new ( "CONSTRAINT_NAME" , typeof ( string ) ) ,
868+ new ( "TABLE_CATALOG" , typeof ( string ) ) ,
869+ new ( "TABLE_SCHEMA" , typeof ( string ) ) ,
870+ new ( "TABLE_NAME" , typeof ( string ) ) ,
871+ new ( "MATCH_OPTION" , typeof ( string ) ) ,
872+ new ( "UPDATE_RULE" , typeof ( string ) ) ,
873+ new ( "DELETE_RULE" , typeof ( string ) ) ,
874+ new ( "REFERENCED_TABLE_CATALOG" , typeof ( string ) ) ,
875+ new ( "REFERENCED_TABLE_SCHEMA" , typeof ( string ) ) ,
876+ new ( "REFERENCED_TABLE_NAME" , typeof ( string ) ) ,
877+ ] ) ;
878+
879+ await DoFillForeignKeysAsync ( ioBehavior , dataTable , restrictionValues , cancellationToken ) . ConfigureAwait ( false ) ;
880+ }
881+
882+ private async Task FillIndexesAsync ( IOBehavior ioBehavior , DataTable dataTable , string tableName , string ? [ ] ? restrictionValues , CancellationToken cancellationToken )
883+ {
884+ if ( restrictionValues is { Length : > 4 } )
885+ throw new ArgumentException ( "More than 4 restrictionValues are not supported for schema 'Indexes'." , nameof ( restrictionValues ) ) ;
886+
887+ dataTable . TableName = tableName ;
888+ dataTable . Columns . AddRange (
889+ [
890+ new ( "INDEX_CATALOG" , typeof ( string ) ) ,
891+ new ( "INDEX_SCHEMA" , typeof ( string ) ) ,
892+ new ( "INDEX_NAME" , typeof ( string ) ) ,
893+ new ( "TABLE_NAME" , typeof ( string ) ) ,
894+ new ( "UNIQUE" , typeof ( bool ) ) ,
895+ new ( "PRIMARY" , typeof ( bool ) ) ,
896+ new ( "TYPE" , typeof ( string ) ) ,
897+ new ( "COMMENT" , typeof ( string ) ) ,
898+ ] ) ;
899+
900+ await DoFillIndexesAsync ( ioBehavior , dataTable , restrictionValues , cancellationToken ) . ConfigureAwait ( false ) ;
901+ }
902+
903+ private async Task FillIndexColumnsAsync ( IOBehavior ioBehavior , DataTable dataTable , string tableName , string ? [ ] ? restrictionValues , CancellationToken cancellationToken )
904+ {
905+ if ( restrictionValues is { Length : > 5 } )
906+ throw new ArgumentException ( "More than 5 restrictionValues are not supported for schema 'IndexColumns'." , nameof ( restrictionValues ) ) ;
907+
908+ dataTable . TableName = tableName ;
909+ dataTable . Columns . AddRange (
910+ [
911+ new ( "INDEX_CATALOG" , typeof ( string ) ) ,
912+ new ( "INDEX_SCHEMA" , typeof ( string ) ) ,
913+ new ( "INDEX_NAME" , typeof ( string ) ) ,
914+ new ( "TABLE_NAME" , typeof ( string ) ) ,
915+ new ( "COLUMN_NAME" , typeof ( string ) ) ,
916+ new ( "ORDINAL_POSITION" , typeof ( int ) ) ,
917+ new ( "SORT_ORDER" , typeof ( string ) ) ,
918+ ] ) ;
919+
920+ await DoFillIndexColumnsAsync ( ioBehavior , dataTable , restrictionValues , cancellationToken ) . ConfigureAwait ( false ) ;
921+ }
922+
835923}
0 commit comments