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.
Static Fields
INSTANCE
public static final StatementParser INSTANCE
Singleton instance of StatementParser.
Type | Description |
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
Name | Description |
sql | String The sql statement to remove comments from and to trim. |
Type | Description |
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.
Name | Description |
sql | String The statement to check (without any comments). |
Type | Description |
boolean |
|
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.
Name | Description |
sql | String The statement to check (without any comments). |
Type | Description |
boolean |
|
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.
Name | Description |
sql | String The statement to check (without any comments). |
Type | Description |
boolean |
|