Summary

Class:CBAM.SQL.CBAMExtensions
Assembly:CBAM.SQL
File(s):/repo-dir/contents/Source/Code/CBAM.SQL/Meta.cs
Covered lines:0
Uncovered lines:42
Coverable lines:42
Total lines:723
Line coverage:0%
Branch coverage:0%

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
PrepareSchemaSearch(...)100%0%
PrepareTableSearch(...)100%0%
PrepareColumnSearch(...)100%0%
PreparePrimaryKeySearch(...)100%0%
PrepareForeignKeySearch(...)100%0%
GetExportedForeignKeyMetadataAsync(...)100%0%
GetImportedForeignKeyMetadataAsync(...)100%0%
GetSchemaMetadataAsync()200%0%
>c__DisplayClass7_0/<<GetSchemaMetadataAsync()400%0%
GetTableMetadataAsync()200%0%
>c__DisplayClass8_0/<<GetTableMetadataAsync()400%0%
GetColumnMetadataAsync()200%0%
>c__DisplayClass9_0/<<GetColumnMetadataAsync()400%0%
GetPrimaryKeyMetadataAsync()200%0%
>c__DisplayClass10_0/<<GetPrimaryKeyMetadataAsync()400%0%
GetCrossReferenceMetadataAsync()200%0%
>c__DisplayClass11_0/<<GetCrossReferenceMetadataAsync()400%0%

File(s)

/repo-dir/contents/Source/Code/CBAM.SQL/Meta.cs

#LineLine coverage
 1/*
 2 * Copyright 2017 Stanislav Muhametsin. All rights Reserved.
 3 *
 4 * Licensed  under the  Apache License,  Version 2.0  (the "License");
 5 * you may not use  this file  except in  compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *   http://www.apache.org/licenses/LICENSE-2.0
 9 *
 10 * Unless required by applicable law or agreed to in writing, software
 11 * distributed  under the  License is distributed on an "AS IS" BASIS,
 12 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
 13 * implied.
 14 *
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18using CBAM.Abstractions;
 19using CBAM.SQL;
 20using System;
 21using System.Collections.Generic;
 22using System.Linq;
 23using System.Text;
 24using System.Threading;
 25using System.Threading.Tasks;
 26using UtilPack.TabularData;
 27
 28namespace CBAM.SQL
 29{
 30   /// <summary>
 31   /// This interface contains all API related to metadata of the database that <see cref="SQLConnection"/> is currently
 32   /// </summary>
 33   /// <remarks>
 34   /// While the API exposed directly by this interface can be used, in most scenarios, the actual usage happens through
 35   /// <list type="bullet">
 36   /// <item><description><see cref="CBAMExtensions.GetSchemaMetadataAsync(SQLConnection, String)"/>,</description></ite
 37   /// <item><description><see cref="CBAMExtensions.GetTableMetadataAsync(SQLConnection, String, String, TableType[])"/>
 38   /// <item><description><see cref="CBAMExtensions.GetColumnMetadataAsync(SQLConnection, String, String, String)"/>,</d
 39   /// <item><description><see cref="CBAMExtensions.GetPrimaryKeyMetadataAsync(SQLConnection, String, String)"/>,</descr
 40   /// <item><description><see cref="CBAMExtensions.GetExportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 41   /// <item><description><see cref="CBAMExtensions.GetImportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 42   /// </list>
 43   /// </remarks>
 44   /// <seealso cref="SQLConnection.DatabaseMetadata"/>
 45   public interface DatabaseMetadata
 46   {
 47      /// <summary>
 48      /// Gets the name of the database that the <see cref="SQLConnection"/> is connected to.
 49      /// </summary>
 50      /// <value>The name of the database that the <see cref="SQLConnection"/> is connected to.</value>
 51      String Name { get; }
 52
 53      /// <summary>
 54      /// Creates a new <see cref="SQLStatementBuilder"/> which contains information for executing schema search with gi
 55      /// </summary>
 56      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 57      /// <returns>An <see cref="SQLStatementBuilder"/> which can be used to search the schema information from the data
 58      /// <seealso cref="CBAMExtensions.GetSchemaMetadataAsync(SQLConnection, String)"/>
 59      /// <seealso cref="ExtractSchemaMetadataAsync(AsyncDataRow)"/>
 60      SQLStatementBuilder CreateSchemaSearch( String schemaNamePattern = null );
 61
 62      /// <summary>
 63      /// Creates a new <see cref="SQLStatementBuilder"/> which contains information for executing table search with giv
 64      /// </summary>
 65      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 66      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 67      /// <param name="tableTypes">The table types. If not <c>null</c> and not empty, can be used to further narrow down
 68      /// <returns>An <see cref="SQLStatementBuilder"/> which can be used to search the table information from the datab
 69      /// <seealso cref="CBAMExtensions.GetTableMetadataAsync(SQLConnection, String, String, TableType[])"/>
 70      /// <seealso cref="ExtractTableMetadataAsync(AsyncDataRow)"/>
 71      /// <seealso cref="TableType"/>
 72      SQLStatementBuilder CreateTableSearch( String schemaNamePattern, String tableNamePattern, params TableType[] table
 73
 74      /// <summary>
 75      /// Creates a new <see cref="SQLStatementBuilder"/> which contains information for executing table column search w
 76      /// </summary>
 77      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 78      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 79      /// <param name="columnNamePattern">The column name pattern. If not <c>null</c>, will narrow down search results b
 80      /// <returns>An <see cref="SQLStatementBuilder"/> which can be used to search the table column information from th
 81      /// <seealso cref="CBAMExtensions.GetColumnMetadataAsync(SQLConnection, String, String, String)"/>
 82      /// <seealso cref="ExtractColumnMetadataAsync(AsyncDataRow)"/>
 83      SQLStatementBuilder CreateColumnSearch( String schemaNamePattern, String tableNamePattern, String columnNamePatter
 84
 85      /// <summary>
 86      /// Creates a new <see cref="SQLStatementBuilder"/> which contains information for executing table primary key sea
 87      /// </summary>
 88      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 89      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 90      /// <returns>An <see cref="SQLStatementBuilder"/> which can be used to search the table primary key information fr
 91      /// <seealso cref="CBAMExtensions.GetPrimaryKeyMetadataAsync(SQLConnection, String, String)"/>
 92      /// <seealso cref="ExtractPrimaryKeyMetadataAsync(AsyncDataRow)"/>
 93      SQLStatementBuilder CreatePrimaryKeySearch( String schemaNamePattern, String tableNamePattern );
 94
 95      /// <summary>
 96      /// Creates a new <see cref="SQLStatementBuilder"/> which contains information for executing table foreign key sea
 97      /// </summary>
 98      /// <param name="primarySchemaName">The schema name of the table containing primary key. If not <c>null</c>, will 
 99      /// <param name="primaryTableName">The name of the table containing primary key. If not <c>null</c>, will narrow d
 100      /// <param name="foreignSchemaName">The schema name of the table containing foreign key. If not <c>null</c>, will 
 101      /// <param name="foreignTableName">The name of the table containing foreign key. If not <c>null</c>, will narrow d
 102      /// <returns>An <see cref="SQLStatementBuilder"/> which can be used to search the table foreign key information fr
 103      /// <seealso cref="CBAMExtensions.GetImportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 104      /// <seealso cref="CBAMExtensions.GetExportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 105      /// <seealso cref="CBAMExtensions.GetCrossReferenceMetadataAsync(SQLConnection, String, String, String, String)"/>
 106      /// <seealso cref="ExtractForeignKeyMetadataAsync(AsyncDataRow)"/>
 107      SQLStatementBuilder CreateForeignKeySearch( String primarySchemaName, String primaryTableName, String foreignSchem
 108
 109      /// <summary>
 110      /// This method will create a new <see cref="SchemaMetadata"/> based on <see cref="AsyncDataRow"/> resulted from e
 111      /// </summary>
 112      /// <param name="row">The data row encountered during processing query produced by <see cref="CreateSchemaSearch(S
 113      /// <returns>A task which will on completion result in <see cref="SchemaMetadata"/> object.</returns>
 114      /// <remarks>
 115      /// Using this method on a <see cref="AsyncDataRow"/> which originates from other <see cref="IAsyncEnumerable{T}"/
 116      /// </remarks>
 117      /// <exception cref="ArgumentNullException">If <paramref name="row"/> is <c>null</c>.</exception>
 118      /// <seealso cref="CBAMExtensions.GetSchemaMetadataAsync(SQLConnection, String)"/>
 119      /// <seealso cref="CreateSchemaSearch(String)"/>
 120      ValueTask<SchemaMetadata> ExtractSchemaMetadataAsync( AsyncDataRow row );
 121
 122      /// <summary>
 123      /// This method will create a new <see cref="TableMetadata"/> based on <see cref="AsyncDataRow"/> resulted from ex
 124      /// </summary>
 125      /// <param name="row">The data row encountered during processing query produced by <see cref="CreateTableSearch(St
 126      /// <returns>A task which will on completion result in <see cref="TableMetadata"/> object.</returns>
 127      /// <remarks>
 128      /// Using this method on a <see cref="AsyncDataRow"/> which originates from other <see cref="IAsyncEnumerable{T}"/
 129      /// </remarks>
 130      /// <seealso cref="CBAMExtensions.GetTableMetadataAsync(SQLConnection, String, String, TableType[])"/>
 131      /// <seealso cref="CreateTableSearch(String, String, TableType[])"/>
 132      ValueTask<TableMetadata> ExtractTableMetadataAsync( AsyncDataRow row );
 133
 134      /// <summary>
 135      /// This method will create a new <see cref="ColumnMetadata"/> based on <see cref="AsyncDataRow"/> resulted from e
 136      /// </summary>
 137      /// <param name="row">The data row encountered during processing query produced by <see cref="CreateColumnSearch(S
 138      /// <returns>A task which will on completion result in <see cref="ColumnMetadata"/> object.</returns>
 139      /// <remarks>
 140      /// Using this method on a <see cref="AsyncDataRow"/> which originates from other <see cref="IAsyncEnumerable{T}"/
 141      /// </remarks>
 142      /// <seealso cref="CBAMExtensions.GetColumnMetadataAsync(SQLConnection, String, String, String)"/>
 143      /// <seealso cref="CreateColumnSearch(String, String, String)"/>
 144      ValueTask<ColumnMetadata> ExtractColumnMetadataAsync( AsyncDataRow row );
 145
 146      /// <summary>
 147      /// This method will create a new <see cref="PrimaryKeyMetadata"/> based on <see cref="AsyncDataRow"/> resulted fr
 148      /// </summary>
 149      /// <param name="row">The data row encountered during processing query produced by <see cref="CreatePrimaryKeySear
 150      /// <returns>A task which will on completion result in <see cref="PrimaryKeyMetadata"/> object.</returns>
 151      /// <remarks>
 152      /// Using this method on a <see cref="AsyncDataRow"/> which originates from other <see cref="IAsyncEnumerable{T}"/
 153      /// </remarks>
 154      /// <seealso cref="CBAMExtensions.GetPrimaryKeyMetadataAsync(SQLConnection, String, String)"/>
 155      /// <seealso cref="CreatePrimaryKeySearch(String, String)"/>
 156      ValueTask<PrimaryKeyMetadata> ExtractPrimaryKeyMetadataAsync( AsyncDataRow row );
 157
 158      /// <summary>
 159      /// This method will create a new <see cref="ForeignKeyMetadata"/> based on <see cref="AsyncDataRow"/> resulted fr
 160      /// </summary>
 161      /// <param name="row">The data row encountered during processing query produced by <see cref="CreateForeignKeySear
 162      /// <returns>A task which will on completion result in <see cref="ForeignKeyMetadata"/> object.</returns>
 163      /// <remarks>
 164      /// Using this method on a <see cref="AsyncDataRow"/> which originates from other <see cref="IAsyncEnumerable{T}"/
 165      /// </remarks>
 166      /// <seealso cref="CBAMExtensions.GetImportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 167      /// <seealso cref="CBAMExtensions.GetExportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 168      /// <seealso cref="CBAMExtensions.GetCrossReferenceMetadataAsync(SQLConnection, String, String, String, String)"/>
 169      /// <seealso cref="CreateForeignKeySearch(String, String, String, String)"/>
 170      ValueTask<ForeignKeyMetadata> ExtractForeignKeyMetadataAsync( AsyncDataRow row );
 171   }
 172
 173   /// <summary>
 174   /// This is common interface for database metadata objects which have a schema name.
 175   /// </summary>
 176   /// <seealso cref="SchemaMetadata"/>
 177   /// <seealso cref="TableMetadata"/>
 178   /// <seealso cref="ColumnMetadata"/>
 179   /// <seealso cref="PrimaryKeyMetadata"/>
 180   /// <seealso cref="ForeignKeyMetadata"/>
 181   public interface DatabaseElementWithSchemaName
 182   {
 183      /// <summary>
 184      /// Gets the name of the schema this database metadata object belongs to.
 185      /// </summary>
 186      /// <value>The name of the schema this database metadata object belongs to.</value>
 187      String SchemaName { get; }
 188   }
 189
 190   /// <summary>
 191   /// This interface represents information about a single schema in the database.
 192   /// </summary>
 193   /// <seealso cref="CBAMExtensions.GetSchemaMetadataAsync(SQLConnection, String)"/>
 194   /// <seealso cref="DatabaseMetadata.ExtractSchemaMetadataAsync(AsyncDataRow)"/>
 195   public interface SchemaMetadata : DatabaseElementWithSchemaName, DatabaseElementWithComment
 196   {
 197   }
 198
 199   /// <summary>
 200   /// This is common interface for database metadata objects which have a table name.
 201   /// </summary>
 202   /// <seealso cref="TableMetadata"/>
 203   /// <seealso cref="ColumnMetadata"/>
 204   /// <seealso cref="PrimaryKeyMetadata"/>
 205   /// <seealso cref="ForeignKeyMetadata"/>
 206   public interface DatabaseElementWithTableName : DatabaseElementWithSchemaName
 207   {
 208      /// <summary>
 209      /// Gets the name of the table this database metadata object belongs to.
 210      /// </summary>
 211      /// <value>The name of the table this database metadata object belongs to.</value>
 212      String TableName { get; }
 213   }
 214
 215   /// <summary>
 216   /// This is common interface for database metadata objects which have a comment.
 217   /// </summary>
 218   /// <seealso cref="SchemaMetadata"/>
 219   /// <seealso cref="TableMetadata"/>
 220   /// <seealso cref="ColumnMetadata"/>
 221   public interface DatabaseElementWithComment
 222   {
 223      /// <summary>
 224      /// Gets the textual comment associated with this database metadata object.
 225      /// </summary>
 226      /// <value>The textual comment associated with this database metadata object.</value>
 227      String Comment { get; }
 228   }
 229
 230   /// <summary>
 231   /// This is common interface for database metadata objects which have some sort of type name.
 232   /// </summary>
 233   /// <seealso cref="TableMetadata"/>
 234   /// <seealso cref="ColumnMetadata"/>
 235   public interface DatabaseElementWithTypeName
 236   {
 237      /// <summary>
 238      /// Gets the textual type name of this database metadata object.
 239      /// </summary>
 240      /// <value>The textual type name of this database metadata object.</value>
 241      String TypeName { get; }
 242   }
 243
 244   /// <summary>
 245   /// This interface contains information about a single table in the database.
 246   /// </summary>
 247   /// <seealso cref="CBAMExtensions.GetTableMetadataAsync(SQLConnection, String, String, TableType[])"/>
 248   /// <seealso cref="DatabaseMetadata.ExtractTableMetadataAsync(AsyncDataRow)"/>
 249   public interface TableMetadata : DatabaseElementWithTableName, DatabaseElementWithComment, DatabaseElementWithTypeNam
 250   {
 251      /// <summary>
 252      /// Gets the type of the table as <see cref="SQL.TableType"/> enumeration.
 253      /// </summary>
 254      /// <value>The type of the table as <see cref="SQL.TableType"/> enumeration.</value>
 255      /// <seealso cref="SQL.TableType"/>
 256      /// <seealso cref="DatabaseElementWithTypeName.TypeName"/>
 257      TableType? TableType { get; }
 258   }
 259
 260   /// <summary>
 261   /// This is common interface for database metadata objects which have column name.
 262   /// </summary>
 263   public interface DatabaseElementWithColumnName : DatabaseElementWithTableName
 264   {
 265      /// <summary>
 266      /// Gets the name of the column this database metadata object belongs to.
 267      /// </summary>
 268      /// <value>The name of the column this database metadata object belongs to.</value>
 269      String ColumnName { get; }
 270   }
 271
 272   /// <summary>
 273   /// This is common interface for database metadata objects which are contained within some other object (e.g. column 
 274   /// </summary>
 275   public interface DatabaseElementWithOrdinalPosition
 276   {
 277      /// <summary>
 278      /// Gets the zero-based ordinal position of this database metadata object within parent object.
 279      /// </summary>
 280      /// <value>The zero-based ordinal position of this database metadata object within parent object.</value>
 281      Int32 OrdinalPosition { get; }
 282   }
 283
 284   /// <summary>
 285   /// This interface contains information about single column of a single table in the database.
 286   /// </summary>
 287   /// <seealso cref="CBAMExtensions.GetColumnMetadataAsync(SQLConnection, String, String, String)"/>
 288   /// <seealso cref="DatabaseMetadata.ExtractColumnMetadataAsync(AsyncDataRow)"/>
 289   public interface ColumnMetadata : DatabaseElementWithColumnName, DatabaseElementWithComment, DatabaseElementWithTypeN
 290   {
 291      //Int32 ColumnSize { get; }
 292
 293      /// <summary>
 294      /// Gets the amount of decimal digits, if applicable.
 295      /// </summary>
 296      /// <value>The amount of decimal digits, if applicable.</value>
 297      Int32? DecimalDigits { get; }
 298
 299      /// <summary>
 300      /// Gets the value indicating whether this column accepts <c>NULL</c>s as valid values.
 301      /// </summary>
 302      /// <value>The value indicating whether this column accepts <c>NULL</c>s as valid values.</value>
 303      Boolean Nullable { get; }
 304
 305      /// <summary>
 306      /// Gets the column default value, if any.
 307      /// </summary>
 308      /// <value>The column default value, if any.</value>
 309      String ColumnDefaultValue { get; }
 310
 311      /// <summary>
 312      /// Gets the column CLR type, if it can be deducted at runtime.
 313      /// </summary>
 314      /// <value>The column CLR type, if it can be deducted at runtime.</value>
 315      Type ColumnCLRType { get; }
 316
 317      /// <summary>
 318      /// Gets the value indicating whether this column is primary key column.
 319      /// </summary>
 320      /// <value>The value indicating whether this column is primary key column.</value>
 321      Boolean IsPrimaryKeyColumn { get; }
 322   }
 323
 324   /// <summary>
 325   /// This is common interface for direct and indirect primary and foreign key information in the database.
 326   /// </summary>
 327   /// <seealso cref="PrimaryKeyMetadata"/>
 328   /// <seealso cref="ForeignKeyMetadata"/>
 329   /// <seealso cref="ForeignKeyMetadata.PrimaryKey"/>
 330   public interface KeyMetadataInfo : DatabaseElementWithColumnName
 331   {
 332      /// <summary>
 333      /// Gets the name of this primary or foreign key information.
 334      /// </summary>
 335      String KeyName { get; }
 336   }
 337
 338   /// <summary>
 339   /// This is common interface for direct primary and foreign key information in the database.
 340   /// </summary>
 341   /// <seealso cref="PrimaryKeyMetadata"/>
 342   /// <seealso cref="ForeignKeyMetadata"/>
 343   public interface KeyMetadata : KeyMetadataInfo, DatabaseElementWithOrdinalPosition
 344   {
 345      /// <summary>
 346      /// Gets the <see cref="ConstraintCharacteristics"/> of this primary or foreign key information, if it exists.
 347      /// </summary>
 348      /// <value>The <see cref="ConstraintCharacteristics"/> of this primary or foreign key information, if it exists.</
 349      ConstraintCharacteristics? Deferrability { get; }
 350   }
 351
 352   /// <summary>
 353   /// This interface contains information about single primary key column of a single table in the database.
 354   /// </summary>
 355   /// <seealso cref="CBAMExtensions.GetPrimaryKeyMetadataAsync(SQLConnection, String, String)"/>
 356   /// <seealso cref="DatabaseMetadata.ExtractPrimaryKeyMetadataAsync(AsyncDataRow)"/>
 357   public interface PrimaryKeyMetadata : KeyMetadata
 358   {
 359   }
 360
 361   /// <summary>
 362   /// This interface contains information about single foreign key column of a single table in the database.
 363   /// </summary>
 364   /// <seealso cref="CBAMExtensions.GetImportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 365   /// <seealso cref="CBAMExtensions.GetExportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 366   /// <seealso cref="CBAMExtensions.GetCrossReferenceMetadataAsync(SQLConnection, String, String, String, String)"/>
 367   /// <seealso cref="DatabaseMetadata.ExtractForeignKeyMetadataAsync(AsyncDataRow)"/>
 368   public interface ForeignKeyMetadata : KeyMetadata
 369   {
 370      /// <summary>
 371      /// Gets the information about the primary key column that this this foreign key column references.
 372      /// </summary>
 373      /// <value>The information about the primary key column that this this foreign key column references.</value>
 374      KeyMetadataInfo PrimaryKey { get; }
 375
 376      /// <summary>
 377      /// Gets the <see cref="ReferentialAction"/> of this foreign key constraint for update action, if any.
 378      /// </summary>
 379      /// <value>The <see cref="ReferentialAction"/> of this foreign key constraint for update action, if any.</value>
 380      ReferentialAction? OnUpdate { get; }
 381
 382      /// <summary>
 383      /// Gets the <see cref="ReferentialAction"/> of this foreign key constraint for delete action, if any.
 384      /// </summary>
 385      /// <value>The <see cref="ReferentialAction"/> of this foreign key constraint for delete action, if any.</value>
 386      ReferentialAction? OnDelete { get; }
 387   }
 388
 389   /// <summary>
 390   /// This enumeration contains possible values for SQL actions when the target of the foreign key changes (<c>ON UPDAT
 391   /// </summary>
 392   public enum ReferentialAction
 393   {
 394      /// <summary>
 395      /// The foreign key will be updated to new value in case of change, and the row will be deleted in case of deletio
 396      /// </summary>
 397      Cascade,
 398
 399      /// <summary>
 400      /// The foreign key will be set to <c>NULL</c> value if the target changes or gets deleted.
 401      /// </summary>
 402      SetNull,
 403
 404      /// <summary>
 405      /// The foreign key will be set to default values if the target changes or gets deleted.
 406      /// </summary>
 407      SetDefault,
 408
 409      /// <summary>
 410      /// The change or deletion of the target will cause an error in that statement.
 411      /// </summary>
 412      Restrict,
 413
 414      /// <summary>
 415      /// A lot like <see cref="Restrict"/>, this will cause an error if the target gets changed or deleted, but the che
 416      /// This means that even with deletion or change, the end-state might be acceptable, valid foreign key references.
 417      /// </summary>
 418      NoAction
 419   }
 420
 421   /// <summary>
 422   /// This enumeraton contains possible values for SQL constraint (e.g. <c>PRIMARY KEY</c>, <c>FOREIGN KEY</c>, etc) ch
 423   /// </summary>
 424   public enum ConstraintCharacteristics
 425   {
 426      /// <summary>
 427      /// The constraint is immediate by default, but may be deferred on demand when needed.
 428      /// </summary>
 429      InitiallyImmediate_Deferrable,
 430
 431      /// <summary>
 432      /// The constraint is always deferred.
 433      /// </summary>
 434      InitiallyDeferred_Deferrable,
 435
 436      /// <summary>
 437      /// The constraint is always immediate.
 438      /// </summary>
 439      NotDeferrable
 440   }
 441
 442   /// <summary>
 443   /// This enumeration specifies for possible table types in table search of <see cref="CBAMExtensions.GetTableMetadata
 444   /// </summary>
 445   public enum TableType
 446   {
 447      /// <summary>
 448      /// This value represents normal SQL table.
 449      /// </summary>
 450      Table,
 451
 452      /// <summary>
 453      /// This value represents a SQL view.
 454      /// </summary>
 455      View,
 456
 457      /// <summary>
 458      /// This value represents a system table, aka catalog.
 459      /// </summary>
 460      SystemTable,
 461
 462      /// <summary>
 463      /// This value represents global temporary table.
 464      /// </summary>
 465      GlobalTemporary,
 466
 467      /// <summary>
 468      /// This value represents local temporary table.
 469      /// </summary>
 470      LocalTemporary,
 471
 472      /// <summary>
 473      /// This value represents a synonym table.
 474      /// </summary>
 475      Synonym,
 476
 477      /// <summary>
 478      /// This value represents the maximum value of this enumeration, and can be used in other enumerations which 'exte
 479      /// </summary>
 480      MaxValue
 481   }
 482
 483   /// <summary>
 484   /// This class contains extension methods for types defined in other assemblies, or rarely used extension methods for
 485   /// </summary>
 486   public static partial class CBAMExtensions
 487   {
 488      /// <summary>
 489      /// Creates a new <see cref="IAsyncEnumerable{T}"/> which can be used to execute schema search with given schema n
 490      /// </summary>
 491      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 492      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 493      /// <returns>An <see cref="IAsyncEnumerable{T}"/> which can be executed to search the schema information from the 
 494      /// <seealso cref="CBAMExtensions.GetSchemaMetadataAsync(SQLConnection, String)"/>
 495      /// <seealso cref="DatabaseMetadata.ExtractSchemaMetadataAsync(AsyncDataRow)"/>
 496      public static IAsyncEnumerable<SQLStatementExecutionResult> PrepareSchemaSearch( this SQLConnection connection, St
 497      {
 0498         return connection.PrepareStatementForExecution( connection.DatabaseMetadata.CreateSchemaSearch( schemaNamePatte
 499      }
 500
 501      /// <summary>
 502      /// Creates a new <see cref="IAsyncEnumerable{T}"/> which can be used to execute table search with given search pa
 503      /// </summary>
 504      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 505      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 506      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 507      /// <param name="tableTypes">The table types. If not <c>null</c> and not empty, can be used to further narrow down
 508      /// <returns>An <see cref="IAsyncEnumerable{T}"/> which can be executed to search the table information from the d
 509      /// <seealso cref="CBAMExtensions.GetTableMetadataAsync(SQLConnection, String, String, TableType[])"/>
 510      /// <seealso cref="DatabaseMetadata.ExtractTableMetadataAsync(AsyncDataRow)"/>
 511      /// <seealso cref="TableType"/>
 512      public static IAsyncEnumerable<SQLStatementExecutionResult> PrepareTableSearch( this SQLConnection connection, Str
 513      {
 0514         return connection.PrepareStatementForExecution( connection.DatabaseMetadata.CreateTableSearch( schemaNamePatter
 515      }
 516
 517      /// <summary>
 518      /// Creates a new <see cref="IAsyncEnumerable{T}"/> which can be used to execute table column search with given se
 519      /// </summary>
 520      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 521      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 522      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 523      /// <param name="columnNamePattern">The column name pattern. If not <c>null</c>, will narrow down search results b
 524      /// <returns>An <see cref="IAsyncEnumerable{T}"/> which can be executed to search the table column information fro
 525      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 526      /// <seealso cref="CBAMExtensions.GetColumnMetadataAsync(SQLConnection, String, String, String)"/>
 527      /// <seealso cref="DatabaseMetadata.ExtractColumnMetadataAsync(AsyncDataRow)"/>
 528      public static IAsyncEnumerable<SQLStatementExecutionResult> PrepareColumnSearch( this SQLConnection connection, St
 529      {
 0530         return connection.PrepareStatementForExecution( connection.DatabaseMetadata.CreateColumnSearch( schemaNamePatte
 531      }
 532
 533      /// <summary>
 534      /// Creates a new <see cref="IAsyncEnumerable{T}"/> which can be used to execute table primary key search with giv
 535      /// </summary>
 536      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 537      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 538      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 539      /// <returns>An <see cref="IAsyncEnumerable{T}"/> which can be executed to search the table primary key informatio
 540      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 541      /// <seealso cref="CBAMExtensions.GetPrimaryKeyMetadataAsync(SQLConnection, String, String)"/>
 542      /// <seealso cref="DatabaseMetadata.ExtractPrimaryKeyMetadataAsync(AsyncDataRow)"/>
 543      public static IAsyncEnumerable<SQLStatementExecutionResult> PreparePrimaryKeySearch( this SQLConnection connection
 544      {
 0545         return connection.PrepareStatementForExecution( connection.DatabaseMetadata.CreatePrimaryKeySearch( schemaNameP
 546      }
 547
 548      /// <summary>
 549      /// Creates a new <see cref="IAsyncEnumerable{T}"/> which can be used to execute table foreign key search with giv
 550      /// </summary>
 551      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 552      /// <param name="primarySchemaName">The schema name of the table containing primary key. If not <c>null</c>, will 
 553      /// <param name="primaryTableName">The name of the table containing primary key. If not <c>null</c>, will narrow d
 554      /// <param name="foreignSchemaName">The schema name of the table containing foreign key. If not <c>null</c>, will 
 555      /// <param name="foreignTableName">The name of the table containing foreign key. If not <c>null</c>, will narrow d
 556      /// <returns>An <see cref="IAsyncEnumerable{T}"/> which can be executed to search the table foreign key informatio
 557      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 558      /// <seealso cref="CBAMExtensions.GetImportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 559      /// <seealso cref="CBAMExtensions.GetExportedForeignKeyMetadataAsync(SQLConnection, String, String)"/>
 560      /// <seealso cref="CBAMExtensions.GetCrossReferenceMetadataAsync(SQLConnection, String, String, String, String)"/>
 561      /// <seealso cref="DatabaseMetadata.ExtractForeignKeyMetadataAsync(AsyncDataRow)"/>
 562      public static IAsyncEnumerable<SQLStatementExecutionResult> PrepareForeignKeySearch( this SQLConnection connection
 563      {
 0564         return connection.PrepareStatementForExecution( connection.DatabaseMetadata.CreateForeignKeySearch( primarySche
 565      }
 566
 567      /// <summary>
 568      /// This is shortcut method to enumerate all foreign key columns of given table, and return the column information
 569      /// </summary>
 570      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 571      /// <param name="schemaName">The schema name of the table to get foreign keys from.</param>
 572      /// <param name="tableName">The table name of the table to get foreign keys from.</param>
 573      /// <returns>Asynchronously returns list of <see cref="ForeignKeyMetadata"/> objects that have information about f
 574      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 575      /// <seealso cref="GetCrossReferenceMetadataAsync(SQLConnection, String, String, String, String)"/>
 576      /// <seealso cref="DatabaseMetadata.CreateForeignKeySearch(String, String, String, String)"/>
 577      /// <seealso cref="DatabaseMetadata.ExtractForeignKeyMetadataAsync(AsyncDataRow)"/>
 578      /// <remarks>
 579      /// Since this method stores all results in a single <see cref="List{T}"/>, use this when it is not expected to re
 580      /// </remarks>
 581      public static ValueTask<List<ForeignKeyMetadata>> GetExportedForeignKeyMetadataAsync( this SQLConnection connectio
 582      {
 0583         return connection.GetCrossReferenceMetadataAsync( schemaName, tableName, null, null );
 584      }
 585
 586      /// <summary>
 587      /// This is shortcut method to enumerate all foreign key columns of other tables that reference primary key of giv
 588      /// </summary>
 589      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 590      /// <param name="schemaName">The schema name of the table that other foreign keys reference.</param>
 591      /// <param name="tableName">The table name of the table that other foreign keys reference.</param>
 592      /// <returns>Asynchronously returns list of <see cref="ForeignKeyMetadata"/> objects that have information about f
 593      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 594      /// <seealso cref="GetCrossReferenceMetadataAsync(SQLConnection, String, String, String, String)"/>
 595      /// <seealso cref="DatabaseMetadata.CreateForeignKeySearch(String, String, String, String)"/>
 596      /// <seealso cref="DatabaseMetadata.ExtractForeignKeyMetadataAsync(AsyncDataRow)"/>
 597      /// <remarks>
 598      /// Since this method stores all results in a single <see cref="List{T}"/>, use this when it is not expected to re
 599      /// </remarks>
 600      public static ValueTask<List<ForeignKeyMetadata>> GetImportedForeignKeyMetadataAsync( this SQLConnection connectio
 601      {
 0602         return connection.GetCrossReferenceMetadataAsync( null, null, schemaName, tableName );
 603      }
 604
 605      /// <summary>
 606      /// This is shortcut method to enumerate all schemas, with given optional schema name filter, in the database, and
 607      /// </summary>
 608      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 609      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 610      /// <returns>Asynchronously returns list of <see cref="SchemaMetadata"/> objects that have information about schem
 611      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 612      /// <seealso cref="DatabaseMetadata.CreateSchemaSearch(String)"/>
 613      /// <seealso cref="DatabaseMetadata.ExtractSchemaMetadataAsync(AsyncDataRow)"/>
 614      /// <remarks>
 615      /// Since this method stores all results in a single <see cref="List{T}"/>, use this when it is not expected to re
 616      /// </remarks>
 617      public static async ValueTask<List<SchemaMetadata>> GetSchemaMetadataAsync( this SQLConnection connection, String 
 618      {
 0619         var md = connection.DatabaseMetadata;
 0620         return await connection
 0621            .PrepareSchemaSearch( schemaNamePattern )
 0622            .IncludeDataRowsOnly()
 0623            .Select( async row => await md.ExtractSchemaMetadataAsync( row ) )
 0624            .ToListAsync();
 0625      }
 626
 627      /// <summary>
 628      /// This is shortcut method to enumerate all tables, with given optional schema name, table name, and table type f
 629      /// </summary>
 630      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 631      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 632      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 633      /// <param name="tableTypes">The table types. If not <c>null</c> and not empty, can be used to further narrow down
 634      /// <returns>Asynchronously returns list of <see cref="TableMetadata"/> objects that have information about table 
 635      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 636      /// <seealso cref="DatabaseMetadata.CreateTableSearch(String, String, TableType[])"/>
 637      /// <seealso cref="DatabaseMetadata.ExtractTableMetadataAsync(AsyncDataRow)"/>
 638      /// <remarks>
 639      /// Since this method stores all results in a single <see cref="List{T}"/>, use this when it is not expected to re
 640      /// </remarks>
 641      public static async ValueTask<List<TableMetadata>> GetTableMetadataAsync( this SQLConnection connection, String sc
 642      {
 0643         var md = connection.DatabaseMetadata;
 0644         return await connection
 0645            .PrepareTableSearch( schemaNamePattern, tableNamePattern )
 0646            .IncludeDataRowsOnly()
 0647            .Select( async row => await md.ExtractTableMetadataAsync( row ) )
 0648            .ToListAsync();
 0649      }
 650
 651      /// <summary>
 652      /// This is shortcut method to enumerate all columns, with given optional schema, table, and column name filters, 
 653      /// </summary>
 654      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 655      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 656      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 657      /// <param name="columnNamePattern">The column name pattern. If not <c>null</c>, will narrow down search results b
 658      /// <returns>Asynchronously returns list of <see cref="ColumnMetadata"/> objects that have information about colum
 659      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 660      /// <seealso cref="DatabaseMetadata.CreateColumnSearch(String, String, String)"/>
 661      /// <seealso cref="DatabaseMetadata.ExtractColumnMetadataAsync(AsyncDataRow)"/>
 662      /// <remarks>
 663      /// Since this method stores all results in a single <see cref="List{T}"/>, use this when it is not expected to re
 664      /// </remarks>
 665      public static async ValueTask<List<ColumnMetadata>> GetColumnMetadataAsync( this SQLConnection connection, String 
 666      {
 0667         var md = connection.DatabaseMetadata;
 0668         return await connection
 0669            .PrepareColumnSearch( schemaNamePattern, tableNamePattern, columnNamePattern )
 0670            .IncludeDataRowsOnly()
 0671            .Select( async row => await md.ExtractColumnMetadataAsync( row ) )
 0672            .ToListAsync();
 0673      }
 674
 675      /// <summary>
 676      /// This is shortcut method to enumerate all primary key columns, with given optional schema and table name filter
 677      /// </summary>
 678      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 679      /// <param name="schemaNamePattern">The schema name pattern. If not <c>null</c>, will narrow down search results b
 680      /// <param name="tableNamePattern">The table name pattern. If not <c>null</c>, will narrow down search results bas
 681      /// <returns>Asynchronously returns list of <see cref="PrimaryKeyMetadata"/> objects that have information about p
 682      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 683      /// <seealso cref="DatabaseMetadata.CreatePrimaryKeySearch(String, String)"/>
 684      /// <seealso cref="DatabaseMetadata.ExtractPrimaryKeyMetadataAsync(AsyncDataRow)"/>
 685      /// <remarks>
 686      /// Since this method stores all results in a single <see cref="List{T}"/>, use this when it is not expected to re
 687      /// </remarks>
 688      public static async ValueTask<List<PrimaryKeyMetadata>> GetPrimaryKeyMetadataAsync( this SQLConnection connection,
 689      {
 0690         var md = connection.DatabaseMetadata;
 0691         return await connection
 0692            .PreparePrimaryKeySearch( schemaNamePattern, tableNamePattern )
 0693            .IncludeDataRowsOnly()
 0694            .Select( async row => await md.ExtractPrimaryKeyMetadataAsync( row ) )
 0695            .ToListAsync();
 0696      }
 697
 698      /// <summary>
 699      /// This is shortcut method to enumerate all foreign key columns, with given primary and foreign table schema name
 700      /// </summary>
 701      /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 702      /// <param name="primarySchemaName">The primary table schema name. If not <c>null</c>, will narrow down search res
 703      /// <param name="primaryTableName">The primary table table name. If not <c>null</c>, will narrow down search resul
 704      /// <param name="foreignSchemaName">The foreign table schema name. If not <c>null</c>, will narrow down search res
 705      /// <param name="foreignTableName">The foreign table table name. If not <c>null</c>, will narrow down search resul
 706      /// <returns>Asynchronously returns list of <see cref="ForeignKeyMetadata"/> objects that have information about f
 707      /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 708      /// <seealso cref="DatabaseMetadata.CreateForeignKeySearch(String, String, String, String)"/>
 709      /// <seealso cref="DatabaseMetadata.ExtractForeignKeyMetadataAsync(AsyncDataRow)"/>
 710      /// <remarks>
 711      /// Since this method stores all results in a single <see cref="List{T}"/>, use this when it is not expected to re
 712      /// </remarks>
 713      public static async ValueTask<List<ForeignKeyMetadata>> GetCrossReferenceMetadataAsync( this SQLConnection connect
 714      {
 0715         var md = connection.DatabaseMetadata;
 0716         return await connection
 0717            .PrepareForeignKeySearch( primarySchemaName, primaryTableName, foreignSchemaName, foreignTableName )
 0718            .IncludeDataRowsOnly()
 0719            .Select( async row => await md.ExtractForeignKeyMetadataAsync( row ) )
 0720            .ToListAsync();
 0721      }
 722   }
 723}