Skip to content

Commit

Permalink
Support resources as parameters with pgsql
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Feb 28, 2023
1 parent 2c8afad commit 14fdf3e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ interfaces to use. It can be configured in one of two ways:
- ``sqlite3``: An SQLite driver that uses the sqlite3 extension.
- ``pdo_pgsql``: A PostgreSQL driver that uses the pdo_pgsql PDO
extension.
- ``pgsql``: A PostgreSQL driver that uses the pgsql extension. This driver does support loading BLOBs from file
resources yet. It is still considered experimental. Use `pdo_pgsql` if you need a stable driver for Postgres.
- ``pgsql``: A PostgreSQL driver that uses the pgsql extension.
- ``pdo_oci``: An Oracle driver that uses the pdo_oci PDO
extension.
**Note that this driver caused problems in our tests. Prefer the oci8 driver if possible.**
Expand Down
6 changes: 5 additions & 1 deletion src/Driver/PgSQL/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use function pg_result_error;
use function pg_send_execute;
use function sprintf;
use function stream_get_contents;

final class Statement implements StatementInterface
{
Expand Down Expand Up @@ -150,7 +151,10 @@ public function execute($params = null): Result
switch ($this->parameterTypes[$parameter]) {
case ParameterType::BINARY:
case ParameterType::LARGE_OBJECT:
$escapedParameters[] = $value === null ? null : pg_escape_bytea($this->connection, $value);
$escapedParameters[] = $value === null ? null : pg_escape_bytea(
$this->connection,
is_resource($value) ? stream_get_contents($value) : $value,
);
break;
default:
$escapedParameters[] = $value;
Expand Down
5 changes: 2 additions & 3 deletions tests/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ class BlobTest extends FunctionalTestCase
{
protected function setUp(): void
{
if (TestUtil::isDriverOneOf('pdo_oci', 'pgsql')) {
if (TestUtil::isDriverOneOf('pdo_oci')) {
// inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported
// see http://php.net/manual/en/pdo.lobs.php#example-1035
// inserting BLOBs as streams with ext-pgsql is not implemented yet.
self::markTestSkipped("DBAL doesn't support storing LOBs represented as streams using PDO_OCI or PgSQL");
self::markTestSkipped("DBAL doesn't support storing LOBs represented as streams using PDO_OCI");
}

$table = new Table('blob_table');
Expand Down

0 comments on commit 14fdf3e

Please sign in to comment.