# Class SqlStatement (3.7.0-rc)

3.7.0-rc 3.6.0 (latest) 3.5.0 3.4.0 3.3.0 3.2.0 2.48.0-rc 2.47.1 2.46.0 2.45.0 2.44.0 2.43.0 2.42.0 2.41.0 2.40.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.1 2.24.0 2.23.0 2.22.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.14.0 2.13.0 2.12.0 2.11.0 Represents a potentially parameterized SQL statement.
Details on case sensitivity for SQL statements and string values can be found here: [Case Sensitivity](https://cloud.google.com/spanner/docs/lexical#case-sensitivity)

<br />

> [!NOTE]
> **Note:** [`SqlStatement`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/classgoogle_1_1cloud_1_1spanner_1_1SqlStatement) 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`](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/classgoogle_1_1cloud_1_1spanner_1_1Value)`>`.

<br />

###### 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](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/classgoogle_1_1cloud_1_1spanner_1_1SqlStatement) without parameters.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `statement` | `std::string` |

### SqlStatement(std::string, ParamType)

Constructs a [SqlStatement](https://docs.cloud.google.com/cpp/docs/reference/spanner/latest/classgoogle_1_1cloud_1_1spanner_1_1SqlStatement) 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.