Breaking: #102875 - Changed Connection method signatures and behaviour

See forge#102875

Description

Signature and behaviour of following methods has been changed:

  • lastInsertId() no longer accepts the sequence and field name.
  • quote() no longer has a type argument and the value must be a string.

Public Connection::PARAM_* class constants has been replaced with the Doctrine DBAL 4 ParameterType and ArrayParameterType enum definitions.

Impact

Calling quote() with a non-string as first argument will result in a PHP error. Still providing the second argument will not emit an error, but may be detected by static code analysers.

Calling lastInsertId() not directly after the record insert or inserting records in another table in between will return the incorrect value.

Affected installations

Only installations calling quote() with a non-string as first argument or not using lastInsertId() directly after the record insert.

Migration

lastInsertId()

Returns the last inserted ID (auto-created) on the connection.

BEFORE

use TYPO3\CMS\Core\Database\Connection as Typo3Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/** @var Typo3Connection $connection */
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
    ->getConnectionForTable('tx_myextension_mytable');

$connection->insert(
    'tx_myextension_mytable',
    [
        'pid' => $pid,
        'some_string' => $someString,
    ],
    [
        Typo3Connection::PARAM_INT,
        Typo3Connection::PARAM_STR,
    ]
);
$uid = $connection->lastInsertId('tx_myextension_mytable');
Copied!

AFTER

use TYPO3\CMS\Core\Database\Connection as Typo3Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/** @var Typo3Connection $connection */
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
    ->getConnectionForTable('tx_myextension_mytable');

$connection->insert(
    'tx_myextension_mytable',
    [
        'pid' => $pid,
        'some_string' => $someString,
    ],
    [
        Typo3Connection::PARAM_INT,
        Typo3Connection::PARAM_STR,
    ]
);
$uid = $connection->lastInsertId();
Copied!