//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// DataHelpers.SQL satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using u = user_rtx;

namespace DataHelpers.SQL {

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

public Task<int> ExecuteNonQuery_A( string commandText ) =>
   ExecuteNonQuery_A( null, commandText );
public Task<int> ExecuteNonQuery_A( string commandText, params SqlParameter[] sqlParams ) =>
   ExecuteNonQuery_A( null, commandText, sqlParams );

public Task<int> ExecuteNonQueryFmt_A( string commandTextFmt, params object?[] args ) =>
   ExecuteNonQueryFmt_A( null, commandTextFmt, args );

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

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

public Task<int> ExecuteNonQueryFmt_A( SqlTransaction? transaction,
                                       string commandTextFmt, params object?[] args ) =>
   ExecuteNonQuery_A( transaction, commandTextFmt.FMT( args ) );

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

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

public Task<SqlDataReader> ExecuteReaderFmt_A( string commandTextFmt, params object?[] args ) =>
   ExecuteReaderFmt_A( null, CommandBehavior.Default, commandTextFmt, args );

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

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

public Task<SqlDataReader> ExecuteReaderFmt_A( SqlTransaction? transaction,
                                               string commandTextFmt,
                                               params object?[] args ) =>
   ExecuteReaderFmt_A( transaction, CommandBehavior.Default, commandTextFmt, args );

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

public Task<SqlDataReader> ExecuteReader_A( [u.opt] CommandBehavior behaviour,
                                            string commandText ) =>
   ExecuteReader_A( null, behaviour, commandText );
public Task<SqlDataReader> ExecuteReader_A( [u.opt] CommandBehavior behaviour,
                                            string commandText,
                                            params SqlParameter[] sqlParams ) =>
   ExecuteReader_A( null, behaviour, commandText, sqlParams );

public Task<SqlDataReader> ExecuteReaderFmt_A( [u.opt] CommandBehavior behaviour,
                                               string commandTextFmt,
                                               params object?[] args ) =>
   ExecuteReaderFmt_A( null, behaviour, commandTextFmt, args );

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

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

public Task<SqlDataReader> ExecuteReaderFmt_A( SqlTransaction? transaction,
                                               [u.opt] CommandBehavior behaviour,
                                               string commandTextFmt,
                                               params object?[] args ) =>
   ExecuteReader_A( transaction, behaviour, commandTextFmt.FMT( args ) );

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

} // DataHelpers.SQL
