Task #72254

Throw sql exceptions with sql error number

Added by Carsten Bleicker almost 4 years ago. Updated over 3 years ago.

Status:
Rejected
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2015-12-15
Due date:
% Done:

0%

TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Sprint Focus:

Description

typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php:862

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

Better:
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:

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

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

}

Also errno never appears in log entries of catched exceptions.

History

#1 Updated by Gerrit Code Review over 3 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

#2 Updated by Morton Jonuschat over 3 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.

#3 Updated by Carsten Bleicker over 3 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

#4 Updated by Carsten Bleicker over 3 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