[BUGFIX] Pass original DBALException along with SqlErrorException 88/59888/3
authorChristian Futterlieb <christian@futterlieb.ch>
Wed, 6 Mar 2019 17:53:01 +0000 (18:53 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Sat, 9 Mar 2019 15:27:01 +0000 (16:27 +0100)
When a
TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException
is thrown, pass the previous exception as 3rd parameter to the
constructor, to get the real reason for the exception.

Resolves: #87852
Releases: master, 9.5, 8.7
Change-Id: I20d711c0038b51a1d0c12d9a975d8c0da1f510f4
Reviewed-on: https://review.typo3.org/c/59888
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Christian Futterlieb <christian@futterlieb.ch>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php

index c06838a..c9e290e 100644 (file)
@@ -147,7 +147,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
 
             $connection->insert($tableName, $fieldValues, $types);
         } catch (DBALException $e) {
-            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230766);
+            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230766, $e);
         }
 
         $uid = 0;
@@ -193,7 +193,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
 
             $connection->update($tableName, $fieldValues, ['uid' => $uid], $types);
         } catch (DBALException $e) {
-            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230767);
+            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230767, $e);
         }
 
         if (!$isRelation) {
@@ -239,7 +239,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
         try {
             $this->connectionPool->getConnectionForTable($tableName)->update($tableName, $fieldValues, $where);
         } catch (DBALException $e) {
-            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230768);
+            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230768, $e);
         }
 
         // always returns true
@@ -260,7 +260,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
         try {
             $this->connectionPool->getConnectionForTable($tableName)->delete($tableName, $where);
         } catch (DBALException $e) {
-            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230769);
+            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230769, $e);
         }
 
         if (!$isRelation && isset($where['uid'])) {
@@ -299,7 +299,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
 
             $result = $queryBuilder->execute()->fetchColumn(0);
         } catch (DBALException $e) {
-            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230770);
+            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230770, $e);
         }
         return $result;
     }
@@ -329,7 +329,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
 
             $row = $queryBuilder->execute()->fetch();
         } catch (DBALException $e) {
-            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230771);
+            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470230771, $e);
         }
         return $row ?: false;
     }
@@ -371,7 +371,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
             try {
                 $rows = $queryBuilder->execute()->fetchAll();
             } catch (DBALException $e) {
-                throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074485);
+                throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074485, $e);
             }
         }
 
@@ -400,14 +400,14 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
             try {
                 $result = $realStatement->execute();
             } catch (DBALException $e) {
-                throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064721);
+                throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064721, $e);
             }
             $rows = $result->fetchAll();
         } elseif ($realStatement instanceof \Doctrine\DBAL\Statement) {
             try {
                 $realStatement->execute($parameters);
             } catch (DBALException $e) {
-                throw new SqlErrorException($e->getPrevious()->getMessage(), 1481281404);
+                throw new SqlErrorException($e->getPrevious()->getMessage(), 1481281404, $e);
             }
             $rows = $realStatement->fetchAll();
         } else {
@@ -418,7 +418,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
                 $connection = $this->connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
                 $statement = $connection->executeQuery($realStatement, $parameters);
             } catch (DBALException $e) {
-                throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064775);
+                throw new SqlErrorException($e->getPrevious()->getMessage(), 1472064775, $e);
             }
 
             $rows = $statement->fetchAll();
@@ -467,7 +467,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
             try {
                 $count = $queryBuilder->execute()->fetchColumn(0);
             } catch (DBALException $e) {
-                throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074379);
+                throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074379, $e);
             }
             if ($query->getOffset()) {
                 $count -= $query->getOffset();
@@ -523,7 +523,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
             }
             return false;
         } catch (DBALException $e) {
-            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470231748);
+            throw new SqlErrorException($e->getPrevious()->getMessage(), 1470231748, $e);
         }
     }