Project

General

Profile

Actions

Bug #67375

closed

Typo3DbBackend in current extbase 7.2.0 doesnt replace the placeholder "?" with boundVariables in extbase 6.2 before

Added by Anonymous almost 9 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2015-06-09
Due date:
% Done:

0%

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

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


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #81272: Parameters in real raw extbase queries do not get replacedClosedDaniel Goerz2017-05-19

Actions
Actions

Also available in: Atom PDF