Class StatementParser

public class StatementParser

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 StatementParser and sent to Spanner, and Spanner will then reject it with some error message.

Inheritance

java.lang.Object > StatementParser

Static Fields

INSTANCE

public static final StatementParser INSTANCE

Singleton instance of StatementParser.

Field Value
TypeDescription
StatementParser

Static Methods

removeCommentsAndTrim(String sql)

public static String removeCommentsAndTrim(String sql)

Removes comments from and trims the given sql statement. Spanner supports three types of comments:

  • Single line comments starting with '--'
  • Single line comments starting with '#'
  • Multi line comments between '/*' and '*/'

Reference: https://cloud.google.com/spanner/docs/lexical#comments

Parameter
NameDescription
sqlString

The sql statement to remove comments from and to trim.

Returns
TypeDescription
String

the sql statement without the comments and leading and trailing spaces.

Methods

isDdlStatement(String sql)

public boolean isDdlStatement(String sql)

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
NameDescription
sqlString

The statement to check (without any comments).

Returns
TypeDescription
boolean

true if the statement is a DDL statement (i.e. starts with 'CREATE', 'ALTER' or 'DROP').

isQuery(String sql)

public boolean isQuery(String sql)

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
NameDescription
sqlString

The statement to check (without any comments).

Returns
TypeDescription
boolean

true if the statement is a SELECT statement (i.e. starts with 'SELECT').

isUpdateStatement(String sql)

public boolean isUpdateStatement(String sql)

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
NameDescription
sqlString

The statement to check (without any comments).

Returns
TypeDescription
boolean

true if the statement is a DML update statement (i.e. starts with 'INSERT', 'UPDATE' or 'DELETE').