public final class Statement implements Serializable
A SQL statement and optional bound parameters that can be executed in a ReadContext.
The SQL query string can contain parameter placeholders. A parameter placeholder consists of @ followed by the parameter name. Parameter names consist of any combination of letters, numbers, and underscores.
Parameters can appear anywhere that a literal value is expected. The same parameter name can
be used more than once, for example: WHERE id > @msg_id AND id < @msg_id + 100
It is an error to execute an SQL query with placeholders for unbound parameters.
Statements are constructed using a builder. Parameter values are specified by calling Builder#bind(String). For example, code to build a query using the clause above and bind a value
to id
might look like the following:
Statement statement = Statement
.newBuilder("SELECT name WHERE id > @msg_id AND id < @msg_id="" +="" 100")="" .bind("msg_id").to(500)="" .build();="">
Statement
instances are immutable.
Implements
SerializableStatic Methods
newBuilder(String sql)
public static Statement.Builder newBuilder(String sql)
Creates a new statement builder with the SQL text sql
.
Name | Description |
sql | String |
Type | Description |
Statement.Builder |
of(String sql)
public static Statement of(String sql)
Creates a Statement
with the given SQL text sql
.
Name | Description |
sql | String |
Type | Description |
Statement |
Methods
analyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)
public ResultSet analyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)
Analyzes the query in context
. statement.analyzeQuery(context, queryMode)
is
exactly equivalent to context.analyzeQuery(statement, queryMode)
.
See Also: ReadContext#analyzeQuery(Statement, com.google.cloud.spanner.ReadContext.QueryAnalyzeMode)
Name | Description |
context | ReadContext |
queryMode | ReadContext.QueryAnalyzeMode |
Type | Description |
ResultSet |
equals(Object o)
public boolean equals(Object o)
Name | Description |
o | Object |
Type | Description |
boolean |
executeQuery(ReadContext context, Options.QueryOption[] options)
public ResultSet executeQuery(ReadContext context, Options.QueryOption[] options)
Executes the query in context
. statement.executeQuery(context)
is exactly
equivalent to context.executeQuery(statement)
.
See Also: ReadContext#executeQuery(Statement, Options.QueryOption...)
Name | Description |
context | ReadContext |
options | QueryOption[] |
Type | Description |
ResultSet |
getParameters()
public Map<String,Value> getParameters()
Returns the parameters bound to this Statement
.
Type | Description |
Map<String,Value> |
getQueryOptions()
public ExecuteSqlRequest.QueryOptions getQueryOptions()
Returns the QueryOptions that will be used with this Statement.
Type | Description |
ExecuteSqlRequest.QueryOptions |
getSql()
public String getSql()
Returns the current SQL statement text.
Type | Description |
String |
hasBinding(String parameter)
public boolean hasBinding(String parameter)
Returns true
if a binding exists for parameter
.
Name | Description |
parameter | String |
Type | Description |
boolean |
hashCode()
public int hashCode()
Type | Description |
int |
toBuilder()
public Statement.Builder toBuilder()
Type | Description |
Statement.Builder |
toString()
public String toString()
Type | Description |
String |