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
Updated by Benni Mack over 9 years ago
- Target version changed from 7.2 (Frontend) to 7.4 (Backend)
Updated by Anonymous over 9 years ago
Why change target to 7.4? This is a central important funktion, that many extensions will break.
Updated by Susanne Moog over 9 years ago
- Target version changed from 7.4 (Backend) to 7.5
Updated by Mathias Brodala about 9 years ago
How about directly using PreparedStatement
here instead?
Updated by Anonymous over 7 years ago
Since 2 years i waiting for some one will fix this bug. So time is comming to take it in the 8 LTS release :-)
@Benni Mack: Do see any possibility?
Updated by Daniel Goerz over 7 years ago
- Related to Bug #81272: Parameters in real raw extbase queries do not get replaced added
Updated by Benni Mack over 5 years ago
- Status changed from New to Needs Feedback
Hey,
we've reworked this part now with proper DBAL and native prepared statements. So this issue is finally solved with TYPO3 v8, right?
Updated by Riccardo De Contardi over 5 years ago
- Status changed from Needs Feedback to Closed
No feedback since the last 90 days => closing this issue. Moreover, version 7.6 has reached its end of life on December 2018 and now support is only available via ELTS (see https://typo3.com/products/extended-support)
If you think that this is the wrong decision or experience the issue again on recent TYPO3 versions like 8.7.x or 9.5.x and have more information about how to reproduce your problem, please reopen it or open a new issue with a reference to this one.
Thank you and best regards