I have to migrate some code from the TYPO3 DB wrapper to Doctrine with the QueryBuilder. In my database are four entries.
The original statement:
$statementToMigrate = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
'job_id,uid,pid,hash',
'tx_test',
'deleted = 0',
null,
null,
null,
'job_id'
);
And my QueryBuilder version:
$table = 'tx_test';
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($table);
$sql = $queryBuilder
->select(
"job_id,uid,pid,hash"
)
->from($table)
->where(
$queryBuilder->expr()->eq('deleted', 0)
)
->execute()
->fetchAll();
The original statement provides me all four entries. The new version only two. Where are the differences? And how can I set " $uidIndexField= ''" in doctrine?
Solution: I added
$queryBuilder
->getRestrictions()
->removeByType(StartTimeRestriction::class)
->removeByType(EndTimeRestriction::class);
and now it works
hi the Querybuilder takes into account the common "restrictions" like start/end date, language, hidden/ deleted. i guess you records are filtered out by some other restrictions.
see here for more about restrictions: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/RestrictionBuilder/Index.html#database-restriction-builder
And how can I set " $uidIndexField= ''" in doctrine?
Doctrine doesn't have such functionality by itself, afaik. Earlier in old Typo3 in the exec_SELECTgetRows method the array was simply traversed to set that index before return. Now it seems you have to do the same on your own. I searched for quite a long time to find good, fast and hopefully native way to achieve that effect with no luck, but finally I stumbled upon that snip:
...
// return $preparedStatement->fetchAll(\PDO::FETCH_ASSOC);
$result = $preparedStatement->fetchAll(\PDO::FETCH_ASSOC);
return array_column($result, null, $uidIndexField);
and finally it looks like that does the trick.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.