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 21, 2024
1 parent 80e7489 commit ce0bf6a
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 @@ -139,24 +139,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();

$result = $peachySql->selectFrom("SELECT user_id, name FROM {$this->table}")
$result = $peachySql->selectFrom("SELECT user_id, name, uuid FROM {$this->table}")
->where(['user_id' => $ids])->query();
$updatedNames = $result->getAll();
$this->assertSame($options->affectedIsRowCount ? 2 : -1, $result->getAffected());
Expand Down

0 comments on commit ce0bf6a

Please sign in to comment.