15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_SQL_STATEMENT_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_SQL_STATEMENT_H
18#include "google/cloud/spanner/value.h"
19#include "google/cloud/spanner/version.h"
20#include "google/cloud/status_or.h"
21#include <google/spanner/v1/spanner.pb.h>
23#include <unordered_map>
28namespace spanner_internal {
29GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
30struct SqlStatementInternals;
31GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
35GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
37
38
39
40
41
42
43
44
45
46
47
48
49
50
54 using ParamType = std::unordered_map<std::string,
Value>;
59 : statement_(std::move(statement)) {}
62 : statement_(std::move(statement)), params_(std::move(params)) {}
71
72
73
74 std::string
const&
sql()
const {
return statement_; }
77
78
79
80 ParamType
const&
params()
const {
return params_; }
83
84
88
89
90
91
93 std::string
const& parameter_name)
const;
96 return a.statement_ == b.statement_ && a.params_ == b.params_;
103
104
105
106
107
108 friend std::ostream& operator<<(std::ostream& os,
SqlStatement const& stmt);
111 friend struct spanner_internal::SqlStatementInternals;
113 std::string statement_;
117GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
121namespace spanner_internal {
122GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
125using SqlStatementProto =
126 ::
google::spanner::v1::ExecuteBatchDmlRequest::Statement;
128struct SqlStatementInternals {
133 return SqlStatementInternals::ToProto(std::move(s));
135GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Represents a potentially parameterized SQL statement.
Definition: sql_statement.h:51
SqlStatement(SqlStatement &&)=default
SqlStatement & operator=(SqlStatement const &)=default
SqlStatement & operator=(SqlStatement &&)=default
SqlStatement(std::string statement)
Constructs a SqlStatement without parameters.
Definition: sql_statement.h:58
ParamType const & params() const
Returns the collection of parameters.
Definition: sql_statement.h:80
SqlStatement(SqlStatement const &)=default
Copy and move.
SqlStatement(std::string statement, ParamType params)
Constructs a SqlStatement with specified parameters.
Definition: sql_statement.h:61
friend bool operator!=(SqlStatement const &a, SqlStatement const &b)
Definition: sql_statement.h:98
friend bool operator==(SqlStatement const &a, SqlStatement const &b)
Definition: sql_statement.h:95
std::vector< std::string > ParameterNames() const
Returns the names of all the parameters.
google::cloud::StatusOr< Value > GetParameter(std::string const ¶meter_name) const
Returns the value of the requested parameter.
std::string const & sql() const
Returns the SQL statement.
Definition: sql_statement.h:74
The Value class represents a type-safe, nullable Spanner value.
Definition: value.h:170
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23