Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-228

Throw an exception if statement execution was failed

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: 2.0-ALPHA4
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      MySQL

      Description

      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));
      }

        Activity

        Hide
        Valery Dubrava added a comment -

        added line break

        Show
        Valery Dubrava added a comment - added line break
        Hide
        Valery Dubrava added a comment -

        little fix

        Show
        Valery Dubrava added a comment - little fix
        Hide
        Benjamin Eberlei added a comment -

        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.

        Show
        Benjamin Eberlei added a comment - 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.
        Hide
        Valery Dubrava added a comment -

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

        Show
        Valery Dubrava added a comment - Oh, it's very simple.. Thanks for suggestion!

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Valery Dubrava
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: