I'm having a problem with using IS DISTINCT FROM with symfony. In my case I want sth like this
SELECT * FROM table orders AS o WHERE o.orderer_id IS DISTINCT FROM o.operator_id
It works fine if I run by using pgAdmin(Postgresql), but I don't know how to write with symfony doctrine. I tried to search about this, but no result for me, so anyone can help. Thanks in advance.
thanks zerkms, I achieve this by
$queryBuilder->andWhere($queryBuilder->expr()->orX(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->isNotNull('tem.operator'),
$queryBuilder->expr()->andX(
$queryBuilder->expr()->neq('tem.orderer', 'tem.operator'),
$queryBuilder->expr()->neq('tem.enterprise', 'tem.operator')
)
),
$queryBuilder->expr()->isNull('tem.operator')
));
Related
I want to using the query
SELECT `uid` FROM `machines` ORDER BY NOT ISNULL(`changed`),`changed` DESC
in my controller .
For this I use the querybuilder like this:
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('forklifts');
$statement = $queryBuilder
->select('*')
->from('machines');
I tryed to add the ORDERBY in this way:
$statement->orderBy("NOT ISNULL(`changed`)");
$statement->addOrderBy("changed", "DESC");
But this don't work.
Is it possible to do this in TYPO3 Querybuilder or is there another solution to this problem?
You can use QueryBuilder::add() to bypass this limitation:
$queryBuilder->add(
'orderBy',
$queryBuilder->expr()->isNotNull('changed'),
true
);
$queryBuilder->addOrderBy('changed', 'DESC');
This is basically what QueryBuilder::addOrderBy() does internally but without automatic identifier quoting. Notice that the ExpressionBuilder is used here instead of a plain SQL snippet to ensure the changed field name is still quoted, even as part of a constraint.
Thank you Mathias for pushing me in the right direction.
In the TYPO3 documentation https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/ExpressionBuilder/Index.html
expr()->not()
is not listed as a method of TYPO3 querybuilder.
But
expr()->isNotNull()
is existing.
So this will work:
$queryBuilder->add(
'orderBy',
$queryBuilder->expr()->isNotNull('changed'),
true
);
$queryBuilder->addOrderBy('changed', 'DESC');
Thank you again
Hi there i want to show all Vertices except the ones called movie.
my statement so far was
SELECT * FROM V WHERE NOT #class="movie"
but unfortunately the response does not contain any records. can anybody explain this to me ? :) Thank you :)
what version are you using? If I try in 3.0.0 your query work but you have to use "class" :
SELECT * FROM V WHERE NOT #class="movie"
Cool i solved it by using:
SELECT * FROM V WHERE #class!="movie"
thanks for your help Idacrema :)
I'm using sailjs + waterline, how to filtering data after populate models? here i try my code and doesn't work :
Approductbranch
.find({deleted:1})
.populate("mproduct_id",{where:{deleted:1}})
.paginate({page:currpage,limit:utils.RowPerPage})
.exec(callback)
in my code above, i want to execute sql like this :
select * from approductbranch a
inner join mproduct a
on a.id = a.mproduct_id
where a.deleted = 1
and b.deleted = 1
how to do this? thank! :)
Good question.
There currently isn't a way to do this directly, but there is an outstanding feature request in the Waterline repository that you can share your thoughts in.
I think you can do like this:
Approductbranch
.find({deleted:1})
.populate("mproduct_id",{deleted:1, skip:currpage * utils.RowPerPage, limit:utils.RowPerPage})
.exec(callback)
it will be OK!
You can filter a set of values before you populate. This is more performant since you're not getting more values than you need: https://github.com/balderdashy/sails-docs/blob/master/reference/waterline/queries/populate.md
I add jenssegers Laravel-MongoDB package into my Laravel 4.2 project, and have a one problem. Maybe can help me. I cann't use DB::raw in select or get method. I need to change name of select column and add columns into one column, but Laravel return me an error.
I try to do something like this:
$arr = StudentMark::join('students', 'students.id','=','student_marks.student_id')
->select(array('student_marks.id',DB::raw('CONCAT(students.name, " ",
students.surname, " (", students.index,") ") AS student')))->get();
But Laravel return me an error:
{"error":{"type":"ErrorException","message":"Illegal offset type","file":".....vendor\\jenssegers\\mongodb\\src\\Jenssegers\\Mongodb\\Query\\Builder.php","line":240}}
Can anybody help me?
I use select with columns, and concating columns do in foreach of results and then return to client, and that solve me a problem. :)
I want to implement functionality that will search the record from mongoDB. I am using ichikaway plugin.
I tried the cakephp like clause mentioned here, but did not worked for me :(.
please let me if there is any approach to achieve this.
Thanks in advance
After doing search around I have found solution
$conditions = array('field_name' => new MongoRegex('/'.$value.'/i'));
where i trans to case-insensitive.