Skip to content

Commit 9051f5f

Browse files
committed
Fix phpGH-15893: Pdo\Pgsql backport fixes from phpGH-16124
1 parent e609a21 commit 9051f5f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,11 +712,15 @@ void pgsqlCopyFromArray_internal(INTERNAL_FUNCTION_PARAMETERS)
712712
}
713713
} ZEND_HASH_FOREACH_END();
714714
} else {
715-
iter = Z_OBJ_P(pg_rows)->ce->get_iterator(Z_OBJCE_P(pg_rows), pg_rows, 0);
715+
iter = Z_OBJCE_P(pg_rows)->get_iterator(Z_OBJCE_P(pg_rows), pg_rows, 0);
716716
if (iter == NULL || EG(exception)) {
717717
RETURN_THROWS();
718718
}
719719

720+
if (iter->funcs->rewind) {
721+
iter->funcs->rewind(iter);
722+
}
723+
720724
for (; iter->funcs->valid(iter) == SUCCESS && EG(exception) == NULL; iter->funcs->move_forward(iter)) {
721725
tmp = iter->funcs->get_current_data(iter);
722726
if (!_pdo_pgsql_send_copy_data(H, tmp)) {

ext/pdo_pgsql/tests/copy_from_iterator.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ $iterator = new class implements Iterator{
4242
}
4343
};
4444

45+
try {
46+
$db->pgsqlCopyFromArray('test_copy_from_traversable',new stdClass());
47+
} catch (\TypeError $e) {
48+
echo $e->getMessage() . PHP_EOL;
49+
}
50+
4551
$db->pgsqlCopyFromArray('test_copy_from_traversable',$iterator);
4652

4753
$stmt = $db->query("select * from test_copy_from_traversable order by 1");
@@ -56,6 +62,7 @@ $db = PDOTest::test_factory(__DIR__ . '/common.phpt');
5662
$db->query('DROP TABLE IF EXISTS test_copy_from_traversable CASCADE');
5763
?>
5864
--EXPECT--
65+
PDO::pgsqlCopyFromArray(): Argument #2 ($rows) must be of type array or Traversable
5966
array (
6067
0 => 1,
6168
1 => 1,

0 commit comments

Comments
 (0)