Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-371

DBALException doesn't forward the SQL exception code

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      PDO exceptions carry the SQL error code. However DBALException doesn't forward any error code from the SQL exception.

      Here is a (really poor/quick) example of usage:

      try {
          $em->flush();
      } catch (DBALException $e) {
          if ($e->getCode() === 23000) {
              echo '';
          } else {
              throw $e;
          }
      }
      

      I think I found where the problem is:

      public static function driverExceptionDuringQuery(\Exception $driverEx, $sql, array $params = array())
      {
          $msg = "An exception occurred while executing '".$sql."'";
          if ($params) {
              $msg .= " with params ".json_encode($params);
          }
          $msg .= ":\n\n".$driverEx->getMessage();
      
          return new self($msg, 0, $driverEx);
      }
      

      In return new self($msg, 0, $driverEx);, the exception is created with an error code of 0.

      Is there a reason for this: is that that the driver exception may not always have a defined error code? (for example if the sql driver is not PDO or the SQL system doesn't support that, but in this case then the error code would be 0 would that be a problem?)

        Activity

        Matthieu Napoli created issue -
        Hide
        Matthieu Napoli added a comment -
        Show
        Matthieu Napoli added a comment - Pull request here: https://github.com/doctrine/dbal/pull/221
        Hide
        Doctrine Bot added a comment -

        A related Github Pull-Request [GH-221] was closed:
        https://github.com/doctrine/dbal/pull/221

        Show
        Doctrine Bot added a comment - A related Github Pull-Request [GH-221] was closed: https://github.com/doctrine/dbal/pull/221
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DBAL-371, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Matthieu Napoli
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: