Questions tagged [dql]

Doctrine Query Language (DQL) is an Object Query Language created for helping users in complex object retrieval.

Summary

DQL stands for Doctrine Query Language and is an Object Query Language derivate that is very similar to the Hibernate Query Language (HQL) or the Java Persistence Query Language (JPQL).

In essence, DQL provides powerful querying capabilities over your object model. Imagine all your objects lying around in some storage (like an object database). When writing DQL queries, think about querying that storage to pick a certain subset of your objects.

Questions

  • How to write DQL statements to achieve a particular SQL statement?
  • Why will a DQL statement not work as expected?

More Information

To learn more about DQL visit

Doctrine 1.2
http://www.doctrine-project.org/projects/orm/1.2/docs/manual/dql-doctrine-query-language/en#dql-doctrine-query-language

Doctrine 2.0
http://www.doctrine-project.org/docs/orm/2.0/en/reference/dql-doctrine-query-language.html

1296 questions
6
votes
2 answers

Doctrine DQL query with SQL functions

I'm porting simple web application written in CodeIgniter to Symfony2 bundle. I'm new into Symfony2 and Doctrine and I've a problem with one SQL query, that I want to rewrite in DQL. I've all ready to go in my bundle, I've created Entity class and…
Darrarski
  • 3,882
  • 6
  • 37
  • 59
6
votes
3 answers

Doctrine 2 Randomly Selecting a Row (Offset 0 or 1 indexed)?

So far, I think doctrine doesn't have a way of selecting a random row. So I am thinking I have a query to get the count of rows // pseudo code $count = SELECT COUNT(i) FROM Item i WHERE ... Then have a real query to get the item using a random…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
6
votes
2 answers

Join and count in DQL

I have a MySQL command and I cannot find the equivalent in DQL. I am trying to fetch the list most commented posts. Here is the MySQL command : SELECT posts.id, COUNT(comments.id) AS num FROM posts LEFT JOIN comments ON ( posts.id = comments.post_id…
Quentin
  • 2,529
  • 2
  • 26
  • 32
6
votes
4 answers

How to retrieve only entity id using Symfony QueryBuilder?

I'm trying to personalize a symfony 2.4 repository query to retrieve only some fields. Everything is ok with flat fields but when retrieving Entity fields, I only get the id (by default) but not the whole entity data. My query: $select =…
Vandervals
  • 5,774
  • 6
  • 48
  • 94
6
votes
1 answer

Invalid PathExpression. Must be a SingleValuedAssociationField

I'm trying to do: class PrixRepository extends EntityRepository { public function findPrixLike($film) { $query = $this->createQueryBuilder('p') ->addSelect('s') …
stax
  • 325
  • 1
  • 2
  • 15
6
votes
2 answers

DELETE query not working in DQL doctrine Symfony2

I am to delete a row based on ID, and i used this query to do the task: $em = $this->getDoctrine()->getManager(); $query = $em->createQuery('DELETE buss from StreetBumbApiBundle:BussOwner buss WHERE buss.id = :bussId') …
Geetika
  • 790
  • 3
  • 13
  • 29
6
votes
2 answers

symfony2/doctrine2 dql where field is not true

im having troubles with checking boolean field with "is not true" clause im getting this error: ("[Syntax Error] line 0, col 510: Error: Expected =, <, <=, <>, >, >=, !=, got 'IS'") query is build with dql. so in code i have it added like this…
KoSMoS
  • 534
  • 2
  • 5
  • 19
6
votes
3 answers

Symfony2 SQLSTATE[42S22]: Column not found: 1054 Unknown column

I'm trying to create a todo list kind of app. At the moment I am just trying to output all the tasks based on the user instanced user id. I'm having some trouble writing the query using $user->getId() as the parameter for user_id. Here's what I…
Tom
  • 258
  • 1
  • 3
  • 12
6
votes
1 answer

DQL query produces error Expected Literal, got 'BY'

I am having a problem with a DQL query to retrieve users and roles from a MySql database. I am using Zend Framework 2 and Doctrine 2. The query is as follows. public function getUsers() { $builder =…
Garry
  • 1,455
  • 1
  • 15
  • 34
6
votes
3 answers

what does positional and named parameter in a query mean?

here we got a positional parameter: SELECT u FROM ForumUser u WHERE u.id = ?1 and here a named parameter: SELECT u FROM ForumUser u WHERE u.username = :name this is DQL (doctrine query language) but i think the concept is the same. could…
never_had_a_name
  • 90,630
  • 105
  • 267
  • 383
6
votes
5 answers

How to ORDER BY DateTime in Doctrine 2?

I'm looking to execute the following query: $qb = $this->getEntityManager()->createQueryBuilder(); $qb->select( 'e' ) ->from( 'Entity\Event', 'e' ) ->setMaxResults( $limit ) ->setFirstResult(…
Miles M.
  • 4,089
  • 12
  • 62
  • 108
6
votes
4 answers

DQL query to return all files in a Cabinet in Documentum?

I want to retrieve all the files from a cabinet (called 'Wombat Insurance Co'). Currently I am using this DQL query: select r_object_id, object_name from dm_document(all) where folder('/Wombat Insurance Co', descend); This is ok except it only…
Jason Pather
  • 1,127
  • 2
  • 12
  • 18
6
votes
1 answer

how to get the difference between 2 dates with Dql

How can I get the difference between 2 dates with Dql? I have tried the following code, but that didn't work. $query =$this->_em->createQuery('select a,DATEDIFF(d,\'now\',a.date) from ABundle:Abonment a where d==1'); How can I solve this?
smarttech
  • 133
  • 1
  • 4
  • 11
6
votes
3 answers

Is there a simple way to combine IS NULL and = :value in Doctrine 2 DQL?

I regularly come across a scenario, where I want to query an entity with a specific value: $query = $em->createQuery('SELECT e FROM Entity e WHERE e.parent = :parent'); $query->setParameter('parent', $parent); Often, this value can be NULL, but…
BenMorel
  • 34,448
  • 50
  • 182
  • 322
5
votes
2 answers

Doctrine DQL RIGHT JOIN?

Is it possible to do a RIGHT OUTER JOIN in Doctrine 2 DQL?
BenMorel
  • 34,448
  • 50
  • 182
  • 322