Task #72254

Throw sql exceptions with sql error number

Added by Carsten Bleicker almost 6 years ago. Updated almost 6 years ago.

Should have
Target version:
Start date:
Due date:
% Done:


Estimated time:
TYPO3 Version:
PHP Version:
Sprint Focus:



throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160);

throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160, $this->databaseHandle->sql_errno());

Passing the sql_errno() to exception is usefull f.e. for API Endpoints having unique constraints.
Currently its not possible to handline Duplicate Key db errors.
With sql_errno() you could do:

  // Create Record ...
}catch(SqlErrorException $e){

  if($e->getSqlErrorNumber() === 1062){
    throw new ThrowableException('Duplicate Entry ...', ....); 


Also errno never appears in log entries of catched exceptions.


Updated by Gerrit Code Review almost 6 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/45986


Updated by Morton Jonuschat almost 6 years ago

  • Status changed from Under Review to Rejected

While I understand your use case the proposed solution violates the interface definition of Exceptions where the third parameter generally is the previous exception. Deviating from this pattern in a single specific circumstance is something we should avoid in the core. Implementing something like this in your application is easy to accomplish as you can catch the SqlErrorException an parse the message of the exception that starts with the error number or you could extend the Typo3DbBackend class and adjust the thrown Exception there.

If you think that this is the wrong decision please write to the mailing list typo3.teams.bugs with issue number and an explanation or open a new ticket and add a relation to this ticket number.


Updated by Carsten Bleicker almost 6 years ago

You want me to extract the errnum from the message?
This means, that any sql error must have an equal structure of error message to parse the errno out of it.
Sure that this is proof? I think its not.

There is an error and TYPO3 strips useful informations.
So either we need to
1. build useful exceptions or
2. return the error without stripping informations

what currently happens is:
1. get error
2. stripping infos
3. building string
4. my app needs to recover 3. to get infos of 1.

wired, if you ask me


Updated by Carsten Bleicker almost 6 years ago

maybe like this:
throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($msq, $errNum);

Or SqlErrorException accepts a 4th param holding the sql error object.

Also available in: Atom PDF