I'm playing with DoctrineExtensions but can not manage it. After register DoctrineExtensions, I have following line of DQL with Zend Framework:
$qb->having(new IfElse("A.type = 0", new FindInSet(1, new GroupConcat('B.id', ',')) >0 , '1') );
But get this error msg:
Exception information:
Message: Expression of type 'DoctrineExtensions\Query\Mysql\IfElse'
not allowed in this context.*
Could you help me to point out what incorrect in my command or any document on how to use DoctrineExtensions?
UPDATED:
I've found a the way to implement custom function by :
I have given it a litle try by adding this line to boostrap:
$config->addCustomStringFunction('IF', 'DoctrineExtensions\Query\Mysql\IfElse');
And use it in DQL as:
$qb->having("IF( A.type = 0, S.status = 0, S.status = 1 )");
But get this error:
Message: [Syntax Error] line 0, col 152: Error: Expected Doctrine\ORM\Query\Lexer::T_COMMA, got '='
Maybe I'm wrong in syntax?
Have you tried
$qb->having("S.status = IF( A.type = 0, 0, 1 )");
Related
I get a compilation error on the line:
GLPADATA &sDamage = sItemCustom.getdamage();
nExtraValue = sItemCustom.GETGRADE_DAMAGE();
uGRADE = sItemCustom.GETGRADE(EMGRINDING_DAMAGE);
AddInfoItemAddonRange ( sDamage.dwLow, sDamage.dwHigh, nExtraValue, uGRADE,ID2GAMEWORD("ITEM_ADVANCED_INFO", 0) );
AddTextNoSplit (uGRADE, NS_UITEXTCOLOR::GOLD);
I don't know how to resolve this error, and what I'm trying to do is to have the uGRADE a different color from the default color of ID2GAMEWORD. I'm currently still learning
I've written the following code to build the query using query builder.
$em = $this->_em;
$qb = $em->createQueryBuilder();
$qb->select('tbl');
$qb->addSelect('COUNT(tbl.macId) AS totalInstallations');
$qb->addSelect('COUNT(DISTINCT tbl.macId) AS uniqueInstallations');
$qb->addSelect('COUNT(CASE
WHEN tbl.updatedOn IS NOT NULL THEN tbl.macId ELSE NULL
END) AS totalUninstallations');
$qb->from('Entity\SoftwareInstallation', 'tbl');
$result = $qb->getQuery()->getArrayResult();
return $result;
But it's not working in the case condition.
I get the below error:
Type: Doctrine\ORM\Query\QueryException
Message: [Syntax Error] line 0, col 152: Error: Expected
Doctrine\ORM\Query\Lexer::T_FROM, got '.'
Filename:
/var/www/html/ghostnew/application/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php
Line Number: 52
Try using SUM() instead of COUNT().
See this answer: Doctrine 2 DQL CASE WHEN in Count
$qb = $this->getDoctrine ()->getEntityManager()->createQueryBuilder();
$qb->delete('MainBundle:StatisticUser', 'u');
$qb->where($qb->expr()->in('sessionid', array_keys($sessionidsToTruncate)));
var_dump($qb->getQuery());
$qb->getQuery()->execute();
private '_dql' => string 'DELETE MainBundle:StatisticUser u WHERE sessionid IN('asdfghjkl')' (length=75)
but i get an error
[Semantical Error] line 0, col 50 near 'sessionid IN': Error: 'sessionid' is not defined.
Can anyone point me to the Problem?
Ok i found the solution with trial and error:
$qb->andWhere($qb->expr()->in('u.sessionid', array_keys($sessionidsToTruncate)));
I try to use lua in a C++ project. For lua executing I write this:
#include <lua.hpp>
...
luaEngine = luaL_newstate();
luaL_openlibs(luaEngine);
register_results(luaEngine); // For register c++ object in the LUA script as metatable
lua_pushstring(luaEngine, resultsId.c_str());
lua_setglobal(luaEngine, "resultsId");
lua_pushboolean(luaEngine, needReloadModel);
lua_setglobal(luaEngine, "needReload");
...
e = luaL_loadbuffer(luaEngine, script.c_str(), script.size(), NULL);
if(e != 0)
// error message
e = lua_pcall(luaEngine, 0, 1, 0);
if(e != 0)
// error message
...
lua_close(luaEngine);
And the lua script:
local Res = ResUpdateLUA(resultsId)
if current_result == "Normal" or current_result=='-' then
status = 'E'
else
status = 'O'
end
needReload = Res:setShowAnalyte('2320', status)
That didn't work and I've got error message:
[string "?"]:7: function arguments expected near <eof>
But when I add
print(needReload)
at the end of the lua script it works nice. What am I doing wrong?
The error message means that Lua reached the end of the source after seeing Res:s but before seeing (.
I suspect that script.size() is wrong. But I can't explain why adding that line works.
Thank you all for your answers. Yes, that was trouble with script.size() coz when it was replaced to e = luaL_loadbuffer(luaEngine, script.c_str(), strlen(script.c_str()), NULL); that started work fine. Sorry for my stupid question.
When using QueryBuilder object with like inside having as below:
$queuebuilder->addSelect('c.customercount*5 as count');
$queuebuilder->add('having', 'count like \'sometext\'');
I get an error:
[Syntax Error] line 0, col 741: Error: Expected '.' or '(', got count
This happpens only with aliased coloumn. How to avoid the error?
thank you.
Try something like this:
$qb->select('count(c.customer) as count');
$qb->having('count > x');
If you want to include where statements you could do something like this:
$qb->select('count(c.customer) as count');
$qb->where('c.username = :username');
$qb->having('count > ?1');
$qb->setParameter('username', "foo");
$qb->setParameter(1, 3); //havin count > 3