Issue Bug Rejected

#90107QueryBuilder Bug in add Clause with append

varioous OG 01/14/20, 12:14 updated 01/14/20, 22:39

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

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 1

  1. Susanne Moog commented and changed status New Rejected 01/14/20, 22:39

    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