//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// CommonHelpers satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace CommonHelpers {

//**************************************************************************************************
partial class HSqlOperator {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="ArgumentNullException" />
public Task<int> ExecuteNonQuery_A(string commandText) =>
   ExecuteNonQuery_A( null, commandText );
/// <exception cref="ArgumentNullException" />
public Task<int> ExecuteNonQuery_A(string commandText,params SqlParameter[] sqlParams) =>
   ExecuteNonQuery_A( null, commandText, sqlParams );

/// <exception cref="ArgumentNullException" />
public Task<int> ExecuteNonQueryFmt_A(string commandTextFmt,params object?[] parameters) =>
   ExecuteNonQueryFmt_A( null, commandTextFmt, parameters );

//--------------------------------------------------------------------------------------------------

/// <exception cref="ArgumentNullException" />
public async Task<int> ExecuteNonQuery_A([HOptional] SqlTransaction? transaction,string commandText)
{
   using (var cmd = PrepareCommand( transaction, commandText ))
      return await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
}
/// <exception cref="ArgumentNullException" />
public async Task<int> ExecuteNonQuery_A( [HOptional] SqlTransaction? transaction,
                                          string commandText, params SqlParameter[] sqlParams )
{
   using (var cmd = PrepareCommand( transaction, commandText, sqlParams))
      return await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
}

/// <exception cref="ArgumentNullException" />
public Task<int> ExecuteNonQueryFmt_A( [HOptional] SqlTransaction? transaction,
                                       string commandTextFmt, params object?[] parameters ) =>
   ExecuteNonQuery_A( transaction, HString.FormatAsText( commandTextFmt, parameters ) );

//==================================================================================================

/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReader_A(string commandText) =>
   ExecuteReader_A( null, CommandBehavior.Default, commandText );
/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReader_A(string commandText,params SqlParameter[] sqlParams) =>
   ExecuteReader_A( CommandBehavior.Default, commandText, sqlParams );

/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReaderFmt_A(string commandTextFmt,params object?[] parameters) =>
   ExecuteReaderFmt_A( null, CommandBehavior.Default, commandTextFmt, parameters );

//--------------------------------------------------------------------------------------------------

/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReader_A( [HOptional] SqlTransaction? transaction,
                                            string commandText ) =>
   ExecuteReader_A( transaction, CommandBehavior.Default, commandText );
/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReader_A( [HOptional] SqlTransaction? transaction,
                                            string commandText,
                                            params SqlParameter[] sqlParams ) =>
   ExecuteReader_A( transaction, CommandBehavior.Default, commandText, sqlParams );

/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReaderFmt_A( [HOptional] SqlTransaction? transaction,
                                               string commandTextFmt,
                                               params object?[] parameters ) =>
   ExecuteReaderFmt_A( transaction, CommandBehavior.Default, commandTextFmt, parameters );

//==================================================================================================

/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReader_A( [HOptional] CommandBehavior behaviour,
                                            string commandText ) =>
   ExecuteReader_A( null, behaviour, commandText );
/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReader_A( [HOptional] CommandBehavior behaviour,
                                            string commandText,
                                            params SqlParameter[] sqlParams ) =>
   ExecuteReader_A( null, behaviour, commandText, sqlParams );

/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReaderFmt_A( [HOptional] CommandBehavior behaviour,
                                               string commandTextFmt,
                                               params object?[] parameters ) =>
   ExecuteReaderFmt_A( null, behaviour, commandTextFmt, parameters );

//--------------------------------------------------------------------------------------------------

/// <exception cref="ArgumentNullException" />
public async Task<SqlDataReader> ExecuteReader_A( [HOptional] SqlTransaction? transaction,
                                                  [HOptional] CommandBehavior behaviour,
                                                  string commandText )
{
   using (var cmd = PrepareCommand( transaction, commandText ))
      return await cmd.ExecuteReaderAsync( behaviour ).ConfigureAwait(false);
}
/// <exception cref="ArgumentNullException" />
public async Task<SqlDataReader> ExecuteReader_A( [HOptional] SqlTransaction? transaction,
                                                  [HOptional] CommandBehavior behaviour,
                                                  string commandText,
                                                  params SqlParameter[] sqlParams )
{
   using (var cmd = PrepareCommand( transaction, commandText, sqlParams ))
      return await cmd.ExecuteReaderAsync( behaviour ).ConfigureAwait(false);
}

/// <exception cref="ArgumentNullException" />
public Task<SqlDataReader> ExecuteReaderFmt_A( [HOptional] SqlTransaction? transaction,
                                               [HOptional] CommandBehavior behaviour,
                                               string commandTextFmt,
                                               params object?[] parameters ) =>
   ExecuteReader_A( transaction, behaviour,
      HString.FormatAsText( commandTextFmt, parameters ) );

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // HSqlOperator
//**************************************************************************************************

} // CommonHelpers
