|
| 1 | +--TEST-- |
| 2 | +PDO PgSQL pgsqlCopyFromArray()/copyFromArray() with a non-stringable row throws without polluting errorInfo |
| 3 | +--EXTENSIONS-- |
| 4 | +pdo_pgsql |
| 5 | +--SKIPIF-- |
| 6 | +<?php |
| 7 | +require __DIR__ . '/config.inc'; |
| 8 | +require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; |
| 9 | +PDOTest::skip(); |
| 10 | +?> |
| 11 | +--FILE-- |
| 12 | +<?php |
| 13 | +require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; |
| 14 | +$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); |
| 15 | +$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); |
| 16 | + |
| 17 | +$db->exec('CREATE TABLE test_copy_non_stringable (v text)'); |
| 18 | + |
| 19 | +try { |
| 20 | + $db->pgsqlCopyFromArray('test_copy_non_stringable', [new stdClass()]); |
| 21 | +} catch (\Error $e) { |
| 22 | + echo $e->getMessage(), PHP_EOL; |
| 23 | +} |
| 24 | + |
| 25 | +var_dump($db->errorInfo()[0]); |
| 26 | + |
| 27 | +$pgsql = PDOTest::test_factory(__DIR__ . '/common.phpt', Pdo\Pgsql::class, true); |
| 28 | +$pgsql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); |
| 29 | + |
| 30 | +try { |
| 31 | + $pgsql->copyFromArray('test_copy_non_stringable', [new stdClass()]); |
| 32 | +} catch (\Error $e) { |
| 33 | + echo $e->getMessage(), PHP_EOL; |
| 34 | +} |
| 35 | + |
| 36 | +var_dump($pgsql->errorInfo()[0]); |
| 37 | +?> |
| 38 | +--CLEAN-- |
| 39 | +<?php |
| 40 | +require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc'; |
| 41 | +$db = PDOTest::test_factory(__DIR__ . '/common.phpt'); |
| 42 | +$db->query('DROP TABLE IF EXISTS test_copy_non_stringable CASCADE'); |
| 43 | +?> |
| 44 | +--EXPECTF-- |
| 45 | +Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d |
| 46 | +Object of class stdClass could not be converted to string |
| 47 | +string(5) "00000" |
| 48 | +Object of class stdClass could not be converted to string |
| 49 | +string(5) "00000" |
0 commit comments