Class SqlStatement (2.23.0)

Represents a potentially parameterized SQL statement.

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

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>.

Example

  // 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)}}));

Constructors

SqlStatement()

SqlStatement(std::string)

Constructs a SqlStatement without parameters.

Parameter
Name Description
statement std::string

SqlStatement(std::string, ParamType)

Constructs a SqlStatement with specified parameters.

Parameters
Name Description
statement std::string
params ParamType

SqlStatement(SqlStatement const &)

Copy and move.

Parameter
Name Description
SqlStatement const &

SqlStatement(SqlStatement &&)

Parameter
Name Description
SqlStatement &&

Operators

operator=(SqlStatement const &)

Parameter
Name Description
SqlStatement const &
Returns
Type Description
SqlStatement &

operator=(SqlStatement &&)

Parameter
Name Description
SqlStatement &&
Returns
Type Description
SqlStatement &

Functions

sql() const

Returns the SQL statement.

No parameter substitution is performed in the statement string.

Returns
Type Description
std::string const &

params() const

Returns the collection of parameters.

Returns
Type Description
ParamType const &

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

ParameterNames() const

Returns the names of all the parameters.

Returns
Type Description
std::vector< std::string >

GetParameter(std::string const &) const

Returns the value of the requested parameter.

Parameter
Name Description
parameter_name std::string const &

name of requested parameter.

Returns
Type Description
google::cloud::StatusOr< Value >

StatusCode::kNotFound returned for invalid names.

Type Aliases

ParamType

Alias Of: std::unordered_map< std::string, Value >

Type alias for parameter collection.