Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

convertToPHPValue should match convertToDatabaseValue #233

Closed
wants to merge 2 commits into from

4 participants

@zyjohn

convertToPHPValue return resource which is not match default convertToDatabaseValue that not make any change. Change to return content of the resource.

@zyjohn zyjohn Update lib/Doctrine/DBAL/Types/BlobType.php
convertToPHPValue return resource which is not match default convertToDatabaseValue that not make and change. Change to return content of the resource.
feb3023
@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-391

@Ocramius
Owner

@zyjohn why not retrieving the stream instead? I didn't understand the original point. Could you provide a failing test case that validates this use case?

@zyjohn

When monitor onFlush event to make a DB journal (compare $entityManager->getUnitOfWork()->getEntityChangeSet($entity), foreach value item[0] as old data, item[1] as new data). If we pass the resource only, the resource is already been read somewhere and the content of the resource is empty. To pass the content value is a simple solution. If you think there is performance issue and prefer to use stream, you need to use rewind($value) whenever you did a stream_get_contents($value) to that resource. Which I don't know how many place should be changed yet.

@guilhermeblanco

You should use type="text". Blobs would be keep as resources and applying such as this change would break BC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 23, 2012
  1. @zyjohn

    Update lib/Doctrine/DBAL/Types/BlobType.php

    zyjohn authored
    convertToPHPValue return resource which is not match default convertToDatabaseValue that not make and change. Change to return content of the resource.
  2. @zyjohn
This page is out of date. Refresh to see the latest.
View
2  lib/Doctrine/DBAL/Types/BlobType.php
@@ -52,7 +52,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform)
} else if ( ! is_resource($value)) {
throw ConversionException::conversionFailed($value, self::BLOB);
}
- return $value;
+ return stream_get_contents($value);
}
public function getName()
View
3  tests/Doctrine/Tests/DBAL/Functional/BlobTest.php
@@ -77,7 +77,6 @@ private function assertBlobContains($text)
$blobValue = Type::getType('blob')->convertToPHPValue($row['blobfield'], $this->_conn->getDatabasePlatform());
- $this->assertInternalType('resource', $blobValue);
- $this->assertEquals($text, stream_get_contents($blobValue));
+ $this->assertEquals($text, $blobValue);
}
}
Something went wrong with that request. Please try again.