I have two identical Symfony 2.8 projects. The only difference in these two projects is that one is running Doctrine ORM version v2.4.8 and the other is running v2.5.5
The problem
I have this following piece of code in both Symfony projects.
$rsm = new ResultSetMapping();
$rsm->addEntityResult('EntityBundle:New', 'u');
$rsm->addFieldResult('u', 'newPK', 'newPK');
$rsm->addFieldResult('u', 'msg', 'msg');
$query = $em->createNativeQuery('StoredProcedureName @a= :a, @b= :b, @c= :c', $rsm);
$query->setParameter('a', 'a');
$query->setParameter('b', 'b');
$query->setParameter('c', 'c');
$result = $query->getArrayResult();
var_dump($result);
My Entity looks like this:
use Doctrine\ORM\Mapping as ORM;
/**
* New
*
* @ORM\Table(name="dbo.New")
* @ORM\Entity()
*/
class New
{
/**
* @var string
*
* @ORM\Column(name="newPK", type="string", length=255, unique=false)
*/
private $newPK;
/**
* @var string
*
* @ORM\Column(name="msg", type="string", length=255, unique=false)
*/
private $msg;
/**
* @return string
*/
public function getNewPK()
{
return $this->newPK;
}
/**
* @param string $newPK
*/
public function setNewPK($newPK)
{
$this->newPK = $newPK;
}
/**
* @return string
*/
public function getMsg()
{
return $this->msg;
}
/**
* @param string $msg
*/
public function setMsg($msg)
{
$this->msg = $msg;
}
}
In my StoredProcedure all I have is this:
CREATE PROCEDURE [dbo].[StoredProcedureName]
AS
SELECT null as newPK, 'aaa' As msg
GO
This code works perfectly fine on version v2.4.8 returning me null value perfectly. However this doesn't work on v2.5.5. All it returns is an array with NULL inside it and not the newPK AND msg value. If I remove the null and replace it with an empty string or anything else for that matter, it works. But for some god forsaken reason, it does not like the NULL value. All I want is to check if null is returned or not but I can't seem to check without doctrine returning me proper values.
Is there anything that changed between these versions that I am not aware of? What do I need to do in order to read NULL values from a native query?
@dipens are the DBAL versions also different?
@Ocramius Yes sorry should have mentioned that. The one with v2.4.8 has v2.5.4 installed. The one with v2.5.5 has v2.5.5 installed.
@dipens did you try running this with DBAL only? Did the results change? What DB/adapter are you using?
@Ocramius With DBAL I am getting the results. I am using freeTDS on Ubuntu 14.04.
Ping @deeky665 could our changes in prepared statements in 2.5 affect this?
@Ocramius the prepared statement stuff was released with 2.5.11, not 2.5.5. We'll have to take a look at the differences between DBAL 2.5.4 and 2.5.5 if I understand correctly.
@dipens can you try adding a test case meanwhile?
@Ocramius Sorry how do I do that?
I did a work around with this one using addScalarResult instead of addFieldResult. The modified code looks like this:
$rsm = new ResultSetMapping();
$rsm->addScalarResult( 'newPK', 'newPK');
$rsm->addScalarResult( 'msg', 'msg');
$query = $em->createNativeQuery('StoredProcedureName @a= :a, @b= :b, @c= :c', $rsm);
$query->setParameter('a', 'a');
$query->setParameter('b', 'b');
$query->setParameter('c', 'c');
$result = $query->getArrayResult();
var_dump($result);
What is the resolution here?
I just edited my close comment. Please have a look
@dipens that still doesn't say much to me - is this therefore a bug? Can it be reproduced?
@Ocramius After upgrading from 2.4 to 2.5 I have the same problem. Late I can send example how reproduce this bug.
@dipens this one
I did a work around with this one using
addScalarResultinstead ofaddFieldResult. The modified code looks like this:$rsm = new ResultSetMapping(); $rsm->addScalarResult( 'newPK', 'newPK'); $rsm->addScalarResult( 'msg', 'msg'); $query = $em->createNativeQuery('StoredProcedureName @a= :a, @b= :b, @c= :c', $rsm); $query->setParameter('a', 'a'); $query->setParameter('b', 'b'); $query->setParameter('c', 'c'); $result = $query->getArrayResult(); var_dump($result);
this one work for me!! thankful....
Most helpful comment
I did a work around with this one using
addScalarResultinstead ofaddFieldResult. The modified code looks like this: