using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Threading;
using System.Threading.Tasks;
using Npgsql.Internal;
namespace Npgsql;
///
public class NpgsqlBatch : DbBatch
{
readonly NpgsqlCommand _command;
///
protected override DbBatchCommandCollection DbBatchCommands => BatchCommands;
///
public new NpgsqlBatchCommandCollection BatchCommands { get; }
///
public override int Timeout
{
get => _command.CommandTimeout;
set => _command.CommandTimeout = value;
}
///
public new NpgsqlConnection? Connection
{
get => _command.Connection;
set => _command.Connection = value;
}
///
protected override DbConnection? DbConnection
{
get => Connection;
set => Connection = (NpgsqlConnection?)value;
}
///
public new NpgsqlTransaction? Transaction
{
get => _command.Transaction;
set => _command.Transaction = value;
}
///
protected override DbTransaction? DbTransaction
{
get => Transaction;
set => Transaction = (NpgsqlTransaction?)value;
}
///
/// Marks all of the batch's result columns as either known or unknown.
/// Unknown results column are requested them from PostgreSQL in text format, and Npgsql makes no
/// attempt to parse them. They will be accessible as strings only.
///
internal bool AllResultTypesAreUnknown
{
get => _command.AllResultTypesAreUnknown;
set => _command.AllResultTypesAreUnknown = value;
}
///
/// Initializes a new .
///
/// A that represents the connection to a PostgreSQL server.
/// The in which the executes.
public NpgsqlBatch(NpgsqlConnection? connection = null, NpgsqlTransaction? transaction = null)
{
var batchCommands = new List(5);
_command = new(batchCommands);
BatchCommands = new NpgsqlBatchCommandCollection(batchCommands);
Connection = connection;
Transaction = transaction;
}
internal NpgsqlBatch(NpgsqlConnector connector)
{
var batchCommands = new List(5);
_command = new(connector, batchCommands);
BatchCommands = new NpgsqlBatchCommandCollection(batchCommands);
}
///
protected override DbBatchCommand CreateDbBatchCommand()
=> new NpgsqlBatchCommand();
///
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
=> ExecuteReader(behavior);
///
public new NpgsqlDataReader ExecuteReader(CommandBehavior behavior = CommandBehavior.Default)
=> _command.ExecuteReader(behavior);
///
protected override async Task ExecuteDbDataReaderAsync(
CommandBehavior behavior,
CancellationToken cancellationToken)
=> await ExecuteReaderAsync(behavior, cancellationToken);
///
public new Task ExecuteReaderAsync(CancellationToken cancellationToken = default)
=> _command.ExecuteReaderAsync(cancellationToken);
///
public new Task ExecuteReaderAsync(
CommandBehavior behavior,
CancellationToken cancellationToken = default)
=> _command.ExecuteReaderAsync(behavior, cancellationToken);
///
public override int ExecuteNonQuery()
=> _command.ExecuteNonQuery();
///
public override Task ExecuteNonQueryAsync(CancellationToken cancellationToken = default)
=> _command.ExecuteNonQueryAsync(cancellationToken);
///
public override object? ExecuteScalar()
=> _command.ExecuteScalar();
///
public override Task