Skip to content

Commit edf1fca

Browse files
committed
Restore stream offsets with subsequent execute
Driver statement instances needs to maintain resources offsets for streams passed to bindValue after the first call to execute. Fixed for PDO, SQLite3
1 parent 950dc7f commit edf1fca

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/Driver/PDO/Statement.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING)
5454

5555
$pdoType = ParameterTypeMap::convertParamType($type);
5656
if ($pdoType === PDO::PARAM_LOB) {
57-
$this->trackParamResource($value);
57+
$this->trackParamResource($param, $value);
5858
}
5959

6060
try {
@@ -157,16 +157,17 @@ public function execute($params = null): ResultInterface
157157
* Track a binary parameter reference at binding time. These
158158
* are cached for later analysis by the getResourceOffsets.
159159
*
160-
* @param mixed $resource
160+
* @param int|string $param
161+
* @param mixed $resource
161162
*/
162-
private function trackParamResource($resource): void
163+
private function trackParamResource($param, $resource): void
163164
{
164165
if (! is_resource($resource)) {
165166
return;
166167
}
167168

168-
$this->paramResources ??= [];
169-
$this->paramResources[] = $resource;
169+
$this->paramResources ??= [];
170+
$this->paramResources[$param] = $resource;
170171
}
171172

172173
/**
@@ -218,7 +219,5 @@ private function restoreResourceOffsets(?array $resourceOffsets): void
218219
foreach ($resourceOffsets as $index => $offset) {
219220
fseek($this->paramResources[$index], $offset, SEEK_SET);
220221
}
221-
222-
$this->paramResources = null;
223222
}
224223
}

src/Driver/SQLite3/Statement.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool
6868

6969
$sqliteType = $this->convertParamType($type);
7070
if ($sqliteType === SQLITE3_BLOB) {
71-
$this->trackParamResource($value);
71+
$this->trackParamResource($param, $value);
7272
}
7373

7474
return $this->statement->bindValue($param, $value, $sqliteType);
@@ -156,16 +156,17 @@ private function convertParamType(int $type): int
156156
* Track a binary parameter reference at binding time. These
157157
* are cached for later analysis by the getResourceOffsets.
158158
*
159-
* @param mixed $resource
159+
* @param int|string $param
160+
* @param mixed $resource
160161
*/
161-
private function trackParamResource($resource): void
162+
private function trackParamResource($param, $resource): void
162163
{
163164
if (! is_resource($resource)) {
164165
return;
165166
}
166167

167-
$this->paramResources ??= [];
168-
$this->paramResources[] = $resource;
168+
$this->paramResources ??= [];
169+
$this->paramResources[$param] = $resource;
169170
}
170171

171172
/**
@@ -217,7 +218,5 @@ private function restoreResourceOffsets(?array $resourceOffsets): void
217218
foreach ($resourceOffsets as $index => $offset) {
218219
fseek($this->paramResources[$index], $offset, SEEK_SET);
219220
}
220-
221-
$this->paramResources = null;
222221
}
223222
}

0 commit comments

Comments
 (0)