Summary

Class:E_CBAM
Assembly:CBAM.SQL
File(s):/repo-dir/contents/Source/Code/CBAM.SQL/Connection.cs
/repo-dir/contents/Source/Code/CBAM.SQL/Statement.cs
Covered lines:24
Uncovered lines:93
Coverable lines:117
Total lines:901
Line coverage:20.5%
Branch coverage:14.5%

Coverage History

Metrics

MethodCyclomatic complexity NPath complexity Sequence coverage Branch coverage
IncludeDataRowsOnly(...)101%0%
GetFirstOrDefaultAsync()400%0%
GetFirstOrDefaultAsync(...)100%0%
GetFirstOrDefaultAsync()401%1%
>c__DisplayClass3_0`1/<<GetFirstOrDefaultAsync()601%0.5%
GetFirstOrDefaultAsync(...)101%0%
DoWriteStatements(...)100%0%
DoWriteStatements(...)100%0%
DoReadStatements(...)100%0%
DoReadStatements(...)100%0%
DoStatements()1800%0%
DoStatements()2500%0%
ExecuteStatementsFromStreamAsync()600%0%
ExecuteStatementsFromStreamAsync()3200%0%
SetParameterBoolean(...)100%0%
SetParameterInt32(...)101%0%
SetParameterInt16(...)100%0%
SetParameterInt64(...)100%0%
SetParameterDateTime(...)100%0%
SetParameterString(...)101%0%
SetParameterArray(...)100%0%
SetParameterObject(...)101%0%
SetNull(...)100%0%
IsSimple(...)201%1%
HasBatchParameters(...)101%0%
GetParametersEnumerable()301%1%
GetParametersEnumerable()301%1%

File(s)

/repo-dir/contents/Source/Code/CBAM.SQL/Connection.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 AsyncEnumeration.Abstractions;
 19using CBAM.Abstractions;
 20using CBAM.SQL;
 21using System;
 22using System.Collections.Generic;
 23using System.Linq;
 24using System.Text;
 25using System.Threading;
 26using System.Threading.Tasks;
 27using UtilPack;
 28using UtilPack.TabularData;
 29
 30namespace CBAM.SQL
 31{
 32   /// <summary>
 33   /// This interfaces extends the generic CBAM <see cref="Connection{TStatement, TStatementInformation, TStatementCreat
 34   /// Furthermore, all generic type arguments of <see cref="Connection{TStatement, TStatementInformation, TStatementCre
 35   /// </summary>
 36   public interface SQLConnection : Connection<SQLStatementBuilder, SQLStatementBuilderInformation, String, SQLStatement
 37   {
 38      /// <summary>
 39      /// Gets the <see cref="SQL.DatabaseMetadata"/> object describing the database this <see cref="SQLConnection"/> is
 40      /// </summary>
 41      /// <value>The <see cref="SQL.DatabaseMetadata"/> object describing the database this <see cref="SQLConnection"/> 
 42      /// <seealso cref="SQL.DatabaseMetadata"/>
 43      DatabaseMetadata DatabaseMetadata { get; }
 44
 45      /// <summary>
 46      /// Potentially asynchronously gets the value indicating whether this <see cref="SQLConnection"/> is read-only, .
 47      /// </summary>
 48      /// <returns>A task which on completion will have value indicating whether this <see cref="SQLConnection"/> is rea
 49      ValueTask<Boolean> GetReadOnlyAsync();
 50
 51      /// <summary>
 52      /// Asynchronously sets the value indicating whether this <see cref="SQLConnection"/> is read-only.
 53      /// </summary>
 54      /// <param name="isReadOnly">Whether this connection should be read-only.</param>
 55      /// <returns>A task which on completion has set the value indicating whether this <see cref="SQLConnection"/> is r
 56      ValueTask<Int64> SetReadOnlyAsync( Boolean isReadOnly );
 57
 58      /// <summary>
 59      /// Potentially asynchronously gets the value indicating current transaction isolation level.
 60      /// </summary>
 61      /// <returns>A task which on completion will have value indicating current transaction isolation level.</returns>
 62      /// <seealso cref="TransactionIsolationLevel"/>
 63      ValueTask<TransactionIsolationLevel> GetDefaultTransactionIsolationLevelAsync();
 64
 65      /// <summary>
 66      /// Asynchronously sets the value indicating current transaction isolation level.
 67      /// </summary>
 68      /// <param name="level">The new transaction isolation level.</param>
 69      /// <returns>A task which on completion has set the value indicating current transaction isolation level. The retu
 70      /// <seealso cref="TransactionIsolationLevel"/>
 71      ValueTask<Int64> SetDefaultTransactionIsolationLevelAsync( TransactionIsolationLevel level );
 72
 73      /// <summary>
 74      /// Given current <see cref="SQLStatementExecutionResult"/> and context of reading SQL from some source (<see cref
 75      /// This is used by <see cref="E_CBAM.ExecuteStatementsFromStreamAsync(SQLConnection, MemorizingPotentiallyAsyncRe
 76      /// </summary>
 77      /// <param name="reader">The source where SQL statement originated.</param>
 78      /// <param name="statementInformation">The <see cref="SQLStatementBuilderInformation"/> about current statement.</
 79      /// <param name="executionResult">The <see cref="SQLStatementExecutionResult"/> encountered when enumerating <see 
 80      /// <returns>A task which should return <c>true</c> on completion if anything was done to <paramref name="reader"/
 81      ValueTask<Boolean> ProcessStatementResultPassively( MemorizingPotentiallyAsyncReader<Char?, Char> reader, SQLState
 82
 83   }
 84
 85   /// <summary>
 86   /// This interface extends generic CBAM interface <see cref="ConnectionVendorFunctionality{TStatement, TStatementCrea
 87   /// This functionality has mostly to do with SQL syntax.
 88   /// </summary>
 89   public interface SQLConnectionVendorFunctionality : ConnectionVendorFunctionality<SQLStatementBuilder, String>
 90   {
 91
 92      /// <summary>
 93      /// Given a string, escapes any characters in it so that it can be interpreted as literal string in this SQL vendo
 94      /// </summary>
 95      /// <param name="str">The string to escape. May be <c>null</c>.</param>
 96      /// <returns>Escaped string.</returns>
 97      String EscapeLiteral( String str );
 98
 99      /// <summary>
 100      /// Given a <see cref="PeekablePotentiallyAsyncReader{TValue}"/> (which can wrap a normal <see cref="String"/>), t
 101      /// </summary>
 102      /// <param name="reader">The reader to advance.</param>
 103      /// <returns>A task which will complete after advance is over. Return value is currently not used, since <see cref
 104      ValueTask<Boolean> TryAdvanceReaderOverSingleStatement( PeekablePotentiallyAsyncReader<Char?> reader );
 105
 106      /// <summary>
 107      /// Returns <c>true</c> if given character is ignored when it appears at start of SQL string.
 108      /// </summary>
 109      /// <param name="c">The character to check.</param>
 110      /// <returns><c>true</c> if <paramref name="c"/> is ignored when it appears at start of SQL string.</returns>
 111      Boolean CanTrimBegin( Char c );
 112
 113      /// <summary>
 114      /// Returns <c>true</c> if given character is ignored when it appears at end of SQL string.
 115      /// </summary>
 116      /// <param name="c">The character to check.</param>
 117      /// <returns><c>true</c> if <paramref name="c"/> is ignored when it appears at end of SQL string.</returns>
 118      Boolean CanTrimEnd( Char c );
 119   }
 120
 121   /// <summary>
 122   /// This enumeration describes the transaction isolation levels in relational databases.
 123   /// </summary>
 124   /// <seealso href="https://en.wikipedia.org/wiki/Isolation_(database_systems)"/>
 125   public enum TransactionIsolationLevel
 126   {
 127      /// <summary>
 128      /// Indicates the <c>READ UNCOMMITTED</c> isolation level.
 129      /// </summary>
 130      ReadUncommitted,
 131      /// <summary>
 132      /// Indicates the <c>READ COMMITTED</c> isolation level.
 133      /// </summary>
 134      ReadCommitted,
 135
 136      /// <summary>
 137      /// Indicates the <c>REPEATABLE READ</c> isolation level.
 138      /// </summary>
 139      RepeatableRead,
 140
 141      /// <summary>
 142      /// Indicates the <c>SERIALIZABLE</c> isolation level.
 143      /// </summary>
 144      Serializable
 145   }
 146
 147   /// <summary>
 148   /// This is common interface for items enumerated by <see cref="IAsyncEnumerable{T}"/> returned by <see cref="Connect
 149   /// </summary>
 150   /// <seealso cref="SQLDataRow"/>
 151   /// <seealso cref="SingleCommandExecutionResult"/>
 152   /// <seealso cref="BatchCommandExecutionResult"/>
 153   public interface SQLStatementExecutionResult
 154   {
 155      /// <summary>
 156      /// Gets the warnings issued by backend during last call of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/>.
 157      /// </summary>
 158      /// <value>The warnings issued by backend during last call of <see cref="IAsyncEnumerator{T}.WaitForNextAsync"/>.<
 159      SQLException[] Warnings { get; }
 160   }
 161
 162   /// <summary>
 163   /// This interface extends <see cref="SQLStatementExecutionResult"/> to provide additional information when backend h
 164   /// </summary>
 165   public interface SingleCommandExecutionResult : SQLStatementExecutionResult
 166   {
 167      /// <summary>
 168      /// Gets the amount of rows affected by the single SQL statement.
 169      /// </summary>
 170      /// <value>The amount of rows affected by the single SQL statement.</value>
 171      Int32 AffectedRows { get; }
 172
 173      /// <summary>
 174      /// Gets the vendor-specific command tag string (e.g. <c>"INSERT"</c>, <c>"UPDATE"</c> etc) of the executed SQL st
 175      /// </summary>
 176      /// <value>The vendor-specific command tag string (e.g. <c>"INSERT"</c>, <c>"UPDATE"</c> etc) of the executed SQL 
 177      String CommandTag { get; }
 178   }
 179
 180   /// <summary>
 181   /// This interface extends <see cref="SQLStatementExecutionResult"/> to provide additional information when backend h
 182   /// </summary>
 183   /// <seealso cref="SQLStatementBuilder.AddBatch"/>
 184   public interface BatchCommandExecutionResult : SQLStatementExecutionResult
 185   {
 186      /// <summary>
 187      /// Gets the amount of rows affected by each executed SQL statement.
 188      /// </summary>
 189      /// <value>The amount of rows affected by each executed SQL statement.</value>
 190      Int32[] AffectedRows { get; }
 191
 192      /// <summary>
 193      /// Gets the vendor-specific command tag string (e.g. <c>"INSERT"</c>, <c>"UPDATE"</c> etc) of the executed SQL st
 194      /// </summary>
 195      /// <value>The vendor-specific command tag string (e.g. <c>"INSERT"</c>, <c>"UPDATE"</c> etc) of the executed SQL 
 196      String CommandTag { get; }
 197   }
 198
 199   /// <summary>
 200   /// This interface extends <see cref="SQLStatementExecutionResult"/> to provide additional information about single r
 201   /// Furthermore, this interface extends <see cref="AsyncDataRow"/> to provide access to the columns of the data row.
 202   /// </summary>
 203   public interface SQLDataRow : AsyncDataRow, SQLStatementExecutionResult
 204   {
 205
 206   }
 207
 208   /// <summary>
 209   /// This enumeration is used by <see cref="E_CBAM.ExecuteStatementsFromStreamAsync(SQLConnection, MemorizingPotential
 210   /// </summary>
 211   public enum WhenExceptionInMultipleStatements
 212   {
 213      /// <summary>
 214      /// This value indicates that an exception should be simply re-thrown.
 215      /// </summary>
 216      Rethrow,
 217      /// <summary>
 218      /// This value indicates that exception should be ignored, and current transaction should be rollbacked (no SQL co
 219      /// The SQL statement processing will continue.
 220      /// </summary>
 221      Continue,
 222      /// <summary>
 223      /// This value indicates that exception should be ignored, and new transaction should be started (current transact
 224      /// The SQL statement processing will continue.
 225      /// </summary>
 226      RollbackAndStartNew
 227   }
 228
 229}
 230
 231/// <summary>
 232/// This class contains extension methods for types defined in this assembly.
 233/// </summary>
 234public static partial class E_CBAM
 235{
 236   /// <summary>
 237   /// This method is a shortcut of calling <see cref="M:E_UtilPack.OfType{T, U}(IAsyncEnumerable{T}, OfTypeInfo{U})"/> 
 238   /// </summary>
 239   /// <param name="enumerable">This SQL <see cref="IAsyncEnumerable{T}"/>.</param>
 240   /// <returns>Asynchronous enumerable which only returns <see cref="SQLDataRow"/>s and filters out all other items.</r
 241   /// <exception cref="NullReferenceException">If this <see cref="IAsyncEnumerable{T}"/> is <c>null</c>.</exception>
 242   public static IAsyncEnumerable<SQLDataRow> IncludeDataRowsOnly( this IAsyncEnumerable<SQLStatementExecutionResult> en
 243   {
 87244      return enumerable.Of().Type<SQLDataRow>();
 245   }
 246
 247
 248   //public static Task ExecuteQueryAsync( this SQLConnection connection, SQLStatementBuilder stmt, Action<SQLDataRow> a
 249   //{
 250   //   return connection.PrepareStatementForExecution( stmt ).EnumerateAsync( res => action( res as SQLDataRow ) );
 251   //}
 252
 253   /// <summary>
 254   /// Shortcut method to get some value from first seen <see cref="SQLDataRow"/> of <see cref="IAsyncEnumerator{T}"/> r
 255   /// </summary>
 256   /// <typeparam name="T">The type of the value to return.</typeparam>
 257   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 258   /// <param name="statement">The <see cref="SQLStatementBuilder"/> to execute.</param>
 259   /// <param name="extractor">The asynchronous callback to get value from <see cref="SQLDataRow"/>.</param>
 260   /// <returns>A task which will return value of <paramref name="extractor"/> if at least one <see cref="SQLDataRow"/> 
 261   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 262   /// <exception cref="ArgumentNullException">If <paramref name="statement"/> or <paramref name="extractor"/> is <c>nul
 263   public static async ValueTask<T> GetFirstOrDefaultAsync<T>( this SQLConnection connection, SQLStatementBuilder statem
 264   {
 0265      ArgumentValidator.ValidateNotNullReference( connection );
 0266      ArgumentValidator.ValidateNotNull( nameof( extractor ), extractor );
 0267      return await connection.PrepareStatementForExecution( statement )
 0268         .IncludeDataRowsOnly()
 0269         .Select( row => extractor( row ) )
 0270         .FirstOrDefaultAsync();
 0271   }
 272
 273   /// <summary>
 274   /// Shortcut method to get some value from first seen <see cref="SQLDataRow"/> of <see cref="IAsyncEnumerator{T}"/> r
 275   /// </summary>
 276   /// <typeparam name="T">The type of the value to return.</typeparam>
 277   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 278   /// <param name="sql">The SQL string.</param>
 279   /// <param name="extractor">The asynchronous callback to get value from <see cref="SQLDataRow"/>.</param>
 280   /// <returns>A task which will return value of <paramref name="extractor"/> if at least one <see cref="SQLDataRow"/> 
 281   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 282   /// <exception cref="ArgumentNullException">If <paramref name="sql"/> or <paramref name="extractor"/> is <c>null</c>.
 283   public static ValueTask<T> GetFirstOrDefaultAsync<T>( this SQLConnection connection, String sql, Func<AsyncDataRow, V
 284   {
 0285      return connection.GetFirstOrDefaultAsync( connection.VendorFunctionality.CreateStatementBuilder( sql ), extractor 
 286   }
 287
 288   /// <summary>
 289   /// Shortcut method to get some value from first seen <see cref="SQLDataRow"/> of <see cref="IAsyncEnumerator{T}"/> r
 290   /// This method lets optionally specify a callback to extract value from single <see cref="AsyncDataColumn"/>, and al
 291   /// </summary>
 292   /// <typeparam name="T">The type of the value to return.</typeparam>
 293   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 294   /// <param name="statement">The <see cref="SQLStatementBuilder"/> to execute.</param>
 295   /// <param name="parameterIndex">The index of the <see cref="AsyncDataColumn"/> to pass to <paramref name="extractor"
 296   /// <param name="extractor">The optional asynchronous callback to use to extract the value from <see cref="AsyncDataC
 297   /// <returns>A task which will return value of <paramref name="extractor"/> if at least one <see cref="SQLDataRow"/> 
 298   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 299   /// <exception cref="ArgumentNullException">If <paramref name="statement"/> is <c>null</c>.</exception>
 300   public static async ValueTask<T> GetFirstOrDefaultAsync<T>( this SQLConnection connection, SQLStatementBuilder statem
 301   {
 75302      return await connection
 75303         .PrepareStatementForExecution( statement )
 75304         .IncludeDataRowsOnly()
 153305         .Select( async row => await ( extractor?.Invoke( row.GetColumn( parameterIndex ) ) ?? row.GetValueAsync<T>( par
 75306         .FirstOrDefaultAsync();
 76307   }
 308
 309   /// <summary>
 310   /// Shortcut method to get some value from first seen <see cref="SQLDataRow"/> of <see cref="IAsyncEnumerator{T}"/> r
 311   /// This method lets optionally specify a callback to extract value from single <see cref="AsyncDataColumn"/>, and al
 312   /// </summary>
 313   /// <typeparam name="T">The type of the value to return.</typeparam>
 314   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 315   /// <param name="sql">The <see cref="SQLStatementBuilder"/> to execute.</param>
 316   /// <param name="parameterIndex">The index of the <see cref="AsyncDataColumn"/> to pass to <paramref name="extractor"
 317   /// <param name="extractor">The optional asynchronous callback to use to extract the value from <see cref="AsyncDataC
 318   /// <returns>A task which will return value of <paramref name="extractor"/> if at least one <see cref="SQLDataRow"/> 
 319   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 320   /// <exception cref="ArgumentNullException">If <paramref name="sql"/> is <c>null</c>.</exception>
 321   public static ValueTask<T> GetFirstOrDefaultAsync<T>( this SQLConnection connection, String sql, Int32 parameterIndex
 322   {
 35323      return connection.GetFirstOrDefaultAsync( connection.VendorFunctionality.CreateStatementBuilder( sql ), parameterI
 324   }
 325
 326   /// <summary>
 327   /// This is helper method to perform some action on <see cref="SQLConnection"/> and make sure that the connection is 
 328   /// </summary>
 329   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 330   /// <param name="action">The asynchronous callback to use <see cref="SQLConnection"/></param>
 331   /// <returns>A task which on completion has executed given <paramref name="action"/> callback.</returns>
 332   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 333   /// <exception cref="ArgumentNullException">If <paramref name="action"/> is <c>null</c>.</exception>
 334   public static Task DoWriteStatements( this SQLConnection connection, Func<SQLConnection, Task> action )
 335   {
 0336      return connection.DoStatements( action, false );
 337   }
 338
 339   /// <summary>
 340   /// This is helper method to perform some asynchronous action on <see cref="SQLConnection"/> and make sure that the c
 341   /// Then, some value whhich is obtained by the asynchronous action, is returned.
 342   /// </summary>
 343   /// <typeparam name="T">The type of return value of callback</typeparam>
 344   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 345   /// <param name="func">The asynchronous callback to use <see cref="SQLConnection"/> and return value of type <typepar
 346   /// <returns>A task which on completion has executed given <paramref name="func"/> callback.</returns>
 347   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 348   /// <exception cref="ArgumentNullException">If <paramref name="func"/> is <c>null</c>.</exception>
 349   public static ValueTask<T> DoWriteStatements<T>( this SQLConnection connection, Func<SQLConnection, ValueTask<T>> fun
 350   {
 0351      return connection.DoStatements( func, false );
 352   }
 353
 354   /// <summary>
 355   /// This is helper method to perform some action on <see cref="SQLConnection"/> and make sure that the connection is 
 356   /// </summary>
 357   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 358   /// <param name="action">The asynchronous callback to use <see cref="SQLConnection"/></param>
 359   /// <returns>A task which on completion has executed given <paramref name="action"/> callback.</returns>
 360   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 361   /// <exception cref="ArgumentNullException">If <paramref name="action"/> is <c>null</c>.</exception>
 362   public static Task DoReadStatements( this SQLConnection connection, Func<SQLConnection, Task> action )
 363   {
 0364      return connection.DoStatements( action, true );
 365   }
 366
 367   /// <summary>
 368   /// This is helper method to perform some asynchronous action on <see cref="SQLConnection"/> and make sure that the c
 369   /// Then, some value whhich is obtained by the asynchronous action, is returned.
 370   /// </summary>
 371   /// <typeparam name="T">The type of return value of callback</typeparam>
 372   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 373   /// <param name="func">The asynchronous callback to use <see cref="SQLConnection"/> and return value of type <typepar
 374   /// <returns>A task which on completion has executed given <paramref name="func"/> callback.</returns>
 375   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 376   /// <exception cref="ArgumentNullException">If <paramref name="func"/> is <c>null</c>.</exception>
 377   public static ValueTask<T> DoReadStatements<T>( this SQLConnection connection, Func<SQLConnection, ValueTask<T>> func
 378   {
 0379      return connection.DoStatements( func, true );
 380   }
 381
 382   /// <summary>
 383   /// This is generic method to execute some asynchronous callback for this <see cref="SQLConnection"/> and make sure t
 384   /// </summary>
 385   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 386   /// <param name="action">The asynchronous callback to use <see cref="SQLConnection"/>.</param>
 387   /// <param name="readOnly">Whether to set <see cref="SQLConnection"/> in readonly mode before calling <paramref name=
 388   /// <returns>A task which on completion has executed given <paramref name="action"/> callback.</returns>
 389   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 390   /// <exception cref="ArgumentNullException">If <paramref name="action"/> is <c>null</c>.</exception>
 391   public static async Task DoStatements( this SQLConnection connection, Func<SQLConnection, Task> action, Boolean readO
 392   {
 0393      ArgumentValidator.ValidateNotNull( nameof( action ), action );
 0394      var needToChange = await connection.GetReadOnlyAsync() != readOnly;
 0395      if ( needToChange )
 396      {
 0397         await connection.SetReadOnlyAsync( readOnly );
 398      }
 399      try
 400      {
 0401         await action( connection );
 402      }
 403      finally
 404      {
 0405         if ( needToChange )
 406         {
 0407            await connection.SetReadOnlyAsync( !readOnly );
 408         }
 409      }
 0410   }
 411
 412   /// <summary>
 413   /// This is generic method to execute some asynchronous callback for this <see cref="SQLConnection"/> and make sure t
 414   /// </summary>
 415   /// <typeparam name="T">The return type of the task of the asynchronous callback.</typeparam>
 416   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 417   /// <param name="func">The asynchronous callback to use <see cref="SQLConnection"/>.</param>
 418   /// <param name="readOnly">Whether to set <see cref="SQLConnection"/> in readonly mode before calling <paramref name=
 419   /// <returns>A task which on completion has executed given <paramref name="func"/> callback, and returns the result o
 420   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 421   /// <exception cref="ArgumentNullException">If <paramref name="func"/> is <c>null</c>.</exception>
 422   public static async ValueTask<T> DoStatements<T>( this SQLConnection connection, Func<SQLConnection, ValueTask<T>> fu
 423   {
 0424      ArgumentValidator.ValidateNotNull( nameof( func ), func );
 0425      var needToChange = await connection.GetReadOnlyAsync() != readOnly;
 0426      if ( needToChange )
 427      {
 0428         await connection.SetReadOnlyAsync( readOnly );
 429      }
 430      try
 431      {
 0432         return await func( connection );
 433      }
 434      finally
 435      {
 0436         if ( needToChange )
 437         {
 0438            await connection.SetReadOnlyAsync( !readOnly );
 439         }
 440      }
 0441   }
 442
 443
 444   /// <summary>
 445   /// This method can be used to read SQL statements from stream (e.g. a file) and passively process each statement wit
 446   /// </summary>
 447   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 448   /// <param name="stream">The <see cref="System.IO.Stream"/> containing the SQL statements.</param>
 449   /// <param name="encoding">The <see cref="Encoding"/> to use when reading textual SQL statemetns from <paramref name=
 450   /// <param name="streamMaxBufferCount">The amount of characters to read for one statement until the buffer is cleared
 451   /// <param name="streamReadChunkCount">The amount bytes to read in one chunk from given <paramref name="stream"/>.</p
 452   /// <param name="onException">Optional callback to react when <see cref="SQLException"/> occurs during passive proces
 453   /// <param name="token">Optional <see cref="CancellationToken"/> to use when creating <see cref="StreamReaderWithResi
 454   /// <returns>A task which will on completion return amount of statements read.</returns>
 455   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 456   /// <exception cref="ArgumentNullException">If <paramref name="stream"/> is <c>null</c>.</exception>
 457   /// <seealso cref="ExecuteStatementsFromStreamAsync(SQLConnection, MemorizingPotentiallyAsyncReader{Char?, Char}, Fun
 458   /// <seealso cref="WhenExceptionInMultipleStatements"/>
 459   public static async ValueTask<Int64> ExecuteStatementsFromStreamAsync(
 460      this SQLConnection connection,
 461      System.IO.Stream stream,
 462      Encoding encoding,
 463      Int32 streamMaxBufferCount = 1024,
 464      Int32 streamReadChunkCount = 1024,
 465      Func<SQLException, WhenExceptionInMultipleStatements> onException = null,
 466      CancellationToken token = default
 467   )
 468   {
 0469      ArgumentValidator.ValidateNotNullReference( connection );
 470
 0471      var streamReader = StreamFactory.CreateUnlimitedReader(
 0472            stream,
 0473            token: token,
 0474            chunkSize: streamReadChunkCount
 0475         );
 0476      var charReader = ReaderFactory.NewNullableMemorizingValueReader(
 0477         new StreamCharacterReaderLogic( ( encoding ?? new UTF8Encoding( false, false ) ).CreateDefaultEncodingInfo() ),
 0478         streamReader
 0479         );
 0480      using ( charReader.ClearStreamWhenStreamBufferTooBig( streamReader, streamMaxBufferCount ) )
 481      {
 0482         return await connection.ExecuteStatementsFromStreamAsync( charReader, onException: onException );
 483      }
 0484   }
 485
 486
 487   /// <summary>
 488   /// This method can be used to read SQL statements from <see cref="MemorizingPotentiallyAsyncReader{TValue, TBufferIt
 489   /// </summary>
 490   /// <param name="connection">This <see cref="SQLConnection"/>.</param>
 491   /// <param name="reader">The <see cref="MemorizingPotentiallyAsyncReader{TValue, TBufferItem}"/> reader to use to rea
 492   /// <param name="onException">Optional callback to react when <see cref="SQLException"/> occurs during passive proces
 493   /// <returns>A task which will on completion return amount of statements read.</returns>
 494   /// <exception cref="NullReferenceException">If this <see cref="SQLConnection"/> is <c>null</c>.</exception>
 495   /// <exception cref="ArgumentNullException">If <paramref name="reader"/> is <c>null</c>.</exception>
 496   /// <seealso cref="ExecuteStatementsFromStreamAsync(SQLConnection, System.IO.Stream, Encoding, Int32, Int32, Func{SQL
 497   /// <seealso cref="WhenExceptionInMultipleStatements"/>
 498   /// <seealso cref="MemorizingPotentiallyAsyncReader{TValue, TBufferItem}"/>
 499   public static async ValueTask<Int64> ExecuteStatementsFromStreamAsync(
 500      this SQLConnection connection,
 501      MemorizingPotentiallyAsyncReader<Char?, Char> reader,
 502      Func<SQLException, WhenExceptionInMultipleStatements> onException = null
 503      )
 504   {
 505      Int32 charsRead;
 0506      var totalStatements = 0;
 0507      var vendorFunc = connection.VendorFunctionality;
 0508      ArgumentValidator.ValidateNotNull( nameof( reader ), reader );
 509      do
 510      {
 0511         reader.ClearBuffer();
 0512         await vendorFunc.TryAdvanceReaderOverSingleStatement( reader );
 0513         charsRead = reader.BufferCount;
 0514         if ( charsRead > 0 )
 515         {
 0516            var start = 0;
 0517            var count = reader.BufferCount;
 518            // Trim begin
 0519            while ( count > 0 && vendorFunc.CanTrimBegin( reader.Buffer[start] ) )
 520            {
 0521               ++start;
 0522               --count;
 523            }
 524            // Trim end
 0525            while ( count > 0 && vendorFunc.CanTrimEnd( reader.Buffer[start + count - 1] ) )
 526            {
 0527               --count;
 528            }
 529
 0530            if ( count > 0 )
 531            {
 0532               WhenExceptionInMultipleStatements? whenException = null;
 0533               var stmt = connection.CreateStatementBuilder( new String( reader.Buffer, start, count ) );
 0534               var enumerable = connection.PrepareStatementForExecution( stmt );
 0535               var stmtInfo = stmt.StatementBuilderInformation;
 536               try
 537               {
 0538                  await enumerable.EnumerateAsync( res =>
 0539                  {
 0540                     connection.ProcessStatementResultPassively( reader, stmtInfo, res );
 0541                  } );
 0542               }
 0543               catch ( SQLException sqle )
 544               {
 545                  try
 546                  {
 0547                     whenException = onException?.Invoke( sqle );
 0548                  }
 0549                  catch
 550                  {
 551                     // Ignore
 0552                  }
 553
 0554                  if ( !whenException.HasValue || whenException == WhenExceptionInMultipleStatements.Rethrow )
 555                  {
 0556                     throw;
 557                  }
 0558               }
 559
 0560               if ( whenException.HasValue )
 561               {
 562                  // Have to issue ROLLBACK statement in order to continue from errors
 563                  // Except that transaction is automatically rollbacked when an error occurs.
 564                  //await connection.ExecuteNonQueryAsync( "ROLLBACK" );
 565
 0566                  if ( whenException.Value == WhenExceptionInMultipleStatements.RollbackAndStartNew )
 567                  {
 568                     // TODO additional optional parameter to specify additional parameters to BEGIN TRANSACTION (isolat
 569                     // or, create DSL to SQLConnection
 0570                     await connection.ExecuteAndIgnoreResults( "BEGIN TRANSACTION" );
 571                  }
 572               }
 573
 0574               ++totalStatements;
 0575            }
 576         }
 577
 0578      } while ( charsRead > 0 );
 579
 0580      return totalStatements;
 0581   }
 582
 583}

/repo-dir/contents/Source/Code/CBAM.SQL/Statement.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 System;
 19using System.Collections.Generic;
 20using System.Linq;
 21using System.Text;
 22using System.Threading;
 23using CBAM.SQL;
 24using System.Reflection;
 25using System.Threading.Tasks;
 26using UtilPack;
 27
 28namespace CBAM.SQL
 29{
 30   /// <summary>
 31   /// This interface provides read-only API for <see cref="SQLStatementBuilder"/>.
 32   /// </summary>
 33   /// <seealso cref="SQLStatementBuilder"/>
 34   /// <seealso cref="SQLStatementBuilder.StatementBuilderInformation"/>
 35   public interface SQLStatementBuilderInformation
 36   {
 37      /// <summary>
 38      /// Gets the amount of SQL parameters (question marks) in this SQL statement.
 39      /// </summary>
 40      /// <value>The amount of SQL parameters (question marks) in this SQL statement.</value>
 41      Int32 SQLParameterCount { get; }
 42
 43      /// <summary>
 44      /// Gets the current count of batch parameters.
 45      /// </summary>
 46      /// <value>The current count of batch parameters.</value>
 47      Int32 BatchParameterCount { get; }
 48
 49      /// <summary>
 50      /// Gets information about parameter at given index.
 51      /// Maximum amount of parametrs can be queried via <see cref="SQLParameterCount"/> property.
 52      /// </summary>
 53      /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &l
 54      /// <returns>The parameter information at given index.</returns>
 55      /// <exception cref="ArgumentException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 56      /// <seealso cref="StatementParameter"/>
 57      StatementParameter GetParameterInfo( Int32 parameterIndex );
 58
 59      /// <summary>
 60      /// Gets information about parameter which has been previously added to batch of parameters.
 61      /// </summary>
 62      /// <param name="batchIndex">The batch index. Should be <c>0 ≤ <paramref name="batchIndex"/> &lt; <see cref="Batch
 63      /// <param name="parameterIndex">The parameter index. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; <see
 64      /// <returns>The parameter information at given batch and parameter indices.</returns>
 65      /// <exception cref="ArgumentException">If either of <paramref name="batchIndex"/> or <paramref name="parameterInd
 66      /// <seealso cref="StatementParameter"/>
 67      StatementParameter GetBatchParameterInfo( Int32 batchIndex, Int32 parameterIndex );
 68
 69      /// <summary>
 70      /// Gets the textual SQL statement of this <see cref="SQLStatementBuilderInformation"/>.
 71      /// </summary>
 72      /// <value>The textual SQL statement of this <see cref="SQLStatementBuilderInformation"/>.</value>
 73      String SQL { get; }
 74   }
 75
 76   /// <summary>
 77   /// This interface extends read-only <see cref="SQLStatementBuilderInformation"/> with modifiable API.
 78   /// Not that just like in JDBC, the parameters for prepared statement should be question marks in statement SQL given
 79   /// </summary>
 80   public interface SQLStatementBuilder : SQLStatementBuilderInformation
 81   {
 82
 83      /// <summary>
 84      /// Sets the parameter at given index to given value
 85      /// </summary>
 86      /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &l
 87      /// <param name="value">The value to set. May be <c>null</c>.</param>
 88      /// <param name="clrType">The type of the value. If value is not <c>null</c> and this parameter is <c>null</c>, th
 89      /// <exception cref="ArgumentNullException">If both <paramref name="value"/> and <paramref name="clrType"/> are <c
 90      /// <exception cref="ArgumentException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 91      /// <seealso cref="E_CBAM.SetNull(SQLStatementBuilder, int, Type)"/>
 92      /// <seealso cref="E_CBAM.SetParameterBoolean(SQLStatementBuilder, int, bool?)"/>
 93      /// <seealso cref="E_CBAM.SetParameterInt16(SQLStatementBuilder, int, short?)"/>
 94      /// <seealso cref="E_CBAM.SetParameterInt32(SQLStatementBuilder, int, int?)"/>
 95      /// <seealso cref="E_CBAM.SetParameterInt64(SQLStatementBuilder, int, long?)"/>
 96      /// <seealso cref="E_CBAM.SetParameterString(SQLStatementBuilder, int, string)"/>
 97      /// <seealso cref="E_CBAM.SetParameterDateTime(SQLStatementBuilder, int, DateTime?)"/>
 98      /// <seealso cref="E_CBAM.SetParameterArray{TElement}(SQLStatementBuilder, int, Array)"/>
 99      void SetParameterObjectWithType( Int32 parameterIndex, Object value, Type clrType );
 100
 101      /// <summary>
 102      /// Given that this builder contains a set of parameters added via <see cref="SetParameterObjectWithType"/>, adds 
 103      /// Then clears the current set of parameters.
 104      /// </summary>
 105      /// <exception cref="InvalidOperationException">If there is at least one parameter that has not been set.</excepti
 106      void AddBatch();
 107
 108      /// <summary>
 109      /// Removes all parameters previously added to batch via <see cref="AddBatch"/> call.
 110      /// </summary>
 111      void RemoveAllBatchedParameters();
 112
 113      /// <summary>
 114      /// Gets the read-only <see cref="SQLStatementBuilderInformation"/> object which has same state as this <see cref=
 115      /// </summary>
 116      /// <value>The read-only <see cref="SQLStatementBuilderInformation"/> object which has same state as this <see cre
 117      /// <remarks>
 118      /// The returned object must not be castable back to this <see cref="SQLStatementBuilder"/>.
 119      /// </remarks>
 120      SQLStatementBuilderInformation StatementBuilderInformation { get; }
 121   }
 122
 123   /// <summary>
 124   /// This interface contains information about a single parameter in <see cref="SQLStatementBuilderInformation"/>.
 125   /// </summary>
 126   public interface StatementParameter // : IEquatable<StatementParameter>
 127   {
 128      /// <summary>
 129      /// Gets the <see cref="Type"/> of the parameter value.
 130      /// </summary>
 131      /// <value>The <see cref="Type"/> of the parameter value.</value>
 132      Type ParameterCILType { get; }
 133
 134      /// <summary>
 135      /// Gets the parameter value.
 136      /// May be <c>null</c>.
 137      /// </summary>
 138      /// <value>The parameter value.</value>
 139      Object ParameterValue { get; }
 140   }
 141}
 142
 143public static partial class E_CBAM
 144{
 145   /// <summary>
 146   /// This is shortcut method to set parameter as a <see cref="Boolean"/> value at given index.
 147   /// </summary>
 148   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 149   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 150   /// <param name="value">The nullable <see cref="Boolean"/> value to set.</param>
 151   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilder"/> is <c>null</c>.</exception>
 152   /// <exception cref="ArgumentException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 153   public static void SetParameterBoolean( this SQLStatementBuilder stmt, Int32 parameterIndex, Boolean? value )
 154   {
 0155      stmt.SetParameterObjectWithType( parameterIndex, value, typeof( Boolean ) );
 0156   }
 157
 158   /// <summary>
 159   /// This is shortcut method to set parameter as a <see cref="Int32"/> value at given index.
 160   /// </summary>
 161   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 162   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 163   /// <param name="value">The nullable <see cref="Int32"/> value to set.</param>
 164   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilder"/> is <c>null</c>.</exception>
 165   /// <exception cref="ArgumentException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 166   public static void SetParameterInt32( this SQLStatementBuilder stmt, Int32 parameterIndex, Int32? value )
 167   {
 3168      stmt.SetParameterObjectWithType( parameterIndex, value, typeof( Int32 ) );
 3169   }
 170
 171   /// <summary>
 172   /// This is shortcut method to set parameter as a <see cref="Int16"/> value at given index.
 173   /// </summary>
 174   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 175   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 176   /// <param name="value">The nullable <see cref="Int16"/> value to set.</param>
 177   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilder"/> is <c>null</c>.</exception>
 178   /// <exception cref="ArgumentException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 179   public static void SetParameterInt16( this SQLStatementBuilder stmt, Int32 parameterIndex, Int16? value )
 180   {
 0181      stmt.SetParameterObjectWithType( parameterIndex, value, typeof( Int16 ) );
 0182   }
 183
 184   /// <summary>
 185   /// This is shortcut method to set parameter as a <see cref="Int64"/> value at given index.
 186   /// </summary>
 187   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 188   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 189   /// <param name="value">The nullable <see cref="Int64"/> value to set.</param>
 190   /// <exception cref="ArgumentException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 191   public static void SetParameterInt64( this SQLStatementBuilder stmt, Int32 parameterIndex, Int64? value )
 192   {
 0193      stmt.SetParameterObjectWithType( parameterIndex, value, typeof( Int64 ) );
 0194   }
 195
 196   /// <summary>
 197   /// This is shortcut method to set parameter as a <see cref="DateTime"/> value at given index.
 198   /// </summary>
 199   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 200   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 201   /// <param name="value">The nullable <see cref="DateTime"/> value to set.</param>
 202   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilder"/> is <c>null</c>.</exception>
 203   /// <exception cref="ArgumentException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 204   public static void SetParameterDateTime( this SQLStatementBuilder stmt, Int32 parameterIndex, DateTime? value )
 205   {
 0206      stmt.SetParameterObjectWithType( parameterIndex, value, typeof( DateTime ) );
 0207   }
 208
 209   /// <summary>
 210   /// This is shortcut method to set parameter as a <see cref="String"/> value at given index.
 211   /// </summary>
 212   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 213   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 214   /// <param name="value">The nullable <see cref="String"/> value to set.</param>
 215   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilder"/> is <c>null</c>.</exception>
 216   /// <exception cref="ArgumentException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 217   public static void SetParameterString( this SQLStatementBuilder stmt, Int32 parameterIndex, String value )
 218   {
 6219      stmt.SetParameterObjectWithType( parameterIndex, value, typeof( String ) );
 6220   }
 221
 222   /// <summary>
 223   /// This is shortcut method to set parameter as an array value at given index.
 224   /// </summary>
 225   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 226   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 227   /// <param name="value">The array to set.</param>
 228   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilder"/> is <c>null</c>.</exception>
 229   /// <exception cref="ArgumentNullException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 230   public static void SetParameterArray<TElement>( this SQLStatementBuilder stmt, Int32 parameterIndex, Array value )
 231   {
 0232      stmt.SetParameterObjectWithType( parameterIndex, value, typeof( TElement[] ) );
 0233   }
 234
 235
 236   /// <summary>
 237   /// This is shortcut method to set parameter as value of specified type, when the type is known at compile time.
 238   /// </summary>
 239   /// <typeparam name="T">The type of the value.</typeparam>
 240   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 241   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 242   /// <param name="value">The value to set.</param>
 243   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilder"/> is <c>null</c>.</exception>
 244   /// <exception cref="ArgumentNullException">If <paramref name="parameterIndex"/> is out of bounds.</exception>
 245   public static void SetParameterObject<T>( this SQLStatementBuilder stmt, Int32 parameterIndex, Object value )
 246   {
 2247      stmt.SetParameterObjectWithType( parameterIndex, value, typeof( T ) );
 2248   }
 249
 250   /// <summary>
 251   /// Sets the parameter at given index to <c>null</c>.
 252   /// </summary>
 253   /// <param name="stmt">This <see cref="SQLStatementBuilder"/>.</param>
 254   /// <param name="parameterIndex">The index of the parameter. Should be <c>0 ≤ <paramref name="parameterIndex"/> &lt; 
 255   /// <param name="clrType">The expected type of the SQL value.</param>
 256   public static void SetNull( this SQLStatementBuilder stmt, Int32 parameterIndex, Type clrType )
 257   {
 0258      stmt.SetParameterObjectWithType( parameterIndex, null, clrType );
 0259   }
 260
 261
 262   /// <summary>
 263   /// Helper method to detect whether this <see cref="SQLStatementBuilderInformation"/> is simple - that is, it contain
 264   /// </summary>
 265   /// <param name="stmt">This <see cref="SQLStatementBuilderInformation"/>.</param>
 266   /// <returns><c>true</c> if this <see cref="SQLStatementBuilderInformation"/> has no batched parameter sets, and also
 267   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilderInformation"/> is <c>null</c>.</ex
 268   public static Boolean IsSimple( this SQLStatementBuilderInformation stmt )
 269   {
 92270      return !stmt.HasBatchParameters() && stmt.SQLParameterCount == 0;
 271   }
 272
 273   /// <summary>
 274   /// Helper method to detect whether this <see cref="SQLStatementBuilderInformation"/> has any batch parameters - that
 275   /// </summary>
 276   /// <param name="stmt">This <see cref="SQLStatementBuilderInformation"/>.</param>
 277   /// <returns><c>true</c> if this <see cref="SQLStatementBuilderInformation"/> has batch parameters; <c>false</c> othe
 278   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilderInformation"/> is <c>null</c>.</ex
 279   public static Boolean HasBatchParameters( this SQLStatementBuilderInformation stmt )
 280   {
 282281      return stmt.BatchParameterCount > 0;
 282   }
 283
 284   /// <summary>
 285   /// Helper method to get enumerable of <see cref="StatementParameter"/>s of this <see cref="SQLStatementBuilderInform
 286   /// </summary>
 287   /// <param name="stmt">This <see cref="SQLStatementBuilderInformation"/>.</param>
 288   /// <returns>An enumerable of <see cref="StatementParameter"/>s of this <see cref="SQLStatementBuilderInformation"/>.
 289   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilderInformation"/> is <c>null</c>.</ex
 290   public static IEnumerable<StatementParameter> GetParametersEnumerable( this SQLStatementBuilderInformation stmt )
 291   {
 42292      var max = stmt.SQLParameterCount;
 195293      for ( var i = 0; i < max; ++i )
 294      {
 51295         yield return stmt.GetParameterInfo( i );
 296      }
 47297   }
 298
 299   /// <summary>
 300   /// Helper method to get enumerable of batched <see cref="StatementParameter"/>s at given batch index.
 301   /// </summary>
 302   /// <param name="stmt">This <see cref="SQLStatementBuilderInformation"/>.</param>
 303   /// <param name="batchIndex">The batch index of the parameter set to enumerate. Should be <c>0 ≤ <paramref name="batc
 304   /// <returns>An enumerable of batched <see cref="StatementParameter"/>s at given batch index.</returns>
 305   /// <exception cref="NullReferenceException">If this <see cref="SQLStatementBuilderInformation"/> is <c>null</c>.</ex
 306   /// <exception cref="ArgumentException">If <paramref name="batchIndex"/> is out of bounds.</exception>
 307   public static IEnumerable<StatementParameter> GetParametersEnumerable( this SQLStatementBuilderInformation stmt, Int3
 308   {
 12309      var max = stmt.SQLParameterCount;
 36310      for ( var i = 0; i < max; ++i )
 311      {
 6312         yield return stmt.GetBatchParameterInfo( batchIndex, i );
 313      }
 12314   }
 315
 316}
 317
 318

Methods/Properties

IncludeDataRowsOnly(System.Collections.Generic.IAsyncEnumerable`1<CBAM.SQL.SQLStatementExecutionResult>)
GetFirstOrDefaultAsync()
GetFirstOrDefaultAsync(CBAM.SQL.SQLConnection,System.String,System.Func`2<UtilPack.TabularData.AsyncDataRow,System.Threading.Tasks.ValueTask`1<T>>)
GetFirstOrDefaultAsync()
>c__DisplayClass3_0`1/<<GetFirstOrDefaultAsync()
GetFirstOrDefaultAsync(CBAM.SQL.SQLConnection,System.String,System.Int32,System.Func`2<UtilPack.TabularData.AsyncDataColumn,System.Threading.Tasks.ValueTask`1<T>>)
DoWriteStatements(CBAM.SQL.SQLConnection,System.Func`2<CBAM.SQL.SQLConnection,System.Threading.Tasks.Task>)
DoWriteStatements(CBAM.SQL.SQLConnection,System.Func`2<CBAM.SQL.SQLConnection,System.Threading.Tasks.ValueTask`1<T>>)
DoReadStatements(CBAM.SQL.SQLConnection,System.Func`2<CBAM.SQL.SQLConnection,System.Threading.Tasks.Task>)
DoReadStatements(CBAM.SQL.SQLConnection,System.Func`2<CBAM.SQL.SQLConnection,System.Threading.Tasks.ValueTask`1<T>>)
DoStatements()
DoStatements()
ExecuteStatementsFromStreamAsync()
ExecuteStatementsFromStreamAsync()
SetParameterBoolean(CBAM.SQL.SQLStatementBuilder,System.Int32,System.Nullable`1<System.Boolean>)
SetParameterInt32(CBAM.SQL.SQLStatementBuilder,System.Int32,System.Nullable`1<System.Int32>)
SetParameterInt16(CBAM.SQL.SQLStatementBuilder,System.Int32,System.Nullable`1<System.Int16>)
SetParameterInt64(CBAM.SQL.SQLStatementBuilder,System.Int32,System.Nullable`1<System.Int64>)
SetParameterDateTime(CBAM.SQL.SQLStatementBuilder,System.Int32,System.Nullable`1<System.DateTime>)
SetParameterString(CBAM.SQL.SQLStatementBuilder,System.Int32,System.String)
SetParameterArray(CBAM.SQL.SQLStatementBuilder,System.Int32,System.Array)
SetParameterObject(CBAM.SQL.SQLStatementBuilder,System.Int32,System.Object)
SetNull(CBAM.SQL.SQLStatementBuilder,System.Int32,System.Type)
IsSimple(CBAM.SQL.SQLStatementBuilderInformation)
HasBatchParameters(CBAM.SQL.SQLStatementBuilderInformation)
GetParametersEnumerable()
GetParametersEnumerable()