Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
bshaffer committed Nov 12, 2024
1 parent fe8fe94 commit f2e1218
Showing 3 changed files with 206 additions and 346 deletions.
1 change: 1 addition & 0 deletions Spanner/src/TransactionalReadTrait.php
Original file line number Diff line number Diff line change
@@ -308,6 +308,7 @@ public function execute($sql, array $options = [])
unset($options['singleUse']);

$result = $this->operation->execute($this->session, $sql, $options);

if (empty($this->id()) && $result->transaction()) {
$this->setId($result->transaction()->id());
}
33 changes: 10 additions & 23 deletions Spanner/tests/ResultGeneratorTrait.php
Original file line number Diff line number Diff line change
@@ -34,37 +34,17 @@
*/
trait ResultGeneratorTrait
{
/**
* Yield a ResultSet response.
*
* @param bool $withStats If true, statistics will be included.
* **Defaults to** `false`.
* @param string|null $transaction If set, the value will be included as the
* transaction ID. **Defaults to** `null`.
* @return \Generator
*/
private function resultGenerator($withStats = false, $transaction = null)
{
return $this->yieldRows([
[
'name' => 'ID',
'type' => Database::TYPE_INT64,
'value' => '10'
]
], $withStats, $transaction);
}

/**
* Yield rows with user-specified data.
*
* @param array[] $rows A list of arrays containing `name`, `type` and `value` keys.
* @param ResultSetStats|null $withStats If true, statistics will be included.
* @param ResultSetStats|null $stats If true, statistics will be included.
* **Defaults to** `false`.
* @param string|null $transactionId If set, the value will be included as the
* transaction ID. **Defaults to** `null`.
* @return \Generator
*/
private function yieldRows(array $rows, $stats = false, $transactionId = null)
private function yieldRows(array $rows, $stats = null, $transactionId = null)
{
$fields = [];
$values = [];
@@ -129,8 +109,15 @@ private function resultGeneratorStream(
->willReturn($this->resultGeneratorChunks($chunks));

} else {
$rows = [
[
'name' => 'ID',
'type' => Database::TYPE_INT64,
'value' => '10'
]
];
$this->stream->readAll()
->willReturn($this->resultGenerator($stats, $transactionId));
->willReturn($this->yieldRows($rows, $stats, $transactionId));
}

return $this->stream->reveal();
Loading

0 comments on commit f2e1218

Please sign in to comment.