Skip to content

Loading…

DDC-228: Throw an exception if statement execution was failed #2979

Closed
doctrinebot opened this Issue · 5 comments

1 participant

@doctrinebot

Jira issue originally created by user cloun:

Recently I have faced with strange behavior: I was adding records to a table, but some was not added. While these were adding, nothing happend. I have find out the source of the problem - I have unique constrain in my table (I forgot about it), and some records are duplicates.

But in order to find out that what was happening, I had to rummage in the bowels of the Doctrine. And I have found out why it happend: in the class Doctrine/ORM/Persisters/StandardEntityPersister, method public function executeInserts() execute $stmt->execute() and doesn't handle return value, and erorr info.

I suggest something like that:\
if (!$stmt->execute() && $catchDriverErrors)\
{\
list($sqlState, $errorCode, $erroMsg) = $stmt->errorInfo();\
throw new \Exception(sprintf("Something bad was happend in Database Layer: %s (%s) '%s'", $sqlState, $errorCode, $erroMsg));\
}\

@doctrinebot

Comment created by cloun:

added line break

@doctrinebot

Comment created by cloun:

little fix

@doctrinebot

Comment created by @beberlei:

Do you use your own PDO connection? If yes, you should call:

$pdo->setAttribute(PDO::ATTR*ERRMODE, PDO::ERRMODE*EXCEPTION);

before passing it to Doctrine.

@doctrinebot

Comment created by cloun:

Oh, it's very simple.. Thanks for suggestion!

@doctrinebot

Issue was closed with resolution "Won't Fix"

@doctrinebot doctrinebot added this to the 2.0-ALPHA4 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.