Class PreparedStatement
Namespace: Oracle.NoSQL.SDK
Assembly: Oracle.NoSQL.SDK.dll
Syntax
public class PreparedStatement : Object
Remarks
An object of this class is returned as a result of PrepareAsync(String, PrepareOptions, CancellationToken). It includes state that can be sent to a server and executed without re-parsing the query. It also includes bind variables which may be set for each successive use of the query. It can be passed to QueryAsync or GetQueryAsyncEnumerable methods for the execution of the query and be reused for multiple queries, potentially with different values of bind variables.
An instance of PreparedStatement is thread-safe if bind variables are not used. If bind variables are used, it is not thread-safe. In this case, you can construct additional instances of PreparedStatement using CopyStatement() in order to share the prepared statement among threads.
Examples
Using prepared queries.// Prepare the query.
var preparedStatement = await client.PrepareAsync(
"DECLARE $id INTEGER; $salary DOUBLE; " +
"SELECT id, firstName, lastName FROM Employees WHERE " +
"id <= $id AND salary <= $salary");
// Set bind variables.
preparedStatement
.SetVariable("$id", 1100)
.SetVariable("$salary", 100500);
// Execute the query.
await foreach(var result in
client.GetQueryAsyncEnumerable(preparedStatement))
{
foreach(var row in result.Rows)
{
// Display the results.
}
}
// Change the value of the bind variable.
preparedStatement.SetVariable("$id", 2000);
// Execute the query again.
await foreach(var result in
client.GetQueryAsyncEnumerable(preparedStatement))
{
// .....
}
Properties
Name | Description |
---|---|
ConsumedCapacity | Cloud Service/Cloud Simulator only. Gets the capacity consumed by the call to PrepareAsync(String, PrepareOptions, CancellationToken) that created this prepared statement. |
QueryPlan | Gets the query execution plan printout if it was requested. |
ResultSchema | Gets the JSON string representing the schema of the query result if it was requested. |
SQLText | Gets the SQL text of this prepared statement. |
Variables | Gets the bind variables. |
Methods
Name | Description |
---|---|
ClearVariables() | Clears all bind variables from the statement. |
CopyStatement() | Returns a copy of this prepared statement without its variables. |
SetVariable(Int32, FieldValue) | Binds an external variable to a given value. The variable is identified by its position within the query string. |
SetVariable(String, FieldValue) | Binds a variable to a given value. The variable is identified by its name. |