Project

General

Profile

Actions

Bug #72089

closed

logicalNot constraint in repository using DBAL throws error in sql parser if it is the first constraint in a queries only logicalAnd

Added by Michael Dittberner over 8 years ago. Updated almost 8 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2015-12-07
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Hi,

when I add some logicalAnd constraints and the first of them is a logicalNot constraint, an exception is thrown with the message
"Catchable fatal error: Argument 1 passed to TYPO3\CMS\Dbal\Database\DatabaseConnection::_quoteWhereClause() must be of the type array, string given, called in XXX\typo3_src\typo3_src-6.2.15\typo3\sysext\dbal\Classes\Database\DatabaseConnection.php on line 1276 and defined in XXX\typo3_src\typo3_src-6.2.15\typo3\sysext\dbal\Classes\Database\DatabaseConnection.php on line 1736".

My repository contains these constraints:
[...]
$andConstraints = array();
$andConstraints[] = $query->logicalNot($query->equals('type', 3)); // Keine internen Termine.
$andConstraints[] = $query->greaterThanOrEqual('date', $currentTimeObj->format('Y-m-d'));
$andConstraints[] = $query->equals('seriesId', (int)$event->getSeriesId());

$query->matching($query->logicalAnd($andConstraints));
$events = $query->execute();
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($events);

The Error occures in typo3\sysext\core\Classes\Database\SqlParser.php, function parseWhereClause() while trying to get the $fieldName in line 1086 and throws the message "SQL engine parse ERROR: No field name found as expected in parseWhereClause(): near "(tx_villaevents_domain_model_event.type = '3') AND"". This message string is then the reason for the thrown error described above where an array is expected.

The full generated SQL where clause is "((NOT (tx_villaevents_domain_model_event.type = '3') AND tx_villaevents_domain_model_event.date >= '2015-12-07') AND tx_villaevents_domain_model_event.series_id = '18742')"

Now the trick:
If I change the ordering of my constraints in my query that the logicalNot is NOT the first, all is fine!

I suggest to fix the bug that a logicalNot can be used as first constraint too.

Environment:
- TYPO3 6.2.15
- dbal 6.2.0 used
- adodb 6.2.0 used
- access to external tables via dbal configured for connection of type "adodb" with driver "mysqli"
- TYPO3 DB is connected as type "native" with default config of LocalConfiguration.

Best regards,
Michael

Actions

Also available in: Atom PDF