Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

typo3 - Extbase - get created sql from query

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In TYPO3 6.2 you can use Extbase DebuggerUtility to debug the query.

Add this code before $query->execute():

/** @var Typo3DbQueryParser $queryParser */
$queryParser = TYPO3CMSCoreUtilityGeneralUtility::makeInstance('TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser');
TYPO3CMSExtbaseUtilityDebuggerUtility::var_dump($queryParser->parseQuery($query));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...