Google Cloud Spanner C++ Client  1.32.1
A C++ Client Library for Google Cloud Spanner
Public Member Functions | List of all members
google::cloud::spanner::v1::DmlResult Class Reference

Represents the result of a data modifying operation using spanner::Client::ExecuteDml(). More...

#include <google/cloud/spanner/results.h>

Public Member Functions

 DmlResult ()=default
 
 DmlResult (std::unique_ptr< spanner_internal::ResultSourceInterface > source)
 
 DmlResult (DmlResult &&)=default
 
DmlResultoperator= (DmlResult &&)=default
 
std::int64_t RowsModified () const
 Returns the number of rows modified by the DML statement. More...
 

Detailed Description

Represents the result of a data modifying operation using spanner::Client::ExecuteDml().

This class encapsulates the result of a Cloud Spanner DML operation, i.e., INSERT, UPDATE, or DELETE.

Note
ExecuteDmlResult returns the number of rows modified.
Example:
using ::google::cloud::StatusOr;
namespace spanner = ::google::cloud::spanner;
std::int64_t rows_inserted;
auto commit_result = client.Commit(
[&client, &rows_inserted](
spanner::Transaction txn) -> StatusOr<spanner::Mutations> {
auto insert = client.ExecuteDml(
std::move(txn),
"INSERT INTO Singers (SingerId, FirstName, LastName)"
" VALUES (10, 'Virginia', 'Watson')"));
if (!insert) return insert.status();
rows_inserted = insert->RowsModified();
});
if (!commit_result) {
throw std::runtime_error(commit_result.status().message());
}
std::cout << "Rows inserted: " << rows_inserted;
Represents a potentially parameterized SQL statement.
Definition: sql_statement.h:51
The representation of a Cloud Spanner transaction.
Definition: transaction.h:58
std::vector< Mutation > Mutations
An ordered sequence of mutations to pass to Client::Commit() or return from the Client::Commit() muta...
Definition: mutations.h:99
Contains all the Cloud Spanner C++ client types and functions.
Definition: backup.cc:21

Definition at line 116 of file results.h.

Constructor & Destructor Documentation

◆ DmlResult() [1/3]

google::cloud::spanner::v1::DmlResult::DmlResult ( )
default

◆ DmlResult() [2/3]

google::cloud::spanner::v1::DmlResult::DmlResult ( std::unique_ptr< spanner_internal::ResultSourceInterface >  source)
inlineexplicit

Definition at line 119 of file results.h.

◆ DmlResult() [3/3]

google::cloud::spanner::v1::DmlResult::DmlResult ( DmlResult &&  )
default

Member Function Documentation

◆ operator=()

DmlResult& google::cloud::spanner::v1::DmlResult::operator= ( DmlResult &&  )
default

◆ RowsModified()

std::int64_t google::cloud::spanner::v1::DmlResult::RowsModified ( ) const

Returns the number of rows modified by the DML statement.

Note
Partitioned DML only provides a lower bound of the rows modified, all other DML statements provide an exact count.

Definition at line 77 of file results.cc.