Bug #67375
closedTypo3DbBackend in current extbase 7.2.0 doesnt replace the placeholder "?" with boundVariables in extbase 6.2 before
0%
Description
It seems because removing deprecation "replacePlaceholders" since 6.2 in this classes the placeholder doesnt replace the boundVariables:
\typo3_src-7.2.0\typo3\sysext\extbase\Classes\Persistence\Generic\Storage\Typo3DbBackend.php
\typo3_src-7.2.0\typo3\sysext\extbase\Classes\Persistence\Generic\Qom\Statement.php
In Statement.php the constructor wants a type of \TYPO3\CMS\Core\Database\PreparedStatement but type of TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement from repository is given, see in screen.
So there a 2 ways to workaround this fault:
1. Outsource, fork and modify from Typo3DbBackend.php
the "replacePlaceholders" method in a helper class or a private function in your repository like this:
private function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo')
{
if (substr_count($sqlString, '?') !== count($parameters)) {
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074);
}
$offset = 0;
foreach ($parameters as $parameter) {
$markPosition = strpos($sqlString, '?', $offset);
if ($markPosition !== FALSE) {
if ($parameter === NULL) {
$parameter = 'NULL';
} elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) {
$items = array();
foreach ($parameter as $item) {
$items[] = $GLOBALS['TYPO3_DB']->fullQuoteStr($item, $tableName);
}
$parameter = '('.implode(',', $items).')';
} else {
$parameter = $GLOBALS['TYPO3_DB']->fullQuoteStr($parameter, $tableName);
}
$sqlString = substr($sqlString, 0, $markPosition).$parameter.substr($sqlString, ($markPosition + 1));
}
$offset = $markPosition + strlen($parameter);
}
}
Use it to replace der boundVariables and use
$this->replacePlaceholders($sql, $constraints, 'tx_myext_domain_model_mymodel');
$query->statement($sql,[]);
with replaced statement in repository.
2. Use Oldshool $GLOBALS['TYPO3_DB']->sql_query
Files