Flush an object with NULL values in LOB fields leads to an error, OCI8 #6952

Open
opened 2026-01-22 15:42:02 +01:00 by admin · 2 comments
Owner

Originally created by @eisberg on GitHub (Mar 22, 2022).

Bug Report

Q A
BC Break yes/no
Version 2.11.2
DBAL Version 3.3.3
Database Driver Oracle, OCI8
PHP 8.1.3

Summary

When working with optional fields in entity that have a BLOB type (blob, clob, text, ..., etc.), we get a warning:

Deprecated: OCILob::writeTemporary(): Passing null to parameter #1 ($data) of type string is deprecated in vendor/doctrine/dbal/src/Driver/OCI8/Statement.php on line 76

The error occurs when working with Oracle (OCI8)

How to reproduce

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="ExampleProcess" table="JOB_PROCESS">
    <id name="id" type="integer" column="id">
      <generator strategy="SEQUENCE"/>
      <sequence-generator sequence-name="PROCESS_ID_SEQ" allocation-size="1" initial-value="1"/>
    </id>
    <field name="response" type="blob" column="response" nullable="true"></field>
  </entity>
</doctrine-mapping>
<?php

class ExampleProcess
{
    private int $id;
    /**
     * @var null|string|resource
     */
    private $response;  // << optional field

    public function getId(): int
    {
        return $this->id;
    }
 

    public function getResponse(): string|null
    {
        if (\is_resource($this->response)) {
            return (string) stream_get_contents($this->response);
        }

        return $this->response ?? null;
    }

    public function setResponse(string|null $response): self
    {
        $this->response = $response;

        return $this;
    }
 
}

Example:

<?php

$test = new ExampleProcess();
$em->persist($test);
$em->flush(); // this will trigger a warning

$test2 = new ExampleProcess();
$test2->setResponse(null);
$em->persist($test2);
$em->flush(); // this will trigger a warning

// unwanted code that allows you to temporarily bypass the problem:
$test3 = new ExampleProcess();
$test3->setResponse("");
$em->persist($test3);
$em->flush(); // this will work fine

Expected behavior

Optional fields are expected to allow NULL values

Originally created by @eisberg on GitHub (Mar 22, 2022). ### Bug Report | Q | A |------------ | ------ | BC Break | yes/no | Version | 2.11.2 | DBAL Version | 3.3.3 | Database Driver| Oracle, OCI8 | PHP | 8.1.3 #### Summary When working with optional fields in entity that have a BLOB type (blob, clob, text, ..., etc.), we get a warning: `Deprecated: OCILob::writeTemporary(): Passing null to parameter #1 ($data) of type string is deprecated in vendor/doctrine/dbal/src/Driver/OCI8/Statement.php on line 76` The error occurs when working with Oracle (OCI8) #### How to reproduce ```xml <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="ExampleProcess" table="JOB_PROCESS"> <id name="id" type="integer" column="id"> <generator strategy="SEQUENCE"/> <sequence-generator sequence-name="PROCESS_ID_SEQ" allocation-size="1" initial-value="1"/> </id> <field name="response" type="blob" column="response" nullable="true"></field> </entity> </doctrine-mapping> ``` ```php <?php class ExampleProcess { private int $id; /** * @var null|string|resource */ private $response; // << optional field public function getId(): int { return $this->id; } public function getResponse(): string|null { if (\is_resource($this->response)) { return (string) stream_get_contents($this->response); } return $this->response ?? null; } public function setResponse(string|null $response): self { $this->response = $response; return $this; } } ``` Example: ```php <?php $test = new ExampleProcess(); $em->persist($test); $em->flush(); // this will trigger a warning $test2 = new ExampleProcess(); $test2->setResponse(null); $em->persist($test2); $em->flush(); // this will trigger a warning // unwanted code that allows you to temporarily bypass the problem: $test3 = new ExampleProcess(); $test3->setResponse(""); $em->persist($test3); $em->flush(); // this will work fine ``` #### Expected behavior Optional fields are expected to allow NULL values
Author
Owner

@derrabus commented on GitHub (Apr 25, 2022):

Sorry for not getting back to you that long. Unfortunately, we don't really have good test coverage for Oracle, mainly because nobody maintains it. Would you be willing to work on a fix for the issue?

@derrabus commented on GitHub (Apr 25, 2022): Sorry for not getting back to you that long. Unfortunately, we don't really have good test coverage for Oracle, mainly because nobody maintains it. Would you be willing to work on a fix for the issue?
Author
Owner

@eisberg commented on GitHub (Apr 25, 2022):

Ok, I'll try to fix it

@eisberg commented on GitHub (Apr 25, 2022): Ok, I'll try to fix it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6952