Class SpannerBatchCommand (3.10.0)

public sealed class SpannerBatchCommand

Represents batched commands to execute against a Spanner database. Currently only DML commands are supported in batch mode.

You can create an instance of SpannerBatchCommand with no initial commands. You can then add commands to a SpannerBatchCommand using the Add(SpannerCommandTextBuilder, SpannerParameterCollection) or Add(String, SpannerParameterCollection) or Add(SpannerCommand) methods.

For batched DML commands use ExecuteNonQueryAsync(CancellationToken) or ExecuteNonQuery() to execute the batched commands.

Inheritance

Object > SpannerBatchCommand

Namespace

Google.Cloud.Spanner.Data

Assembly

Google.Cloud.Spanner.Data.dll

Properties

CommandTimeout

public int CommandTimeout { get; set; }

Gets or sets the wait time before terminating the attempt to execute a command and generating an error. Defaults to the timeout from the connection string.

Property Value
TypeDescription
Int32
Remarks

A value of '0' normally indicates that no timeout should be used (it waits an infinite amount of time). However, if you specify AllowImmediateTimeouts=true in the connection string, '0' will cause a timeout that expires immediately. This is normally used only for testing purposes.

CommandType

public SpannerBatchCommandType CommandType { get; set; }

The type of this batch command. If initialy set to None, this value will be calculated when the first command is added to the batch.

Only DML commands are currently supported in batch mode.

You can set this property freely as long as there are no commands in this bacth command. Once there are commands in this batch command an attempt to change this property's value will throw and ArgumentException.

Property Value
TypeDescription
SpannerBatchCommandType

Connection

public SpannerConnection Connection { get; }

The connection to the data source. This is never null.

Property Value
TypeDescription
SpannerConnection

Priority

public Priority Priority { get; set; }

The RPC priority to use for this command. The default priority is Unspecified.

Property Value
TypeDescription
Priority

Tag

public string Tag { get; set; }

The statement tag to send to Cloud Spanner for this command.

Property Value
TypeDescription
String

Transaction

public SpannerTransaction Transaction { get; }

The transaction to use when executing this command. If this is null, the command will be executed without a transaction.

Property Value
TypeDescription
SpannerTransaction

Methods

Add(SpannerCommand)

public void Add(SpannerCommand command)

Adds a command to the collection of batch commands to be executed by this SpannerBatchCommand. Only CommandText and Parameters will be taken into account. Other SpannerCommand properties like SpannerConnection and DbTransaction will be ignored.

Parameter
NameDescription
commandSpannerCommand

The command to be added.

Add(SpannerCommandTextBuilder, SpannerParameterCollection)

public void Add(SpannerCommandTextBuilder commandTextBuilder, SpannerParameterCollection parameters = null)

Adds a command to the collection of batch commands to be executed by this SpannerBatchCommand.

Parameters
NameDescription
commandTextBuilderSpannerCommandTextBuilder

A SpannerCommandTextBuilder representing the command to be added. Must not be null or empty. Currently only DML commands are supported in batch operations.

parametersSpannerParameterCollection

The parameters associated with commandTextBuilder. If commandTextBuilder doesn't require parameters then parameters can be either

null
or empty.

Add(String, SpannerParameterCollection)

public void Add(string commandText, SpannerParameterCollection parameters = null)

Adds a command to the collection of batch commands to be executed by this SpannerBatchCommand.

Parameters
NameDescription
commandTextString

The command text to be added. Must not be null or empty. Currently only DML commands are supported in batch operations.

parametersSpannerParameterCollection

The parameters associated with commandText. If commandText doesn't require parameters then parameters can be either

null
or empty.

ExecuteNonQuery()

public IEnumerable<long> ExecuteNonQuery()

Executes the batch commands sequentially. If a command fails, execution is halted and this method will throw an SpannerBatchNonQueryException containing information about the failure and the number of affected rows by each of the commands that executed successfully before the failure ocurred.

Returns
TypeDescription
IEnumerable<Int64>

The number of rows affected by each of the executed commands.

ExecuteNonQueryAsync(CancellationToken)

public Task<IReadOnlyList<long>> ExecuteNonQueryAsync(CancellationToken cancellationToken = default(CancellationToken))

Executes the batch commands sequentially. The execution of this method overall is asynchronous.

Parameter
NameDescription
cancellationTokenCancellationToken

A cancellation token for the operation.

Returns
TypeDescription
Task<IReadOnlyList<Int64>>

A task that once completed will indicate the number of rows affected by each of the executed commands. If a command fails, execution is halted and this method will return a faulted task with an SpannerBatchNonQueryException containing information about the failure and the number of affected rows by each of the commands that executed successfully before the failure ocurred.