Reference documentation and code samples for the Cloud Spanner Client class Result.
Represent a Cloud Spanner lookup result (either read or executeSql).
Example:
use Google\Cloud\Spanner\SpannerClient;
$spanner = new SpannerClient();
$database = $spanner->connect('my-instance', 'my-database');
$result = $database->execute('SELECT * FROM Posts');
Namespace
Google \ Cloud \ SpannerMethods
__construct
Parameters | |
---|---|
Name | Description |
operation |
Google\Cloud\Spanner\Operation
Runs operations against Google Cloud Spanner. |
session |
Google\Cloud\Spanner\Session\Session
The session used for any operations executed. |
call |
callable
A callable, yielding a generator filled with results. |
transactionContext |
string
The transaction's context. |
mapper |
Google\Cloud\Spanner\ValueMapper
Maps values. |
retries |
int
Number of attempts to resume a broken stream, assuming a resume token is present. Defaults to 3. |
rows
Return the formatted and decoded rows. If the stream is interrupted and a resume token is available, attempts will be made on your behalf to resume.
Example:
$rows = $result->rows();
Parameter | |
---|---|
Name | Description |
format |
string
Determines the format in which rows are returned.
|
Returns | |
---|---|
Type | Description |
Generator |
columns
Return column names.
Will be populated once the result set is iterated upon.
Example:
$columns = $result->columns();
Returns | |
---|---|
Type | Description |
array|null |
metadata
Return result metadata.
Will be populated once the result set is iterated upon.
Example:
$metadata = $result->metadata();
Returns | |
---|---|
Type | Description |
array|null |
[ResultSetMetadata](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ResultSetMetadata). |
session
Return the session associated with the result stream.
Example:
$session = $result->session();
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Session\Session |
stats
Get the query plan and execution statistics for the query that produced this result set.
By default, statistics are returned by default only when executing a DML
statement. To receive statistics for a SELECT statement, set
$options.queryMode
to Result::MODE_PROFILE
, as demonstrated below.
Setting $options.queryMode
to Result::MODE_PLAN
will return the query
plan without any results or execution statistics information.
Example:
$stats = $result->stats();
// Executing a query with stats returned.
use Google\Cloud\Spanner\Result;
$res = $database->execute('SELECT * FROM Posts', [
'queryMode' => Result::MODE_PROFILE
]);
Returns | |
---|---|
Type | Description |
array|null |
[ResultSetStats](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#google.spanner.v1.ResultSetStats). |
snapshot
Returns a snapshot which was begun in the read or execute, if one exists.
Will be populated once the result set is iterated upon.
Example:
$snapshot = $result->snapshot();
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Snapshot|null |
transaction
Returns a transaction which was begun in the read or execute, if one exists.
Will be populated once the result set is iterated upon.
Example:
$transaction = $result->transaction();
Returns | |
---|---|
Type | Description |
Google\Cloud\Spanner\Transaction|null |
getIterator
Returns | |
---|---|
Type | Description |
Generator |
Constants
BUFFER_RESULT_LIMIT
Value: 10
RETURN_NAME_VALUE_PAIR
Value: 'nameValuePair'
RETURN_ASSOCIATIVE
Value: 'associative'
RETURN_ZERO_INDEXED
Value: 'zeroIndexed'
MODE_NORMAL
Value: \Google\Cloud\Spanner\V1\ExecuteSqlRequest\QueryMode::NORMAL
MODE_PLAN
Value: \Google\Cloud\Spanner\V1\ExecuteSqlRequest\QueryMode::PLAN
MODE_PROFILE
Value: \Google\Cloud\Spanner\V1\ExecuteSqlRequest\QueryMode::PROFILE