public final class Statement extends Object implements Serializable
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 Statement.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.
Modifier and Type | Class and Description |
---|---|
static class |
Statement.Builder
Builder for
Statement . |
Modifier and Type | Method and Description |
---|---|
ResultSet |
analyzeQuery(ReadContext context,
ReadContext.QueryAnalyzeMode queryMode)
Analyzes the query in
context . |
boolean |
equals(Object o) |
ResultSet |
executeQuery(ReadContext context,
Options.QueryOption... options)
Executes the query in
context . |
Map<String,Value> |
getParameters()
Returns the parameters bound to this
Statement . |
ExecuteSqlRequest.QueryOptions |
getQueryOptions()
Returns the
ExecuteSqlRequest.QueryOptions that will be used with this Statement . |
String |
getSql()
Returns the current SQL statement text.
|
boolean |
hasBinding(String parameter)
Returns
true if a binding exists for parameter . |
int |
hashCode() |
static Statement.Builder |
newBuilder(String sql)
Creates a new statement builder with the SQL text
sql . |
static Statement |
of(String sql)
Creates a
Statement with the given SQL text sql . |
Statement.Builder |
toBuilder() |
String |
toString() |
public static Statement.Builder newBuilder(String sql)
sql
.public boolean hasBinding(String parameter)
true
if a binding exists for parameter
.public ResultSet executeQuery(ReadContext context, Options.QueryOption... options)
context
. statement.executeQuery(context)
is exactly
equivalent to context.executeQuery(statement)
.public ResultSet analyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)
context
. statement.analyzeQuery(context, queryMode)
is
exactly equivalent to context.analyzeQuery(statement, queryMode)
.public String getSql()
public ExecuteSqlRequest.QueryOptions getQueryOptions()
ExecuteSqlRequest.QueryOptions
that will be used with this Statement
.public Map<String,Value> getParameters()
Statement
.public Statement.Builder toBuilder()
Copyright © 2021 Google LLC. All rights reserved.