0

In Typo3 extbase, what's the most efficient way to update maybe 300 records, without calling 300 separate occasions of open-connection -> do update -> close connection?

The Basic CRUD page of the manual, Docs » API Overview » Database (doctrine-dbal) » Basic CRUD (https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/Database/BasicCrud/Index.html#update-multiple-rows) suggests that you should update multiple rows using

GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content')
    ->update(
        'tt_content',
        [ 'bodytext' => 'bernd' ], // set
        [ 'bodytext' => 'klaus' ] // where
    );

But this code implies updating only a single row. How do I do something like this below...?

GeneralUtility::makeInstance(ConnectionPool::class)
 ->getConnectionForTable('tt_content')
 ->update(
  'table_name',
  [ 'field' => 'newValue', 'uid'=>'1' ], // set field:value, where field:value
  [ 'field' => 'newValue', 'uid'=>'7' ], // set field:value, where field:value
  [ 'field' => 'newValue', 'uid'=>'5' ], // set field:value, where field:value
  [ 'field' => 'newValue', 'uid'=>'9' ], // set field:value, where field:value
etc.
  );

instead of

foreach($arrUpdate $key => $row) {
  ...get a new db connection and do a single update...
};

Many thanks in advance for any suggestions anyone has.

David Green
  • 103
  • 9
  • I guess most of the answers are already here https://stackoverflow.com/questions/27667013/doctrine-2-conditional-multiple-row-update-with-querybuilder – Wolfgang Oct 16 '19 at 19:52
  • Many thanks Wolfgang - it sounds like what I want can't be done. I'm avoiding using repositories because they're a nightmare. I simply cannot get along with ORM. I need a load of non-simple queries cross referencing each other and the whole flow of how updates are done in repositories was so confusing that I gave up. So I've built the whole project using connection and querybuilder in the models. It may be non-standard, but it works. An equivalent of ->bulkInsert that does ->bulkUpdate is the only thing I need that's missing. Time for me to build one maybe... :-) – David Green Oct 17 '19 at 09:36

0 Answers0