and, or doesn't work in DQL #5950

Closed
opened 2026-01-22 15:22:59 +01:00 by admin · 10 comments
Owner

Originally created by @winnilein on GitHub (Apr 12, 2018).

I migrate a mysql db to sqlAnywhere(sqla) to test my app developed with Doctrine2.

Acces to sqla works,
DQL like

$query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng );

$query->setParameters(array(
'lng' => 'DE'
));

$result = $query->getResult();

also runs funny.

$query = $em->createQuery('SELECT e FROM countries e WHERE e.connum = :num );

$query->setParameters(array(
'num' => '4'
));

$result = $query->getResult();

also no problems!

BUT!

$query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng AND e.connum = :num');

$query->setParameters(array(
'lng' => 'DE',
'num' => '4',
));

$result = $query->getResult();

doesn't work!!

$result = empty!

with operator OR it's the same problem!

Any idea!

Originally created by @winnilein on GitHub (Apr 12, 2018). I migrate a mysql db to sqlAnywhere(sqla) to test my app developed with Doctrine2. Acces to sqla works, DQL like $query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng ); $query->setParameters(array( 'lng' => 'DE' )); $result = $query->getResult(); also runs funny. $query = $em->createQuery('SELECT e FROM countries e WHERE e.connum = :num ); $query->setParameters(array( 'num' => '4' )); $result = $query->getResult(); also no problems! ## BUT! $query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng AND e.connum = :num'); $query->setParameters(array( 'lng' => 'DE', 'num' => '4', )); $result = $query->getResult(); doesn't work!! $result = empty! with operator OR it's the same problem! Any idea! # #
admin closed this issue 2026-01-22 15:23:00 +01:00
Author
Owner

@Ocramius commented on GitHub (Apr 12, 2018):

What's the executed SQL query? Can you run that manually and verify the output? Also make sure the parameter types match.

@Ocramius commented on GitHub (Apr 12, 2018): What's the executed SQL query? Can you run that manually and verify the output? Also make sure the parameter types match.
Author
Owner

@winnilein commented on GitHub (Apr 13, 2018):

Interactive sql works!

grafik

But if i change my test-pgm to this ..

grafik

look at the sql statement!

SELECT e FROM countries e WHERE e.conlng = :lng or e.connum = :num

and the result in the sceenshot.

It woorks with an OR operator??!

I'm very irritated !

@winnilein commented on GitHub (Apr 13, 2018): Interactive sql works! ![grafik](https://user-images.githubusercontent.com/38318899/38720441-91189f92-3ef6-11e8-9d20-b188b7e0eb70.png) But if i change my test-pgm to this .. ![grafik](https://user-images.githubusercontent.com/38318899/38721092-197090d2-3ef9-11e8-9c87-2db46a9e2065.png) look at the sql statement! ## SELECT e FROM countries e WHERE e.conlng = :lng or e.connum = :num and the result in the sceenshot. It woorks with an OR operator??! ## I'm very irritated !
Author
Owner

@Ocramius commented on GitHub (Apr 13, 2018):

SELECT e FROM countries e WHERE e.conlng = :lng or e.connum = :num

Is this the same SQL statement that the ORM runs?
Use a DebugStack logger to see if the SQL statement is the same.

The one difference I noticed is that sometimes your parameters are string, sometimes int: try looking for differences there as well as in the executed SQL string.

I'm very irritated !

This is not a support hotline: if you need to get irritated over volunteers helping you out, you can instead hire somebody to help you out, and be (contractually) allowed to be irritated instead.

@Ocramius commented on GitHub (Apr 13, 2018): > `SELECT e FROM countries e WHERE e.conlng = :lng or e.connum = :num` Is this the same SQL statement that the ORM runs? Use a [`DebugStack`](https://github.com/doctrine/dbal/blob/0f23ed9ba28db2b392eeaaf5938ce804e52084b9/lib/Doctrine/DBAL/Logging/DebugStack.php) logger to see if the SQL statement is the same. The one difference I noticed is that sometimes your parameters are `string`, sometimes `int`: try looking for differences there as well as in the executed SQL string. > I'm very irritated ! This is not a support hotline: if you need to get irritated over volunteers helping you out, you can instead hire somebody to help you out, and be (contractually) allowed to be irritated instead.
Author
Owner

@winnilein commented on GitHub (Apr 13, 2018):

grafik

The result ofDebugStack!?

@winnilein commented on GitHub (Apr 13, 2018): ![grafik](https://user-images.githubusercontent.com/38318899/38734156-d37fd23c-3f24-11e8-8f14-eae024415161.png) The result ofDebugStack!?
Author
Owner

@Ocramius commented on GitHub (Apr 13, 2018):

@winnilein can you expand on params and types there?

@Ocramius commented on GitHub (Apr 13, 2018): @winnilein can you expand on `params` and `types` there?
Author
Owner

@winnilein commented on GitHub (Apr 13, 2018):

grafik

@winnilein commented on GitHub (Apr 13, 2018): ![grafik](https://user-images.githubusercontent.com/38318899/38742174-1fc9735c-3f3c-11e8-9ea9-dc64dbcc730b.png)
Author
Owner

@Ocramius commented on GitHub (Apr 13, 2018):

Both are bound as string there - can you try passing in an integer and running the SQL statement manually with either string or int, and see if there is a difference?

@Ocramius commented on GitHub (Apr 13, 2018): Both are bound as `string` there - can you try passing in an integer and running the SQL statement manually with either `string` or `int`, and see if there is a difference?
Author
Owner

@winnilein commented on GitHub (Apr 13, 2018):

native sql..
grafik

and the result of my script..

grafik

my script..

<?php
include "Bootstrap.php";
require_once 'Entities/countries.php';
error_reporting(E_ALL);

$stack = new \Doctrine\DBAL\Logging\DebugStack();
$stack->enabled;
$em->getConfiguration()->setSQLLogger($stack);

$query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng AND e.connum = :num');

$LNG = 'DE';
$NUM = 4;

  $query->setParameters(array(
    'lng' => $LNG,
    'num' => $NUM,
            ));
 

$result = $query->getResult();
        
            if (!$result) {
            
                echo 'Noting found!';
                
            
            } else {
        
                foreach ($result as $row) {
                    $TXT=$row->getContxt();
                    echo $TXT;   
                }     
     
            }    
            
      echo '<pre>';
\Doctrine\Common\Util\Debug::dump($stack, 5);      

@winnilein commented on GitHub (Apr 13, 2018): native sql.. ![grafik](https://user-images.githubusercontent.com/38318899/38754033-914eaabe-3f60-11e8-90ea-475087e3c644.png) and the result of my script.. ![grafik](https://user-images.githubusercontent.com/38318899/38754086-c5245d48-3f60-11e8-87b9-fd36462da3c9.png) my script.. ``` <?php include "Bootstrap.php"; require_once 'Entities/countries.php'; error_reporting(E_ALL); $stack = new \Doctrine\DBAL\Logging\DebugStack(); $stack->enabled; $em->getConfiguration()->setSQLLogger($stack); $query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng AND e.connum = :num'); $LNG = 'DE'; $NUM = 4; $query->setParameters(array( 'lng' => $LNG, 'num' => $NUM, )); $result = $query->getResult(); if (!$result) { echo 'Noting found!'; } else { foreach ($result as $row) { $TXT=$row->getContxt(); echo $TXT; } } echo '<pre>'; \Doctrine\Common\Util\Debug::dump($stack, 5); ```
Author
Owner

@winnilein commented on GitHub (Apr 13, 2018):

For your entertainment..

$query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng AND e.connum = :num');

$NUM = 4;

result ->

grafik

and now !

$query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng or e.connum = :num');

$NUM = '4';

result..

grafik

f****** web apps
i think i continue programming midrange applications

@winnilein commented on GitHub (Apr 13, 2018): ## For your entertainment.. `$query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng AND e.connum = :num');` `$NUM = 4;` result -> ![grafik](https://user-images.githubusercontent.com/38318899/38754410-01e1203a-3f62-11e8-8c54-a62626a5d075.png) ## and now ! `$query = $em->createQuery('SELECT e FROM countries e WHERE e.conlng = :lng or e.connum = :num');` ` $NUM = '4';` result.. ![grafik](https://user-images.githubusercontent.com/38318899/38754495-627ebbbe-3f62-11e8-9078-388115a1b4fe.png) f****** web apps i think i continue programming midrange applications
Author
Owner

@Ocramius commented on GitHub (Apr 13, 2018):

Closing: nobody's spare time is worth following up on this attitude.

If you don't have the willpower to contribute to this conversation in a constructive way, then please consider hiring somebody doing it for you instead.

@Ocramius commented on GitHub (Apr 13, 2018): Closing: nobody's spare time is worth following up on this attitude. If you don't have the willpower to contribute to this conversation in a constructive way, then please consider hiring somebody doing it for you instead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5950