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
Related
I am getting the following error, when tries to save the following script.
"Script compilation failed at line 19 in procedure 'BusComp_PreWriteRecord':
Syntax error at Line 31 position 59:Expected ')'
(SBL-SCR-00128)"
function BusComp_PreWriteRecord ()
{
var obj = TheApplication().GetBusObject("Service Request");
var optybc = obj.GetBusComp("Service Request");
optybc.ActivateField("SR Type");
//optybc.ActivateField(“Typeâ€);
optybc.SetViewMode(3);
optybc.ClearToQuery();
optybc.SetSearchSpec("SR Type",this.GetFieldV alue("SR Type"));
//optybc.SetSearchSpec(“Typeâ€,this.GetFieldV alue(“Typeâ€));
optybc.ExecuteQuery(ForwardOnly);
if(optybc.FirstRecord())
{
TheApplication().RaiseErrorText("Duplicate Records");
}
}
Does anyone knows the reason for the above error?
It might be that you are missing brackets in code that is "above" PreWriteRecord()
for example these methods
Siebel compiles all event code as one large code, so missing parentheses in other places will create issue in subsequent events.
I'm starting to look into testing so thought id do something simple like see if a page loads correctly.
Here is my test;
<?php
use App\Users\Models\User;
class BlogPostsTest extends TestCase {
protected $baseUrl = 'http://localhost:8000';
public function testBlogPostsAreAccessible()
{
$this->be( User::findOrFail(1) );
$response = $this->call( 'GET', '/admin/blog-posts' );
$this->assertEquals( 200, $response->getStatusCode() );
}
}
Which returns and error
1) BlogPostsTest::testBlogPostsAreAccessible Error: Call to undefined
method
Symfony\Component\Debug\Exception\FatalThrowableError::getStatusCode()
/Users/ss/git/modules/admin/admin-blog/app/Exceptions/Handler.php:77
/Users/ss/git/modules/admin/admin-blog/app/Exceptions/Handler.php:58
/Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:291
/Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:107
/Users/ss/git/modules/admin/admin-blog/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:515
/Users/ss/git/modules/admin/admin-blog/tests/ExampleTest.php:12
FAILURES! Tests: 1, Assertions: 0, Errors: 1.
The error is coming from $this->call() does anyone know why this is?
regards
Are you sure your 'admin/blog-posts' returns an actual response object? Can you dd() the output in your test? So:
dd($response);
To see what it is your code is returning?
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'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 )");