Extbase - get created sql from query
extbase, sql, typo3
Solution
Check this snippet, although it's not very comfortable in use it helps a lot:
in general you need this code at the end of the `buildQuery(array $sql)` method (*) - right before `return $statement;`
if (in_array("your_table_name", $sql['tables'])) {
var_dump($statement);
print_r($statement);
}
(*) Class file:
- TYPO3 ver.: 4.x: `typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php`
- TYPO3 ver.: 6.x: `typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php`
In 6.2.x ...
You can try within `\TYPO3\CMS\Core\Database\DatabaseConnection::exec_SELECTquery` method, just add the condition after fetching the $query, like (trim is important!):
public function exec_SELECTquery($select_fields, $from_table, $where_clause, $groupBy = '', $orderBy = '', $limit = '') {
$query = $this->SELECTquery($select_fields, $from_table, $where_clause, $groupBy, $orderBy, $limit);
if (trim($from_table) == 'fe_users') {
DebuggerUtility::var_dump($query);
}
// rest of method
Problem
i want to get some database tables from my typo3 extensions. The Extension is based on extbase. The query always returns nothing but the data exists I've tried this: ``` $query = $this->createQuery(); $query->statement('SELECT * FROM `my_table` WHERE field = ? ORDER BY date DESC LIMIT 1', array($condition)); $results = $query->execute(); ``` and this: ``` $query = $this->createQuery(); $query->matching($query->equals('field', $condition)); $query->setOrderings(array('date' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING)); $query->setLimit(1); $results = $query->execute(); ``` both returns null as result. Is it possible to get the sql that the class creates to look where the bug is? I've looked in some extbase persistent classes but didn't find a clue EDIT: For those who are interested.. i found a "solution". If you create the query with the statement() method, you can print the query with this function ``` echo $query->getStatement()->getStatement(); ``` It doesn't replace the placeholder. But you can get the Variables with this method ``` var_dump($query->getStatement()->getBoundVariables()); ``` Thats the best Solution that i found, without editing the extbase extenstions