$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)));
Related
I have a controller class and inside a method of the controller class, I have List Defined as below.
List<TrackedStoreProductsViewModel> currTrackProds = _context.Tracked_Products.Select(p => new TrackedStoreProductsViewModel()
{
TrackedProducts = p,
currentPrice = _context.Store_Products.Where(x => trackedId.Contains(x.product_id)).FirstOrDefault(s => s.product_id == p.product_id).Product_Price_History.OrderByDescending(pr => pr.price_timestamp).Select(pr => pr.price).FirstOrDefault(),
userEmailId = _context.User_Accounts.FirstOrDefault(u => u.account_number == p.account_number).email_id,
userFirstName = _context.User_Info.FirstOrDefault(u => u.account_number == p.account_number).first_name
}
).ToList();
Here I am getting the following exception error
Here the exception error is 'Unknown column 't.Store_Productsproduct_id' in 'field list'.
I checked all the models related to this, set up a breakup point stepped in still couldn't find where it is defined that way? Can someone suggest me an approach I can possibly follow to fix this issue?
I have read the other undefined method questions and tried to apply the suggestions to my error with no luck. The full error is
Fatal error: Call to undefined method ModelExtensionExtension::getExtensions() in /home/*user*/public_html/*domain*/system/storage/modification/catalog/controller/common/header.php on line 9
Here is the code, line 9 is: $analytics = $this->model_extension_extension->getExtensions('analytics');
<?php
class ControllerCommonHeader extends Controller {
public function index() {
// Analytics
$this->load->model('extension/extension');
$data['analytics'] = array();
$analytics = $this->model_extension_extension->getExtensions('analytics');
foreach ($analytics as $analytic) {
if ($this->config->get($analytic['code'] . '_status')) {
$data['analytics'][] = $this->load->controller('analytics/' . $analytic['code']);
}
}
This problem referrer to config.php file.
Verify that your CATALOG and MODIFICATION dir is correct.
In my case I solved this problem fixing this paths.
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
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
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 )");