Bug #90107

QueryBuilder Bug in add Clause with append

Added by varioous OG 11 days ago. Updated 11 days ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2020-01-14
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
7.3
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

Hello,

i have the query:

$count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows("uid", "tx_vayoga_domain_model_login", "user_id = " . intval($PA['row']['uid']) . " and FROM_UNIXTIME(crdate) > (NOW() - INTERVAL 30 DAY) ");

Our first try was:

$count = $queryBuilder->count('uid')
        ->from('tx_vayoga_domain_model_login')
        ->where(
            $queryBuilder->expr()->eq('user_id', $queryBuilder->createNamedParameter(intval($this->data['databaseRow']['uid']), \PDO::PARAM_INT))
        )
        ->add('where', 'FROM_UNIXTIME(crdate) > (NOW() - INTERVAL 30 DAY)', true)
        ->execute()->fetchColumn(0);

But the append of the Querybuilder is not working, the whole where is always overwritten.

Then we changed it to:

  $count = $queryBuilder->count('uid')
            ->from('tx_vayoga_domain_model_login')
            ->add('where', 'FROM_UNIXTIME(crdate) > (NOW() - INTERVAL 3000 DAY)', true)
            ->andWhere(
                $queryBuilder->expr()->eq('user_id', $queryBuilder->createNamedParameter(intval($this->data['databaseRow']['uid']), \PDO::PARAM_INT))
            )
            ->execute()->fetchColumn(0);

The last statement is working correct. I guess there is a Bug somewhere in the add method.

Thanks and kind regards,
Harald

History

#1 Updated by Susanne Moog 11 days ago

  • Status changed from New to Rejected

The QueryBuilder in use is the doctrine query builder (see https://www.doctrine-project.org/projects/doctrine-dbal/en/2.9/reference/query-builder.html). At a quick look it seems to be a problem if there aren't multiple where statements (array) before add is called, as it simply overwrites the string in that case.

If you think this is a bug, please report it at the doctrine dbal bug tracker: https://github.com/doctrine/dbal/issues

Also available in: Atom PDF