Cloud Spanner Client - Class Result (1.76.0)

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 \ Spanner

Methods

__construct

Parameters
NameDescription
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
NameDescription
format string

Determines the format in which rows are returned. Result::RETURN_NAME_VALUE_PAIR returns items as a multi-dimensional array containing a name and a value key. Ex: [0 => ['name' => 'column1', 'value' => 'my_value']]. Result::RETURN_ASSOCIATIVE returns items as an associative array with the column name as the key. Please note with this option, if duplicate column names are present a \RuntimeException will be thrown. Result::RETURN_ZERO_INDEXED returns items as a 0 indexed array, with the key representing the column number as found by executing Google\Cloud\Spanner\Result::columns(). Ex: [0 => 'my_value']. Defaults to Result::RETURN_ASSOCIATIVE.

Returns
TypeDescription
Generator

columns

Return column names.

Will be populated once the result set is iterated upon.

Example:

$columns = $result->columns();
Returns
TypeDescription
array|null

metadata

Return result metadata.

Will be populated once the result set is iterated upon.

Example:

$metadata = $result->metadata();
Returns
TypeDescription
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
TypeDescription
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
TypeDescription
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
TypeDescription
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
TypeDescription
Google\Cloud\Spanner\Transaction|null

getIterator

Returns
TypeDescription
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