# Class AbstractStatementParser (6.118.0)

6.118.0 (latest) 6.116.0 6.111.1 6.108.0 6.107.0 6.103.0 6.102.1 6.101.1 6.100.0 6.99.0 6.98.1 6.97.1 6.96.1 6.95.1 6.94.0 6.93.0 6.89.0 6.88.0 6.87.0 6.86.0 6.85.0 6.83.0 6.82.0 6.80.1 6.79.0 6.77.0 6.74.1 6.72.0 6.71.0 6.69.0 6.68.0 6.66.0 6.65.1 6.62.0 6.60.0 6.58.0 6.57.0 6.56.0 6.55.0 6.54.0 6.53.0 6.52.1 6.51.0 6.50.1 6.49.0 6.25.1 6.24.0 6.23.4 6.22.0 6.21.2 6.20.0 6.19.1 6.18.0 6.17.4 6.14.1

    public abstract class AbstractStatementParser

Internal class for the Spanner Connection API.

Parses ClientSideStatements and normal SQL statements. The parser is able to recognize
the type of statement, allowing the connection API to know which method on Spanner should be
called. The parser does not validate the validity of statements, except for ClientSideStatements. This means that an invalid DML statement could be accepted by the [AbstractStatementParser](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AbstractStatementParser) and sent to Spanner, and Spanner will then reject it with some error
message.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> AbstractStatementParser

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Fields

### DEFAULT_MAX_STATEMENT_CACHE_SIZE_MB

    public static final int DEFAULT_MAX_STATEMENT_CACHE_SIZE_MB

The default maximum size of the statement cache in Mb.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

## Static Methods

### getInstance(Dialect dialect)

    public static AbstractStatementParser getInstance(Dialect dialect)

Get an instance of [AbstractStatementParser](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AbstractStatementParser) for the specified dialect.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `dialect` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Dialect` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AbstractStatementParser` |   |

## Methods

### checkReturningClause(String sql)

    public boolean checkReturningClause(String sql)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Checks if the given SQL string contains a Returning clause. This method is used only in case of
a DML statement.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The sql string without comments that has to be evaluated. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | A boolean indicating whether the sql string has a Returning clause or not. |

### checkReturningClauseInternal(String sql)

    protected abstract boolean checkReturningClauseInternal(String sql)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Checks if the given SQL string contains a Returning clause. This method is used only in case of
a DML statement.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The sql string without comments that has to be evaluated. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | A boolean indicating whether the sql string has a Returning clause or not. |

### convertPositionalParametersToNamedParameters(char paramChar, String sql)

    public AbstractStatementParser.ParametersInfo convertPositionalParametersToNamedParameters(char paramChar, String sql)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Converts all positional parameters (?) in the given sql string into named parameters. The
parameters are named @p1, @p2, etc. for GoogleSQL, and $1, $2, etc. for PostgreSQL. This method
is used when converting a JDBC statement that uses positional parameters to a Cloud Spanner
[Statement](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement) instance that requires named parameters.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `paramChar` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The sql string that should be converted to use named parameters |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AbstractStatementParser.ParametersInfo` | A ParametersInfo object containing a string with named parameters instead of positional parameters and the number of parameters. |

### isDdlStatement(String sql) (deprecated)

    public boolean isDdlStatement(String sql)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

**Deprecated.** *Use [#parse(Statement)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AbstractStatementParser#com_google_cloud_spanner_connection_AbstractStatementParser_parse_com_google_cloud_spanner_Statement_) instead*

Checks whether the given statement is (probably) a DDL statement. The method does not check the
validity of the statement, only if it is a DDL statement based on the first word in the
statement.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The statement to check (without any comments). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if the statement is a DDL statement (i.e. starts with 'CREATE', 'ALTER' or 'DROP'). |

### isQuery(String sql) (deprecated)

    public boolean isQuery(String sql)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

**Deprecated.** *Use [#parse(Statement)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AbstractStatementParser#com_google_cloud_spanner_connection_AbstractStatementParser_parse_com_google_cloud_spanner_Statement_) instead*

Checks whether the given statement is (probably) a SELECT query. The method does not check the
validity of the statement, only if it is a SELECT statement based on the first word in the
statement.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The statement to check (without any comments). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if the statement is a SELECT statement (i.e. starts with 'SELECT'). |

### isUpdateStatement(String sql) (deprecated)

    public boolean isUpdateStatement(String sql)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

**Deprecated.** *Use [#parse(Statement)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AbstractStatementParser#com_google_cloud_spanner_connection_AbstractStatementParser_parse_com_google_cloud_spanner_Statement_) instead*

Checks whether the given statement is (probably) an update statement. The method does not check
the validity of the statement, only if it is an update statement based on the first word in the
statement.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The statement to check (without any comments). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` | `true` if the statement is a DML update statement (i.e. starts with 'INSERT', 'UPDATE' or 'DELETE'). |

### parse(Statement statement)

    public AbstractStatementParser.ParsedStatement parse(Statement statement)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Parses the given statement and categorizes it as one of the possible StatementTypes.
The validity of the statement is not checked, unless it is a client-side statement.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `statement` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Statement` The statement to parse. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement` | the parsed and categorized statement. |

### removeCommentsAndTrim(String sql)

    public String removeCommentsAndTrim(String sql)

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

Removes comments from and trims the given sql statement using the dialect of this parser.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sql` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` The sql statement to remove comments from and to trim. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` | the sql statement without the comments and leading and trailing spaces. |