Reputation: 111
I need to clear (TRUNCATE) a database table through the repository of my TYPO3 extension. I already have various working SELECT queries. They look like this:
public function getUsergroups() {
$query = $this->createQuery();
$query->getQuerySettings()->setReturnRawQueryResult(TRUE);
$query->statement('SELECT * FROM fe_groups WHERE hidden=0 AND deleted=0');
$result = $query->execute();
return $result;
}
This works.
Then there is the function for clearing the database table, it looks like this:
public function updateProductPermissions($submitArray) {
$query = $this->createQuery();
$query->getQuerySettings()->setReturnRawQueryResult(TRUE);
$query->statement('TRUNCATE TABLE tx_chiliproducts_domain_model_permission')->execute();
return true;
}
When this function gets executed, I get the following error:
Fatal error: Call to a member function fetch_assoc() on a non-object in /srv/globalroot/typo3_src-6.1.1/typo3/sysext/core/Classes/Database/DatabaseConnection.php on line 1029
What's the difference between executing a SELECT and executing a TRUNCATE statement? Why does one work and the other does not?
Upvotes: 3
Views: 3335
Reputation: 4578
I am not sure if you can truncate through the extbase persistence layer. If you want to make your life easy, just use the normal TYPO3 CMS database class:
$GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('table');
Keep in mind that extbase might not know about this truncate and that it might still have some objects in the cache.
The API way would be to call $repository->removeAll()
.
Upvotes: 6