Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Duplicate
-
Affects Version/s: 2.1.6
-
Fix Version/s: None
-
Component/s: DQL
-
Security Level: All
-
Labels:None
Description
Maybe I am doing something wrong, but here is the case:
I created a custom Doctrine Type:
class BinaryType extends Type { const BINARY = 'binary'; public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return sprintf('BINARY(%d)', $fieldDeclaration['length']); } public function getName() { return self::BINARY; } public function convertToPhpValue($value, AbstractPlatform $platform) { if ($value !== null) { $value= unpack('H*', $value); return array_shift($value); } } public function convertToDatabaseValue($value, AbstractPlatform $platform) { if ($value !== null) { return pack('H*', $value); } } }
Now I have a simple table with Photographerguid field as binary (the custom type created) and run a simple query:
$q = $repository->createQueryBuilder('p')->select('p.name, p.surname, p.photographerguid')->where("p.name = 'peter'");
$result = $q->getQuery()->getResult();
The function convertToPhpValue is not run on the value of Photographerguid, so it returns %&@#!((@#
The reason is that in AbstractHydrator::_gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents) function
all fields of a query are determined as scalar (isScalar), and convertToPHPValue($value, $this->_platform) is not run on them.
What is the difference between scalarMappings and fieldMappings?
How to make data conversion work in both directions?
Activity
ross neacoders
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
Maybe I am doing something wrong, but here is the case: I created a custom Doctrine Type: {qoute} class BinaryType extends Type { const BINARY = 'binary'; public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return sprintf('BINARY(%d)', $fieldDeclaration['length']); } public function getName() { return self::BINARY; } public function convertToPhpValue($value, AbstractPlatform $platform) { if ($value !== null) { $value= unpack('H*', $value); return array_shift($value); } } public function convertToDatabaseValue($value, AbstractPlatform $platform) { if ($value !== null) { return pack('H*', $value); } } } {quote} Now I have a simple table with Photographerguid field as binary $q = $repository->createQueryBuilder('p')->select('p.name, p.surname, p.photographerguid')->where("p.name = 'peter'"); $result = $q->getQuery()->getResult(); The function convertToPhpValue is not run on the value of Photographerguid. The reason is that in AbstractHydrator::_gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents) function all fields are determined as scalar, and convertToPHPValue($value, $this->_platform) is not run on them. What is the difference between scalarMappings and fieldMappings? How to make data conversion work in both directions? |
Maybe I am doing something wrong, but here is the case: I created a custom Doctrine Type: {code} class BinaryType extends Type { const BINARY = 'binary'; public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return sprintf('BINARY(%d)', $fieldDeclaration['length']); } public function getName() { return self::BINARY; } public function convertToPhpValue($value, AbstractPlatform $platform) { if ($value !== null) { $value= unpack('H*', $value); return array_shift($value); } } public function convertToDatabaseValue($value, AbstractPlatform $platform) { if ($value !== null) { return pack('H*', $value); } } } {code} Now I have a simple table with Photographerguid field as binary $q = $repository->createQueryBuilder('p')->select('p.name, p.surname, p.photographerguid')->where("p.name = 'peter'"); $result = $q->getQuery()->getResult(); The function convertToPhpValue is not run on the value of Photographerguid. The reason is that in AbstractHydrator::_gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents) function all fields are determined as scalar, and convertToPHPValue($value, $this->_platform) is not run on them. What is the difference between scalarMappings and fieldMappings? How to make data conversion work in both directions? |
ross neacoders
made changes -
| Description |
Maybe I am doing something wrong, but here is the case: I created a custom Doctrine Type: {code} class BinaryType extends Type { const BINARY = 'binary'; public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return sprintf('BINARY(%d)', $fieldDeclaration['length']); } public function getName() { return self::BINARY; } public function convertToPhpValue($value, AbstractPlatform $platform) { if ($value !== null) { $value= unpack('H*', $value); return array_shift($value); } } public function convertToDatabaseValue($value, AbstractPlatform $platform) { if ($value !== null) { return pack('H*', $value); } } } {code} Now I have a simple table with Photographerguid field as binary $q = $repository->createQueryBuilder('p')->select('p.name, p.surname, p.photographerguid')->where("p.name = 'peter'"); $result = $q->getQuery()->getResult(); The function convertToPhpValue is not run on the value of Photographerguid. The reason is that in AbstractHydrator::_gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents) function all fields are determined as scalar, and convertToPHPValue($value, $this->_platform) is not run on them. What is the difference between scalarMappings and fieldMappings? How to make data conversion work in both directions? |
Maybe I am doing something wrong, but here is the case: I created a custom Doctrine Type: {code} class BinaryType extends Type { const BINARY = 'binary'; public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return sprintf('BINARY(%d)', $fieldDeclaration['length']); } public function getName() { return self::BINARY; } public function convertToPhpValue($value, AbstractPlatform $platform) { if ($value !== null) { $value= unpack('H*', $value); return array_shift($value); } } public function convertToDatabaseValue($value, AbstractPlatform $platform) { if ($value !== null) { return pack('H*', $value); } } } {code} Now I have a simple table with Photographerguid field as binary (the custom type created) and run a simple query: {code} $q = $repository->createQueryBuilder('p')->select('p.name, p.surname, p.photographerguid')->where("p.name = 'peter'"); $result = $q->getQuery()->getResult(); {code} The function convertToPhpValue is not run on the value of Photographerguid, so it returns %^&@#!(^(@# The reason is that in AbstractHydrator::_gatherRowData(array $data, array &$cache, array &$id, array &$nonemptyComponents) function all fields of a query are determined as scalar (isScalar), and convertToPHPValue($value, $this->_platform) is not run on them. What is the difference between scalarMappings and fieldMappings? How to make data conversion work in both directions? |
Benjamin Eberlei
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Duplicate [ 3 ] |
Benjamin Eberlei
made changes -
| Workflow | jira [ 13658 ] | jira-feedback [ 15332 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback [ 15332 ] | jira-feedback2 [ 17196 ] |
Benjamin Eberlei
made changes -
| Workflow | jira-feedback2 [ 17196 ] | jira-feedback3 [ 19451 ] |