Skip to content

Commit

Permalink
Test setting binary column values in multiple rows via loop
Browse files Browse the repository at this point in the history
This didn't work prior to using PDO.
  • Loading branch information
theodorejb committed Oct 20, 2024
1 parent fca3d8b commit 52b9ad1
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions test/DbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,27 @@ public function testIteratorQuery(): void
$this->assertSame($colVals, $colValsCompare);

// use a prepared statement to update both of the rows
$sql = "UPDATE {$this->table} SET name = ? WHERE user_id = ?";
$sql = "UPDATE {$this->table} SET name = ?, uuid = ? WHERE user_id = ?";
$_id = $_name = null;
$stmt = $peachySql->prepare($sql, [&$_name, &$_id]);
$_uuid = $peachySql->makeBinaryParam(null);
$stmt = $peachySql->prepare($sql, [&$_name, &$_uuid, &$_id]);

$realNames = [
['user_id' => $ids[0], 'name' => 'Rasmus Lerdorf'],
['user_id' => $ids[1], 'name' => 'Linus Torvalds'],
['user_id' => $ids[0], 'name' => 'Rasmus Lerdorf', 'uuid' => Uuid::uuid4()->getBytes()],
['user_id' => $ids[1], 'name' => 'Linus Torvalds', 'uuid' => Uuid::uuid4()->getBytes()],
];

foreach ($realNames as $_row) {
$_id = $_row['user_id'];
$_name = $_row['name'];
/** @psalm-suppress MixedArrayAssignment */
$_uuid[0] = $_row['uuid'];
$stmt->execute();
}

$stmt->close();

$updatedNames = $peachySql->selectFrom("SELECT user_id, name FROM {$this->table}")
$updatedNames = $peachySql->selectFrom("SELECT user_id, name, uuid FROM {$this->table}")
->where(['user_id' => $ids])->query()->getAll();

$this->assertSame($realNames, $updatedNames);
Expand Down

0 comments on commit 52b9ad1

Please sign in to comment.