0

Zend Framework 内の Doctrine クエリに問題があります。クエリを作成するコードを以下に添付します。

    $qb = $this->createQueryBuilder("m");
    $qb->select("partial m.{_follow,_contacts}");
    //$qb->from("Key\Members\Domain\AbstractMember as m");

    $first = true;
    $types = array();
    for($i = 0; $i < count($networkIds); $i++){
        if($first){
            $first = false;
            $qb->where("m._id = ?".$i);
        } else{
            $qb->orWhere("m._id = ?".$i);
        }
        $qb->setParameter($i, $networkIds[$i], 'binary');
    }

    $this->_logger->log('query:'.$qb->getDQL(), Zend_Log::DEBUG);
    $result = $this->_em->createQuery($qb->getDQL())->getResult();

私が知る限り、DQL は問題ないように見えます。

SELECT partial m.{_follow,_contacts} FROM Key\Members\Domain\Member m WHERE (m._id = ?0) OR (m._id = ?1) OR (m._id = ?2)

配列は次のようになり$networkIdsます。

array(3) { [0]=> string(32) "01915617be6f4723b0ed61d6cb30fa5a" [1]=> string(32) "083f375e256244a9accaa176f814333e" [2]=> string(32) "3e43cbafa4174a9fa8197f1c85af812a" }

ログからの例外:

2013-01-07T20:47:28+00:00 ErrorController::errorAction() ERR (3): Controller error occured in for URI "/marketing/reach" in module "portlets", controller "member", action "onecolumn". Exception message was: Invalid parameter format, ? given, but :<name> or ?<num> expected.. Backtrace: #0 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/AST/InputParameter.php(46): Doctrine\ORM\Query\QueryException::invalidParameterFormat('?')
#1 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(2116): Doctrine\ORM\Query\AST\InputParameter->__construct('?')
#2 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(2253): Doctrine\ORM\Query\Parser->InputParameter()
#3 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(2211): Doctrine\ORM\Query\Parser->ArithmeticPrimary()
#4 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(2179): Doctrine\ORM\Query\Parser->ArithmeticFactor()
#5 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(2153): Doctrine\ORM\Query\Parser->ArithmeticTerm()
#6 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(2140): Doctrine\ORM\Query\Parser->SimpleArithmeticExpression()
#7 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(2469): Doctrine\ORM\Query\Parser->ArithmeticExpression()
#8 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(2003): Doctrine\ORM\Query\Parser->ComparisonExpression()
#9 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1926): Doctrine\ORM\Query\Parser->SimpleConditionalExpression()
#10 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1885): Doctrine\ORM\Query\Parser->ConditionalPrimary()
#11 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1855): Doctrine\ORM\Query\Parser->ConditionalFactor()
#12 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1831): Doctrine\ORM\Query\Parser->ConditionalTerm()
#13 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1922): Doctrine\ORM\Query\Parser->ConditionalExpression()
#14 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1885): Doctrine\ORM\Query\Parser->ConditionalPrimary()
#15 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1855): Doctrine\ORM\Query\Parser->ConditionalFactor()
#16 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1831): Doctrine\ORM\Query\Parser->ConditionalTerm()
#17 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(1211): Doctrine\ORM\Query\Parser->ConditionalExpression()
#18 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(766): Doctrine\ORM\Query\Parser->WhereClause()
#19 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(735): Doctrine\ORM\Query\Parser->SelectStatement()
#20 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(207): Doctrine\ORM\Query\Parser->QueryLanguage()
#21 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query/Parser.php(278): Doctrine\ORM\Query\Parser->getAST()
#22 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query.php(203): Doctrine\ORM\Query\Parser->parse()
#23 /srv/www/www.cookies.com/current/library/Doctrine/ORM/Query.php(223): Doctrine\ORM\Query->_parse()
#24 /srv/www/www.cookies.com/current/library/Doctrine/ORM/AbstractQuery.php(543): Doctrine\ORM\Query->_doExecute()
#25 /srv/www/www.cookies.com/current/library/Doctrine/ORM/AbstractQuery.php(366): Doctrine\ORM\AbstractQuery->execute(Array, 1)
#26 /srv/www/www.cookies.com/current/library/Key/Members/Repositories/MemberRepository.php(1281): Doctrine\ORM\AbstractQuery->getResult()
#27 /srv/www/www.cookies.com/current/application/modules/marketing/controllers/ReachController.php(53): Key\Members\Repositories\MemberRepository->fetchAllNetworkIds(Array)
#28 /srv/www/www.cookies.com/current/library/Zend/Controller/Action.php(513): Marketing_ReachController->indexAction()
#29 /srv/www/www.cookies.com/current/library/Jarlssen/Rest/Controller.php(59): Zend_Controller_Action->dispatch('indexAction')
#30 /srv/www/www.cookies.com/current/library/Key/Common/Controller/ActionController.php(232): Jarlssen_Rest_Controller->dispatch('indexAction')
#31 /srv/www/www.cookies.com/current/library/Zend/Controller/Dispatcher/Standard.php(295): Key\Common\Controller\ActionController->dispatch('indexAction')
#32 /srv/www/www.cookies.com/current/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#33 /srv/www/www.cookies.com/current/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#34 /srv/www/www.cookies.com/current/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#35 /srv/www/www.cookies.com/current/public/index.php(71): Zend_Application->run()
#36 {main}

問題はsetParameter()通話のどこかにあると思いますが、何が問題なのかわかりません。binaryまた、パラメーターなしで、setParameters()代わりに使用してみました。何か案は?

4

1 に答える 1

1

ここでの問題は $qb->where("m._id = ?".$i);In place of .you have to use,です。

そのため、ラインは

  $qb->where("m._id = ?",$i);

  $qb->orWhere("m._id = ?",$i);
于 2013-01-08T03:32:05.223 に答える