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

Represents a potentially parameterized SQL statement. More...

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

Public Types

using ParamType = std::unordered_map< std::string, Value >
 Type alias for parameter collection. More...

Public Member Functions

 SqlStatement ()=default
 SqlStatement (std::string statement)
 Constructs a SqlStatement without parameters. More...
 SqlStatement (std::string statement, ParamType params)
 Constructs a SqlStatement with specified parameters. More...
 SqlStatement (SqlStatement const &)=default
 Copy and move. More...
 SqlStatement (SqlStatement &&)=default
SqlStatementoperator= (SqlStatement const &)=default
SqlStatementoperator= (SqlStatement &&)=default
std::string const & sql () const
 Returns the SQL statement. More...
ParamType const & params () const
 Returns the collection of parameters. More...
std::vector< std::string > ParameterNames () const
 Returns the names of all the parameters. More...
google::cloud::StatusOr< ValueGetParameter (std::string const &parameter_name) const
 Returns the value of the requested parameter. More...


bool operator== (SqlStatement const &a, SqlStatement const &b)
bool operator!= (SqlStatement const &a, SqlStatement const &b)
std::ostream & operator<< (std::ostream &os, SqlStatement const &stmt)
 Outputs a string representation of the given stmt to the given os. More...

Detailed Description

Represents a potentially parameterized SQL statement.

Details on case sensitivity for SQL statements and string values can be found here: Case Sensitivity

SqlStatement equality comparisons are case-sensitive.

Parameter placeholders are specified by @<param name> in the SQL string. Values for parameters are a collection of std::pair<std::string const, google::cloud:spanner::Value>.

// Cloud Spanner STRUCT<> types are represented by std::tuple<...>. The
// following represents a STRUCT<> with two unnamed STRING fields.
using NameType = std::tuple<std::string, std::string>;
auto singer_info = NameType{"Elena", "Campbell"};
auto rows = client.ExecuteQuery(spanner::SqlStatement(
"SELECT SingerId FROM Singers WHERE (FirstName, LastName) = @name",
{{"name", spanner::Value(singer_info)}}));
Represents a potentially parameterized SQL statement.
Definition: sql_statement.h:51
The Value class represents a type-safe, nullable Spanner value.
Definition: value.h:168

Definition at line 51 of file sql_statement.h.

Member Typedef Documentation

◆ ParamType

using google::cloud::spanner::v1::SqlStatement::ParamType = std::unordered_map<std::string, Value>

Type alias for parameter collection.

Definition at line 54 of file sql_statement.h.

Constructor & Destructor Documentation

◆ SqlStatement() [1/5]

google::cloud::spanner::v1::SqlStatement::SqlStatement ( )

◆ SqlStatement() [2/5]

google::cloud::spanner::v1::SqlStatement::SqlStatement ( std::string  statement)

Constructs a SqlStatement without parameters.

Definition at line 58 of file sql_statement.h.

◆ SqlStatement() [3/5]

google::cloud::spanner::v1::SqlStatement::SqlStatement ( std::string  statement,
ParamType  params 

Constructs a SqlStatement with specified parameters.

Definition at line 61 of file sql_statement.h.

◆ SqlStatement() [4/5]

google::cloud::spanner::v1::SqlStatement::SqlStatement ( SqlStatement const &  )

Copy and move.

◆ SqlStatement() [5/5]

google::cloud::spanner::v1::SqlStatement::SqlStatement ( SqlStatement &&  )

Member Function Documentation

◆ GetParameter()

google::cloud::StatusOr< Value > google::cloud::spanner::v1::SqlStatement::GetParameter ( std::string const &  parameter_name) const

Returns the value of the requested parameter.

parameter_namename of requested parameter.
StatusCode::kNotFound returned for invalid names.

Definition at line 51 of file

◆ operator=() [1/2]

SqlStatement& google::cloud::spanner::v1::SqlStatement::operator= ( SqlStatement &&  )

◆ operator=() [2/2]

SqlStatement& google::cloud::spanner::v1::SqlStatement::operator= ( SqlStatement const &  )

◆ ParameterNames()

std::vector< std::string > google::cloud::spanner::v1::SqlStatement::ParameterNames ( ) const

Returns the names of all the parameters.

Definition at line 42 of file

◆ params()

ParamType const& google::cloud::spanner::v1::SqlStatement::params ( ) const

Returns the collection of parameters.

If no parameters were specified, the container will be empty.

Definition at line 80 of file sql_statement.h.

◆ sql()

std::string const& google::cloud::spanner::v1::SqlStatement::sql ( ) const

Returns the SQL statement.

No parameter substitution is performed in the statement string.

Definition at line 74 of file sql_statement.h.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( SqlStatement const &  a,
SqlStatement const &  b 

Definition at line 98 of file sql_statement.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
SqlStatement const &  stmt 

Outputs a string representation of the given stmt to the given os.

This is intended for debugging and human consumption only, not machine consumption, as the output format may change without notice.

Definition at line 60 of file

◆ operator==

bool operator== ( SqlStatement const &  a,
SqlStatement const &  b 

Definition at line 95 of file sql_statement.h.