Zwei Techniken zum debuggen von TYPO3 6.x DB queries:
1. Constraints "sammeln" und ausgeben:
Beim zusammenstellen der Query die Constraints folgendermassen festhalten:
$constraints[] = $query->logicalAnd($searchConstraints);
...
Und abschliessend ausgeben:
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($constraints);
2. SQL Query ausgeben:
/**
* Debugs a SQL query from a QueryResult
*
* @param \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $queryResult
* @param boolean $explainOutput
* @return void
*/
public function debugQuery(\TYPO3\CMS\Extbase\Persistence\Generic\QueryResult $queryResult, $explainOutput = FALSE) {
$GLOBALS['TYPO3_DB']->debugOuput = 2;
if ($explainOutput) {
$GLOBALS['TYPO3_DB']->explainOutput = true;
}
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = true;
$queryResult->toArray();
DebuggerUtility::var_dump($GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
$GLOBALS['TYPO3_DB']->store_lastBuiltQuery = false;
$GLOBALS['TYPO3_DB']->explainOutput = false;
$GLOBALS['TYPO3_DB']->debugOuput = false;
}
...und dann zur Ausgabe z.B.:
$events = $this->eventRepository->findDemanded($demand, $limit); $this->debugQuery($events);
Quelle:
http://blog.undkonsorten.com/sql-queries-debuggen-in-typo3
No comments:
Post a Comment