Package com.google.cloud.spanner
Class Statement
- java.lang.Object
-
- com.google.cloud.spanner.Statement
-
- All Implemented Interfaces:
Serializable
public final class Statement extends Object implements Serializable
A SQL statement and optional bound parameters that can be executed in aReadContext.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 + 100It 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 toidmight 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();Statementinstances are immutable.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStatement.BuilderBuilder forStatement.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ResultSetanalyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)Analyzes the query incontext.booleanequals(Object o)ResultSetexecuteQuery(ReadContext context, Options.QueryOption... options)Executes the query incontext.Map<String,Value>getParameters()Returns the parameters bound to thisStatement.ExecuteSqlRequest.QueryOptionsgetQueryOptions()Returns theExecuteSqlRequest.QueryOptionsthat will be used with thisStatement.StringgetSql()Returns the current SQL statement text.booleanhasBinding(String parameter)Returnstrueif a binding exists forparameter.inthashCode()static Statement.BuildernewBuilder(String sql)Creates a new statement builder with the SQL textsql.static Statementof(String sql)Creates aStatementwith the given SQL textsql.Statement.BuildertoBuilder()StringtoString()
-
-
-
Method Detail
-
newBuilder
public static Statement.Builder newBuilder(String sql)
Creates a new statement builder with the SQL textsql.
-
hasBinding
public boolean hasBinding(String parameter)
Returnstrueif a binding exists forparameter.
-
executeQuery
public ResultSet executeQuery(ReadContext context, Options.QueryOption... options)
Executes the query incontext.statement.executeQuery(context)is exactly equivalent tocontext.executeQuery(statement).
-
analyzeQuery
public ResultSet analyzeQuery(ReadContext context, ReadContext.QueryAnalyzeMode queryMode)
Analyzes the query incontext.statement.analyzeQuery(context, queryMode)is exactly equivalent tocontext.analyzeQuery(statement, queryMode).
-
getSql
public String getSql()
Returns the current SQL statement text.
-
getQueryOptions
public ExecuteSqlRequest.QueryOptions getQueryOptions()
Returns theExecuteSqlRequest.QueryOptionsthat will be used with thisStatement.
-
getParameters
public Map<String,Value> getParameters()
Returns the parameters bound to thisStatement.
-
toBuilder
public Statement.Builder toBuilder()
-
-